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

cms_up.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002 * File: cms_up.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.
00006 *
00007 * NOTES:
00008 * There are no update functions for enumerations, or pointers.
00009 ****************************************************************************/
00010 
00011 /* Includes */
00012 #include "cms.hh"               /* class CMS */
00013 #include "cms_up.hh"            /* class CMS_UPDATER */
00014 #include "rcs_prnt.hh"          /* rcs_print_error() */
00015 #include "dbg_mem.h"            // DEBUG_MALLOC,DEBUG_FREE
00016 
00017 #ifdef EXTERN_C_STD_HEADERS
00018 extern "C"
00019 {
00020 #endif
00021 #include <stdlib.h>             // malloc(), free()
00022 #include <string.h>             // memset()
00023 #ifdef EXTERN_C_STD_HEADERS
00024 }
00025 #endif
00026 
00027 /* Member functions for CMS_UPDATER Class */
00028 CMS_UPDATER::CMS_UPDATER (CMS * _cms_parent, int create_encoded_data,
00029                           long _neutral_size_factor):
00030   /**********************************************
00031   * Aliases to variables in the CMS parent
00032   * using aliases lets CMS and its CMS_UPDATER share this information
00033   * more conveniently and allowed the CMS_UPDATER functions to be pulled out
00034   * of CMS with fewer changes. (WPS - 6/12/95)
00035   *********************************************/
00036 encoded_data (_cms_parent->encoded_data),
00037 encoded_header (_cms_parent->encoded_header),
00038 encoded_queuing_header (_cms_parent->encoded_queuing_header),
00039 status (_cms_parent->status),
00040 size (_cms_parent->size),
00041 encoded_header_size (_cms_parent->encoded_header_size),
00042 encoded_queuing_header_size (_cms_parent->encoded_queuing_header_size),
00043 using_external_encoded_data (_cms_parent->using_external_encoded_data),
00044 pointer_check_disabled (_cms_parent->pointer_check_disabled),
00045 encoded_data_size (_cms_parent->encoded_data_size)
00046 {
00047   cms_parent = _cms_parent;
00048   mode = CMS_NO_UPDATE;
00049   neutral_size_factor = _neutral_size_factor;
00050   if (encoded_data == NULL && create_encoded_data)
00051     {
00052       if (cms_parent->enc_max_size > 0
00053           && cms_parent->enc_max_size < neutral_size_factor * size)
00054         {
00055           set_encoded_data (DEBUG_MALLOC (cms_parent->enc_max_size),
00056                             cms_parent->enc_max_size);
00057         }
00058       else
00059         {
00060           set_encoded_data (DEBUG_MALLOC (neutral_size_factor * size),
00061                             neutral_size_factor * size);
00062         }
00063       using_external_encoded_data = 0;
00064     }
00065 }
00066 
00067 CMS_UPDATER::~CMS_UPDATER ()
00068 {
00069 #ifdef CMS_SUPPORT_POINTERS
00070   if (NULL != ptr_table)
00071     {
00072       delete ptr_table;
00073     }
00074 #endif
00075 }
00076 
00077 #ifdef CMS_SUPPORT_POINTERS
00078 
00079 CMS_STATUS
00080   CMS_UPDATER::update_ptr (int (*update_ptr_func) (void *, CMS *),
00081                            void **x, long xsize)
00082 {
00083   if (NULL == update_ptr_func || NULL == x)
00084     {
00085       return (status = CMS_UPDATE_ERROR);
00086     }
00087 
00088   int padsize;
00089   int table_index = pointers_in_table;
00090 
00091   if (encoding)
00092     {
00093       if (NULL == *x)
00094         {
00095           table_index = -1;
00096           pointer_check_disabled = 1;
00097           update (table_index);
00098           pointer_check_disabled = 0;
00099           return (status);
00100         }
00101       ptr_table_entry = ptr_table;
00102       table_index = 0;
00103       while (ptr_table_entry->ptr != *x && ptr_table_entry->ptr != NULL)
00104         {
00105           ptr_table_entry++;
00106           table_index++;
00107         }
00108       if (ptr_table_entry->ptr == NULL)
00109         {
00110           pointers_in_table++;
00111           ptr_table_entry->ptr = *x;
00112           pointer_check_disabled = 1;
00113           update (pointers_in_table);
00114           pointer_check_disabled = 0;
00115           update_ptr_func (*x, cms_parent);
00116         }
00117       else
00118         {
00119           pointer_check_disabled = 1;
00120           update (table_index);
00121           pointer_check_disabled = 0;
00122         }
00123     }
00124   else
00125     {
00126       pointer_check_disabled = 1;
00127       update (table_index);
00128       pointer_check_disabled = 0;
00129       if (table_index == -1)
00130         {
00131           *x = NULL;
00132           return (status);
00133         }
00134       if (table_index < pointers_in_table)
00135         {
00136           *x = ptr_table[table_index].ptr;
00137         }
00138       else
00139         {
00140           if (NULL == unused_pointer_buf || xsize > unused_pointer_buf_size)
00141             {
00142               return (status = CMS_UPDATE_ERROR);
00143             }
00144           *x = (void *) unused_pointer_buf;
00145           unused_pointer_buf_size -= ((long) xsize);
00146           unused_pointer_buf += xsize;
00147           if (((unsigned long) unused_pointer_buf) % 16 != 0)
00148             {
00149               padsize = 16 - ((unsigned long) unused_pointer_buf) % 16;
00150               unused_pointer_buf_size -= ((long) padsize);
00151               unused_pointer_buf += padsize;
00152             }
00153           update_ptr_func (*x, cms_parent);
00154           ptr_table_entry->ptr = *x;
00155           ptr_table_entry++;
00156           pointers_in_table++;
00157         }
00158     }
00159   return (status);
00160 }
00161 
00162 CMS_STATUS
00163 CMS_UPDATER::set_pointer_buffer (char *_buf, long _size)
00164 {
00165   unsigned int padsize;
00166   unused_pointer_buf = pointer_buf = _buf;
00167   unused_pointer_buf_size = pointer_buf_size = _size;
00168   if (((unsigned long) unused_pointer_buf) % 16 != 0)
00169     {
00170       padsize = 16 - ((unsigned long) unused_pointer_buf) % 16;
00171       unused_pointer_buf_size -= ((long) padsize);
00172       unused_pointer_buf += padsize;
00173     }
00174   return (status);
00175 }
00176 
00177 #endif
00178   // ifdef CMS_SUPPORT_POINTERS
00179 
00180 void
00181 CMS_UPDATER::rewind ()
00182 {
00183 }
00184 
00185 int
00186 CMS_UPDATER::set_mode (CMS_UPDATER_MODE _mode)
00187 {
00188   mode = _mode;
00189   switch (mode)
00190     {
00191     case CMS_NO_UPDATE:
00192       break;
00193 
00194     case CMS_ENCODE_DATA:
00195       encoding = 1;
00196       break;
00197 
00198     case CMS_DECODE_DATA:
00199       encoding = 0;
00200       break;
00201 
00202     case CMS_ENCODE_HEADER:
00203       encoding = 1;
00204       break;
00205 
00206     case CMS_DECODE_HEADER:
00207       encoding = 0;
00208       break;
00209 
00210     case CMS_ENCODE_QUEUING_HEADER:
00211       encoding = 1;
00212       break;
00213 
00214     case CMS_DECODE_QUEUING_HEADER:
00215       encoding = 0;
00216       break;
00217 
00218     default:
00219       rcs_print_error ("CMS updater in invalid mode.\n");
00220       return (-1);
00221     }
00222   return (0);
00223 }
00224 
00225 CMS_UPDATER_MODE
00226 CMS_UPDATER::get_mode ()
00227 {
00228   return mode;
00229 }
00230 
00231 
00232 int
00233 CMS_UPDATER::check_pointer (char RCS_HUGE * _pointer, long _bytes)
00234 {
00235   if (NULL == cms_parent)
00236     {
00237       return (-1);
00238     }
00239   return (cms_parent->check_pointer (_pointer, _bytes));
00240 }
00241 
00242 void
00243 CMS_UPDATER::set_encoded_data (void *_encoded_data, long _encoded_data_size)
00244 {
00245   if (NULL != encoded_data &&
00246       !using_external_encoded_data && encoded_data != _encoded_data)
00247     {
00248       DEBUG_FREE (encoded_data);
00249       encoded_data = NULL;
00250     }
00251   encoded_data = _encoded_data;
00252   encoded_data_size = _encoded_data_size;
00253   using_external_encoded_data = 1;
00254 }

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