XmlRpcDaemon.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002  
00003     Copyright (c) 2004 Media Development Loan Fund
00004   
00005     This file is part of the Campcaster project.
00006     https://www.campware.org/
00007     To report bugs, send an e-mail to [email protected]
00008   
00009     Campcaster is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013    
00014     Campcaster is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018   
00019     You should have received a copy of the GNU General Public License
00020     along with Campcaster; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022   
00023   
00024     Author   : $Author: fgerlits $
00025     Version  : $Revision: 2329 $
00026     Location : $URL: svn://code.campware.org/campcaster/trunk/campcaster/src/products/scheduler/src/XmlRpcDaemon.h $
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 /* ============================================================ include files */
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 /* ================================================================ constants */
00070 
00071 
00072 /* =================================================================== macros */
00073 
00074 
00075 /* =============================================================== data types */
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 /* ================================================= external data structures */
00430 
00431 
00432 /* ====================================================== function prototypes */
00433 
00434 
00435 } // namespace Scheduler
00436 } // namespace LiveSupport
00437 
00438 #endif // XmlRpcDaemon_h
00439  

Generated on Thu Sep 20 02:00:32 2007 for Campcaster by  1.4.7