The Assimilation Monitoring 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  int count = 0;
49 
50  // Put the heartbeat interval in the message (if asked)
51  if (config->getint(config, CONFIGNAME_HBTIME) > 0) {
52  gint hbtime = config->getint(config, CONFIGNAME_HBTIME);
54  intf->setint(intf, hbtime);
55  frameset_append_frame(ret, &intf->baseclass);
56  UNREF2(intf);
57  }
58  // Put the heartbeat deadtime in the message (if asked)
59  if (config->getint(config, CONFIGNAME_DEADTIME) > 0) {
60  gint deadtime = config->getint(config, CONFIGNAME_DEADTIME);
62  intf->setint(intf, deadtime);
63  frameset_append_frame(ret, &intf->baseclass);
64  UNREF2(intf);
65  }
66  // Put the heartbeat warntime in the message (if asked)
67  if (config->getint(config, CONFIGNAME_WARNTIME) > 0) {
68  gint warntime = config->getint(config, CONFIGNAME_WARNTIME);
70  intf->setint(intf, warntime);
71  frameset_append_frame(ret, &intf->baseclass);
72  UNREF2(intf);
73  }
74 
75  // Put all the addresses we were given in the message.
76  for (count=0; count < addrcount; ++count) {
77  IpPortFrame* hbaddr = ipportframe_netaddr_new(FRAMETYPE_IPPORT, &addrs[count]);
78  frameset_append_frame(ret, &hbaddr->baseclass);
79  UNREF2(hbaddr);
80  }
81  return ret;
82 }
83 
84 
90 FrameSet*
92 {
94  GHashTableIter iter;
95  gpointer key;
96  gpointer data;
97 
98  // First we go through the integer values (if any)
99  // Next we go through the string values (if any)
100  // Lastly we go through the NetAddr values (if any)
101 
102  // Integer values
103  if (!cfg->_values) {
104  return NULL;
105  }
106  g_hash_table_iter_init(&iter, cfg->_values);
107  while (g_hash_table_iter_next(&iter, &key, &data)) {
108  char * name = key;
109  CstringFrame* n;
110 
111  switch (cfg->gettype(cfg, key)) {
112  case CFG_INT64:
113  case CFG_STRING:
114  case CFG_NETADDR:
115  break;
116  default: // Completely ignore everything else
117  continue;
118  }
119 
121  // Put the name into the frameset
122  n->baseclass.setvalue(&n->baseclass, g_strdup(name), strlen(name)+1
125  UNREF2(n);
126 
127  // Now put the value in...
128  switch(cfg->gettype(cfg, key)) {
129  case CFG_EEXIST:
130  case CFG_NULL:
131  case CFG_BOOL:
132  case CFG_FLOAT:
133  case CFG_ARRAY:
134  case CFG_CFGCTX:
135  case CFG_FRAME:
136  break; // Ignore these...
137 
138  case CFG_INT64: {
139  gint64 value = cfg->getint(cfg, name);
141  v->setint(v, value);
143  UNREF2(v);
144  break;
145  }
146  case CFG_STRING: {
147  const char * value = cfg->getstring(cfg, name);
149  v->baseclass.setvalue(&v->baseclass, g_strdup(value)
150  , strlen(value)+1, frame_default_valuefinalize);
152  UNREF2(v);
153  break;
154  }
155  case CFG_NETADDR: {
156  NetAddr * value = cfg->getaddr(cfg, name);
159  UNREF2(v);
160  break;
161  }
162  }
163  }
164  return fs;
165 }