00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef XmlRpcDaemon_h
00030 #define XmlRpcDaemon_h
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #ifdef HAVE_CONFIG_H
00040 #include "configure.h"
00041 #endif
00042
00043 #if HAVE_SYS_TYPES_H
00044 #include <sys/types.h>
00045 #else
00046 #error "Need sys/types.h"
00047 #endif
00048
00049 #if HAVE_UNISTD_H
00050 #include <unistd.h>
00051 #else
00052 #error "Need unistd.h"
00053 #endif
00054
00055 #include <string>
00056 #include <stdexcept>
00057 #include <libxml++/libxml++.h>
00058 #include <XmlRpc.h>
00059
00060 #include "LiveSupport/Core/Ptr.h"
00061
00062
00063 namespace LiveSupport {
00064 namespace Scheduler {
00065
00066 using namespace XmlRpc;
00067 using namespace LiveSupport::Core;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00124 class XmlRpcDaemon
00125 {
00126 private:
00130 static const std::string configElementNameStr;
00131
00136 std::string xmlRpcHost;
00137
00142 unsigned int xmlRpcPort;
00143
00148 std::string pidFileName;
00149
00154 bool configured;
00155
00161 bool background;
00162
00166 Ptr<XmlRpcServer>::Ref xmlRpcServer;
00167
00175 bool
00176 daemonize(void) throw (std::runtime_error);
00177
00181 void
00182 savePid(void) throw();
00183
00189 pid_t
00190 loadPid(void) throw();
00191
00192 protected:
00196 XmlRpcDaemon (void) throw ()
00197 {
00198 background = true;
00199 configured = false;
00200 xmlRpcServer.reset(new XmlRpcServer());
00201 }
00202
00206 virtual
00207 ~XmlRpcDaemon(void) throw ()
00208 {
00209 }
00210
00218 void
00219 checkForConfiguration(void) const throw (std::logic_error)
00220 {
00221 if (!configured) {
00222 throw std::logic_error("not yet configured");
00223 }
00224 }
00225
00237 void
00238 configureXmlRpcDaemon(const xmlpp::Element & element)
00239 throw (std::invalid_argument,
00240 std::logic_error);
00241
00242
00246 virtual void
00247 registerXmlRpcFunctions(Ptr<XmlRpcServer>::Ref xmlRpcServer)
00248 throw (std::logic_error)
00249 = 0;
00250
00260 virtual void
00261 startup (void) throw (std::logic_error);
00262
00263
00264 public:
00271 static const std::string
00272 getConfigElementName(void) throw ()
00273 {
00274 return configElementNameStr;
00275 }
00276
00285 const bool
00286 isConfigured(void) const throw ()
00287 {
00288 return configured;
00289 }
00290
00297 void
00298 setBackground(const bool background) throw ()
00299 {
00300 this->background = background;
00301 }
00302
00309 const bool
00310 getBackground(void) const throw ()
00311 {
00312 return background;
00313 }
00314
00329 virtual void
00330 configure(const xmlpp::Element & element)
00331 throw (std::invalid_argument,
00332 std::logic_error)
00333 = 0;
00334
00344 const std::string
00345 getXmlRpcHost(void) const throw (std::logic_error)
00346 {
00347 checkForConfiguration();
00348 return xmlRpcHost;
00349 }
00350
00360 const unsigned int
00361 getXmlRpcPort(void) const throw (std::logic_error)
00362 {
00363 checkForConfiguration();
00364 return xmlRpcPort;
00365 }
00366
00374 const std::string
00375 getPidFileName(void) const throw (std::logic_error)
00376 {
00377 checkForConfiguration();
00378 return pidFileName;
00379 }
00380
00387 void
00388 start (void) throw (std::logic_error);
00389
00399 bool
00400 isRunning (void) throw (std::logic_error);
00401
00411 void
00412 stop (void) throw (std::logic_error);
00413
00424 virtual void
00425 shutdown (void) throw (std::logic_error);
00426 };
00427
00428
00429
00430
00431
00432
00433
00434
00435 }
00436 }
00437
00438 #endif // XmlRpcDaemon_h
00439