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 | |
---|
22 | MO_Liste::MO_Liste() { |
---|
23 | mp_assert(gb_main); |
---|
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 | |
---|
32 | MO_Liste::~MO_Liste() { |
---|
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 | |
---|
42 | void MO_Liste::get_all_species() { |
---|
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 | } |
---|
70 | if (MP_init_local_com_struct()) { |
---|
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; |
---|
86 | aisc_get(mp_pd_gl.link, PT_LOCS, mp_pd_gl.locs, |
---|
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); |
---|
115 | GB_push_transaction(gb_main); |
---|
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 | } |
---|
126 | GB_pop_transaction(gb_main); |
---|
127 | } |
---|
128 | else |
---|
129 | aw_message("DB-query produced no species.\n"); |
---|
130 | |
---|
131 | |
---|
132 | aisc_close(mp_pd_gl.link, mp_pd_gl.com); |
---|
133 | free(bs.data); |
---|
134 | |
---|
135 | delete match_name; |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | positiontype MO_Liste::fill_marked_bakts() { |
---|
141 | long j = 0; |
---|
142 | GBDATA *gb_species; |
---|
143 | |
---|
144 | |
---|
145 | GB_push_transaction(gb_main); |
---|
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 | { |
---|
168 | put_entry(GBT_read_name(gb_species)); |
---|
169 | } |
---|
170 | |
---|
171 | GB_pop_transaction(gb_main); |
---|
172 | |
---|
173 | anz_elem_marked = laenge; |
---|
174 | |
---|
175 | return laenge; |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | |
---|
180 | long MO_Liste::get_laenge() { |
---|
181 | return laenge; |
---|
182 | } |
---|
183 | |
---|
184 | long MO_Liste::debug_get_current() { |
---|
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 | |
---|
212 | Bakt_Info* MO_Liste::get_bakt_info_by_index(long index) { |
---|
213 | return (0<index) && (index < current) ? mo_liste[index] : NULp; |
---|
214 | } |
---|
215 | |
---|