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