(file) Return to ServerRunStatus.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Service

  1 martin 1.5 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.6 //
  3 martin 1.5 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.6 //
 10 martin 1.5 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.6 //
 17 martin 1.5 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.6 //
 20 martin 1.5 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.6 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.5 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.6 //
 28 martin 1.5 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #ifndef Pegasus_ServerRunStatus_h
 33            #define Pegasus_ServerRunStatus_h
 34            
 35 dave.sudlik 1.2 #ifdef PEGASUS_OS_TYPE_WINDOWS
 36                 #include <windows.h>
 37                 #endif
 38 kumpf       1.1 #include <Pegasus/Common/Config.h>
 39                 #include <Pegasus/Common/String.h>
 40                 #include <Service/Linkage.h>
 41                 
 42                 PEGASUS_NAMESPACE_BEGIN
 43                 
 44 ouyang.jian 1.3 #if defined(PEGASUS_OS_TYPE_WINDOWS)
 45 kumpf       1.1 typedef int PEGASUS_PID_T;
 46                 #else
 47                 typedef pid_t PEGASUS_PID_T;
 48                 #endif
 49                 
 50                 /**
 51                     The ServerRunStatus class is used to manage the run status of a
 52                     server.  It can be used to determine if an instance of the server is
 53                     already running, to kill a running instance, and to indicate that an
 54                     instance is being started.
 55                 
 56                     The implementation varies per platform.  On Unix platforms, a PID file
 57                     is used to record the process ID of the running server.  On Windows,
 58                     an event handle is used and the PID parameters are not meaningful.
 59                 */
 60                 class PEGASUS_SERVICE_LINKAGE ServerRunStatus
 61                 {
 62                 public:
 63                 
 64                     /**
 65                         Constructs a ServerRunStatus instance with the specified server
 66 kumpf       1.1         parameters.
 67                     */
 68                     ServerRunStatus(
 69                         const char* serverName,
 70                         const char* pidFilePath);
 71                 
 72                     /**
 73                         Destructs the ServerRunStatus instance.  On Windows, this
 74                         indicates to the system that this instance of the server is no
 75                         longer running.
 76                     */
 77                     ~ServerRunStatus();
 78                 
 79                     /**
 80                         Determines whether the server is running, based on the parameters
 81                         specified in the constructor.
 82                     */
 83                     Boolean isServerRunning();
 84                 
 85                     /**
 86                         Indicates that this instance of the server is now running.
 87 kumpf       1.1     */
 88                     void setServerRunning();
 89                 
 90                     /**
 91 karl        1.6.8.1         Indicates that this instance of the server is not running.
 92                         */
 93                         void setServerNotRunning();
 94                     
 95                         /**
 96 kumpf       1.1             On platforms that use a PID file, this method allows a parent process
 97                             ID to be specified.  This allows the isServerRunning() method to take
 98                             the parent process into consideration.
 99                         */
100                         void setParentPid(PEGASUS_PID_T parentPid);
101                     
102                         /**
103                             Sends a SIGKILL signal to the running server process on platforms
104                             that support signals.
105                         */
106                         Boolean kill();
107                     
108                     private:
109                     
110                         /**
111                             Determines whether the specified process ID is an instance of the
112                             server specified in the constructor.
113                         */
114                         Boolean _isServerProcess(PEGASUS_PID_T pid);
115                     
116                         const char* _serverName;
117 kumpf       1.4     
118                         /**
119                             The path to the PID file for this server.  The PID of the server
120                             process is written to this file by setServerRunning().  The
121                             isServerRunning() and kill() methods also use this file.
122                             NOTE: The PID file is not used in the Windows implementation.
123                         */
124 kumpf       1.1         const char* _pidFilePath;
125 kumpf       1.4     
126                         /**
127                             Indicates whether this ServerRunStatus instance is for the server that
128                             is actually running.  A call to setServerRunning() sets this to true.
129                             If this flag is true when the ServerRunStatus instance is destructed,
130                             the PID file is removed.
131                         */
132                         Boolean _isRunningServerInstance;
133                     
134 kumpf       1.1         PEGASUS_PID_T _parentPid;
135                     
136                     #ifdef PEGASUS_OS_TYPE_WINDOWS
137                         HANDLE _event;
138                         Boolean _wasAlreadyRunning;
139                     #endif
140                     };
141                     
142                     PEGASUS_NAMESPACE_END
143                     
144                     #endif // Pegasus_ServerRunStatus_h

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2