Cat
serverDim.cpp
Go to the documentation of this file.
1 // $Id: serverDim.cpp,v 1.8 2007/02/05 14:59:08 fmachefe Exp $
2 
3 // Include files
4 
5 #ifdef _NETWORK_
6 #include <dis.hxx>
7 #include <iostream>
8 #ifndef WIN32
9 #include <unistd.h>
10 #endif
11 
12 //CATCore include files
13 #include "Fct.h"
14 #include "CAT.h"
15 
16 //CATCmd include files
17 #include "Interpreter.h"
18 
19 #include "serverDim.h"
20 
21 serverErrorHandler::serverErrorHandler() {
22  DimServer::addErrorHandler(this);
23 }
24 
25 void serverErrorHandler::errorHandler(int severity, int code, char *msg) {
26  int index = 0;
27  char **services;
28  std::cout << severity << " " << msg << std::endl;
29 #ifdef _NETWORK_
30  services = DimServer::getClientServices();
31  std::cout<< "from "<< DimServer::getClientName() << " services:" << std::endl;
32  while(services[index])
33  {
34  std::cout << services[index] << std::endl;
35  index++;
36  }
37 #endif
38 }
39 
40 ExitHandler::ExitHandler() {DimServer::addExitHandler(this);}
41 
42 void ExitHandler::exitHandler(int code){
43  std::cout << "exit code " << code << std::endl;
44 }
45 
46 
47 CmndServ::CmndServ( Interpreter *interpreter ) :
48 #ifdef _NETWORK_
49  DimCommand((application()->name()+"/command").c_str(),
50  "C") {
51 #endif
52  m_interpreter = interpreter;
53 }
54 
55 void CmndServ::commandHandler() {
56 #ifdef _NETWORK_
57  m_command = std::string ( getString() );
58  msgSvc( 0, "",
59  std::string ( DimServer::getClientName() ) + "Cmnd>" +
60  std::string ( m_command ) );
61  start( );
62 #endif
63 }
64 
65 void CmndServ::threadHandler() {
66  // msgSvc(INFO,"thread", m_command);
67  m_interpreter-> ctrl ("");
68  m_interpreter-> cmdline ( true , m_command );
69 }
70 
71 
72 CtrlServ::CtrlServ( Interpreter *interpreter ) :
73 #ifdef _NETWORK_
74  DimCommand((application()->name()+"/control").c_str(),
75  "C") {
76 #endif
77  m_interpreter = interpreter;
78 }
79 
80 void CtrlServ::commandHandler() {
81 #ifdef _NETWORK_
82  m_command = std::string ( getString() );
83  msgSvc( DEBUG , "",
84  std::string ( DimServer::getClientName() ) + "Ctrl>" +
85  std::string ( m_command ) );
86  if ( 0 == m_command.compare("stop") ||
87  0 == m_command.compare("kill") ||
88  0 == m_command.compare("pause") ||
89  0 == m_command.compare("resume") ) {
90  m_interpreter -> ctrl ( m_command ) ;
91  }
92 #endif
93 }
94 
95 Timer::Timer( int time ,
96  DimService* srv) {
97  msgSvc( INFO , "" , "Creating Timer [delay="+
98  itos( time ) +
99  "s]" );
100  m_srv = srv ;
101  m_delay = time ;
102  start( m_delay );
103 };
104 
105 void Timer::timerHandler() {
106  msgSvc( DEBUG , "Timer" , "Timer triggered server update" );
107  m_srv->updateService ();
108  start ( m_delay );
109 }
110 
111 #endif
std::string itos(int)
Definition: Tools.cpp:46
StatusCode start()
Start Service.
Definition: Server.cpp:98
Application * application()
Definition: Tools.cpp:42
StatusCode cmdline(std::vector< std::string >)
Definition: Server.cpp:128
list index
Definition: images.py:1021