#include <nmlqr.hh>
Collaboration diagram for NML_QR_SERVER:
Public Methods | |
NML_QR_SERVER (NML_FORMAT_PTR f_ptr, char *qr_name, char *process_name, char *config_file) | |
~NML_QR_SERVER () | |
NMLTYPE | readQuery () |
NMLTYPE | waitForQuery (double timeout) |
NMLmsg * | getQueryAddress () |
int | replyToLastQuery (NMLmsg *message_to_send) |
int | valid () |
int | reset () |
Protected Attributes | |
NML * | replyChannel |
NML_QUERY_CHANNEL * | queryChannel |
NML_ID_CHANNEL * | idChannel |
int | reply_subdiv |
char * | subdiv_allocation_table |
|
Definition at line 113 of file nmlqr.cc. 00116 { 00117 00118 queryChannel = NULL; 00119 replyChannel = NULL; 00120 idChannel = NULL; 00121 reply_subdiv = -1; 00122 subdiv_allocation_table = NULL; 00123 00124 char repbufname[40]; 00125 sprintf (repbufname, "%sReply", qr_name); 00126 char querybufname[40]; 00127 sprintf (querybufname, "%sQuery", qr_name); 00128 char idbufname[40]; 00129 sprintf (idbufname, "%sID", qr_name); 00130 idChannel = 00131 new NML_ID_CHANNEL (f_ptr, idbufname, process_name, config_file); 00132 queryChannel = 00133 new NML_QUERY_CHANNEL (f_ptr, querybufname, process_name, config_file); 00134 replyChannel = new NML (f_ptr, repbufname, process_name, config_file); 00135 00136 if (replyChannel->get_total_subdivisions () > 1) 00137 { 00138 subdiv_allocation_table = 00139 (char *) DEBUG_MALLOC (replyChannel->get_total_subdivisions ()); 00140 } 00141 memset (subdiv_allocation_table, 0, 00142 replyChannel->get_total_subdivisions ()); 00143 } |
|
Definition at line 146 of file nmlqr.cc. 00147 { 00148 if (NULL != queryChannel) 00149 { 00150 delete queryChannel; 00151 queryChannel = NULL; 00152 } 00153 if (NULL != idChannel) 00154 { 00155 delete idChannel; 00156 idChannel = NULL; 00157 } 00158 if (NULL != replyChannel) 00159 { 00160 delete replyChannel; 00161 replyChannel = NULL; 00162 } 00163 if (NULL != subdiv_allocation_table) 00164 { 00165 DEBUG_FREE (subdiv_allocation_table); 00166 subdiv_allocation_table = NULL; 00167 } 00168 } |
|
Definition at line 171 of file nmlqr.cc. 00172 { 00173 while (1) 00174 { 00175 NMLTYPE query_read_type; 00176 switch (query_read_type = queryChannel->read ()) 00177 { 00178 case ID_REQUEST_TYPE: 00179 { 00180 int subdiv_found = 0; 00181 for (int i = 0; i < replyChannel->get_total_subdivisions (); i++) 00182 { 00183 if (subdiv_allocation_table[i] == 0) 00184 { 00185 subdiv_allocation_table[i] = 1; 00186 ID_REPLY idMsg; 00187 idMsg.subdiv = i; 00188 idChannel->write (idMsg); 00189 subdiv_found = 1; 00190 break; 00191 } 00192 } 00193 if (!subdiv_found) 00194 { 00195 // Send the message we are full. 00196 ID_REPLY idMsg; 00197 idMsg.subdiv = -1; 00198 idChannel->write (idMsg); 00199 } 00200 } 00201 break; 00202 00203 case ID_REPLY_TYPE: 00204 return -1; // Very weird a reply message in the query buffer. 00205 break; 00206 00207 case ID_DELETE_TYPE: 00208 { 00209 ID_DELETE *idDeleteMsg = 00210 (ID_DELETE *) queryChannel->get_address (); 00211 if (idDeleteMsg->subdiv >= 0 00212 && idDeleteMsg->subdiv < 00213 replyChannel->get_total_subdivisions ()) 00214 { 00215 subdiv_allocation_table[idDeleteMsg->subdiv] = 0; 00216 } 00217 } 00218 break; 00219 00220 default: 00221 NML_QUERY_MSG * qMsg = 00222 (NML_QUERY_MSG *) queryChannel->get_address (); 00223 reply_subdiv = qMsg->subdiv_for_reply; 00224 return query_read_type; 00225 } 00226 } 00227 } |
|
Definition at line 230 of file nmlqr.cc. 00231 { 00232 while (1) 00233 { 00234 NMLTYPE query_read_type; 00235 switch (query_read_type = queryChannel->blocking_read (timeout)) 00236 { 00237 case ID_REQUEST_TYPE: 00238 { 00239 int subdiv_found = 0; 00240 for (int i = 0; i < replyChannel->get_total_subdivisions (); i++) 00241 { 00242 if (subdiv_allocation_table[i] == 0) 00243 { 00244 subdiv_allocation_table[i] = 1; 00245 ID_REPLY idMsg; 00246 idMsg.subdiv = i; 00247 idChannel->write (idMsg); 00248 subdiv_found = 1; 00249 break; 00250 } 00251 } 00252 if (!subdiv_found) 00253 { 00254 // Send the message we are full. 00255 ID_REPLY idMsg; 00256 idMsg.subdiv = -1; 00257 idChannel->write (idMsg); 00258 } 00259 } 00260 break; 00261 00262 case ID_REPLY_TYPE: 00263 return -1; // Very weird a reply message in the query buffer. 00264 break; 00265 00266 case ID_DELETE_TYPE: 00267 { 00268 ID_DELETE *idDeleteMsg = 00269 (ID_DELETE *) queryChannel->get_address (); 00270 if (idDeleteMsg->subdiv >= 0 00271 && idDeleteMsg->subdiv < 00272 replyChannel->get_total_subdivisions ()) 00273 { 00274 subdiv_allocation_table[idDeleteMsg->subdiv] = 0; 00275 } 00276 } 00277 break; 00278 00279 default: 00280 NML_QUERY_MSG * qMsg = 00281 (NML_QUERY_MSG *) queryChannel->get_address (); 00282 reply_subdiv = qMsg->subdiv_for_reply; 00283 return query_read_type; 00284 } 00285 } 00286 } |
|
Definition at line 289 of file nmlqr.cc. 00290 { 00291 if (NULL == queryChannel) 00292 { 00293 return NULL; 00294 } 00295 return queryChannel->get_address (); 00296 } |
|
Definition at line 300 of file nmlqr.cc. 00301 { 00302 if (NULL == replyChannel) 00303 { 00304 return -1; 00305 } 00306 if (reply_subdiv < 0 00307 || reply_subdiv > replyChannel->get_total_subdivisions ()) 00308 { 00309 return -1; 00310 } 00311 return replyChannel->write_subdivision (reply_subdiv, message_to_send); 00312 } |
|
Definition at line 316 of file nmlqr.cc. Referenced by reset().
|
|
|
|
|
|
|
|
|
|
|
|
|