ARB
MP_mo_liste.cxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : MP_mo_liste.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #include "MP_externs.hxx"
12 #include "MultiProbe.hxx"
13 
14 #include <aw_msg.hxx>
15 #include <arbdbt.h>
16 #include <client.h>
17 
18 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Methoden MO_Liste
19 
20 GBDATA *MO_Liste::gb_main = NULp;
21 
24 
25  laenge = 0;
26  mo_liste = NULp;
27  current = 0;
28  hashptr = NULp;
29  // Nach dem new muss die MO_Liste erst mit fill_all_bakts bzw fill_marked_bakts gefuellt werden
30 }
31 
33  while (laenge) {
34  delete mo_liste[laenge-1];
35  laenge--;
36  }
37  delete [] mo_liste;
38  if (hashptr) GBS_free_hash(hashptr);
39 }
40 
41 
43  const char *servername = NULp;
44  char *match_name = NULp;
45  char toksep[2];
46  char *probe = NULp;
47  char *locs_error = NULp;
48  bytestring bs;
49  int i = 0;
50  long j = 0, nr_of_species;
51 
52  if (!(servername=MP_probe_pt_look_for_server())) {
53  return;
54  }
55 
56  GB_ERROR openerr = NULp;
57  mp_pd_gl.link = aisc_open(servername, mp_pd_gl.com, AISC_MAGIC_NUMBER, &openerr);
58  mp_pd_gl.locs.clear();
59  servername = NULp;
60 
61  if (openerr) {
62  aw_message(openerr);
63  return;
64  }
65 
66  if (!mp_pd_gl.link) {
67  aw_message ("Cannot contact Probe bank server ");
68  return;
69  }
71  aw_message ("Cannot contact Probe bank server (2)");
72  // @@@ missing aisc_close
73  return;
74  }
75 
76 
77  if (aisc_put(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, NULp)) {
78  free(probe);
79  aw_message ("Connection to PT_SERVER lost (4)");
80  // @@@ missing aisc_close
81  return;
82  }
83 
84 
85  bs.data = NULp;
87  LOCS_MP_ALL_SPECIES_STRING, &bs,
88  LOCS_MP_COUNT_ALL_SPECIES, &nr_of_species,
89  LOCS_ERROR, &locs_error,
90  NULp);
91 
92  if (*locs_error) {
93  aw_message(locs_error);
94  }
95 
96  free(locs_error);
97 
98  laenge = nr_of_species;
99  mo_liste = new Bakt_Info*[laenge+2];
100  while (j<laenge+2) {
101  mo_liste[j] = NULp;
102  j++;
103  }
104  current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULp
105 
106  // Initialisieren der Hashtabelle
107 
108  hashptr = GBS_create_hash(laenge + 1, GB_IGNORE_CASE);
109 
110 
111  toksep[0] = 1;
112  toksep[1] = 0;
113  if (bs.data) {
114  match_name = strtok(bs.data, toksep);
116  while (match_name) {
117  i++;
118  if (!GBT_find_species(gb_main, match_name)) {
119  pt_server_different = true;
120  // @@@ missing aisc_close
121  return;
122  }
123  put_entry(match_name);
124  match_name = strtok(NULp, toksep);
125  }
127  }
128  else
129  aw_message("DB-query produced no species.\n");
130 
131 
133  free(bs.data);
134 
135  delete match_name;
136 }
137 
138 
139 
141  long j = 0;
142  GBDATA *gb_species;
143 
144 
146  laenge = GBT_count_marked_species(gb_main); // laenge ist immer zuviel oder gleich der Anzahl wirklick markierter. weil pT-Server nur
147  // die Bakterien mit Sequenz zurueckliefert.
148 
149  if (!laenge) {
150  aw_message("Please mark some species!");
151  laenge = 1;
152  }
153  mo_liste = new Bakt_Info*[laenge+2];
154 
155  while (j<laenge+2) {
156  mo_liste[j] = NULp;
157  j++;
158  }
159  current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULp
160 
161  hashptr = GBS_create_hash(laenge, GB_IGNORE_CASE);
162 
163 
164  for (gb_species = GBT_first_marked_species(gb_main);
165  gb_species;
166  gb_species = GBT_next_marked_species(gb_species))
167  {
169  }
170 
172 
173  anz_elem_marked = laenge;
174 
175  return laenge;
176 }
177 
178 
179 
181  return laenge;
182 }
183 
185  return current;
186 }
187 
188 long MO_Liste::put_entry(const char* name) {
189  // Pruefe: Gibts den Bakter schon in dieser Liste??
190  if (get_index_by_entry(name)) {
191  // wanns den Bakter scho gibt nicht eintragen
192  }
193  else {
194  mo_liste[current] = new Bakt_Info(name); // MEL koennte mit match_name zusammenhaengen
195  GBS_write_hash(hashptr, name, current);
196  current++;
197  }
198  return current;
199 }
200 
201 char* MO_Liste::get_entry_by_index(long index) {
202  if ((0<index) && (index < current))
203  return mo_liste[index]->get_name();
204  else
205  return NULp;
206 }
207 
208 long MO_Liste::get_index_by_entry(const char* key) {
209  return key ? GBS_read_hash(hashptr, key) : 0;
210 }
211 
213  return (0<index) && (index < current) ? mo_liste[index] : NULp;
214 }
215 
bool pt_server_different
Definition: MP_main.cxx:29
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:113
T_PT_LOCS locs
Definition: mpdefs.h:51
long debug_get_current()
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:457
Bakt_Info * get_bakt_info_by_index(long index)
const char * MP_probe_pt_look_for_server()
Definition: MP_noclass.cxx:777
char * get_name()
Definition: MultiProbe.hxx:186
int aisc_close(aisc_com *link, AISC_Object &object)
Definition: client.c:249
long get_laenge()
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:541
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2458
int MP_init_local_com_struct()
Definition: MP_noclass.cxx:765
positiontype fill_marked_bakts()
int aisc_put(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:539
char * data
Definition: bytestring.h:16
long get_index_by_entry(const char *key)
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
Definition: aditem.cxx:116
unsigned long positiontype
Definition: SoTl.hxx:42
char * get_entry_by_index(long index)
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2488
long GBT_count_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:349
struct mp_gl_struct mp_pd_gl
Definition: MP_Window.cxx:32
#define AISC_MAGIC_NUMBER
Definition: client_privat.h:51
aisc_com * aisc_open(const char *path, AISC_Object &main_obj, long magic, GB_ERROR *error)
Definition: client.c:205
void aw_message(const char *msg)
Definition: AW_status.cxx:932
long put_entry(const char *name)
#define NULp
Definition: cxxforward.h:97
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:136
aisc_com * link
Definition: mpdefs.h:50
int aisc_get(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:266
#define mp_assert(cond)
Definition: mkptypes.cxx:32
GBDATA * gb_main
Definition: adname.cxx:33
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:437
T_PT_MAIN com
Definition: mpdefs.h:52
int anz_elem_marked
Definition: MP_main.cxx:27
void get_all_species()
Definition: MP_mo_liste.cxx:42
long GBS_read_hash(const GB_HASH *hs, const char *key)
Definition: adhash.cxx:395
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253