/ src / libnml / nml / nmlmsg.cc
nmlmsg.cc
  1  /********************************************************************
  2  * Description: nmlmsg.cc
  3  *
  4  *   Derived from a work by Fred Proctor & Will Shackleford
  5  *
  6  * Author:
  7  * License: LGPL Version 2
  8  * System: Linux
  9  *    
 10  * Copyright (c) 2004 All rights reserved.
 11  *
 12  * Last change: 
 13  ********************************************************************/
 14  
 15  #ifdef __cplusplus
 16  extern "C" {
 17  #endif
 18  #include <string.h>		// memset
 19  
 20  #ifdef __cplusplus
 21  }
 22  #endif
 23  #include "cms.hh"
 24  #include "nmlmsg.hh"
 25  #include "rcs_print.hh"		/* rcs_error_print() */
 26  /* NMLmsg Functions. */ int NMLmsg::automatically_clear = 1;
 27  
 28  /* Constructor */
 29  NMLmsg::NMLmsg(NMLTYPE t, long s)
 30  {
 31      type = t;
 32      size = s;
 33      if (automatically_clear) {
 34  	clear();
 35      }
 36      if (size < ((long) sizeof(NMLmsg))) {
 37  	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
 38  	    sizeof(NMLmsg));
 39  	size = sizeof(NMLmsg);
 40      }
 41      if (type <= 0) {
 42  	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
 43  	    (int)type);
 44      }
 45  };
 46  
 47  NMLmsg::NMLmsg(NMLTYPE t, size_t s)
 48  {
 49      type = t;
 50      size = s;
 51      if (automatically_clear) {
 52  	clear();
 53      }
 54      if (size < ((long) sizeof(NMLmsg))) {
 55  	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
 56  	    sizeof(NMLmsg));
 57  	size = sizeof(NMLmsg);
 58      }
 59      if (type <= 0) {
 60  	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
 61  	    (int)type);
 62      }
 63  }
 64  
 65  NMLmsg::NMLmsg(NMLTYPE t, long s, int noclear)
 66  {
 67      if (automatically_clear && !noclear) {
 68  	clear();
 69      }
 70      type = t;
 71      size = s;
 72      if (size < ((long) sizeof(NMLmsg))) {
 73  	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
 74  	    sizeof(NMLmsg));
 75  	size = sizeof(NMLmsg);
 76      }
 77      if (type <= 0) {
 78  	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
 79  	    (int)type);
 80      }
 81  };
 82  
 83  void NMLmsg::clear()
 84  {
 85      long temp_size;
 86      NMLTYPE temp_type;
 87      temp_size = size;
 88      temp_type = type;
 89      memset((void *) this, 0, size);
 90      size = temp_size;
 91      type = temp_type;
 92      if (size < ((long) sizeof(NMLmsg))) {
 93  	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
 94  	    sizeof(NMLmsg));
 95  	size = sizeof(NMLmsg);
 96      }
 97  }
 98  
 99  /* Error message stub for base class. */
100   /* update should only be called with derived classes. */
101  void NMLmsg::update(CMS * cms)
102  {
103      rcs_print_error("update called for NMLmsg base class.");
104      rcs_print_error("(This is an error.)\n");
105      cms->status = CMS_MISC_ERROR;
106  }