FACT++  1.0
cpp_server.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <dis.hxx>
3 #ifndef WIN32
4 #include <unistd.h>
5 #endif
6 using namespace std;
7 #include <string>
8 
9 class ErrorHandler : public DimErrorHandler
10 {
11  void errorHandler(int severity, int code, char *msg)
12  {
13  int index = 0;
14  char **services;
15  if(code){}
16  cout << severity << " " << msg << endl;
17  services = DimServer::getClientServices();
18  cout<< "from "<< DimServer::getClientName() << " services:" << endl;
19  while(services[index])
20  {
21  cout << services[index] << endl;
22  index++;
23  }
24  }
25 public:
27 };
28 
29 class ExitHandler : public DimExitHandler
30 {
31  void exitHandler(int code)
32  {
33  cout << "exit code " << code << endl;
34  }
35 public:
37 };
38 
39 class CmndServ : public DimCommand, public DimTimer
40 {
41  DimService servstr;
43  {
44  int index = 0;
45  char **services;
46  cout << "Command " << getString() << " received" << endl;
47  servstr.updateService(getString());
48  services = DimServer::getClientServices();
49  cout<< "from "<< DimServer::getClientName() << " services:" << endl;
50  while(services[index])
51  {
52  cout << services[index] << endl;
53  index++;
54  }
55  }
56 public :
57  CmndServ() : DimCommand("TEST/CMND","C"),
58  servstr("TEST/STRVAL","empty") {};
59 };
60 
61 /*
62 class CmndServMany : public DimCommand
63 {
64  void commandHandler()
65  {
66  cout << "Command " << getString() << " received" << endl;
67  }
68 public :
69  CmndServMany(char *name) : DimCommand(name,"C") {};
70 };
71 */
72 
73 void add_serv(const int & ival)
74 {
75  DimService *abc;
76 
77  abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
78 }
79 
80 void add_serv_str(const string & s1)
81 {
82  DimService *abc;
83 
84  abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
85 }
86 
87 void add_serv_bool(const bool & boolval)
88 {
90 
91 // serv = new DimService("TEST/BOOLVAL_CONST",(short &)boolval);
92  serv = new DimService("TEST/BOOLVAL_CONST","C:1", (void *)&boolval, 1);
93 }
94 
95 class ServWithHandler : public DimService
96 {
97  int value;
98 
100  {
101  value++;
102 // setData(value);
103  }
104 public :
105  ServWithHandler(char *name) : DimService(name, value) { value = 0;};
106 };
107 
108 int main()
109 {
110  int ival = 0;
111 // ErrorHandler errHandler;
112 // ExitHandler exHandler;
113 // DimServer::setDnsNode("axdes2.cern.ch");
114  string s1;
115  bool boolval;
116  ServWithHandler *testServ;
117  DimServerDns *newDns;
118  char *extraDns;
119 
120  DimServer::start("TEST");
121  extraDns = DimUtil::getEnvVar("EXTRA_DNS_NODE");
122 // newDns = new DimServerDns(extraDns, 0, "new_TEST");
123  newDns = new DimServerDns(extraDns);
124 
125 /*
126  int i, arr[15000];
127  DimService *servp;
128  DimCommand *cmndp;
129  char str[132];
130 */
131 // float farr[4];
132 // DimService *farrp;
133 
134  s1 = "hello";
135  add_serv(ival);
136  DimService servint("TEST/INTVAL",ival);
137  DimService new_servint(newDns, "new_TEST/INTVAL",ival);
138  DimServer::start(newDns, "new_TEST");
139 
140  add_serv_str(s1);
141  boolval = 0;
142  add_serv_bool(boolval);
143  CmndServ cmdsvr;
144 
145  testServ = new ServWithHandler("MY_NEW_TEST_SERVICE_WITH_HANDLER");
146 
147 // farr[0] = 1.2;
148 // farr[1] = 2.3;
149 // farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
150 
151 
152 /*
153 // DimServer::autoStartOff();
154  DimServer::start("TEST");
155 
156  for(i = 0; i < 15000; i++)
157  {
158  arr[i] = i;
159  sprintf(str,"ServiceManyTest/%05d",i);
160  servp = new DimService(str,arr[i]);
161  servp->setQuality(1);
162  servp->updateService(arr[i]);
163 // DimServer::start("TEST");
164  sprintf(str,"CommandManyTest/%05d",i);
165  cmndp = new CmndServMany(str);
166 // DimServer::start("TEST");
167  }
168 */
169 
170  while(1)
171  {
172  sleep(5);
173  s1 = "hello1";
174  if(!boolval)
175  boolval = 1;
176  else
177  boolval = 0;
178  ival++;
179  servint.updateService();
180  new_servint.updateService();
181  }
182  return 0;
183 }
184 
static char * getClientName()
Definition: discpp.cxx:579
int main()
Definition: cpp_server.cxx:108
void exitHandler(int code)
Definition: cpp_server.cxx:31
void add_serv_str(const string &s1)
Definition: cpp_server.cxx:80
DimService * new_servint
Definition: README_v19.txt:381
void add_serv(const int &ival)
Definition: cpp_server.cxx:73
static char * getEnvVar(char *varName)
Definition: dimcpp.cxx:118
STL namespace.
void add_serv_bool(const bool &boolval)
Definition: cpp_server.cxx:87
ServWithHandler(char *name)
Definition: cpp_server.cxx:105
void commandHandler()
Definition: cpp_server.cxx:42
Definition: dis.c:69
int updateService()
Definition: discpp.cxx:1016
void addErrorHandler()
Definition: discpp.cxx:744
static void start()
Definition: discpp.cxx:512
void addExitHandler()
Definition: discpp.cxx:738
void serviceHandler()
Definition: cpp_server.cxx:99
char * extraDns
Definition: README_v19.txt:380
static char ** getClientServices()
Definition: discpp.cxx:601
Definition: dim.hxx:20
void errorHandler(int severity, int code, char *msg)
Definition: cpp_server.cxx:11