The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cmalib.c
Go to the documentation of this file.
1 
25 #include <projectcommon.h>
26 #include <string.h>
27 #include <cmalib.h>
28 #include <frameset.h>
29 #include <intframe.h>
30 #include <ipportframe.h>
31 #include <cstringframe.h>
32 #include <frametypes.h>
33 #include <cmalib.h>
34 
35 
41 FrameSet*
43  , guint16 msgtype
44  , NetAddr* addrs
45  , int addrcount)
46 {
47  FrameSet* ret = frameset_new(msgtype);
48  ConfigContext* msgcfg = configcontext_new(0);
49  char* json;
50  CstringFrame* jsframe;
51  int count = 0;
52 
53  // Put the heartbeat interval in the message (if asked)
54  if (config->getint(config, CONFIGNAME_INTERVAL) > 0) {
55  gint hbtime = config->getint(config, CONFIGNAME_INTERVAL);
57  intf->setint(intf, hbtime);
58  frameset_append_frame(ret, &intf->baseclass);
59  UNREF2(intf);
60  msgcfg->setint(msgcfg, CONFIGNAME_INTERVAL, hbtime);
61  }else{
63  }
64  // Put the heartbeat deadtime in the message (if asked)
65  if (config->getint(config, CONFIGNAME_TIMEOUT) > 0) {
66  gint deadtime = config->getint(config, CONFIGNAME_TIMEOUT);
68  intf->setint(intf, deadtime);
69  frameset_append_frame(ret, &intf->baseclass);
70  UNREF2(intf);
71  msgcfg->setint(msgcfg, CONFIGNAME_TIMEOUT, deadtime);
72  }else{
74  }
75  // Put the heartbeat warntime in the message (if asked)
76  if (config->getint(config, CONFIGNAME_WARNTIME) > 0) {
77  gint warntime = config->getint(config, CONFIGNAME_WARNTIME);
79  intf->setint(intf, warntime);
80  frameset_append_frame(ret, &intf->baseclass);
81  UNREF2(intf);
82  msgcfg->setint(msgcfg, CONFIGNAME_WARNTIME, warntime);
83  }else{
85  }
86  json = msgcfg->baseclass.toString(&msgcfg->baseclass);
87  UNREF(msgcfg);
88  jsframe = cstringframe_new(FRAMETYPE_RSCJSON, 0);
89  jsframe->baseclass.setvalue(&jsframe->baseclass, json
90  , strlen(json)+1, frame_default_valuefinalize);
91  frameset_append_frame(ret, &jsframe->baseclass);
92  UNREF2(jsframe);
93 
94 
95  // Put all the addresses we were given in the message.
96  for (count=0; count < addrcount; ++count) {
97  IpPortFrame* hbaddr = ipportframe_netaddr_new(FRAMETYPE_IPPORT, &addrs[count]);
98  frameset_append_frame(ret, &hbaddr->baseclass);
99  UNREF2(hbaddr);
100  }
101  return ret;
102 }
103 
104 
110 FrameSet*
112 {
114  char* json;
115  CstringFrame* jsframe;
116 
117  if (!cfg || !cfg->_values) {
118  g_warning("%s.%d: NULL ConfigContext parameter", __FUNCTION__, __LINE__);
119  return NULL;
120  }
121  json = cfg->baseclass.toString(&cfg->baseclass);
122  if (json == NULL) {
123  g_warning("%s.%d: Invalid ConfigContext parameter", __FUNCTION__, __LINE__);
124  return NULL;
125  }
127  jsframe->baseclass.setvalue(&jsframe->baseclass, json
128  , strlen(json)+1, frame_default_valuefinalize);
129  frameset_append_frame(fs, &jsframe->baseclass);
130  UNREF2(jsframe);
131 
132  return fs;
133 }
#define CONFIGNAME_INTERVAL
How long to wait between events.
Frame baseclass
Definition: ipportframe.h:41
#define CONFIG_DEFAULT_WARNTIME
Default warning time.
This is an IntFrame class TLV (type, length, value) frame - representing an integer of some specified...
Definition: intframe.h:39
Implements minimal client-oriented Frame and Frameset capabilities.
#define FRAMETYPE_HBWARNTIME
FRAMETYPE_HBWARNTIME Frame (frametype 16) Frame subclass - IntFrame class.
Definition: frametypes.h:277
WINEXPORT IpPortFrame * ipportframe_netaddr_new(guint16 frame_type, NetAddr *addr)
Construct and initialize an IpPortFrame class from a IP NetAddr class.
Definition: ipportframe.c:234
IntFrame * intframe_new(guint16 frametype, int intbytes)
Construct new IntFrame object.
Definition: intframe.c:181
Describes interfaces to C-String Frame (Cstringframe) C-Class It holds conventional zero-terminated b...
FrameSet * frameset_new(guint16 frameset_type)
Construct a new frameset of the given type.
Definition: frameset.c:110
#define FRAMETYPE_HBINTERVAL
FRAMETYPE_HBINTERVAL Frame (frametype 14) Frame subclass - IntFrame class.
Definition: frametypes.h:251
#define CONFIG_DEFAULT_HBTIME
Default heartbeat interval.
#define FRAMETYPE_CONFIGJSON
FRAMETYPE_CONFIGJSON Frame (frametype 20) Frame subclass - CstringFrame class.
Definition: frametypes.h:313
gint64(* getint)(const ConfigContext *, const char *name)
Get integer value.
Definition: configcontext.h:74
Implements the IntFrame class - integers in a frame.
AssimObj baseclass
Definition: configcontext.h:72
void frameset_append_frame(FrameSet *fs, Frame *f)
Append frame to the front of the end of the frame list.
Definition: frameset.c:143
#define __FUNCTION__
#define CONFIGNAME_WARNTIME
How long w/o heartbeats before whining?
#define CONFIGNAME_TIMEOUT
How before declaring a serious problem...
#define FRAMETYPE_IPPORT
FRAMETYPE_IPPORT Frame (frametype 13) Frame subclass - IpPortFrame class.
Definition: frametypes.h:238
FrameSet * create_sendexpecthb(ConfigContext *config, guint16 msgtype, NetAddr *addrs, int addrcount)
Create a FrameSet class to send and expect heartbeats from the same sets of addresses.
Definition: cmalib.c:42
#define FRAMETYPE_RSCJSON
FRAMETYPE_RSCJSON Frame (frametype 27) Frame subclass - CstringFrame class.
Definition: frametypes.h:400
#define CONFIG_DEFAULT_DEADTIME
Default "deadtime".
This is our CstringFrame class object - used for holding C-style NULL terminated strings.
Definition: cstringframe.h:36
Project common header file.
Header file defining the data layouts for our Frames.
void(* setint)(ConfigContext *, const char *name, gint value)
Set integer value.
Definition: configcontext.h:75
GHashTable * _values
table of Values
Definition: configcontext.h:73
#define FRAMESETTYPE_SETCONFIG
Initial configuration packet.
Definition: framesettypes.h:53
FSTATIC void frame_default_valuefinalize(gpointer value)
Finalize a Frame.
Definition: frame.c:56
The NetAddr class class represents a general network address - whether IP, MAC, or any other type of ...
Definition: netaddr.h:43
#define FRAMETYPE_HBDEADTIME
FRAMETYPE_HBDEADTIME Frame (frametype 15) Frame subclass - IntFrame class.
Definition: frametypes.h:264
FrameSet * create_setconfig(ConfigContext *cfg)
Create a FRAMESETTYPE_SETCONFIG FrameSet class.
Definition: cmalib.c:111
Frame baseclass
base Frame class object
Definition: intframe.h:40
Describes interfaces to Address Frame (IpPortFrame) C-Class.
void(* setint)(IntFrame *self, guint64 value)
set the integer to the given value
Definition: intframe.h:43
FrameSet class - used for collecting Frames when not on the wire, and for marshalling/demarshalling t...
Definition: frameset.h:45
gchar *(* toString)(gconstpointer)
Produce malloc-ed string representation.
Definition: assimobj.h:58
ConfigContext * configcontext_new(gsize objsize)
Construct a new ConfigContext object - with no values defaulted.
void(* setvalue)(Frame *self, gpointer value, guint32 length, GDestroyNotify valfinal)
member function for setting value
Definition: frame.h:52
#define UNREF2(obj)
Definition: assimobj.h:36
#define UNREF(obj)
Definition: assimobj.h:35
Basic utility functions for the CMA.
WINEXPORT CstringFrame * cstringframe_new(guint16 frame_type, gsize framesize)
Construct a new CstringFrame - allowing for "derived" frame types...
Definition: cstringframe.c:101