9#include "daq/rfarm/manager/RFNSM.h"
13#include <nsm2/nsmlib2.h>
14#include <nsm2/belle2nsm.h>
19#define RFNSMOUT stdout
41 if (!(g_context = b2nsm_init2(nodename, 0, 0, 0, 0))) {
43 fprintf(RFNSMOUT,
"RFNSM : %s initialization failure, %s\n",
44 nodename, b2nsm_strerror());
47 nsmlib_usesig(g_context, 0);
48 m_nodename = nodename;
51 b2nsm_logging(RFNSMOUT);
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
113 RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED);
121void RFNSM::AllocMem(
char* format)
123 printf(
"AllocMem : format file = %s\n", format);
125 m_info = (
RfNodeInfo*)b2nsm_allocmem(m_nodename.c_str(), format,
128 fprintf(RFNSMOUT,
"RFNSM : %s allocmem failure, %s\n",
129 m_nodename.c_str(), b2nsm_strerror());
132 m_formatfile = string(format);
140 int nsmstate = RFNSM_Status::Instance().get_state();
141 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
142 int stat = g_nsmserver->Configure(msg, ctx);
145 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
146 b2nsm_ok(msg,
"Configured", NULL);
148 RFNSM_Status::Instance().set_state(nsmstate);
149 b2nsm_error(msg, NULL);
156 int nsmstate = RFNSM_Status::Instance().get_state();
157 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
158 int stat = g_nsmserver->UnConfigure(msg, ctx);
161 RFNSM_Status::Instance().set_state(RFSTATE_UNCONFIGURED);
162 b2nsm_ok(msg,
"Unconfigured", NULL);
164 RFNSM_Status::Instance().set_state(nsmstate);
165 b2nsm_error(msg, NULL);
171 int nsmstate = RFNSM_Status::Instance().get_state();
172 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
173 int stat = g_nsmserver->Start(msg, ctx);
175 RFNSM_Status::Instance().set_state(RFSTATE_RUNNING);
176 b2nsm_ok(msg,
"Running", NULL);
178 RFNSM_Status::Instance().set_state(nsmstate);
179 b2nsm_error(msg, NULL);
185 int nsmstate = RFNSM_Status::Instance().get_state();
186 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
187 int stat = g_nsmserver->Stop(msg, ctx);
189 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
190 b2nsm_ok(msg,
"Stopped", NULL);
192 RFNSM_Status::Instance().set_state(nsmstate);
193 b2nsm_error(msg, NULL);
199 int nsmstate = RFNSM_Status::Instance().get_state();
200 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
201 int stat = g_nsmserver->Pause(msg, ctx);
203 RFNSM_Status::Instance().set_state(RFSTATE_IDLE);
204 b2nsm_ok(msg,
"Idle", NULL);
206 RFNSM_Status::Instance().set_state(nsmstate);
207 b2nsm_error(msg, NULL);
213 int nsmstate = RFNSM_Status::Instance().get_state();
214 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
215 int stat = g_nsmserver->Resume(msg, ctx);
217 RFNSM_Status::Instance().set_state(RFSTATE_RUNNING);
218 b2nsm_ok(msg,
"Running", NULL);
220 RFNSM_Status::Instance().set_state(nsmstate);
221 b2nsm_error(msg, NULL);
227 int nsmstate = RFNSM_Status::Instance().get_state();
228 RFNSM_Status::Instance().set_state(RFSTATE_TRANSITION);
229 int stat = g_nsmserver->Restart(msg, ctx);
231 RFNSM_Status::Instance().set_state(RFSTATE_CONFIGURED);
232 b2nsm_ok(msg,
"Configured", NULL);
234 RFNSM_Status::Instance().set_state(nsmstate);
235 b2nsm_error(msg, NULL);
248 int curstate = RFNSM_Status::Instance().get_state();
249 b2nsm_ok(msg, RFSTATE[curstate].c_str(), NULL);
257 int flag = rfs.get_flag();
265 RFNSM_Status::Instance().set_flag(-1);
279RFNSM_Status::RFNSM_Status()
283RFNSM_Status::~RFNSM_Status()
295void RFNSM_Status::set_flag(
int val)
300int RFNSM_Status::get_flag()
305void RFNSM_Status::set_state(
int val)
310int RFNSM_Status::get_state()
Abstract base class for different kinds of events.