Cat
Server.cpp
Go to the documentation of this file.
1 // $Id: Server.cpp,v 1.10 2007/06/12 11:25:53 fmachefe Exp $
2 // Include files
3 
4 #include <iostream>
5 #ifndef WIN32
6 #include <unistd.h>
7 #endif
8 
9 #include <string>
10 #include <algorithm>
11 #include <time.h>
12 
13 //
14 #include "Application.h"
15 #include "Server.h"
16 
17 //-----------------------------------------------------------------------------
18 // Implementation file for class : Server
19 //
20 // 2005-03-03 : Frédéric Machefert
21 //-----------------------------------------------------------------------------
22 
23 //=============================================================================
24 // Standard constructor, initializes variables
25 //=============================================================================
28 #ifdef _NETWORK_
29  m_updateDelay = 1;
30  m_app->info("Server built.","Server::Server");
31  m_servCmd = new CmndServ ( m_app );
32  m_servCtrl = new CtrlServ ( m_app );
33  m_servTimer = 0;
34  m_servState = 0;
35  m_servConfig = 0;
36 #else
37  m_app->warning("Compilation without NETWORK capabilities","Server::Server");
38 #endif
39 }
40 
41 //=============================================================================
42 // Destructor
43 //=============================================================================
45 #ifdef _NETWORK_
46  delete m_servCmd;
47  delete m_servCtrl;
48  if ( 0 != m_servState ) {
49  delete m_servState;
50  }
51  if ( 0 != m_servTimer ) {
52  delete m_servTimer;
53  }
54  if ( 0 != m_servConfig ) {
55  delete m_servConfig;
56  }
57  m_servCmd = 0;
58  m_servCtrl = 0;
59  m_servTimer = 0;
60  m_servState = 0;
61  m_servConfig = 0;
62 #endif
63 }
64 
65 //=========================================================================
66 //
67 //=========================================================================
69 #ifdef _NETWORK_
70  m_servState->updateService();
71  m_app->debug("Updating state service.","Server::updateState");
72 #else
73  m_app->warning("Updating server services not available (NETWORK mode off).",
74  "Server::updateState");
75  return StatusCode::FAILURE;
76 #endif
77  return StatusCode::SUCCESS;
78 }
79 
80 //=========================================================================
81 //
82 //=========================================================================
84 #ifdef _NETWORK_
85  m_servConfig->updateService();
86  m_app->debug("Updating proc database service.","Server::updateConfig");
87 #else
88  m_app->warning("Updating server services not available (NETWORK mode off).",
89  "Server::updateConfig");
90  return StatusCode::FAILURE;
91 #endif
92  return StatusCode::SUCCESS;
93 }
94 
95 //=========================================================================
96 //
97 //=========================================================================
99 #ifdef _NETWORK_
100  m_app->info("Starting CAT server " + application()->name(),"Server::start");
101  DimServer::start(m_app->name().c_str());
102  std::string str = m_app->name() ;
103  str = m_app->name() ;
104  str.append ("/state");
105  m_servState = new DimService ( str.c_str(),"I:4;C",
106  m_app->state(),
107  sizeof(*(m_app->state())) );
108  m_servTimer = new Timer ( updateDelay() , m_servState );
109  str = application()->name() ;
110  str.append ("/config");
111  m_servConfig = new DimService ( str.c_str(),"C",
112  m_app->config(),
113  sizeof(*(m_app->config())) );
114 
115  m_app->procDb()->startServices();
116 #else
117  m_app->warning("compilation without NETWORK capabilities. Cannot start server.",
118  "Server::star");
119  return StatusCode::FAILURE;
120 #endif
121  return StatusCode::SUCCESS;
122 }
123 
124 
125 //=========================================================================
126 //
127 //=========================================================================
128 StatusCode Server::cmdline ( std::vector < std::string > cmd ){
129  if ( cmd.size()==0){
130  char line[200];
131  std::string tmp;
132  sprintf(line,"Timer [timer] : %i", updateDelay() );
133  m_app->info(line,"Server::cmdline");
134  return StatusCode::SUCCESS;
135  }
136 
137  transform(cmd[0].begin(),cmd[0].end(),cmd[0].begin(),tolower);
138 
139  if (cmd[0].compare("timer")==0){
140  if ( cmd.size() == 2 ) {
141  setUpdateDelay ( atoi(cmd[1].c_str()) );
142  this -> updateConfig();
143  this -> updateState();
144  }
145  this -> updateConfig();
146  this -> updateState();
147  return StatusCode::SUCCESS;
148  }
149  return StatusCode::FAILURE;
150 }
151 
152 //=============================================================================
153 
154 
155 
void info(std::string mymsg)
Definition: Object.h:38
Application * m_app
Definition: Server.h:79
Server(Application *)
Standard constructor.
Definition: Server.cpp:26
virtual ~Server()
Destructor.
Definition: Server.cpp:44
StatusCode start()
Start Service.
Definition: Server.cpp:98
StatusCode updateConfig()
Update Config Service.
Definition: Server.cpp:83
Config * config()
Application * application()
Definition: Tools.cpp:42
StatusCode cmdline(std::vector< std::string >)
Definition: Server.cpp:128
int updateDelay()
Definition: Server.h:54
void debug(std::string mymsg)
Definition: Object.h:37
ProcDataBase * procDb()
Definition: Application.h:111
State * state()
StatusCode updateState()
Update State Service.
Definition: Server.cpp:68
std::string name() const
Definition: Object.h:28
int m_updateDelay
Definition: Server.h:80
void warning(std::string mymsg)
Definition: Object.h:39
void setUpdateDelay(int updateDelay)
Definition: Server.h:41