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

NODE_LINK Class Reference

#include <nodelink.hh>

Collaboration diagram for NODE_LINK:

Collaboration graph
[legend]

Public Methods

 NODE_LINK (NML_FORMAT_PTR, char *name, char *file, NODE *node, NODE_LINK_TYPE link_type=NODE_WM_AND_SUBORDINATE)
 ~NODE_LINK ()
void new_command (RCS_CMD_MSG *new_cmd_msg)
void new_command (RCS_GENERIC_CMD_ID)
int send_command ()
int get_status ()
int read_wm ()

Data Fields

NMLTYPE status_type
RCS_STAT_MSGstatus_msg
int status_new
NMLTYPE prev_status_type
NMLTYPE wm_type
RCS_WM_MSGwm_msg
int new_wm
NODE_STATUS_TYPE node_status
char * name
NODEparent_node
int sub_list_id
int wm_list_id

Private Attributes

RCS_CMD_CHANNELcmd
RCS_STAT_CHANNELstatus
RCS_WM_CHANNELwm
int serial_number
RCS_CMD_MSGcmd_msg
int new_cmd
RCS_GENERIC_CMDgeneric_command
NODE_LINK_TYPE type_of_link

Friends

class NODE_LINK_LIST

Constructor & Destructor Documentation

NODE_LINK::NODE_LINK NML_FORMAT_PTR    f_ptr,
char *    n,
char *    file,
NODE   node,
NODE_LINK_TYPE    link_type = NODE_WM_AND_SUBORDINATE
 

Definition at line 55 of file nodelink.cc.

00057 {
00058   char *command_buffer;
00059   char *status_buffer;
00060   char *wm_buffer;
00061 
00062   /* Set pointers to dynamically allocated memory buffers to NULL */
00063   /* so the destructor */
00064   /* doesn't delete them unless they are actually created. */
00065   name = NULL;
00066   cmd = NULL;
00067   status = NULL;
00068   wm = NULL;
00069   parent_node = node;
00070 
00071 
00072   if (NULL == node)
00073     {
00074       rcs_print_error
00075         ("NODE_LINK::Constructor - parent node must not be NULL.\n");
00076       return;
00077     }
00078 
00079   if (!node->valid)
00080     {
00081       return;
00082     }
00083 
00084   type_of_link = link_type;
00085 
00086 
00087   /* Store the name in a new place. */
00088   name = (char *) malloc (strlen (n) + 1);
00089   if (NULL == name)
00090     {
00091       node->valid = 0;
00092       rcs_print_error ("%s: Error constructing NODE_LINK %s.\n", node->name,
00093                        n);
00094       return;
00095     }
00096   strcpy (name, n);
00097 
00098   if ((NODE_SUBORDINATE_ONLY == link_type)
00099       || (NODE_WM_AND_SUBORDINATE == link_type))
00100     {
00101       if (-1 ==
00102           (sub_list_id =
00103            parent_node->sub_list->store_at_tail (this, sizeof (NODE_LINK),
00104                                                  0)))
00105         {
00106           parent_node->valid = 0;
00107           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00108                            node->name, n);
00109           return;
00110         }
00111 
00112       /* Compute command buffer name and create NML channel to it. */
00113       command_buffer =
00114         (char *) malloc (strlen (name) + RCS_COMMAND_SUFFIX_LENGTH + 1);
00115       if (NULL == command_buffer)
00116         {
00117           node->valid = 0;
00118           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00119                            node->name, name);
00120           return;
00121         }
00122       strcpy (command_buffer, name);
00123       strcat (command_buffer, RCS_COMMAND_SUFFIX);      /* append suffix */
00124       cmd = new RCS_CMD_CHANNEL (f_ptr, command_buffer, node->name, file);
00125       free (command_buffer);
00126 
00127       if (NULL == cmd)
00128         {
00129           node->valid = 0;
00130           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00131                            node->name, name);
00132           return;
00133         }
00134       if (!cmd->valid ())
00135         {
00136           node->valid = 0;
00137           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00138                            node->name, name);
00139           return;
00140         }
00141 
00142       /* Create buffer to use for generic Commands(init, halt, etc.) */
00143       generic_command = new RCS_GENERIC_CMD;
00144       if (NULL == generic_command)
00145         {
00146           node->valid = 0;
00147           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00148                            node->name, name);
00149           return;
00150         }
00151 
00152       /* Compute status buffer name and create NML channel to it. */
00153       status_buffer =
00154         (char *) malloc (strlen (name) + RCS_STATUS_SUFFIX_LENGTH + 1);
00155       if (NULL == status_buffer)
00156         {
00157           node->valid = 0;
00158           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00159                            node->name, name);
00160           return;
00161         }
00162       strcpy (status_buffer, name);
00163       strcat (status_buffer, RCS_STATUS_SUFFIX);        /* append suffix */
00164       status = new RCS_STAT_CHANNEL (f_ptr, status_buffer, node->name, file);
00165       free (status_buffer);
00166       if (NULL == status)
00167         {
00168           node->valid = 0;
00169           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00170                            node->name, name);
00171           return;
00172         }
00173       if (!status->valid ())
00174         {
00175           node->valid = 0;
00176           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00177                            node->name, name);
00178           return;
00179         }
00180 
00181       node->num_of_subord++;
00182     }
00183 
00184   if ((NODE_WM_ONLY == link_type) || (NODE_WM_AND_SUBORDINATE == link_type))
00185     {
00186       if (-1 ==
00187           (wm_list_id =
00188            parent_node->wm_in_list->store_at_tail (this, sizeof (NODE_LINK),
00189                                                    0)))
00190         {
00191           parent_node->valid = 0;
00192           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00193                            node->name, n);
00194           return;
00195         }
00196 
00197       /* Compute command buffer name and create NML channel to it. */
00198       wm_buffer = (char *) malloc (strlen (name) + RCS_WM_SUFFIX_LENGTH + 1);
00199       if (NULL == wm_buffer)
00200         {
00201           node->valid = 0;
00202           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00203                            node->name, name);
00204           return;
00205         }
00206       strcpy (wm_buffer, name);
00207       strcat (wm_buffer, RCS_WM_SUFFIX);        /* append suffix */
00208       wm = new RCS_WM_CHANNEL (f_ptr, wm_buffer, node->name, file);
00209       free (wm_buffer);
00210 
00211       if (NULL == wm)
00212         {
00213           node->valid = 0;
00214           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00215                            node->name, name);
00216           return;
00217         }
00218       if (!wm->valid ())
00219         {
00220           node->valid = 0;
00221           rcs_print_error ("%s: Error constructing NODE_LINK to %s.\n",
00222                            node->name, name);
00223           return;
00224         }
00225     }
00226 
00227   serial_number = 0;
00228   new_cmd = 0;
00229 
00230 }

NODE_LINK::~NODE_LINK  
 

Definition at line 239 of file nodelink.cc.

00240 {
00241   if (NULL != parent_node)
00242     {
00243       if (NULL != parent_node->sub_list)
00244         {
00245           if ((NODE_SUBORDINATE_ONLY == type_of_link)
00246               || (NODE_WM_AND_SUBORDINATE == type_of_link))
00247             {
00248               parent_node->sub_list->delete_node (sub_list_id);
00249             }
00250           if ((NODE_WM_ONLY == type_of_link)
00251               || (NODE_WM_AND_SUBORDINATE == type_of_link))
00252             {
00253               parent_node->wm_in_list->delete_node (wm_list_id);
00254             }
00255         }
00256     }
00257   if (NULL != cmd)
00258     {
00259       delete cmd;
00260       cmd = NULL;
00261     }
00262   if (NULL != status)
00263     {
00264       delete status;
00265       status = NULL;
00266     }
00267   if (NULL != wm)
00268     {
00269       delete wm;
00270       wm = NULL;
00271     }
00272   if (NULL != name)
00273     {
00274       free (name);
00275       name = NULL;
00276     }
00277 }


Member Function Documentation

void NODE_LINK::new_command RCS_CMD_MSG   new_cmd_msg
 

Definition at line 448 of file nodelink.cc.

Referenced by NODE::send_command_to_all().

00449 {
00450   cmd_msg = new_cmd_msg;
00451   new_cmd = 1;
00452   node_status = NODE_WAITING;
00453 }

void NODE_LINK::new_command RCS_GENERIC_CMD_ID    new_id
 

Definition at line 468 of file nodelink.cc.

00469 {
00470   generic_command->gen_id = new_id;
00471   cmd_msg = generic_command;
00472   new_cmd = 1;
00473 }

int NODE_LINK::send_command  
 

Definition at line 387 of file nodelink.cc.

Referenced by NODE::send_subordinates_commands().

00388 {
00389   if ((NULL == cmd) || (NULL == parent_node))
00390     {
00391       return (-1);
00392     }
00393 
00394   if (new_cmd)
00395     {
00396       serial_number++;
00397       cmd_msg->serial_number = serial_number;
00398 
00399       rcs_print_debug (PRINT_COMMANDS_SENT,
00400                        "%s: Sent new command to %s.\n", parent_node->name,
00401                        name);
00402       rcs_print_debug (PRINT_COMMANDS_SENT,
00403                        "  (type = %ld (0x%lX), serial_num = %d)\n",
00404                        cmd_msg->type, cmd_msg->type, serial_number);
00405       node_status = NODE_WAITING;
00406       if (parent_node->config_flags & NODE_WAIT_FOR_COMMANDS_TO_BE_READ)
00407         {
00408           if (-1 == cmd->write_if_read (cmd_msg))
00409             {
00410               if (cmd->error_type == NML_BUFFER_NOT_READ)
00411                 {
00412                   return (0);
00413                 }
00414               else
00415                 {
00416                   node_status = NODE_ERROR;
00417                   return (-1);
00418                 }
00419             }
00420         }
00421       else
00422         {
00423           if (-1 == cmd->write (cmd_msg))
00424             {
00425               node_status = NODE_ERROR;
00426               return (-1);
00427             }
00428         }
00429       new_cmd = 0;
00430     }
00431 
00432   return (0);
00433 }

int NODE_LINK::get_status  
 

Definition at line 293 of file nodelink.cc.

Referenced by NODE::get_subordinates_status().

00294 {
00295   if (NULL == status)
00296     {
00297       return (-1);
00298     }
00299 
00300   if (-1 == (status_type = status->read ()))
00301     {
00302       node_status = NODE_ERROR;
00303       return (-1);
00304     }
00305   else if (0 != status_type)
00306     {
00307       status_msg = status->get_address ();
00308       node_status = (NODE_STATUS_TYPE) status_msg->node_status;
00309       if ((node_status == NODE_DONE) &&
00310           (serial_number != status_msg->serial_number))
00311         {
00312           node_status = NODE_WAITING;
00313         }
00314 
00315       rcs_print_debug (PRINT_STATUS_RECIEVED,
00316                        "%s: Recieved new status from %s.\n",
00317                        parent_node->name, name);
00318       rcs_print_debug (PRINT_STATUS_RECIEVED,
00319                        "  (type = %ld (0x%lX), serial_num = %d,",
00320                        status_msg->type,
00321                        status_msg->type, status_msg->serial_number);
00322       rcs_print_debug (PRINT_STATUS_RECIEVED, " status = %d)\n", node_status);
00323       status_new = 1;
00324     }
00325   else
00326     {
00327       status_new = 0;
00328     }
00329 
00330   return (0);
00331 }

int NODE_LINK::read_wm  
 

Definition at line 347 of file nodelink.cc.

Referenced by NODE::read_world_model_in().

00348 {
00349   if (NULL == wm)
00350     {
00351       return (-1);
00352     }
00353 
00354   if (-1 == (wm_type = wm->read ()))
00355     {
00356       node_status = NODE_ERROR;
00357       return (-1);
00358     }
00359   else if (0 != wm_type)
00360     {
00361       wm_msg = wm->get_address ();
00362       new_wm = 1;
00363       rcs_print_debug (PRINT_NEW_WM,
00364                        "%s: Recieved new world model data from %s.\n",
00365                        parent_node->name, name);
00366       rcs_print_debug (PRINT_NEW_WM, " (type = %ld (0x%lX))", wm_msg->type,
00367                        wm_msg->type);
00368     }
00369   else
00370     {
00371       new_wm = 0;
00372     }
00373 
00374   return (0);
00375 }


Friends And Related Function Documentation

friend class NODE_LINK_LIST [friend]
 

Definition at line 39 of file nodelink.hh.


Field Documentation

RCS_CMD_CHANNEL* NODE_LINK::cmd [private]
 

Definition at line 30 of file nodelink.hh.

RCS_STAT_CHANNEL* NODE_LINK::status [private]
 

Definition at line 31 of file nodelink.hh.

RCS_WM_CHANNEL* NODE_LINK::wm [private]
 

Definition at line 32 of file nodelink.hh.

int NODE_LINK::serial_number [private]
 

Definition at line 33 of file nodelink.hh.

RCS_CMD_MSG* NODE_LINK::cmd_msg [private]
 

Definition at line 34 of file nodelink.hh.

int NODE_LINK::new_cmd [private]
 

Definition at line 35 of file nodelink.hh.

RCS_GENERIC_CMD* NODE_LINK::generic_command [private]
 

Definition at line 36 of file nodelink.hh.

NODE_LINK_TYPE NODE_LINK::type_of_link [private]
 

Definition at line 37 of file nodelink.hh.

NMLTYPE NODE_LINK::status_type
 

Definition at line 46 of file nodelink.hh.

RCS_STAT_MSG* NODE_LINK::status_msg
 

Definition at line 47 of file nodelink.hh.

int NODE_LINK::status_new
 

Definition at line 48 of file nodelink.hh.

NMLTYPE NODE_LINK::prev_status_type
 

Definition at line 49 of file nodelink.hh.

NMLTYPE NODE_LINK::wm_type
 

Definition at line 50 of file nodelink.hh.

RCS_WM_MSG* NODE_LINK::wm_msg
 

Definition at line 51 of file nodelink.hh.

int NODE_LINK::new_wm
 

Definition at line 52 of file nodelink.hh.

NODE_STATUS_TYPE NODE_LINK::node_status
 

Definition at line 53 of file nodelink.hh.

Referenced by NODE::get_subordinates_status().

char* NODE_LINK::name
 

Definition at line 54 of file nodelink.hh.

Referenced by NODE::get_subordinates_status(), NODE::read_world_model_in(), and NODE::send_subordinates_commands().

NODE* NODE_LINK::parent_node
 

Definition at line 55 of file nodelink.hh.

int NODE_LINK::sub_list_id
 

Definition at line 57 of file nodelink.hh.

int NODE_LINK::wm_list_id
 

Definition at line 58 of file nodelink.hh.


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