summaryrefslogtreecommitdiff
path: root/src/libnml/nml/nmlmsg.cc
blob: d3267f71327dff3cd590e75e67cce94fa0bbb9c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/********************************************************************
* Description: nmlmsg.cc
*
*   Derived from a work by Fred Proctor & Will Shackleford
*
* Author:
* License: LGPL Version 2
* System: Linux
*    
* Copyright (c) 2004 All rights reserved.
*
* Last change: 
********************************************************************/

#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>		// memset

#ifdef __cplusplus
}
#endif
#include "cms.hh"
#include "nmlmsg.hh"
#include "rcs_print.hh"		/* rcs_error_print() */
/* NMLmsg Functions. */ int NMLmsg::automatically_clear = 1;

/* Constructor */
NMLmsg::NMLmsg(NMLTYPE t, long s)
{
    type = t;
    size = s;
    if (automatically_clear) {
	clear();
    }
    if (size < ((long) sizeof(NMLmsg))) {
	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
	    sizeof(NMLmsg));
	size = sizeof(NMLmsg);
    }
    if (type <= 0) {
	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
	    (int)type);
    }
};

NMLmsg::NMLmsg(NMLTYPE t, size_t s)
{
    type = t;
    size = s;
    if (automatically_clear) {
	clear();
    }
    if (size < ((long) sizeof(NMLmsg))) {
	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
	    sizeof(NMLmsg));
	size = sizeof(NMLmsg);
    }
    if (type <= 0) {
	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
	    (int)type);
    }
}

NMLmsg::NMLmsg(NMLTYPE t, long s, int noclear)
{
    if (automatically_clear && !noclear) {
	clear();
    }
    type = t;
    size = s;
    if (size < ((long) sizeof(NMLmsg))) {
	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
	    sizeof(NMLmsg));
	size = sizeof(NMLmsg);
    }
    if (type <= 0) {
	rcs_print_error("NMLmsg: type(=%d) should be greater than zero.\n",
	    (int)type);
    }
};

void NMLmsg::clear()
{
    long temp_size;
    NMLTYPE temp_type;
    temp_size = size;
    temp_type = type;
    memset((void *) this, 0, size);
    size = temp_size;
    type = temp_type;
    if (size < ((long) sizeof(NMLmsg))) {
	rcs_print_error("NMLmsg: size(=%ld) must be atleast %zu\n", size,
	    sizeof(NMLmsg));
	size = sizeof(NMLmsg);
    }
}

/* Error message stub for base class. */
 /* update should only be called with derived classes. */
void NMLmsg::update(CMS * cms)
{
    rcs_print_error("update called for NMLmsg base class.");
    rcs_print_error("(This is an error.)\n");
    cms->status = CMS_MISC_ERROR;
}