Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

NML_QR_SERVER Class Reference

#include <nmlqr.hh>

Collaboration diagram for NML_QR_SERVER:

Collaboration graph
[legend]

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)
NMLmsggetQueryAddress ()
int replyToLastQuery (NMLmsg *message_to_send)
int valid ()
int reset ()

Protected Attributes

NMLreplyChannel
NML_QUERY_CHANNELqueryChannel
NML_ID_CHANNELidChannel
int reply_subdiv
char * subdiv_allocation_table

Constructor & Destructor Documentation

NML_QR_SERVER::NML_QR_SERVER NML_FORMAT_PTR    f_ptr,
char *    qr_name,
char *    process_name,
char *    config_file
 

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 }

NML_QR_SERVER::~NML_QR_SERVER  
 

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 }


Member Function Documentation

NMLTYPE NML_QR_SERVER::readQuery  
 

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 }

NMLTYPE NML_QR_SERVER::waitForQuery double    timeout
 

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 }

NMLmsg * NML_QR_SERVER::getQueryAddress  
 

Definition at line 289 of file nmlqr.cc.

00290 {
00291   if (NULL == queryChannel)
00292     {
00293       return NULL;
00294     }
00295   return queryChannel->get_address ();
00296 }

int NML_QR_SERVER::replyToLastQuery NMLmsg   message_to_send
 

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 }

int NML_QR_SERVER::valid  
 

Definition at line 316 of file nmlqr.cc.

Referenced by reset().

00317 {
00318   if (!idChannel->valid ())
00319     {
00320       return 0;
00321     }
00322   if (!queryChannel->valid ())
00323     {
00324       return 0;
00325     }
00326   if (!replyChannel->valid ())
00327     {
00328       return 0;
00329     }
00330   return 1;
00331 }

int NML_QR_SERVER::reset  
 

Definition at line 334 of file nmlqr.cc.

00335 {
00336   if (!idChannel->valid ())
00337     {
00338       idChannel->reset ();
00339     }
00340   if (!queryChannel->valid ())
00341     {
00342       queryChannel->reset ();
00343     }
00344   if (!replyChannel->valid ())
00345     {
00346       replyChannel->reset ();
00347     }
00348   return valid ();
00349 }


Field Documentation

NML* NML_QR_SERVER::replyChannel [protected]
 

Definition at line 58 of file nmlqr.hh.

NML_QUERY_CHANNEL* NML_QR_SERVER::queryChannel [protected]
 

Definition at line 59 of file nmlqr.hh.

NML_ID_CHANNEL* NML_QR_SERVER::idChannel [protected]
 

Definition at line 60 of file nmlqr.hh.

int NML_QR_SERVER::reply_subdiv [protected]
 

Definition at line 61 of file nmlqr.hh.

char* NML_QR_SERVER::subdiv_allocation_table [protected]
 

Definition at line 62 of file nmlqr.hh.


The documentation for this class was generated from the following files:
Generated on Sun Dec 2 15:58:51 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001