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

cms_xup.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002 * File: cms_xup.cc
00003 * Author(s): Will Shackleford, Fred Proctor
00004 * Purpose: Provides the interface to CMS used by NML update functions including
00005 * a CMS update function for all the basic C data types to convert NMLmsgs to XDR.
00006 *
00007 * NOTES:
00008 * There are no update functions for enumerations, or pointers.
00009 * The update function for long doubles is included, but it is recommended that
00010 * doubles be used instead of long doubles since they will be faster and
00011 * the increased range and precision of long doubles will be lost anyway.
00012 ****************************************************************************/
00013 
00014 /* Includes */
00015 extern "C"
00016 {
00017 #include <stdlib.h>             /* malloc(), free() */
00018 
00019 };
00020 
00021 #include "dbg_mem.h"            /* DEBUG_FREE,DEBUG_MALLOC,DEBUG_CALLOC */
00022 
00023 
00024 // This function exists because sparcworks_sun4 header files
00025 // define free as int free(char *) instead of void free(void *);
00026 static void
00027 corrected_free (void *ptr)
00028 {
00029 #ifdef sparcworks_sun4
00030   DEGUB_FREE ((char *) ptr);
00031 #else
00032   DEBUG_FREE (ptr);
00033 #endif
00034 }
00035 
00036 #include "cms.hh"               /* class CMS */
00037 #include "cms_xup.hh"           /* class CMS_XDR_UPDATER  */
00038 #include "rcs_prnt.hh"          /* rcs_print_error() */
00039 
00040 
00041 
00042 #if defined(linuxppc) || defined(linuxPPC) || defined(darwin)
00043 #ifdef xdr_destroy
00044 #undef xdr_destroy
00045 #endif
00046 #define xdr_destroy(xdrs)                               \
00047         if ((xdrs)->x_ops->x_destroy)                   \
00048                 ((void (*)(XDR *)) (*(xdrs)->x_ops->x_destroy))(xdrs)
00049 #ifdef xdr_setpos
00050 #undef xdr_setpos
00051 #endif
00052 #define xdr_setpos(xdrs,pos)                            \
00053                 ((bool_t (*)(XDR *, const u_int)) (*(xdrs)->x_ops->x_setpostn))(xdrs,pos)
00054 
00055 #ifdef xdr_getpos
00056 #undef xdr_getpos
00057 #endif
00058 #define xdr_getpos(xdrs)                                \
00059                 ((u_int (*)(XDR *)) (*(xdrs)->x_ops->x_getpostn))(xdrs)
00060 
00061 #endif
00062 
00063 #if defined(VXWORKS) && defined(NO_DCE_RPC) && !defined(HAVE_XDR_VECTOR)
00064 static inline bool_t
00065 xdr_vector (XDR * xdrs, char *arrp, const u_int size,
00066             const u_int elsize, const xdrproc_t elproc)
00067 {
00068   if (NULL == xdrs || NULL == arrp)
00069     {
00070       return FALSE;
00071     }
00072   for (int i = 0; i < size; i++)
00073     {
00074       if (!elproc (xdrs, arrp))
00075         {
00076           return FALSE;
00077         }
00078       arrp += elsize;
00079     }
00080   return TRUE;
00081 }
00082 #endif
00083 
00084 
00085 /* Member functions for CMS_XDR_UPDATER Class */
00086 CMS_XDR_UPDATER::CMS_XDR_UPDATER (CMS * _cms_parent):CMS_UPDATER (_cms_parent,
00087              0, 2)
00088 {
00089   /* Set pointers to NULL. */
00090   encode_data_stream = (XDR *) NULL;
00091   decode_data_stream = (XDR *) NULL;
00092   encode_header_stream = (XDR *) NULL;
00093   decode_header_stream = (XDR *) NULL;
00094   encode_queuing_header_stream = (XDR *) NULL;
00095   decode_queuing_header_stream = (XDR *) NULL;
00096   encoded_header = NULL;
00097   encoded_queuing_header = NULL;
00098 
00099   if (!cms_parent->isserver)
00100     {
00101       encoded_data = NULL;
00102     }
00103   using_external_encoded_data = 0;
00104 
00105 #if 0
00106   if (load_rpc_interface () < 0)
00107     {
00108       rcs_print_error
00109         ("CMS_XDR_UPDATER requires the rpc interface and it failed to load.\n");
00110       status = CMS_UPDATE_ERROR;
00111       return;
00112     }
00113 #endif
00114   /* Store and validate constructors arguments. */
00115   cms_parent = _cms_parent;
00116   if (NULL == cms_parent)
00117     {
00118       rcs_print_error ("CMS parent for updater is NULL.\n");
00119       status = CMS_UPDATE_ERROR;
00120       return;
00121     }
00122 
00123   /* Allocate memory for: */
00124   /*  - encoded copies of the global buffer and the header */
00125   /*  - XDR streams. */
00126   /*  (Also initialize the XDR streams.) */
00127 
00128   /* Allocate the encoded header too large, */
00129   /* and find out what size it really is. */
00130   encoded_header = DEBUG_MALLOC (neutral_size_factor * sizeof (CMS_HEADER));
00131   if (encoded_header == NULL)
00132     {
00133       rcs_print_error ("CMS:can't malloc encoded_header");
00134       status = CMS_CREATE_ERROR;
00135       return;
00136     }
00137 
00138   encode_header_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00139   if (encode_header_stream == NULL)
00140     {
00141       cms_parent->status = CMS_CREATE_ERROR;
00142       rcs_print_error ("CMS:can't malloc encode_header_stream");
00143       return;
00144     }
00145   xdrmem_create ((XDR *) encode_header_stream, (char *) encoded_header,
00146                  (int) neutral_size_factor * sizeof (CMS_HEADER), XDR_ENCODE);
00147 
00148   decode_header_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00149   if (decode_header_stream == NULL)
00150     {
00151       rcs_print_error ("CMS:can't malloc decode_header_stream");
00152       status = CMS_CREATE_ERROR;
00153       return;
00154     }
00155   xdrmem_create ((XDR *) decode_header_stream, (char *) encoded_header,
00156                  (int) neutral_size_factor * sizeof (CMS_HEADER), XDR_DECODE);
00157 
00158   /* If queuing is enabled, then initialize streams for */
00159   /* encoding and decoding the header with the queue information. */
00160   if (cms_parent->queuing_enabled)
00161     {
00162       /* Allocate the encoded header too large, */
00163       /* and find out what size it really is. */
00164       encoded_queuing_header =
00165         DEBUG_MALLOC (neutral_size_factor * sizeof (CMS_QUEUING_HEADER));
00166       if (encoded_queuing_header == NULL)
00167         {
00168           rcs_print_error ("CMS:can't malloc encoded_queuing_header");
00169           status = CMS_CREATE_ERROR;
00170           return;
00171         }
00172       encode_queuing_header_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00173       if (encode_queuing_header_stream == NULL)
00174         {
00175           status = CMS_CREATE_ERROR;
00176           rcs_print_error ("CMS:can't malloc encode_queuing_header_stream");
00177           return;
00178         }
00179       xdrmem_create ((XDR *) encode_queuing_header_stream,
00180                      (char *) encoded_queuing_header,
00181                      (int) neutral_size_factor * sizeof (CMS_QUEUING_HEADER),
00182                      XDR_ENCODE);
00183 
00184       decode_queuing_header_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00185       if (decode_queuing_header_stream == NULL)
00186         {
00187           rcs_print_error ("CMS:can't malloc decode_queuing_header_stream");
00188           status = CMS_CREATE_ERROR;
00189           return;
00190         }
00191       xdrmem_create ((XDR *) decode_queuing_header_stream,
00192                      (char *) encoded_queuing_header,
00193                      (int) neutral_size_factor * sizeof (CMS_QUEUING_HEADER),
00194                      XDR_DECODE);
00195     }
00196   if (!cms_parent->isserver)
00197     {
00198       if (cms_parent->enc_max_size > 0
00199           && cms_parent->enc_max_size < neutral_size_factor * size)
00200         {
00201           set_encoded_data (DEBUG_MALLOC (cms_parent->enc_max_size),
00202                             cms_parent->enc_max_size);
00203         }
00204       else
00205         {
00206           set_encoded_data (DEBUG_MALLOC (neutral_size_factor * size),
00207                             neutral_size_factor * size);
00208         }
00209     }
00210   using_external_encoded_data = 0;
00211 }
00212 
00213 CMS_XDR_UPDATER::~CMS_XDR_UPDATER ()
00214 {
00215   /* If encoded buffers were used destroy the xdr streams and free */
00216   /* memory used for encoded buffers. */
00217   if (NULL != encode_data_stream)
00218     {
00219       xdr_destroy (encode_data_stream);
00220       corrected_free (encode_data_stream);
00221       encode_data_stream = (XDR *) NULL;
00222     }
00223   if (NULL != decode_data_stream)
00224     {
00225       xdr_destroy (decode_data_stream);
00226       corrected_free (decode_data_stream);
00227       decode_data_stream = (XDR *) NULL;
00228     }
00229   if (NULL != encode_header_stream)
00230     {
00231       xdr_destroy (((XDR *) encode_header_stream));
00232       corrected_free (encode_header_stream);
00233       encode_header_stream = (XDR *) NULL;
00234     }
00235   if (NULL != decode_header_stream)
00236     {
00237       xdr_destroy (((XDR *) decode_header_stream));
00238       corrected_free (decode_header_stream);
00239       decode_header_stream = (XDR *) NULL;
00240     }
00241   if (NULL != encode_queuing_header_stream)
00242     {
00243       xdr_destroy (((XDR *) encode_queuing_header_stream));
00244       corrected_free (encode_queuing_header_stream);
00245       encode_queuing_header_stream = (XDR *) NULL;
00246     }
00247   if (NULL != decode_queuing_header_stream)
00248     {
00249       xdr_destroy (((XDR *) decode_queuing_header_stream));
00250       corrected_free (decode_queuing_header_stream);
00251       decode_queuing_header_stream = (XDR *) NULL;
00252     }
00253   if (NULL != encoded_data && !using_external_encoded_data)
00254     {
00255       corrected_free (encoded_data);
00256       encoded_data = NULL;
00257     }
00258   if (NULL != encoded_header)
00259     {
00260       corrected_free (encoded_header);
00261       encoded_header = NULL;
00262     }
00263   if (NULL != encoded_queuing_header)
00264     {
00265       corrected_free (encoded_queuing_header);
00266       encoded_queuing_header = NULL;
00267     }
00268 #if 0
00269   unload_rpc_interface ();
00270 #endif
00271 }
00272 
00273 void
00274 CMS_XDR_UPDATER::set_encoded_data (void *_encoded_data,
00275                                    long _encoded_data_size)
00276 {
00277   /* If the encoded data area has already been setup then release it. */
00278   if (NULL != encoded_data && !using_external_encoded_data)
00279     {
00280       corrected_free (encoded_data);
00281       encoded_data = NULL;
00282     }
00283 
00284   encoded_data_size = _encoded_data_size;
00285   encoded_data = _encoded_data;
00286   using_external_encoded_data = 1;
00287   if (encoded_data == NULL)
00288     {
00289       rcs_print_error ("CMS: Attempt to set  encoded_data buffer to NULL.\n");
00290       status = CMS_MISC_ERROR;
00291       return;
00292     }
00293   /* Allocate memory for XDR structures. */
00294   if (NULL == encode_data_stream)
00295     {
00296       encode_data_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00297     }
00298   else
00299     {
00300       xdr_destroy (encode_data_stream);
00301     }
00302   if (NULL == encode_data_stream)
00303     {
00304       rcs_print_error ("CMS:can't malloc encode_data_stream");
00305       status = CMS_CREATE_ERROR;
00306       return;
00307     }
00308   if (NULL == decode_data_stream)
00309     {
00310       decode_data_stream = (XDR *) DEBUG_MALLOC (sizeof (XDR));
00311     }
00312   else
00313     {
00314       xdr_destroy (decode_data_stream);
00315     }
00316   if (NULL == decode_data_stream)
00317     {
00318       rcs_print_error ("CMS:can't malloc decode_data_stream");
00319       status = CMS_CREATE_ERROR;
00320       return;
00321     }
00322 
00323   /* Initialize the XDR streams. */
00324   int nsize = (int) (neutral_size_factor * size);
00325   if (nsize > cms_parent->max_encoded_message_size
00326       && cms_parent->max_encoded_message_size > 0)
00327     {
00328       nsize = cms_parent->max_encoded_message_size;
00329     }
00330   if (nsize > cms_parent->enc_max_size && cms_parent->enc_max_size > 0)
00331     {
00332       nsize = cms_parent->enc_max_size;
00333     }
00334   xdrmem_create (encode_data_stream, (char *) encoded_data, nsize,
00335                  XDR_ENCODE);
00336   xdrmem_create (decode_data_stream, (char *) encoded_data, nsize,
00337                  XDR_DECODE);
00338 
00339 }
00340 
00341 int
00342 CMS_XDR_UPDATER::set_mode (CMS_UPDATER_MODE _mode)
00343 {
00344   mode = _mode;
00345   CMS_UPDATER::set_mode (_mode);
00346   switch (mode)
00347     {
00348     case CMS_NO_UPDATE:
00349       current_stream = (XDR *) NULL;
00350       break;
00351 
00352     case CMS_ENCODE_DATA:
00353       current_stream = encode_data_stream;
00354       break;
00355 
00356     case CMS_DECODE_DATA:
00357       current_stream = decode_data_stream;
00358       break;
00359 
00360     case CMS_ENCODE_HEADER:
00361       current_stream = encode_header_stream;
00362       break;
00363 
00364     case CMS_DECODE_HEADER:
00365       current_stream = decode_header_stream;
00366       break;
00367 
00368     case CMS_ENCODE_QUEUING_HEADER:
00369       current_stream = encode_queuing_header_stream;
00370       break;
00371 
00372     case CMS_DECODE_QUEUING_HEADER:
00373       current_stream = decode_queuing_header_stream;
00374       break;
00375 
00376     default:
00377       rcs_print_error ("CMS updater in invalid mode.(%d)\n", mode);
00378       return (-1);
00379     }
00380   return (0);
00381 }
00382 
00383 int
00384 CMS_XDR_UPDATER::check_pointer (char RCS_HUGE * _pointer, long _bytes)
00385 {
00386   if (NULL == cms_parent || NULL == current_stream)
00387     {
00388       rcs_print_error ("CMS_XDR_UPDATER: Required pointer is NULL.\n");
00389       return (-1);
00390     }
00391   if (
00392       (current_stream == encode_data_stream) ||
00393       (current_stream == decode_data_stream) ||
00394       (mode == CMS_ENCODE_DATA) || (mode == CMS_DECODE_DATA))
00395     {
00396       int xdr_pos = xdr_getpos (current_stream);
00397       if (xdr_pos + _bytes > encoded_data_size)
00398         {
00399           rcs_print_error
00400             ("Encoded message buffer full. (xdr_pos=%d,_bytes=%d,(xdr_pos+_bytes)=%d,encoded_data_size=%d)\n",
00401              xdr_pos, _bytes, (xdr_pos + _bytes), encoded_data_size);
00402           return -1;
00403         }
00404     }
00405   return (cms_parent->check_pointer (_pointer, _bytes));
00406 }
00407 
00408 /* Repositions the data buffer to the very beginning */
00409 void
00410 CMS_XDR_UPDATER::rewind ()
00411 {
00412   CMS_UPDATER::rewind ();
00413   if (NULL != current_stream)
00414     {
00415       xdr_setpos (current_stream, 0);
00416     }
00417   else
00418     {
00419       rcs_print_error
00420         ("CMS_XDR_UPDATER: Can't rewind because current_stream is NULL.\n");
00421     }
00422   if (NULL != cms_parent)
00423     {
00424       cms_parent->format_size = 0;
00425     }
00426 }
00427 
00428 
00429 int
00430 CMS_XDR_UPDATER::get_encoded_msg_size ()
00431 {
00432   if (NULL == current_stream)
00433     {
00434       rcs_print_error
00435         ("CMS_XDR_UPDATER can not provide encoded_msg_size because the current stream is NULL.\n");
00436       return (-1);
00437     }
00438   return (xdr_getpos (current_stream));
00439 }
00440 
00441 
00442 /* Char functions */
00443 
00444 CMS_STATUS
00445 CMS_XDR_UPDATER::update (char &x)
00446 {
00447   /* Check to see if the pointers are in the proper range. */
00448   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (char)))
00449     {
00450       return (CMS_UPDATE_ERROR);
00451     }
00452   if (xdr_char (current_stream, &x) != TRUE)
00453     {
00454       rcs_print_error ("CMS_XDR_UPDATER: xdr_char failed.\n");
00455       return (status = CMS_UPDATE_ERROR);
00456     }
00457   return (status);
00458 }
00459 
00460 CMS_STATUS
00461 CMS_XDR_UPDATER::update (char *x, unsigned int len)
00462 {
00463   /* Check to see if the pointers are in the proper range. */
00464   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (char)))
00465     {
00466       return (CMS_UPDATE_ERROR);
00467     }
00468 
00469   if (xdr_bytes (current_stream, (char **) &x, &len, len) != TRUE)
00470     {
00471       rcs_print_error ("CMS_XDR_UPDATER: xdr_bytes failed.\n");
00472       return (status = CMS_UPDATE_ERROR);
00473     }
00474   return (status);
00475 }
00476 
00477 CMS_STATUS
00478 CMS_XDR_UPDATER::update (unsigned char &x)
00479 {
00480   /* Check to see if the pointers are in the proper range. */
00481   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (char)))
00482     {
00483       return (CMS_UPDATE_ERROR);
00484     }
00485   if (xdr_u_char (current_stream, (unsigned char *) &x) != TRUE)
00486     {
00487       rcs_print_error ("CMS_XDR_UPDATER: xdr_u_char failed.\n");
00488       return (status = CMS_UPDATE_ERROR);
00489     }
00490   return (status);
00491 }
00492 
00493 CMS_STATUS
00494 CMS_XDR_UPDATER::update (unsigned char *x, unsigned int len)
00495 {
00496   /* Check to see if the pointers are in the proper range. */
00497   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (unsigned char)))
00498     {
00499       return (CMS_UPDATE_ERROR);
00500     }
00501 
00502   if (xdr_bytes (current_stream, (char **) &x, &len, len) != TRUE)
00503     {
00504       rcs_print_error ("CMS_XDR_UPDATER: xdr_bytes failed.\n");
00505       return (status = CMS_UPDATE_ERROR);
00506     }
00507   return (status);
00508 }
00509 
00510 /* SHORT */
00511 
00512 CMS_STATUS
00513 CMS_XDR_UPDATER::update (short &x)
00514 {
00515   /* Check to see if the pointers are in the proper range. */
00516   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (short)))
00517     {
00518       return (CMS_UPDATE_ERROR);
00519     }
00520 
00521   if (xdr_short (current_stream, &x) != TRUE)
00522     {
00523       rcs_print_error ("CMS_XDR_UPDATER: xdr_short failed.\n");
00524       return (status = CMS_UPDATE_ERROR);
00525     }
00526   return (status);
00527 }
00528 
00529 CMS_STATUS
00530 CMS_XDR_UPDATER::update (short *x, unsigned int len)
00531 {
00532   /* Check to see if the pointers are in the proper range. */
00533   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (short)))
00534     {
00535       return (CMS_UPDATE_ERROR);
00536     }
00537 
00538   if (xdr_vector (current_stream, (char *) x, len, sizeof (short),
00539                   (xdrproc_t) xdr_short) != TRUE)
00540     {
00541       rcs_print_error
00542         ("CMS_XDR_UPDATER: xdr_vector(... xdr_short) failed.\n");
00543       return (status = CMS_UPDATE_ERROR);
00544     }
00545   return (status);
00546 }
00547 
00548 CMS_STATUS
00549 CMS_XDR_UPDATER::update (unsigned short &x)
00550 {
00551   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned short)))
00552     {
00553       return (CMS_UPDATE_ERROR);
00554     }
00555 
00556   if (xdr_u_short (current_stream, &x) != TRUE)
00557     {
00558       rcs_print_error ("CMS_XDR_UPDATER: xdr_u_short failed.\n");
00559       return (status = CMS_UPDATE_ERROR);
00560     }
00561 
00562   return (status);
00563 }
00564 
00565 CMS_STATUS
00566 CMS_XDR_UPDATER::update (unsigned short *x, unsigned int len)
00567 {
00568   if (-1 ==
00569       check_pointer ((char RCS_HUGE *) x, len * sizeof (unsigned short)))
00570     {
00571       return (CMS_UPDATE_ERROR);
00572     }
00573 
00574   if (xdr_vector (current_stream,
00575                   (char *) x, len,
00576                   sizeof (unsigned short), (xdrproc_t) xdr_u_short) != TRUE)
00577     {
00578       rcs_print_error
00579         ("CMS_XDR_UPDATER: xdr_vector(... xdr_u_short) failed.\n");
00580       return (status = CMS_UPDATE_ERROR);
00581     }
00582   return (status);
00583 }
00584 
00585 /* INT */
00586 
00587 CMS_STATUS
00588 CMS_XDR_UPDATER::update (int &x)
00589 {
00590   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (int)))
00591     {
00592       return (CMS_UPDATE_ERROR);
00593     }
00594 
00595   if (xdr_int (current_stream, &x) != TRUE)
00596     {
00597       rcs_print_error ("CMS_XDR_UPDATER: xdr_int failed.\n");
00598       return (status = CMS_UPDATE_ERROR);
00599     }
00600   return (status);
00601 }
00602 
00603 CMS_STATUS
00604 CMS_XDR_UPDATER::update (int *x, unsigned int len)
00605 {
00606   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (int)))
00607     {
00608       return (CMS_UPDATE_ERROR);
00609     }
00610   if (xdr_vector (current_stream, (char *) x, len, sizeof (int),
00611                   (xdrproc_t) xdr_int) != TRUE)
00612     {
00613       rcs_print_error ("CMS_XDR_UPDATER: xdr_vector( ... xdr_int) failed.\n");
00614       return (status = CMS_UPDATE_ERROR);
00615     }
00616   return (status);
00617 }
00618 
00619 CMS_STATUS
00620 CMS_XDR_UPDATER::update (unsigned int &x)
00621 {
00622   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned int)))
00623     {
00624       return (CMS_UPDATE_ERROR);
00625     }
00626 
00627   if (xdr_u_int (current_stream, &x) != TRUE)
00628     {
00629       rcs_print_error ("CMS_XDR_UPDATER: xdr_u_int failed.\n");
00630       return (status = CMS_UPDATE_ERROR);
00631     }
00632   return (status);
00633 }
00634 
00635 CMS_STATUS
00636 CMS_XDR_UPDATER::update (unsigned int *x, unsigned int len)
00637 {
00638   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (unsigned int)))
00639     {
00640       return (CMS_UPDATE_ERROR);
00641     }
00642 
00643   if (xdr_vector (current_stream,
00644                   (char *) x, len,
00645                   sizeof (unsigned int), (xdrproc_t) xdr_u_int) != TRUE)
00646     {
00647       rcs_print_error
00648         ("CMS_XDR_UPDATER: xdr_vector(... xdr_u_int) failed.\n");
00649       return (status = CMS_UPDATE_ERROR);
00650     }
00651   return (status);
00652 }
00653 
00654 
00655 /* LONG */
00656 
00657 CMS_STATUS
00658 CMS_XDR_UPDATER::update (long &x)
00659 {
00660   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (long)))
00661     {
00662       return (CMS_UPDATE_ERROR);
00663     }
00664 
00665   if (xdr_long (current_stream, &x) != TRUE)
00666     {
00667       rcs_print_error ("CMS_XDR_UPDATER: xdr_long failed.\n");
00668       return (status = CMS_UPDATE_ERROR);
00669     }
00670   return (status);
00671 }
00672 
00673 CMS_STATUS
00674 CMS_XDR_UPDATER::update (long *x, unsigned int len)
00675 {
00676   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (long)))
00677     {
00678       return (CMS_UPDATE_ERROR);
00679     }
00680 
00681   if (xdr_vector (current_stream, (char *) x, len, sizeof (long),
00682                   (xdrproc_t) xdr_long) != TRUE)
00683     {
00684       rcs_print_error ("CMS_XDR_UPDATER: xdr_vector(... xdr_long) failed.\n");
00685       return (status = CMS_UPDATE_ERROR);
00686     }
00687   return (status);
00688 }
00689 
00690 CMS_STATUS
00691 CMS_XDR_UPDATER::update (unsigned long &x)
00692 {
00693   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (unsigned long)))
00694     {
00695       return (CMS_UPDATE_ERROR);
00696     }
00697 
00698   if (xdr_u_long (current_stream, &x) != TRUE)
00699     {
00700       rcs_print_error ("CMS_XDR_UPDATER: xdr_u_long failed.\n");
00701       return (status = CMS_UPDATE_ERROR);
00702     }
00703 
00704   return (status);
00705 }
00706 
00707 CMS_STATUS
00708 CMS_XDR_UPDATER::update (unsigned long *x, unsigned int len)
00709 {
00710   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (unsigned long)))
00711     {
00712       return (CMS_UPDATE_ERROR);
00713     }
00714 
00715   if (xdr_vector (current_stream,
00716                   (char *) x, len, sizeof (unsigned long),
00717                   (xdrproc_t) xdr_u_long) != TRUE)
00718     {
00719       rcs_print_error
00720         ("CMS_XDR_UPDATER: xdr_vector(... xdr_u_long) failed.\n");
00721       return (status = CMS_UPDATE_ERROR);
00722     }
00723   return (status);
00724 }
00725 
00726 /* FLOAT */
00727 
00728 CMS_STATUS
00729 CMS_XDR_UPDATER::update (float &x)
00730 {
00731   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (float)))
00732     {
00733       return (CMS_UPDATE_ERROR);
00734     }
00735 
00736   if (xdr_float (current_stream, &x) != TRUE)
00737     {
00738       rcs_print_error ("CMS_XDR_UPDATER: xdr_float failed.\n");
00739       return (status = CMS_UPDATE_ERROR);
00740     }
00741   return (status);
00742 }
00743 
00744 CMS_STATUS
00745 CMS_XDR_UPDATER::update (float *x, unsigned int len)
00746 {
00747   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (float)))
00748     {
00749       return (CMS_UPDATE_ERROR);
00750     }
00751 
00752   if (xdr_vector (current_stream, (char *) x, len, sizeof (float),
00753                   (xdrproc_t) xdr_float) != TRUE)
00754     {
00755       rcs_print_error
00756         ("CMS_XDR_UPDATER: xdr_vector(... xdr_float) failed.\n");
00757       return (status = CMS_UPDATE_ERROR);
00758     }
00759   return (status);
00760 }
00761 
00762 CMS_STATUS
00763 CMS_XDR_UPDATER::update (double &x)
00764 {
00765   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (double)))
00766     {
00767       return (CMS_UPDATE_ERROR);
00768     }
00769 
00770   if (xdr_double (current_stream, &x) != TRUE)
00771     {
00772       rcs_print_error ("CMS_XDR_UPDATER: xdr_double failed.\n");
00773       return (status = CMS_UPDATE_ERROR);
00774     }
00775   return (status);
00776 }
00777 
00778 CMS_STATUS
00779 CMS_XDR_UPDATER::update (double *x, unsigned int len)
00780 {
00781   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (double)))
00782     {
00783       return (CMS_UPDATE_ERROR);
00784     }
00785 
00786   if (xdr_vector (current_stream, (char *) x, len, sizeof (double),
00787                   (xdrproc_t) xdr_double) != TRUE)
00788     {
00789       rcs_print_error
00790         ("CMS_XDR_UPDATER: xdr_vector(... xdr_double) failed.\n");
00791       return (status = CMS_UPDATE_ERROR);
00792     }
00793 
00794   return (status);
00795 }
00796 
00797 /* NOTE: Because XDR does not include seperate facilities for long doubles. */
00798 /* Some resolution will be lost if long doubles are passed through XDR. */
00799 /* This routine is included only for the sake of completeness. */
00800 /* Avoid using long doubles in NML messages. */
00801 CMS_STATUS
00802 CMS_XDR_UPDATER::update (long double &x)
00803 {
00804   if (-1 == check_pointer ((char RCS_HUGE *) &x, sizeof (long double)))
00805     {
00806       return (CMS_UPDATE_ERROR);
00807     }
00808 
00809   double y;
00810 #ifdef __BORLANDC__
00811   /* The Borland C++ compiler seems to need a little help in converting */
00812   /* long doubles to ordinary doubles. */
00813   if (x > 1E308)
00814     x = 1E308;
00815   if (x < -1E308)
00816     x = -1E308;
00817   if ((-2E-308 < x) && (x < 2E-308))
00818     x = 0.0;
00819 #endif
00820 
00821   y = (double) x;
00822 
00823 
00824   if (xdr_double (current_stream, &y) != TRUE)
00825     {
00826       rcs_print_error ("CMS_XDR_UPDATER: xdr_double failed.\n");
00827       return (status = CMS_UPDATE_ERROR);
00828     }
00829   x = (long double) y;
00830   return (status);
00831 }
00832 
00833 CMS_STATUS
00834 CMS_XDR_UPDATER::update (long double *x, unsigned int len)
00835 {
00836   if (-1 == check_pointer ((char RCS_HUGE *) x, len * sizeof (long double)))
00837     {
00838       return (CMS_UPDATE_ERROR);
00839     }
00840 
00841   unsigned int i;
00842   double *y;
00843   y = (double *) DEBUG_MALLOC (sizeof (double) * len);
00844   for (i = 0; i < len; i++)
00845     {
00846 #ifdef __BORLANDC__
00847       /* The Borland C++ compiler seems to need a little help in converting */
00848       /* long doubles to ordinary doubles. */
00849       if (x[i] > 1E308)
00850         x[i] = 1E308;
00851       if (x[i] < -1E308)
00852         x[i] = -1E308;
00853       if ((-2E-308 < x[i]) && (x[i] < 2E-308))
00854         x[i] = 0.0;
00855 #endif
00856       y[i] = (double) x[i];
00857     }
00858 
00859 
00860   if (xdr_vector (current_stream, (char *) y, len, sizeof (double),
00861                   (xdrproc_t) xdr_double) != TRUE)
00862     {
00863       rcs_print_error
00864         ("CMS_XDR_UPDATER: xdr_vector(... xdr_double) failed.\n");
00865       return (status = CMS_UPDATE_ERROR);
00866     }
00867 
00868   for (i = 0; i < len; i++)
00869     {
00870       x[i] = (long double) y[i];
00871     }
00872   corrected_free (y);
00873   return (status);
00874 }

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