Belle II Software development
NSMMessage Class Reference
Inheritance diagram for NSMMessage:
Serializable

Public Member Functions

 NSMMessage (const NSMNode &node)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd, int npar, int *pars)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd, int par, const std::string &data)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd, int par)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd, const std::string &data)
 
 NSMMessage (const NSMNode &node, const NSMVar &var)
 
 NSMMessage (const NSMNode &node, const DAQLogMessage &log)
 
 NSMMessage (const NSMNode &node, const DAQLogMessage &log, const NSMCommand &cmd)
 
 NSMMessage (const NSMNode &node, const NSMData &data)
 
 NSMMessage (const NSMCommand &cmd)
 
 NSMMessage (const NSMCommand &cmd, int par)
 
 NSMMessage (const NSMCommand &cmd, int npar, int *pars)
 
 NSMMessage (const NSMNode &node, const NSMCommand &cmd, int npar, int *pars, const std::string &data)
 
 NSMMessage (const NSMCommand &cmd, const std::string &data)
 
 NSMMessage (const NSMVar &var)
 
 NSMMessage (const DAQLogMessage &log)
 
 NSMMessage (const NSMData &data)
 
 NSMMessage (const NSMMessage &msg)
 
const NSMMessageoperator= (const NSMMessage &msg)
 
void init ()
 
void init (const NSMNode &node, const NSMVar &var)
 
void init (const NSMNode &node, const DAQLogMessage &log)
 
void init (const NSMNode &node, const DAQLogMessage &log, const NSMCommand &cmd)
 
void init (const NSMNode &node, const NSMData &data)
 
const char * getRequestName () const
 
const char * getNodeName () const
 
unsigned short getRequestId () const
 
unsigned short getSequenceId () const
 
unsigned short getNodeId () const
 
unsigned short getNParams () const
 
int getParam (int i) const
 
unsigned int * getParams ()
 
const unsigned int * getParams () const
 
unsigned int getLength () const
 
const char * getData () const
 
void setRequestName (const std::string &name)
 
void setRequestName (const NSMCommand &cmd)
 
void setRequestName ()
 
void setNodeName (const std::string &name)
 
void setNodeName (const NSMNode &node)
 
void setRequestId (unsigned short id)
 
void setSequenceId (unsigned short id)
 
void setNodeId (unsigned short id)
 
void setNParams (unsigned short id)
 
void setParam (int i, unsigned int v)
 
void setData (int len, const char *data)
 
void setData (const std::string &text)
 
const NSMVar getVar ()
 
NSMMessage wait (int timeout)
 
void push (const NSMMessage &msg)
 
void readObject (Reader &) override
 
void writeObject (Writer &) const override
 
size_t read (NSMcontext *nsmc)
 
NSMmsggetMsg ()
 

Static Public Attributes

static const unsigned int DATA_SIZE = NSM_TCPDATSIZ
 

Private Member Functions

int try_read (int sock, char *buf, int datalen)
 

Private Attributes

NSMcontextm_nsmc
 
NSMmsg m_nsm_msg
 
Buffer m_data
 
std::string m_nodename
 
std::string m_reqname
 
bool m_hasobj
 
NSMVar m_var
 

Friends

class NSMCommunicator
 

Detailed Description

Definition at line 36 of file NSMMessage.h.

Constructor & Destructor Documentation

◆ NSMMessage() [1/20]

Definition at line 117 of file NSMMessage.cc.

118{
119 init();
120}

◆ NSMMessage() [2/20]

NSMMessage ( const NSMNode node)
explicit

Definition at line 122 of file NSMMessage.cc.

123{
124 init();
125 m_nodename = node.getName();
126}

◆ NSMMessage() [3/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd 
)

Definition at line 128 of file NSMMessage.cc.

130{
131 init();
132 m_nodename = node.getName();
133 m_reqname = cmd.getLabel();
134}

◆ NSMMessage() [4/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd,
int  npar,
int *  pars 
)

Definition at line 136 of file NSMMessage.cc.

139{
140 init();
141 m_nodename = node.getName();
142 m_reqname = cmd.getLabel();
143 m_nsm_msg.npar = npar;
144 memcpy(m_nsm_msg.pars, pars, sizeof(int) * npar);
145}

◆ NSMMessage() [5/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd,
int  par,
const std::string &  data 
)

Definition at line 160 of file NSMMessage.cc.

163{
164 init();
165 m_nodename = node.getName();
166 m_reqname = cmd.getLabel();
167 m_nsm_msg.npar = 1;
168 m_nsm_msg.pars[0] = par;
169 setData(obj);
170}

◆ NSMMessage() [6/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd,
int  par 
)

Definition at line 189 of file NSMMessage.cc.

191{
192 init();
193 m_nodename = node.getName();
194 m_reqname = cmd.getLabel();
195 m_nsm_msg.npar = 1;
196 m_nsm_msg.pars[0] = par;
197}

◆ NSMMessage() [7/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd,
const std::string &  data 
)

Definition at line 199 of file NSMMessage.cc.

202{
203 init();
204 m_nodename = node.getName();
205 m_reqname = cmd.getLabel();
206 setData(data);
207}

◆ NSMMessage() [8/20]

NSMMessage ( const NSMNode node,
const NSMVar var 
)

Definition at line 221 of file NSMMessage.cc.

222{
223 init(node, var);
224}

◆ NSMMessage() [9/20]

NSMMessage ( const NSMNode node,
const DAQLogMessage log 
)

Definition at line 231 of file NSMMessage.cc.

232{
233 init(node, log);
234}

◆ NSMMessage() [10/20]

NSMMessage ( const NSMNode node,
const DAQLogMessage log,
const NSMCommand cmd 
)

Definition at line 236 of file NSMMessage.cc.

238{
239 init(node, log, cmd);
240}

◆ NSMMessage() [11/20]

NSMMessage ( const NSMNode node,
const NSMData data 
)

Definition at line 226 of file NSMMessage.cc.

227{
228 init(node, data);
229}

◆ NSMMessage() [12/20]

NSMMessage ( const NSMCommand cmd)
explicit

Definition at line 209 of file NSMMessage.cc.

210{
211 init();
212 m_reqname = cmd.getLabel();
213}

◆ NSMMessage() [13/20]

NSMMessage ( const NSMCommand cmd,
int  par 
)

Definition at line 172 of file NSMMessage.cc.

174{
175 init();
176 m_reqname = cmd.getLabel();
177 m_nsm_msg.npar = 1;
178 m_nsm_msg.pars[0] = par;
179}

◆ NSMMessage() [14/20]

NSMMessage ( const NSMCommand cmd,
int  npar,
int *  pars 
)

Definition at line 257 of file NSMMessage.cc.

259{
260 init();
261 m_reqname = cmd.getLabel();
262 m_nsm_msg.npar = npar;
263 memcpy(m_nsm_msg.pars, pars, sizeof(int) * npar);
264}

◆ NSMMessage() [15/20]

NSMMessage ( const NSMNode node,
const NSMCommand cmd,
int  npar,
int *  pars,
const std::string &  data 
)

Definition at line 147 of file NSMMessage.cc.

151{
152 init();
153 m_nodename = node.getName();
154 m_reqname = cmd.getLabel();
155 m_nsm_msg.npar = npar;
156 memcpy(m_nsm_msg.pars, pars, sizeof(int) * npar);
157 setData(data);
158}

◆ NSMMessage() [16/20]

NSMMessage ( const NSMCommand cmd,
const std::string &  data 
)

Definition at line 181 of file NSMMessage.cc.

183{
184 init();
185 m_reqname = cmd.getLabel();
186 setData(data);
187}

◆ NSMMessage() [17/20]

NSMMessage ( const NSMVar var)
explicit

Definition at line 242 of file NSMMessage.cc.

243{
244 init(NSMNode(), var);
245}

◆ NSMMessage() [18/20]

NSMMessage ( const DAQLogMessage log)
explicit

Definition at line 252 of file NSMMessage.cc.

253{
254 init(NSMNode(), log);
255}

◆ NSMMessage() [19/20]

NSMMessage ( const NSMData data)
explicit

Definition at line 247 of file NSMMessage.cc.

248{
249 init(NSMNode(), data);
250}

◆ NSMMessage() [20/20]

NSMMessage ( const NSMMessage msg)

Definition at line 215 of file NSMMessage.cc.

216{
217 init();
218 *this = msg;
219}

◆ ~NSMMessage()

virtual ~NSMMessage ( )
inlinevirtual

Definition at line 68 of file NSMMessage.h.

68{ }

Member Function Documentation

◆ getData()

const char * getData ( ) const

Definition at line 388 of file NSMMessage.cc.

389{
390 if (m_nsm_msg.len > 0) return (const char*)m_data.ptr();
391 else return NULL;
392}

◆ getLength()

unsigned int getLength ( ) const

Definition at line 383 of file NSMMessage.cc.

384{
385 return m_nsm_msg.len;
386}

◆ getMsg()

NSMmsg * getMsg ( )
inline

Definition at line 119 of file NSMMessage.h.

119{ return &m_nsm_msg; }

◆ getNodeId()

unsigned short getNodeId ( ) const

Definition at line 345 of file NSMMessage.cc.

346{
347 return m_nsm_msg.node;
348}

◆ getNodeName()

const char * getNodeName ( ) const

Definition at line 326 of file NSMMessage.cc.

327{
328 if (m_nodename.size() > 0) return m_nodename.c_str();
329 if (m_nsmc != NULL)
330 return nsmlib_nodename(m_nsmc, m_nsm_msg.node);
331 else
332 return m_nodename.c_str();
333}

◆ getNParams()

unsigned short getNParams ( ) const

Definition at line 350 of file NSMMessage.cc.

351{
352 return m_nsm_msg.npar;
353}

◆ getParam()

int getParam ( int  i) const

Definition at line 355 of file NSMMessage.cc.

356{
357 return m_nsm_msg.pars[i];
358}

◆ getParams() [1/2]

unsigned int * getParams ( )

Definition at line 376 of file NSMMessage.cc.

377{
378 return m_nsm_msg.pars;
379}

◆ getParams() [2/2]

const unsigned int * getParams ( ) const

Definition at line 371 of file NSMMessage.cc.

372{
373 return m_nsm_msg.pars;
374}

◆ getRequestId()

unsigned short getRequestId ( ) const

Definition at line 335 of file NSMMessage.cc.

336{
337 return m_nsm_msg.req;
338}

◆ getRequestName()

const char * getRequestName ( ) const

Definition at line 281 of file NSMMessage.cc.

282{
283 if (m_reqname.size() > 0) return m_reqname.c_str();
284 if (m_nsmc != NULL) {
285 const char* reqname = nsmlib_reqname(m_nsmc, m_nsm_msg.req);
286 if (reqname != NULL) {
287 m_reqname = reqname;
288 }
289 return m_reqname.c_str();
290 } else {
291 m_reqname = "";
292 return m_reqname.c_str();
293 }
294}

◆ getSequenceId()

unsigned short getSequenceId ( ) const

Definition at line 340 of file NSMMessage.cc.

341{
342 return m_nsm_msg.seq;
343}

◆ init() [1/5]

void init ( )

Definition at line 37 of file NSMMessage.cc.

38{
39 m_nsmc = NULL;
40 memset(&m_nsm_msg, 0, sizeof(NSMmsg));
41 m_hasobj = false;
42}
Definition: nsm2.h:224

◆ init() [2/5]

void init ( const NSMNode node,
const DAQLogMessage log 
)

Definition at line 75 of file NSMMessage.cc.

76{
77 init();
78 m_nodename = node.getName();
79 m_reqname = NSMCommand::LOG.getLabel();
80 setNParams(3);
81 setParam(0, (int)log.getPriority());
82 setParam(1, log.getDateInt());
83 setParam(2, log.getId());
84 setData(log.getMessage());
85}

◆ init() [3/5]

void init ( const NSMNode node,
const DAQLogMessage log,
const NSMCommand cmd 
)

Definition at line 87 of file NSMMessage.cc.

89{
90 init();
91 m_nodename = node.getName();
92 m_reqname = cmd.getLabel();
93 setNParams(3);
94 setParam(0, (int)log.getPriority());
95 setParam(1, log.getDateInt());
96 setParam(2, log.getId());
97 setData(log.getMessage());
98}

◆ init() [4/5]

void init ( const NSMNode node,
const NSMData data 
)

Definition at line 100 of file NSMMessage.cc.

101{
102 init();
103 m_nodename = node.getName();
104 m_reqname = NSMCommand::DATASET.getLabel();
105 setNParams(2);
106 setParam(0, data.getRevision());
107 setParam(1, data.getSize());
108 std::string s = data.getName() + "\n" + data.getFormat();
109 int len = s.size() + 1 + data.getSize();
110 m_nsm_msg.len = len;
111 m_data = Buffer(len);
112 memcpy(m_data.ptr(), s.c_str(), s.size());
113 memcpy(m_data.ptr() + s.size() + 1, data.get(), data.getSize());
114 m_hasobj = false;
115}

◆ init() [5/5]

void init ( const NSMNode node,
const NSMVar var 
)

Definition at line 44 of file NSMMessage.cc.

45{
46 init();
47 m_nodename = node.getName();
48 m_reqname = NSMCommand::VSET.getLabel();
49 m_nsm_msg.npar = 6;
50 m_nsm_msg.pars[0] = (int)var.getType();
51 m_nsm_msg.pars[1] = (int)var.getLength();
52 m_nsm_msg.pars[2] = var.getNode().size();
53 m_nsm_msg.pars[3] = var.getName().size();
54 m_nsm_msg.pars[4] = var.getId();
55 m_nsm_msg.pars[5] = var.getDate();
56 if (var.getType() != NSMVar::NONE) {
57 int size = var.getNode().size() + 1 + var.getName().size() + 1 + var.size();
58 m_data = Buffer(size);
59 char* pdata = (char*)m_data.ptr();
60 memset(pdata, 0, size);
61 memcpy(pdata, var.getNode().c_str(), var.getNode().size());
62 pdata += var.getNode().size();
63 *pdata = '\0';
64 pdata++;
65 memcpy(pdata, var.getName().c_str(), var.getName().size());
66 pdata += var.getName().size();
67 *pdata = '\0';
68 pdata++;
69 memcpy(pdata, var.get(), var.size());
70 m_hasobj = false;
71 m_nsm_msg.len = size;
72 }
73}

◆ operator=()

const NSMMessage & operator= ( const NSMMessage msg)

Definition at line 266 of file NSMMessage.cc.

267{
268 m_nsmc = msg.m_nsmc;
269 memcpy(&m_nsm_msg, &(msg.m_nsm_msg), sizeof(m_nsm_msg));
270 m_nsm_msg.npar = msg.m_nsm_msg.npar;
271 m_nsm_msg.len = msg.m_nsm_msg.len;
272 m_nodename = msg.m_nodename;
273 m_reqname = msg.m_reqname;
274 m_hasobj = msg.m_hasobj;
275 //m_data = msg.m_data;
276 m_data = Buffer(m_nsm_msg.len);
277 memcpy(m_data.ptr(), msg.m_data.ptr(), m_nsm_msg.len);
278 return *this;
279}

◆ read()

size_t read ( NSMcontext nsmc)

Definition at line 448 of file NSMMessage.cc.

449{
450 if (nsmc == NULL) return 0;
451 m_nsmc = nsmc;
452 int sock = nsmc->sock;
453 size_t count = 0;
454 int ret = 0;
455 NSMtcphead hp;
456 int datalen = sizeof(NSMtcphead);
457 if ((ret = try_read(sock, (char*)&hp, datalen)) < 0) {
458 throw (NSMHandlerException("Failed to read header"));
459 }
460 count += ret;
461 m_nsm_msg.req = ntohs(hp.req);
462 m_nsm_msg.seq = ntohs(hp.seq);
463 m_nsm_msg.node = ntohs(hp.src);
464 m_nsm_msg.npar = hp.npar;
465 m_nsm_msg.len = ntohs(hp.len);
466 m_nsm_msg.pars[0] = m_nsm_msg.pars[1] = 0;
467
468 datalen = sizeof(int32) * m_nsm_msg.npar;
469 if (datalen > 0) {
470 if ((ret = try_read(sock, (char*)(m_nsm_msg.pars), datalen)) < 0) {
471 throw (NSMHandlerException("Failed to read params"));
472 }
473 count += ret;
474 for (int i = 0; i < m_nsm_msg.npar; i++) {
475 m_nsm_msg.pars[i] = ntohl(m_nsm_msg.pars[i]);
476 }
477 }
478
479 datalen = m_nsm_msg.len;
480 if (datalen > 0) {
481 m_data = Buffer(datalen);
482 if ((ret = try_read(sock, (char*)m_data.ptr(), datalen)) < 0) {
483 throw (NSMHandlerException("Failed to read data"));
484 }
485 count += ret;
486 }
487 return count;
488}

◆ readObject()

void readObject ( Reader reader)
overridevirtual

Implements Serializable.

Definition at line 490 of file NSMMessage.cc.

491{
492 setRequestName(reader.readString());
493 setNodeName(reader.readString());
494 setNParams(reader.readInt());
495 for (int i = 0; i < getNParams(); i++) {
496 setParam(i, reader.readInt());
497 }
498 size_t len = reader.readInt();
499 m_nsm_msg.len = len;
500 if (len > 0) {
501 m_data = Buffer(len);
502 reader.read(m_data.ptr(), len);
503 }
504}

◆ setData() [1/2]

void setData ( const std::string &  text)

Definition at line 429 of file NSMMessage.cc.

430{
431 setData(text.size() + 1, text.c_str());
432}

◆ setData() [2/2]

void setData ( int  len,
const char *  data 
)

Definition at line 419 of file NSMMessage.cc.

420{
421 m_nsm_msg.len = len;
422 if (len > 0 && data != NULL) {
423 m_data = Buffer(len);
424 memcpy(m_data.ptr(), data, len);
425 }
426 m_hasobj = false;
427}

◆ setNodeId()

void setNodeId ( unsigned short  id)

Definition at line 404 of file NSMMessage.cc.

405{
406 m_nsm_msg.node = id;
407}

◆ setNodeName() [1/2]

void setNodeName ( const NSMNode node)

Definition at line 321 of file NSMMessage.cc.

322{
323 m_nodename = node.getName();
324}

◆ setNodeName() [2/2]

void setNodeName ( const std::string &  name)

Definition at line 316 of file NSMMessage.cc.

317{
318 m_nodename = nodename;
319}

◆ setNParams()

void setNParams ( unsigned short  id)

Definition at line 409 of file NSMMessage.cc.

410{
411 m_nsm_msg.npar = npar;
412}

◆ setParam()

void setParam ( int  i,
unsigned int  v 
)

Definition at line 414 of file NSMMessage.cc.

415{
416 m_nsm_msg.pars[i] = v;
417}

◆ setRequestId()

void setRequestId ( unsigned short  id)

Definition at line 394 of file NSMMessage.cc.

395{
396 m_nsm_msg.req = id;
397}

◆ setRequestName() [1/3]

void setRequestName ( )

Definition at line 296 of file NSMMessage.cc.

297{
298 if (m_nsmc != NULL) {
299 const char* reqname = nsmlib_reqname(m_nsmc, m_nsm_msg.req);
300 if (reqname != NULL) {
301 m_reqname = reqname;
302 }
303 }
304}

◆ setRequestName() [2/3]

void setRequestName ( const NSMCommand cmd)

Definition at line 311 of file NSMMessage.cc.

312{
313 m_reqname = cmd.getLabel();
314}

◆ setRequestName() [3/3]

void setRequestName ( const std::string &  name)

Definition at line 306 of file NSMMessage.cc.

307{
308 m_reqname = reqname;
309}

◆ setSequenceId()

void setSequenceId ( unsigned short  id)

Definition at line 399 of file NSMMessage.cc.

400{
401 m_nsm_msg.seq = id;
402}

◆ try_read()

int try_read ( int  sock,
char *  buf,
int  datalen 
)
private

Definition at line 434 of file NSMMessage.cc.

435{
436 int recvlen = 0;
437 while (recvlen < datalen) {
438 int ret;
439 if ((ret = ::read(sock, buf + recvlen, datalen)) <= 0) {
440 if (ret == -1 && errno == EINTR) continue;
441 if (ret < 0) return -1;
442 }
443 recvlen += ret;
444 }
445 return recvlen;
446}

◆ writeObject()

void writeObject ( Writer writer) const
overridevirtual

Implements Serializable.

Definition at line 506 of file NSMMessage.cc.

507{
508 writer.writeString(getRequestName());
509 writer.writeString(getNodeName());
510 writer.writeInt(getNParams());
511 for (int i = 0; i < getNParams(); i++) {
512 writer.writeInt(getParam(i));
513 }
514 if (m_hasobj) {
515 writer.writeInt(-1);
516 } else {
517 writer.writeInt(getLength());
518 }
519 if (getLength() > 0) {
520 writer.write(m_data.ptr(), getLength());
521 }
522}

Friends And Related Function Documentation

◆ NSMCommunicator

friend class NSMCommunicator
friend

Definition at line 38 of file NSMMessage.h.

Member Data Documentation

◆ DATA_SIZE

const unsigned int DATA_SIZE = NSM_TCPDATSIZ
static

Definition at line 41 of file NSMMessage.h.

◆ m_data

Buffer m_data
private

Definition at line 127 of file NSMMessage.h.

◆ m_hasobj

bool m_hasobj
private

Definition at line 130 of file NSMMessage.h.

◆ m_nodename

std::string m_nodename
mutableprivate

Definition at line 128 of file NSMMessage.h.

◆ m_nsm_msg

NSMmsg m_nsm_msg
private

Definition at line 126 of file NSMMessage.h.

◆ m_nsmc

NSMcontext* m_nsmc
mutableprivate

Definition at line 125 of file NSMMessage.h.

◆ m_reqname

std::string m_reqname
mutableprivate

Definition at line 129 of file NSMMessage.h.

◆ m_var

NSMVar m_var
private

Definition at line 131 of file NSMMessage.h.


The documentation for this class was generated from the following files: