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

rcs_oi.cc

Go to the documentation of this file.
00001 
00002 extern "C"
00003 {
00004 #include <stdlib.h>             /* malloc() */
00005 #include <string.h>             /* strcpy(), strcat(), strlen() */
00006 }
00007 
00008 #include "nml.hh"
00009 #include "nmlmsg.hh"
00010 #include "cms.hh"
00011 
00012 #include "node.hh"              /* class NODE */
00013 #include "rcs_oi.hh"
00014 
00015 /* Constructor */
00016 RCS_OI::RCS_OI (NML_FORMAT_PTR fptr, char *_name, char *_process,
00017                 char *file, NODE * _node)
00018 {
00019   char *request_buffer_name;
00020   char *reply_buffer_name;
00021 
00022   node = _node;
00023   request_channel = NULL;
00024   reply_channel = NULL;
00025   request_msg = NULL;
00026   reply_msg = NULL;
00027   new_request_msg = 0;
00028   new_reply_msg = 0;
00029   mode = OI_ACCEPTING_REQUESTS;
00030 
00031   /* Construct request_buffer_name */
00032   request_buffer_name = (char *) malloc (strlen (_name)
00033                                          + strlen (node->suffix.req) + 1);
00034   strcpy (request_buffer_name, _name);
00035   strcat (request_buffer_name, node->suffix.req);
00036 
00037   /* Open request channel. */
00038   request_channel = new RCS_OI_REQUEST_CHANNEL (fptr,
00039                                                 request_buffer_name, _process,
00040                                                 file);
00041   delete request_buffer_name;
00042 
00043   /* Construct reply_buffer_name */
00044   reply_buffer_name = (char *) malloc (strlen (_name)
00045                                        + strlen (node->suffix.reply) + 1);
00046   strcpy (reply_buffer_name, _name);
00047   strcat (reply_buffer_name, node->suffix.reply);
00048 
00049   /* Open reply channel. */
00050   reply_channel = new RCS_OI_REPLY_CHANNEL (fptr,
00051                                             reply_buffer_name, _process,
00052                                             file);
00053   delete reply_buffer_name;
00054 
00055   /* Add this RCS_OI to the list in the parent node. */
00056   if (NULL != node)
00057     {
00058       if (NULL != node->operator_interface_list)
00059         {
00060           oi_list_id =
00061             node->operator_interface_list->store_at_tail (this,
00062                                                           sizeof (RCS_OI), 0);
00063         }
00064     }
00065 }
00066 
00067 RCS_OI::RCS_OI ()
00068 {
00069   node = NULL;
00070   request_channel = NULL;
00071   reply_channel = NULL;
00072   request_msg = NULL;
00073   reply_msg = NULL;
00074   request_flag = 0;
00075   cmd_for_node = NULL;
00076   cmd_for_node_new = 0;
00077   new_request_msg = 0;
00078   new_reply_msg = 0;
00079 }
00080 
00081 /* Destructor */
00082 RCS_OI::~RCS_OI ()
00083 {
00084   if (NULL != request_channel)
00085     {
00086       delete request_channel;
00087       request_channel = NULL;
00088     }
00089   if (NULL != reply_channel)
00090     {
00091       delete reply_channel;
00092       reply_channel = NULL;
00093     }
00094   if (NULL != node)
00095     {
00096       if (NULL != node->operator_interface_list)
00097         {
00098           node->operator_interface_list->delete_node (oi_list_id);
00099         }
00100     }
00101 }
00102 
00103 /* interpret incoming requests */
00104 void
00105 RCS_OI::interpret_request ()
00106 {
00107 }
00108 
00109 /* convert request to command  */
00110 void
00111 RCS_OI::choose_command_for_node ()
00112 {
00113 }
00114 
00115 /* form replies */
00116 void
00117 RCS_OI::choose_reply ()
00118 {
00119 }
00120 
00121 /************************************************************
00122   Function: get_requests()
00123   Purpose: To read communications channels to determine if the
00124     operator has made a request.
00125 
00126   Returns:
00127     0 No new request.
00128     -1 A communications error occured.
00129     1 A new request was recieved.
00130 ************************************************************/
00131 int
00132 RCS_OI::get_request ()
00133 {
00134   NMLTYPE temp;
00135   if (NULL != request_channel)
00136     {
00137       switch (temp = request_channel->read ())
00138         {
00139         case -1:                /* error */
00140           return -1;
00141         case 0:         /* old */
00142           new_request_msg = 0;
00143           return 0;
00144         default:                /* new */
00145           request_flag = 1;
00146           new_request_msg = 1;
00147           request_type = temp;
00148           request_msg = request_channel->get_address ();
00149           return 1;
00150         }
00151     }
00152   else
00153     {
00154       return -1;
00155     }
00156 }
00157 
00158 /************************************************************
00159   Function: get_requests()
00160   Purpose: To inform the OI that the NODE has moved to a new
00161   mode.
00162 ************************************************************/
00163 void
00164 RCS_OI::set_mode (OI_MODE_TYPE new_mode)
00165 {
00166   mode = new_mode;
00167 }
00168 
00169 /************************************************************
00170   Function: acknowledge_request()
00171   Purpose: To inform the OI that the NODE has acknowledged it's
00172   request.
00173 ************************************************************/
00174 void
00175 RCS_OI::acknowledge_request ()
00176 {
00177   request_flag = 0;
00178 }
00179 
00180 /************************************************************
00181   Function: acknowledge_request()
00182   Purpose: To inform the OI that the NODE has completed  it's
00183   request.
00184 ************************************************************/
00185 void
00186 RCS_OI::request_done ()
00187 {
00188 }
00189 
00190 
00191 /************************************************************
00192   Function: acknowledge_request()
00193   Purpose: To allow the OI to process it's
00194   request.
00195 
00196   Note: It will be called every cycle whether or not the NODE
00197   will actually accept requests from the OI.
00198 ************************************************************/
00199 void
00200 RCS_OI::cycle ()
00201 {
00202   interpret_request ();
00203   choose_command_for_node ();
00204   choose_reply ();
00205 }
00206 
00207 /************************************************************
00208   Function: send_replies()
00209   Purpose: Send the operator(s) some info.
00210 
00211   Returns:
00212   -1 if an error occurred.
00213   0 otherwise.
00214 ************************************************************/
00215 int
00216 RCS_OI::send_reply ()
00217 {
00218   if (NULL != reply_channel)
00219     {
00220       if (new_reply_msg)
00221         {
00222           return (reply_channel->write (reply_msg));
00223         }
00224       return 0;
00225     }
00226   else
00227     {
00228       return -1;
00229     }
00230 }

Generated on Sun Dec 2 15:56:51 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001