55#if defined(_WIN32) || defined(ICE_DOXYGEN)
95 [[nodiscard]] std::string
name()
const;
105 static void setModuleHandle(HMODULE);
108 void serviceMain(
int,
const wchar_t*
const[]);
120 virtual bool start(
int argc,
char* argv[],
int& status) = 0;
141 virtual void error(
const std::string& msg);
149 virtual void trace(
const std::string& msg);
153 virtual void print(
const std::string& msg);
180 bool _service =
false;
189 void configureService(
const std::string& name);
192 void terminateService(DWORD);
193 bool waitForServiceState(SC_HANDLE, DWORD, SERVICE_STATUS&);
194 void showServiceStatus(
const std::string&, SERVICE_STATUS&);
196 SERVICE_STATUS_HANDLE _statusHandle;
197 std::vector<std::string> _serviceArgs;
207 void configureDaemon(
bool changeDirectory,
bool closeFiles,
const std::string& pidFile);
211 bool _changeDirectory =
true;
212 bool _closeFiles =
true;
213 std::string _pidFile;
Collects output and flushes it via a logger method.
LoggerOutput< Service, Service *, &Service::trace > ServiceTrace
Logger utility class for a trace message.
int main(int argc, const wchar_t *const argv[], InitializationData initData={})
The primary entry point for services.
int main(const StringSeq &args, InitializationData initData={})
The primary entry point for services.
void enableInterrupt()
Makes this service call handleInterrupt when it receives a signal.
virtual bool start(int argc, char *argv[], int &status)=0
Prepares a service for execution, including the creation and activation of object adapters and servan...
void disableInterrupt()
Ignores signals.
int main(int argc, const char *const argv[], InitializationData initData={})
The primary entry point for services.
LoggerOutput< Service, Service *, &Service::error > ServiceError
Logger utility class for an error.
virtual void interrupt()
Notifies the service that the program received a signal.
virtual void warning(const std::string &msg)
Logs a warning.
LoggerOutput< Service, Service *, &Service::warning > ServiceWarning
Logger utility class for a warning.
virtual Ice::CommunicatorPtr initializeCommunicator(int &argc, char *argv[], InitializationData initData)
Initializes a communicator.
virtual void trace(const std::string &msg)
Logs trace information.
virtual bool shutdown()
Shuts down the service. The default implementation calls Communicator::shutdown.
virtual void waitForShutdown()
Blocks until the service shuts down. The default implementation calls Communicator::waitForShutdown.
virtual void print(const std::string &msg)
Logs a literal message.
Ice::CommunicatorPtr communicator() const
Gets the communicator created by the service.
virtual void syserror(const std::string &msg)
Logs a system error, which includes a description of the current system error code.
virtual bool stop()
Cleans up resources after shutting down.
bool service() const
Indicates whether the program is running as a Win32 service or Unix daemon.
virtual void error(const std::string &msg)
Logs an error.
std::string name() const
Gets the program name.
virtual void handleInterrupt(int sig)
Handles a signal.
LoggerOutput< Service, Service *, &Service::syserror > ServiceSysError
Logger utility class for a system error.
Service()
Default constructor.
static Service * instance()
Gets the Service singleton.
LoggerOutput< Service, Service *, &Service::print > ServicePrint
Logger utility class for a literal message.
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
std::shared_ptr< Logger > LoggerPtr
A shared pointer to a Logger.
std::vector< std::string > StringSeq
A sequence of strings.
Represents a set of options that you can specify when initializing a communicator.