Belle II Software development
RFNSM Class Reference
Inheritance diagram for RFNSM:
RFNodeManager

Public Member Functions

 RFNSM (char *nodename, RFServerBase *)
 
void AllocMem (char *format)
 
RfNodeInfoGetNodeInfo ()
 

Static Public Member Functions

static NSMcontextGetContext ()
 

Static Private Member Functions

static void m_Configure (NSMmsg *, NSMcontext *)
 
static void m_UnConfigure (NSMmsg *, NSMcontext *)
 
static void m_Start (NSMmsg *, NSMcontext *)
 
static void m_Stop (NSMmsg *, NSMcontext *)
 
static void m_Pause (NSMmsg *, NSMcontext *)
 
static void m_Resume (NSMmsg *, NSMcontext *)
 
static void m_Restart (NSMmsg *, NSMcontext *)
 
static void m_Status (NSMmsg *, NSMcontext *)
 
static void m_OK (NSMmsg *, NSMcontext *)
 
static void m_ERROR (NSMmsg *, NSMcontext *)
 

Private Attributes

std::string m_nodename
 
std::string m_formatfile
 
RfNodeInfom_info
 

Static Private Attributes

static NSMcontextg_context = 0
 

Detailed Description

Definition at line 61 of file RFNSM.h.

Constructor & Destructor Documentation

◆ RFNSM()

RFNSM ( char *  nodename,
RFServerBase server 
)

Definition at line 34 of file RFNSM.cc.

35{
36
37 // Set debug level
38 // nsmlib_debuglevel ( 1 );
39
40 // Initialize NSM
41 if (!(g_context = b2nsm_init2(nodename, 0, 0, 0, 0))) {
42 //if (!(g_context = b2nsm_init(nodename))) {
43 fprintf(RFNSMOUT, "RFNSM : %s initialization failure, %s\n",
44 nodename, b2nsm_strerror());
45 g_context = 0;
46 }
47 nsmlib_usesig(g_context, 0);
48 m_nodename = nodename;
49
50 // Redirect log message to standard output
51 b2nsm_logging(RFNSMOUT);
52
53 // Set debug
54 nsmlib_debuglevel(0);
55
56 // Register server
57 g_nsmserver = server;
58
59 // Hook server functions to NSM
60 // if (b2nsm_callback("RF_CONFIGURE", m_Configure) < 0) {
61 if (b2nsm_callback("RC_LOAD", m_Configure) < 0) {
62 fprintf(stderr, "RFNSM : %s hooking CONFIGURE failed, %s\n",
63 m_nodename.c_str(), b2nsm_strerror());
64 }
65 // if (b2nsm_callback("RF_UNCONFIGURE", m_UnConfigure) < 0) {
66 if (b2nsm_callback("RC_ABORT", m_UnConfigure) < 0) {
67 fprintf(stderr, "RFNSM : %s hooking UNCONFIGURE failed, %s\n",
68 m_nodename.c_str(), b2nsm_strerror());
69 }
70 // if (b2nsm_callback("RF_START", m_Start) < 0) {
71 if (b2nsm_callback("RC_START", m_Start) < 0) {
72 fprintf(stderr, "RFNSM : %s hooking START failed, %s\n",
73 m_nodename.c_str(), b2nsm_strerror());
74 }
75 // if (b2nsm_callback("RF_STOP", m_Stop) < 0) {
76 if (b2nsm_callback("RC_STOP", m_Stop) < 0) {
77 fprintf(stderr, "RFNSM : %s hooking STOP failed, %s\n",
78 m_nodename.c_str(), b2nsm_strerror());
79 }
80 // if (b2nsm_callback("RF_PAUSE", m_Pause) < 0) {
81 if (b2nsm_callback("RC_PAUSE", m_Pause) < 0) {
82 fprintf(stderr, "RFNSM : %s hooking PAUSE failed, %s\n",
83 m_nodename.c_str(), b2nsm_strerror());
84 }
85 // if (b2nsm_callback("RF_RESUME", m_Resume) < 0) {
86 if (b2nsm_callback("RC_RESUME", m_Resume) < 0) {
87 fprintf(stderr, "RFNSM : %s hooking RESUME failed, %s\n",
88 m_nodename.c_str(), b2nsm_strerror());
89 }
90 // if (b2nsm_callback("RF_RESTART", m_Restart) < 0) {
91 if (b2nsm_callback("RC_RECOVER", m_Restart) < 0) {
92 fprintf(stderr, "RFNSM : %s hooking RESTART failed, %s\n",
93 m_nodename.c_str(), b2nsm_strerror());
94 }
95
96 // Status function
97 if (b2nsm_callback("RC_STATUS", m_Status) < 0) {
98 fprintf(stderr, "RFNSM : %s hooking STATUS failed, %s\n",
99 m_nodename.c_str(), b2nsm_strerror());
100 }
101
102 // Hook communication functions
103 if (b2nsm_callback("OK", m_OK) < 0) {
104 fprintf(stderr, "RFNSM : %s hooking OK failed, %s\n",
105 m_nodename.c_str(), b2nsm_strerror());
106 }
107 if (b2nsm_callback("ERROR", m_ERROR) < 0) {
108 fprintf(stderr, "RFNSM : %s hooking ERROR failed, %s\n",
109 m_nodename.c_str(), b2nsm_strerror());
110 }
111
112 // Node status = Unconfigured
113 RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED);
114}

◆ ~RFNSM()

~RFNSM ( )

Definition at line 116 of file RFNSM.cc.

117{
118}

Member Function Documentation

◆ AllocMem()

void AllocMem ( char *  format)

Definition at line 121 of file RFNSM.cc.

122{
123 printf("AllocMem : format file = %s\n", format);
124 // Allocate shared memory
125 m_info = (RfNodeInfo*)b2nsm_allocmem(m_nodename.c_str(), format,
126 1, 3);
127 if (!m_info) {
128 fprintf(RFNSMOUT, "RFNSM : %s allocmem failure, %s\n",
129 m_nodename.c_str(), b2nsm_strerror());
130 }
131
132 m_formatfile = string(format);
133
134}

◆ GetContext()

static NSMcontext * GetContext ( )
inlinestatic

Definition at line 69 of file RFNSM.h.

69{ return g_context; }

◆ GetNodeInfo()

RfNodeInfo * GetNodeInfo ( )

Definition at line 272 of file RFNSM.cc.

273{
274 return m_info;
275}

◆ m_Configure()

void m_Configure ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 137 of file RFNSM.cc.

138{
139 fflush(stdout);
140 int nsmstate = RFNSM_Status::Instance().get_state();
141 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
142 int stat = g_nsmserver->Configure(msg, ctx);
143 fflush(stdout);
144 if (stat == 0) {
145 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
146 b2nsm_ok(msg, "Configured", NULL);
147 } else {
148 RFNSM_Status::Instance().set_state(nsmstate);
149 b2nsm_error(msg, NULL);
150 }
151}

◆ m_ERROR()

void m_ERROR ( NSMmsg ,
NSMcontext  
)
staticprivate

Definition at line 263 of file RFNSM.cc.

264{
265 RFNSM_Status::Instance().set_flag(-1);
266 // printf ( "ERROR received. m_flag set to -1\n" );
267}

◆ m_OK()

void m_OK ( NSMmsg ,
NSMcontext  
)
staticprivate

Definition at line 254 of file RFNSM.cc.

255{
256 RFNSM_Status& rfs = RFNSM_Status::Instance();
257 int flag = rfs.get_flag();
258 flag++;
259 rfs.set_flag(flag);
260 // printf ( "OK received. flag set to %d\n", flag );
261}

◆ m_Pause()

void m_Pause ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 197 of file RFNSM.cc.

198{
199 int nsmstate = RFNSM_Status::Instance().get_state();
200 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
201 int stat = g_nsmserver->Pause(msg, ctx);
202 if (stat == 0) {
203 RFNSM_Status::Instance().set_state(RFSTATE_IDLE);
204 b2nsm_ok(msg, "Idle", NULL);
205 } else {
206 RFNSM_Status::Instance().set_state(nsmstate);
207 b2nsm_error(msg, NULL);
208 }
209}

◆ m_Restart()

void m_Restart ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 225 of file RFNSM.cc.

226{
227 int nsmstate = RFNSM_Status::Instance().get_state();
228 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
229 int stat = g_nsmserver->Restart(msg, ctx);
230 if (stat == 0) {
231 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
232 b2nsm_ok(msg, "Configured", NULL);
233 } else {
234 RFNSM_Status::Instance().set_state(nsmstate);
235 b2nsm_error(msg, NULL);
236 }
237}

◆ m_Resume()

void m_Resume ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 211 of file RFNSM.cc.

212{
213 int nsmstate = RFNSM_Status::Instance().get_state();
214 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
215 int stat = g_nsmserver->Resume(msg, ctx);
216 if (stat == 0) {
217 RFNSM_Status::Instance().set_state(RFSTATE_RUNNING);
218 b2nsm_ok(msg, "Running", NULL);
219 } else {
220 RFNSM_Status::Instance().set_state(nsmstate);
221 b2nsm_error(msg, NULL);
222 }
223}

◆ m_Start()

void m_Start ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 169 of file RFNSM.cc.

170{
171 int nsmstate = RFNSM_Status::Instance().get_state();
172 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
173 int stat = g_nsmserver->Start(msg, ctx);
174 if (stat == 0) {
175 RFNSM_Status::Instance().set_state(RFSTATE_RUNNING);
176 b2nsm_ok(msg, "Running", NULL);
177 } else {
178 RFNSM_Status::Instance().set_state(nsmstate);
179 b2nsm_error(msg, NULL);
180 }
181}

◆ m_Status()

void m_Status ( NSMmsg msg,
NSMcontext  
)
staticprivate

Definition at line 239 of file RFNSM.cc.

240{
241 /* Old imp
242 int stat = g_nsmserver->Status(msg, ctx);
243 if (stat == 0)
244 b2nsm_ok(msg, "Status", NULL);
245 else
246 b2nsm_error(msg, NULL);
247 */
248 int curstate = RFNSM_Status::Instance().get_state();
249 b2nsm_ok(msg, RFSTATE[curstate].c_str(), NULL);
250
251}

◆ m_Stop()

void m_Stop ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 183 of file RFNSM.cc.

184{
185 int nsmstate = RFNSM_Status::Instance().get_state();
186 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
187 int stat = g_nsmserver->Stop(msg, ctx);
188 if (stat == 0) {
189 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
190 b2nsm_ok(msg, "Stopped", NULL);
191 } else {
192 RFNSM_Status::Instance().set_state(nsmstate);
193 b2nsm_error(msg, NULL);
194 }
195}

◆ m_UnConfigure()

void m_UnConfigure ( NSMmsg msg,
NSMcontext ctx 
)
staticprivate

Definition at line 153 of file RFNSM.cc.

154{
155 fflush(stdout);
156 int nsmstate = RFNSM_Status::Instance().get_state();
157 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
158 int stat = g_nsmserver->UnConfigure(msg, ctx);
159 fflush(stdout);
160 if (stat == 0) {
161 RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED);
162 b2nsm_ok(msg, "Unconfigured", NULL);
163 } else {
164 RFNSM_Status::Instance().set_state(nsmstate);
165 b2nsm_error(msg, NULL);
166 }
167}

Member Data Documentation

◆ g_context

NSMcontext * g_context = 0
staticprivate

Definition at line 75 of file RFNSM.h.

◆ m_formatfile

std::string m_formatfile
private

Definition at line 73 of file RFNSM.h.

◆ m_info

RfNodeInfo* m_info
private

Definition at line 74 of file RFNSM.h.

◆ m_nodename

std::string m_nodename
private

Definition at line 72 of file RFNSM.h.


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