Belle II Software development
NSMMessage.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#ifndef _Belle2_NSMMessage_hh
9#define _Belle2_NSMMessage_hh
10
11extern "C" {
12#include <nsm2/nsm2.h>
13}
14
15#include "daq/slc/nsm/NSMCommand.h"
16#include "daq/slc/nsm/NSMNode.h"
17#include "daq/slc/nsm/NSMVar.h"
18
19#include "daq/slc/database/DAQLogMessage.h"
20
21#include <daq/slc/system/Buffer.h>
22
23#include <daq/slc/base/Serializable.h>
24
25#include <string>
26
27namespace Belle2 {
33 class NSMCommunicator;
34 class NSMData;
35
36 class NSMMessage : public Serializable {
37
38 friend class NSMCommunicator;
39
40 public:
41 static const unsigned int DATA_SIZE;
42
43 public:
44 NSMMessage();
45 explicit NSMMessage(const NSMNode& node);
46 NSMMessage(const NSMNode& node, const NSMCommand& cmd);
47 NSMMessage(const NSMNode& node, const NSMCommand& cmd,
48 int npar, int* pars);
49 NSMMessage(const NSMNode& node, const NSMCommand& cmd,
50 int par, const std::string& data);
51 NSMMessage(const NSMNode& node, const NSMCommand& cmd, int par);
52 NSMMessage(const NSMNode& node, const NSMCommand& cmd,
53 const std::string& data);
54 NSMMessage(const NSMNode& node, const NSMVar& var);
55 NSMMessage(const NSMNode& node, const DAQLogMessage& log);
56 NSMMessage(const NSMNode& node, const DAQLogMessage& log, const NSMCommand& cmd);
57 NSMMessage(const NSMNode& node, const NSMData& data);
58 explicit NSMMessage(const NSMCommand& cmd);
59 NSMMessage(const NSMCommand& cmd, int par);
60 NSMMessage(const NSMCommand& cmd, int npar, int* pars);
61 NSMMessage(const NSMNode& node, const NSMCommand& cmd, int npar, int* pars,
62 const std::string& data);
63 NSMMessage(const NSMCommand& cmd, const std::string& data);
64 explicit NSMMessage(const NSMVar& var);
65 explicit NSMMessage(const DAQLogMessage& log);
66 explicit NSMMessage(const NSMData& data);
67 NSMMessage(const NSMMessage& msg);
68 virtual ~NSMMessage() { }
69
70 public:
71 const NSMMessage& operator=(const NSMMessage& msg);
72
73 public:
74 void init();
75 void init(const NSMNode& node, const NSMVar& var);
76 void init(const NSMNode& node, const DAQLogMessage& log);
77 void init(const NSMNode& node, const DAQLogMessage& log, const NSMCommand& cmd);
78 void init(const NSMNode& node, const NSMData& data);
79 const char* getRequestName() const;
80 const char* getNodeName() const;
81 unsigned short getRequestId() const;
82 unsigned short getSequenceId() const;
83 unsigned short getNodeId() const;
84 unsigned short getNParams() const;
85 int getParam(int i) const;
86#if NSM_PACKAGE_VERSION >= 1914
87 int* getParams();
88 const int* getParams() const;
89#else
90 unsigned int* getParams();
91 const unsigned int* getParams() const;
92#endif
93 unsigned int getLength() const;
94 const char* getData() const;
95 void setRequestName(const std::string& name);
96 void setRequestName(const NSMCommand& cmd);
97 void setRequestName();
98 void setNodeName(const std::string& name);
99 void setNodeName(const NSMNode& node);
100 void setRequestId(unsigned short id);
101 void setSequenceId(unsigned short id);
102 void setNodeId(unsigned short id);
103 void setNParams(unsigned short id);
104 void setParam(int i, unsigned int v);
105 void setData(int len, const char* data) ;
106 void setData(const std::string& text) ;
107 const NSMVar getVar();
108
109 public:
110 NSMMessage wait(int timeout);
111 void push(const NSMMessage& msg);
112
113 public:
114 void readObject(Reader&) override;
115 void writeObject(Writer&) const override;
116
117 public:
118 size_t read(NSMcontext* nsmc);
119 NSMmsg* getMsg() { return &m_nsm_msg; }
120
121 private:
122 int try_read(int sock, char* buf, int datalen);
123
124 private:
125 mutable NSMcontext* m_nsmc;
126 NSMmsg m_nsm_msg;
127 Buffer m_data;
128 mutable std::string m_nodename;
129 mutable std::string m_reqname;
130 bool m_hasobj;
131 NSMVar m_var;
132
133 };
134
136};
137
138#endif
Abstract base class for different kinds of events.
Definition: nsm2.h:224