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

cms.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 * File: cms.hh                                                           *
00003 * Authors: Fred Proctor, Will Shackleford                                *
00004 * Purpose: C++ Header file for the Communication Management System (CMS).*
00005 *          Includes:                                                     *
00006 *                    1. class CMS.                                       *
00007 *                    2. class CMS_UPDATER                                *
00008 *                    2. enum CMS_STATUS.                                 *
00009 *                    3. enum CMSMODE.                                    *
00010 *                    4. enum CMSBUFFERTYPE.                              *
00011 *                    5. enum CMSPROCESSTYPE.                             *
00012 *************************************************************************/
00013 
00014 #ifndef CMS_HH
00015 #define CMS_HH
00016 
00017 #include "rcs_defs.hh"          /* RCS_EXPORT, EXTERN_C_STD_HEADERS */
00018 
00019 /* Include Files */
00020 #ifdef EXTERN_C_STD_HEADERS
00021 extern "C"
00022 {
00023 #endif
00024 
00025 #ifndef UNDER_CE
00026 #include <stddef.h>             /* size_t */
00027 #endif
00028 
00029 
00030 #ifdef EXTERN_C_STD_HEADERS
00031 }
00032 #endif
00033 
00034 #include "cms_cfg.hh"           /* CMS_CONFIG_LINELEN */
00035 #include "linklist.hh"          // RCS_LINKED_LIST
00036 #include "physmem.hh"           /* PHYSMEM_HANDLE */
00037 #include "posemath.h"           // PM_CARTESIAN, etc ...
00038 
00039 /* Enumerated Data Types */
00040 
00041 /* Return values for CMS::read, CMS::write, ... */
00042 enum CMS_STATUS
00043 {
00044 /* ERROR conditions */
00045   CMS_MISC_ERROR = -1,          /* A miscellaneous  error occured. */
00046   CMS_UPDATE_ERROR = -2,        /* An error occured during an update. */
00047   CMS_INTERNAL_ACCESS_ERROR = -3,       /* An error occured during an internal access function. */
00048   CMS_NO_MASTER_ERROR = -4,     /* An error occured becouse */
00049   /* the master was not started */
00050   CMS_CONFIG_ERROR = -5,        /* There was an error in the configuration */
00051   CMS_TIMED_OUT = -6,           /* operation timed out. */
00052   CMS_QUEUE_FULL = -7,          /* A write failed because queuing was */
00053   /* enabled but there was no room to add to */
00054   /* the queue. */
00055   CMS_CREATE_ERROR = -8,        /* Something could not be created.  */
00056   CMS_PERMISSIONS_ERROR = -9,   // Problem with permissions
00057   CMS_NO_SERVER_ERROR = -10,    // The server has not been started or could not be contacted.
00058   CMS_RESOURCE_CONFLICT_ERROR = -11,    // Two or more CMS buffers are trying to use the same resource.
00059   CMS_NO_IMPLEMENTATION_ERROR = -12,    // An operation was attempted which has not yet been implemented for the current platform or protocol.
00060   CMS_INSUFFICIENT_SPACE_ERROR = -13,   // The size of the buffer was insufficient for the requested operation.
00061   CMS_LIBRARY_UNAVAILABLE_ERROR = -14,  // A DLL or Shared Object library needed for the current protocol could not be found or initialized.
00062   CMS_SERVER_SIDE_ERROR = -15,  // The server reported an error.
00063   CMS_NO_BLOCKING_SEM_ERROR = -16,      // A blocking_read operartion was tried but no semaphore for the blocking was configured or available.
00064 
00065 /* NON Error Conditions.*/
00066   CMS_STATUS_NOT_SET = 0,       /* The status variable has not been set yet. */
00067   CMS_READ_OLD = 1,             /* Read successful, but data is old. */
00068   CMS_READ_OK = 2,              /* Read successful so far. */
00069   CMS_WRITE_OK = 3,             /* Write successful so far. */
00070   CMS_WRITE_WAS_BLOCKED = 4,    /* Write if read did not succeed, because */
00071   /* the buffer had not been read yet. */
00072   CMS_CLEAR_OK = 5,             /* A clear operation was successful.  */
00073   CMS_CLOSED = 6                /* The channel has been closed.  */
00074 };
00075 
00076 /* Mode used within update functions. */
00077 enum CMSMODE
00078 {
00079   CMS_NOT_A_MODE = 0,
00080   CMS_ENCODE,
00081   CMS_DECODE,
00082   CMS_RAW_OUT,
00083   CMS_RAW_IN,
00084   CMS_READ,
00085   CMS_WRITE
00086 };
00087 
00088 typedef long int CMSID;
00089 
00090 /* Mode stored for use by the internal access function. */
00091 enum CMS_INTERNAL_ACCESS_TYPE
00092 {
00093   CMS_ZERO_ACCESS = 0,
00094   CMS_READ_ACCESS,
00095   CMS_CHECK_IF_READ_ACCESS,
00096   CMS_PEEK_ACCESS,
00097   CMS_WRITE_ACCESS,
00098   CMS_WRITE_IF_READ_ACCESS,
00099   CMS_CLEAR_ACCESS,
00100   CMS_GET_MSG_COUNT_ACCESS,
00101   CMS_GET_DIAG_INFO_ACCESS
00102 };
00103 
00104 /* What type of global memory buffer. */
00105 enum CMS_BUFFERTYPE
00106 {
00107   CMS_SHMEM_TYPE,
00108   CMS_GLOBMEM_TYPE,
00109   CMS_PHANTOM_BUFFER,
00110   CMS_LOCMEM_TYPE,
00111   CMS_FILEMEM_TYPE,
00112   CMS_BBDMEM_TYPE,
00113   CMS_RTLMEM_TYPE
00114 };
00115 
00116 /* How will this process access the buffer. */
00117 enum CMS_PROCESSTYPE
00118 {
00119   CMS_REMOTE_TYPE,
00120   CMS_LOCAL_TYPE,
00121   CMS_PHANTOM_USER,
00122   CMS_AUTO_TYPE
00123 };
00124 
00125 enum CMS_REMOTE_PORT_TYPE
00126 {
00127   CMS_NO_REMOTE_PORT_TYPE = 0,
00128   CMS_RPC_REMOTE_PORT_TYPE,
00129   CMS_TTY_REMOTE_PORT_TYPE,
00130   CMS_TCP_REMOTE_PORT_TYPE,
00131   CMS_STCP_REMOTE_PORT_TYPE,
00132   CMS_UDP_REMOTE_PORT_TYPE
00133 };
00134 
00135 /* This structure will be placed at the beginning of every */
00136  /* CMS buffer. */
00137 struct RCS_EXPORT CMS_HEADER
00138 {
00139   long was_read;                /* Has the buffer been read since */
00140   /* the last write? */
00141   long write_id;                /* Id of last write. */
00142   long in_buffer_size;          /* How much of the buffer is currently used. */
00143 };
00144 
00145 class RCS_EXPORT CMS_DIAG_PROC_INFO;
00146 class RCS_EXPORT CMS_DIAG_HEADER;
00147 class RCS_EXPORT CMS_DIAGNOSTICS_INFO;
00148 
00149 struct RCS_EXPORT CMS_QUEUING_HEADER
00150 {
00151   long head;
00152   long tail;
00153   long queue_length;
00154   long end_queue_space;
00155   long write_id;
00156 };
00157 
00158 enum CMS_NEUTRAL_ENCODING_METHOD
00159 {
00160   CMS_NO_ENCODING,
00161   CMS_XDR_ENCODING,
00162   CMS_ASCII_ENCODING,
00163   CMS_DISPLAY_ASCII_ENCODING
00164 };
00165 
00166 /* CMS class declaration. */
00167 class RCS_EXPORT CMS;
00168 class RCS_EXPORT CMS_UPDATER;
00169 
00170 /* CMS class definition. */
00171 class RCS_EXPORT CMS
00172 {
00173 public:
00174   void *operator new (size_t);
00175   void operator delete (void *);
00176 
00177 public:
00178   /* Constructors and Destructors. */
00179     CMS (long size);
00180     CMS (char *bufline, char *procline, int set_to_server = 0);
00181     virtual ~ CMS ();
00182 
00183   /* Simple read/write interface functions. */
00184   virtual CMS_STATUS clear ();  /* Has the buffer been read recently? */
00185   virtual int check_if_read (); /* Has the buffer been read recently? */
00186   virtual int get_msg_count (); /* Has the buffer been read recently? */
00187   virtual int check_if_transfers_complete ();   /* Has DMA completed */
00188   virtual CMS_STATUS read ();   /* Read from  buffer. */
00189   virtual CMS_STATUS blocking_read (double _timeout);   /* Read from  buffer, wait for new data. */
00190   virtual CMS_STATUS peek ();   /* Read without setting flag. */
00191   virtual CMS_STATUS write (void *user_data);   /* Write to buffer. */
00192   virtual CMS_STATUS write_if_read (void *user_data);   /* Write to buffer. */
00193   virtual int login (const char *name, const char *passwd);
00194   virtual void reconnect ();
00195   virtual void disconnect ();
00196 
00197   /* Protocol Defined Virtual Function Stubs. */
00198   virtual CMS_STATUS main_access (void *_local);
00199 
00200   /* Neutrally Encoded Buffer positioning functions. */
00201   void rewind ();               /* positions at beginning */
00202   int get_encoded_msg_size ();  /* Store last position in header.size */
00203 
00204   /* Buffer access control functions. */
00205   void set_mode (CMSMODE im);   /* Determine read/write mode.(check neutral) */
00206 
00207   /* Select a temparary updator -- This is used by the nml msg2string and string2msg functions. */
00208   void set_temp_updater (CMS_NEUTRAL_ENCODING_METHOD);
00209 
00210   /* Restore the normal update. */
00211   void restore_normal_updater ();
00212 
00213 
00214   /*******************************************************/
00215   /* CMS INTERNAL ACCESS FUNCTIONS located in cms_in.cc  */
00216   /*******************************************************/
00217   CMS_STATUS internal_access (PHYSMEM_HANDLE * _global, void *_local);
00218   CMS_STATUS internal_access (void *_global, long global_size, void *_local);
00219   CMS_STATUS internal_clear (); /* Zero the global memory.  */
00220   int check_if_read_raw ();
00221   int check_if_read_encoded ();
00222   int get_msg_count_raw ();
00223   int get_msg_count_encoded ();
00224   CMS_STATUS read_raw ();       /* Read from raw buffers. */
00225   CMS_STATUS read_encoded ();   /* Read from neutrally encoded buffers. */
00226   CMS_STATUS peek_raw ();       /* Read  without setting flags. */
00227   CMS_STATUS peek_encoded ();   /* Read  without setting flags. */
00228   CMS_STATUS write_raw (void *user_data);       /* Write to raw buffers. */
00229   CMS_STATUS write_encoded ();  /* Write to neutrally encoded buffers. */
00230   CMS_STATUS write_if_read_raw (void *user_data);       /* Write if read. */
00231   CMS_STATUS write_if_read_encoded ();  /* Write if read. */
00232   int queue_check_if_read_raw ();
00233   int queue_check_if_read_encoded ();
00234   CMS_STATUS queue_read_raw (); /* Read from raw buffers. */
00235   CMS_STATUS queue_read_encoded ();     /* Read from neutral buffers. */
00236   CMS_STATUS queue_peek_raw (); /* Read  without setting flags. */
00237   CMS_STATUS queue_peek_encoded ();     /* Read  without setting flags. */
00238   CMS_STATUS queue_write_raw (void *user_data); /* Write to raw bufs */
00239   CMS_STATUS queue_write_encoded ();    /* Write to neutral buffers. */
00240   CMS_STATUS queue_write_if_read_raw (void *user_data);
00241   CMS_STATUS queue_write_if_read_encoded ();    /* Write if read. */
00242   virtual void clean_buffers ();
00243 
00244   /***********************************************/
00245   /* CMS UPDATE  FUNCTIONS located in cms_up.cc  */
00246   /***********************************************/
00247   /* Access functions for primitive C language data types */
00248   CMS_STATUS update (char &x);
00249   CMS_STATUS update (unsigned char &x);
00250   CMS_STATUS update (short int &x);
00251   CMS_STATUS update (unsigned short int &x);
00252   CMS_STATUS update (int &x);
00253   CMS_STATUS update (unsigned int &x);
00254   CMS_STATUS update (long int &x);
00255   CMS_STATUS update (unsigned long int &x);
00256   CMS_STATUS update (float &x);
00257   CMS_STATUS update (double &x);
00258   CMS_STATUS update (long double &x);
00259   CMS_STATUS update (char *x, unsigned int len);
00260   CMS_STATUS update (unsigned char *x, unsigned int len);
00261   CMS_STATUS update (short *x, unsigned int len);
00262   CMS_STATUS update (unsigned short *x, unsigned int len);
00263   CMS_STATUS update (int *x, unsigned int len);
00264   CMS_STATUS update (unsigned int *x, unsigned int len);
00265   CMS_STATUS update (long *x, unsigned int len);
00266   CMS_STATUS update (unsigned long *x, unsigned int len);
00267   CMS_STATUS update (float *x, unsigned int len);
00268   CMS_STATUS update (double *x, unsigned int len);
00269   CMS_STATUS update (long double *x, unsigned int len);
00270 
00271   /*************************************************************************
00272    * CMS UPDATE FUNCTIONS for POSEMATH classes, defined in cms_pm.cc       *
00273    ************************************************************************/
00274   // translation types
00275   CMS_STATUS update (PM_CARTESIAN & x); // Cart
00276   CMS_STATUS update (PM_SPHERICAL & x); // Sph
00277   CMS_STATUS update (PM_CYLINDRICAL & x);       // Cyl
00278 
00279   // rotation types
00280   CMS_STATUS update (PM_ROTATION_VECTOR & x);   // Rot
00281   CMS_STATUS update (PM_ROTATION_MATRIX & x);   // Mat
00282   CMS_STATUS update (PM_QUATERNION & x);        // Quat
00283   CMS_STATUS update (PM_EULER_ZYZ & x); // Zyz
00284   CMS_STATUS update (PM_EULER_ZYX & x); // Zyx
00285   CMS_STATUS update (PM_RPY & x);       // Rpy
00286 
00287   // pose types
00288   CMS_STATUS update (PM_POSE & x);      // Pose
00289   CMS_STATUS update (PM_HOMOGENEOUS & x);       // Hom
00290 
00291   // CMS UPDATE FUNCTIONS for arrays of POSEMATH types.
00292   // translation types
00293   CMS_STATUS update (PM_CARTESIAN * x, int n);  // Cart
00294   CMS_STATUS update (PM_SPHERICAL * x, int n);  // Sph
00295   CMS_STATUS update (PM_CYLINDRICAL * x, int n);        // Cyl
00296 
00297   // rotation types
00298   CMS_STATUS update (PM_ROTATION_VECTOR * x, int n);    // Rot
00299   CMS_STATUS update (PM_ROTATION_MATRIX * x, int n);    // Mat
00300   CMS_STATUS update (PM_QUATERNION * x, int n); // Quat
00301   CMS_STATUS update (PM_EULER_ZYZ * x, int n);  // Zyz
00302   CMS_STATUS update (PM_EULER_ZYX * x, int n);  // Zyx
00303   CMS_STATUS update (PM_RPY * x, int n);        // Rpy
00304 
00305   // pose types
00306   CMS_STATUS update (PM_POSE * x, int n);       // Pose
00307   CMS_STATUS update (PM_HOMOGENEOUS * x, int n);        // Hom
00308 
00309 
00310 #ifdef CMS_SUPPORT_POINTERS
00311   virtual CMS_STATUS update_ptr (int (*update_ptr_func) (void *, CMS *),
00312                                  void **x, long xsize);
00313   virtual CMS_STATUS set_pointer_buffer (char *buf, long size);
00314 #endif
00315   /* comm protocol parameters shared by all protocols */
00316   int fatal_error_occurred;
00317   int consecutive_timeouts;
00318   CMS_HEADER header;            /* Information to be stored in CMS buffer. */
00319   int queuing_enabled;          /* queue messages in the buffer  */
00320   CMS_QUEUING_HEADER queuing_header;    /* information for multi-slot buffers.  */
00321   CMSMODE mode;                 /* This process is reading or writing? */
00322   long size;                    /* size of cms */
00323   long max_message_size;        /* size of cms buffer available for user */
00324   /* messages = size - CMS Header space */
00325   long max_encoded_message_size;        /* Maximum size of message after being encoded. */
00326   long guaranteed_message_space;        /* Largest size message before being encoded
00327                                            that can be guaranteed to fit after xdr. */
00328   int neutral;                  /* neutral data format in buffer */
00329 
00330   CMS_STATUS status;            /* Status of the last CMS access. */
00331   void set_cms_status (CMS_STATUS);     /* Catch changes in cms status.  */
00332   int spawn_server;
00333 
00334   /* Buffers for local copies of global buffer. */
00335   void *encoded_data;           /* pointer to local copy of  encoded data */
00336   int using_external_encoded_data;
00337   void set_encoded_data (void *, long _encoded_data_size);
00338   void *data;                   /* pointer to local copy of data (raw)  */
00339   void *subdiv_data;            // pointer to current subdiv;
00340 
00341   /* Intersting Info Saved from the Configuration File. */
00342   char BufferName[CMS_CONFIG_LINELEN];
00343   char BufferHost[CMS_CONFIG_LINELEN];
00344   char ProcessName[CMS_CONFIG_LINELEN];
00345   char BufferLine[CMS_CONFIG_LINELEN];
00346   char ProcessLine[CMS_CONFIG_LINELEN];
00347   char ProcessHost[CMS_CONFIG_LINELEN];
00348   char buflineupper[CMS_CONFIG_LINELEN];
00349   char proclineupper[CMS_CONFIG_LINELEN];
00350   char PermissionString[CMS_CONFIG_LINELEN];
00351   int is_local_master;
00352   int force_raw;
00353   int split_buffer;             /* Will the buffer be split into two areas */
00354   /* so that one area can be read while the */
00355   /* other is written to? */
00356   char toggle_bit;
00357   int first_read_done;
00358   int first_write_done;
00359   int write_permission_flag;
00360   int read_permission_flag;
00361   unsigned long rpc_program_number;
00362   int tcp_port_number;
00363   int stcp_port_number;
00364   int udp_port_number;
00365   long buffer_number;
00366   int delete_totally;
00367   long total_messages_missed;
00368   long messages_missed_on_last_read;
00369   char RCS_HUGE *format_low_ptr;
00370   char RCS_HUGE *format_high_ptr;
00371   long format_size;
00372   int check_pointer (char RCS_HUGE * ptr, long bytes);
00373   int isserver;                 /* Is the process a server. */
00374   int is_phantom;               /* Is this a phantom CMS channel? */
00375   CMS_BUFFERTYPE BufferType;
00376   CMS_PROCESSTYPE ProcessType;
00377   CMS_REMOTE_PORT_TYPE remote_port_type;
00378   int pointer_check_disabled;
00379 
00380   CMSID in_buffer_id;           /* Last id read, used to determine if new. */
00381   void *encoded_header;         /* pointer to local copy of encoded header */
00382   void *encoded_queuing_header; /* pointer to local copy of encoded queue info */
00383   long encoded_header_size;     /* Dynamically determined size */
00384   long encoded_queuing_header_size;     /* Dynamically determined size */
00385 
00386   /* Header Neutral Formatting Functions. */
00387   int encode_header ();         /* header-> ENCODE-> encoded_header */
00388   int decode_header ();         /* encoded_header -> DECODE -> header */
00389   int encode_queuing_header (); /* queuing_header -> encoded_queuing_header */
00390   int decode_queuing_header (); /* encoded_queuing_header ->queuing_header */
00391   /* XDR of ASCII */
00392   CMS_NEUTRAL_ENCODING_METHOD neutral_encoding_method;
00393   CMS_NEUTRAL_ENCODING_METHOD temp_updater_encoding_method;
00394 
00395 public:
00396   /* Type of internal access. */
00397     CMS_INTERNAL_ACCESS_TYPE internal_access_type;
00398   PHYSMEM_HANDLE *handle_to_global_data;
00399   PHYSMEM_HANDLE *dummy_handle;
00400   int write_just_completed;
00401   CMSMODE read_mode;
00402   CMSMODE write_mode;
00403   int read_updater_mode;
00404   int write_updater_mode;
00405   CMSMODE last_im;
00406   /* data buffer stuff */
00407 
00408 
00409   CMS_STATUS check_id (CMSID id);       /* Determine if the buffer is new. */
00410   friend class CMS_SERVER;
00411   friend class CMS_SERVER_HANDLER;
00412 public:
00413   double timeout;
00414   long connection_number;
00415   long total_connections;
00416   CMS_UPDATER *updater;
00417   CMS_UPDATER *normal_updater;
00418   CMS_UPDATER *temp_updater;
00419 
00420 private:
00421   unsigned long encode_state;   /* Store position for save, restore. */
00422   unsigned long decode_state;   /* Store position for save, restore. */
00423   void open (void);             /* Allocate memory and intialize XDR streams */
00424   static int number_of_cms_objects;     /* Used to decide when to initialize */
00425   /* and cleanup PC-NFS Toolkit DLLs */
00426 
00427 public:
00428   long sizeof_message_header;   /* Used by BBD protocol to strip off */
00429   double blocking_timeout;
00430   double min_compatible_version;
00431   int confirm_write;
00432   int disable_final_write_raw_for_dma;
00433   virtual const char *status_string (int);
00434 
00435   int total_subdivisions;
00436   int current_subdivision;
00437   long subdiv_size;
00438   int set_subdivision (int _subdiv);
00439   long encoded_data_size;
00440   long enc_max_size;
00441   long enable_diagnostics;
00442   CMS_DIAG_PROC_INFO *dpi;
00443   virtual CMS_DIAG_PROC_INFO *get_diag_proc_info ();
00444   virtual void set_diag_proc_info (CMS_DIAG_PROC_INFO *);
00445   virtual void setup_diag_proc_info ();
00446   virtual void calculate_and_store_diag_info (PHYSMEM_HANDLE * _handle,
00447                                               void *);
00448   virtual void internal_retrieve_diag_info (PHYSMEM_HANDLE * _handle, void *);
00449   CMS_DIAGNOSTICS_INFO *di;
00450   virtual CMS_DIAGNOSTICS_INFO *get_diagnostics_info ();
00451   int first_diag_store;
00452   double pre_op_total_bytes_moved;
00453   double time_bias;
00454   int skip_area;
00455   unsigned long half_offset;
00456   long half_size;
00457   int fast_mode;
00458   long size_without_diagnostics;
00459   int disable_diag_store;
00460   long diag_offset;
00461   int last_id_side0;
00462   int last_id_side1;
00463   int use_autokey_for_connection_number;
00464   /* RCS_CMD_MSG, RCS_STAT_MSG stuff */
00465 
00466 private:
00467     CMS (CMS & cms);            // Don't copy me.
00468 
00469 };
00470 
00471 class CMS_HOST_ALIAS_ENTRY
00472 {
00473 public:
00474   char host[64];
00475   char alias[64];
00476 };
00477 
00478 
00479 extern RCS_LINKED_LIST *cmsHostAliases;
00480 
00481 enum CMS_CONNECTION_MODE
00482 {
00483   CMS_NORMAL_CONNECTION_MODE = 0,       // all config file parameters are honored.
00484   CMS_FORCE_LOCAL_CONNECTION_MODE = 1,  // all connections are forced to be local
00485   CMS_FORCE_REMOTE_CONNECTION_MODE = 2  // all connections are forced to be remote
00486 };
00487 
00488 extern CMS_CONNECTION_MODE cms_connection_mode;
00489 
00490 
00491 extern char *cms_check_for_host_alias (char *in);
00492 extern int cms_encoded_data_explosion_factor;
00493 extern int cms_print_queue_free_space;
00494 extern int cms_print_queue_full_messages;
00495 
00496 
00497 #endif /* !defined(CMS_HH) */

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