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 = NULL; |
---|
21 | |
---|
22 | MO_Liste::MO_Liste() { |
---|
23 | mp_assert(gb_main); |
---|
24 | |
---|
25 | laenge = 0; |
---|
26 | mo_liste = NULL; |
---|
27 | current = 0; |
---|
28 | hashptr = NULL; |
---|
29 | // Nach dem new muss die MO_Liste erst mit fill_all_bakts bzw fill_marked_bakts gefuellt werden |
---|
30 | } |
---|
31 | |
---|
32 | MO_Liste::~MO_Liste() |
---|
33 | { |
---|
34 | while (laenge) |
---|
35 | { |
---|
36 | delete mo_liste[laenge-1]; |
---|
37 | laenge--; |
---|
38 | } |
---|
39 | delete [] mo_liste; |
---|
40 | if (hashptr) GBS_free_hash(hashptr); |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | void MO_Liste::get_all_species() { |
---|
45 | const char *servername = NULL; |
---|
46 | char *match_name = NULL; |
---|
47 | char toksep[2]; |
---|
48 | char *probe = NULL; |
---|
49 | char *locs_error = 0; |
---|
50 | bytestring bs; |
---|
51 | int i = 0; |
---|
52 | long j = 0, nr_of_species; |
---|
53 | |
---|
54 | if (!(servername=MP_probe_pt_look_for_server())) { |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | GB_ERROR openerr = NULL; |
---|
59 | mp_pd_gl.link = aisc_open(servername, mp_pd_gl.com, AISC_MAGIC_NUMBER, &openerr); |
---|
60 | mp_pd_gl.locs.clear(); |
---|
61 | servername = 0; |
---|
62 | |
---|
63 | if (openerr) { |
---|
64 | aw_message(openerr); |
---|
65 | return; |
---|
66 | } |
---|
67 | |
---|
68 | if (!mp_pd_gl.link) { |
---|
69 | aw_message ("Cannot contact Probe bank server "); |
---|
70 | return; |
---|
71 | } |
---|
72 | if (MP_init_local_com_struct()) { |
---|
73 | aw_message ("Cannot contact Probe bank server (2)"); |
---|
74 | // @@@ missing aisc_close |
---|
75 | return; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | if (aisc_put(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, NULL)) |
---|
80 | { |
---|
81 | free(probe); |
---|
82 | aw_message ("Connection to PT_SERVER lost (4)"); |
---|
83 | // @@@ missing aisc_close |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | bs.data = 0; |
---|
89 | aisc_get(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, |
---|
90 | LOCS_MP_ALL_SPECIES_STRING, &bs, |
---|
91 | LOCS_MP_COUNT_ALL_SPECIES, &nr_of_species, |
---|
92 | LOCS_ERROR, &locs_error, |
---|
93 | NULL); |
---|
94 | |
---|
95 | if (*locs_error) |
---|
96 | { |
---|
97 | aw_message(locs_error); |
---|
98 | } |
---|
99 | |
---|
100 | free(locs_error); |
---|
101 | |
---|
102 | laenge = nr_of_species; |
---|
103 | mo_liste = new Bakt_Info*[laenge+2]; |
---|
104 | while (j<laenge+2) |
---|
105 | { |
---|
106 | mo_liste[j] = NULL; |
---|
107 | j++; |
---|
108 | } |
---|
109 | current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULL |
---|
110 | |
---|
111 | // Initialisieren der Hashtabelle |
---|
112 | |
---|
113 | hashptr = GBS_create_hash(laenge + 1, GB_IGNORE_CASE); |
---|
114 | |
---|
115 | |
---|
116 | toksep[0] = 1; |
---|
117 | toksep[1] = 0; |
---|
118 | if (bs.data) |
---|
119 | { |
---|
120 | |
---|
121 | match_name = strtok(bs.data, toksep); |
---|
122 | GB_push_transaction(gb_main); |
---|
123 | while (match_name) |
---|
124 | { |
---|
125 | i++; |
---|
126 | if (!GBT_find_species(gb_main, match_name)) |
---|
127 | { // Testen, ob Bakterium auch im Baum existiert, um |
---|
128 | pt_server_different = true; |
---|
129 | // @@@ missing aisc_close |
---|
130 | return; |
---|
131 | } |
---|
132 | put_entry(match_name); |
---|
133 | match_name = strtok(0, toksep); |
---|
134 | } |
---|
135 | GB_pop_transaction(gb_main); |
---|
136 | } |
---|
137 | else |
---|
138 | aw_message("DB-query produced no species.\n"); |
---|
139 | |
---|
140 | |
---|
141 | aisc_close(mp_pd_gl.link, mp_pd_gl.com); |
---|
142 | free(bs.data); |
---|
143 | |
---|
144 | delete match_name; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | positiontype MO_Liste::fill_marked_bakts() |
---|
150 | { |
---|
151 | long j = 0; |
---|
152 | GBDATA *gb_species; |
---|
153 | |
---|
154 | |
---|
155 | GB_push_transaction(gb_main); |
---|
156 | laenge = GBT_count_marked_species(gb_main); // laenge ist immer zuviel oder gleich der Anzahl wirklick markierter. weil pT-Server nur |
---|
157 | // die Bakterien mit Sequenz zurueckliefert. |
---|
158 | |
---|
159 | if (!laenge) { |
---|
160 | aw_message("Please mark some species!"); |
---|
161 | laenge = 1; |
---|
162 | } |
---|
163 | mo_liste = new Bakt_Info*[laenge+2]; |
---|
164 | |
---|
165 | while (j<laenge+2) |
---|
166 | { |
---|
167 | mo_liste[j] = NULL; |
---|
168 | j++; |
---|
169 | } |
---|
170 | current = 1; // ACHTUNG, CURRENT beginnt bei 1, da Hash bei 1 beginnt, d.h. Array[0] ist NULL |
---|
171 | |
---|
172 | hashptr = GBS_create_hash(laenge, GB_IGNORE_CASE); |
---|
173 | |
---|
174 | |
---|
175 | for (gb_species = GBT_first_marked_species(gb_main); |
---|
176 | gb_species; |
---|
177 | gb_species = GBT_next_marked_species(gb_species)) |
---|
178 | { |
---|
179 | put_entry(GBT_read_name(gb_species)); |
---|
180 | } |
---|
181 | |
---|
182 | GB_pop_transaction(gb_main); |
---|
183 | |
---|
184 | anz_elem_marked = laenge; |
---|
185 | |
---|
186 | return laenge; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | long MO_Liste::get_laenge() |
---|
192 | { |
---|
193 | return laenge; |
---|
194 | } |
---|
195 | |
---|
196 | long MO_Liste::debug_get_current() |
---|
197 | { |
---|
198 | return current; |
---|
199 | } |
---|
200 | |
---|
201 | long MO_Liste::put_entry(const char* name) { |
---|
202 | // Pruefe: Gibts den Bakter schon in dieser Liste?? |
---|
203 | if (get_index_by_entry(name)) // wanns den Bakter scho gibt |
---|
204 | { |
---|
205 | // nicht eintragen |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | mo_liste[current] = new Bakt_Info(name); // MEL koennte mit match_name zusammenhaengen |
---|
210 | GBS_write_hash(hashptr, name, current); |
---|
211 | current++; |
---|
212 | } |
---|
213 | return current; |
---|
214 | } |
---|
215 | |
---|
216 | char* MO_Liste::get_entry_by_index(long index) |
---|
217 | { |
---|
218 | if ((0<index) && (index < current)) |
---|
219 | return mo_liste[index]->get_name(); |
---|
220 | else |
---|
221 | return NULL; |
---|
222 | } |
---|
223 | |
---|
224 | long MO_Liste::get_index_by_entry(const char* key) |
---|
225 | { |
---|
226 | if (key) |
---|
227 | return (GBS_read_hash(hashptr, key)); |
---|
228 | else |
---|
229 | return 0; |
---|
230 | } |
---|
231 | |
---|
232 | Bakt_Info* MO_Liste::get_bakt_info_by_index(long index) |
---|
233 | { |
---|
234 | if ((0<index) && (index < current)) |
---|
235 | return mo_liste[index]; |
---|
236 | else |
---|
237 | return NULL; |
---|
238 | } |
---|
239 | |
---|