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