/* Copyright (C) 2008 Andreas Baumann This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef WOLF_SERVICE_H #define WOLF_SERVICE_H /** * @addtogroup wolf_win32 Windows-specific * @{ */ /** * @addtogroup wolf_service Windows Service * @{ */ /** * @file service.h * @brief helper to write a Windows service * @author Andreas Baumann */ #define WIN32_MEAN_AND_LEAN #include #include "errors.h" #ifdef __cplusplus extern "C" { #endif /** * @brief structure to fill out when creating a Windows service. */ typedef struct wolf_service_params_t { LPCTSTR service_name; /**< internal name of the service (for instance for 'net start "service_name"') */ LPCTSTR service_display_name; /**< the displayed name of the service (for instance shown in the service control application) */ LPCTSTR service_description; /**< the description (as shown in the service control application) */ } wolf_service_params_t; /** * Installs the current binary as a Windows service. * * @param params steers how the service should be created * * @return WOLF_OK if the service was created, or an WOLF_ERR_INTERNAL * (which also gets logged with wolf_log) */ wolf_error_t wolf_service_install( wolf_service_params_t params ); /** * Uninstalls the current binary as a Windows service. * * @param service_name the name of the service to remove from the service infrastructure * * @return WOLF_OK if the service was removed, or an WOLF_ERR_INTERNAL * (which also gets logged with wolf_log) */ wolf_error_t wolf_service_remove( LPCTSTR service_name ); /** * Start the service * * @param service_name the name of the service previously registered with * wolf_service_install * @param service_main the main function (which should implement startup/shutdown * and the main processing loop) * * @return Doesn't return till the service terminates, then it * returns WOLF_OK. * On the other hand if we don't get called as service * we get a WOLF_ERR_INVALID_STATE indicating that the * service is run in the console, in this case you can * call wolf_service_start_console instead of this function. */ wolf_error_t wolf_service_start( LPTSTR service_name, LPSERVICE_MAIN_FUNCTION service_main ); wolf_error_t wolf_service_start_console( LPTSTR service_name, LPSERVICE_MAIN_FUNCTION service_main, DWORD argc, LPTSTR *argv ); /** * @brief events which can happen in a service */ typedef enum wolf_service_event_t { WOLF_SERVICE_NO_EVENT, /**< no event happened */ WOLF_SERVICE_EVENT_TERMINATE /**< terminate the service now */ } wolf_service_event_t; /** * Suspend the current thread till an event happens. At the moment * we only get the SERVICE_EVENT_TERMINATE event. * * @param timeout wait at most timeout seconds, then return also * without an event happening, error is set to * WOLF_ERR_TIMEOUT in this case * @param error WOLF_OK if an event occured, WOLF_ERR_TIMEOUT if * no signal happened after timeout seconds * * @return the event which happened */ typedef wolf_service_event_t (*LPWOLF_SERVICE_SUSPEND_FUNCTION)( int timeout, wolf_error_t *error ); /** * The current version of the suspend function, depends whether we started the service * in the console or really as service */ extern LPWOLF_SERVICE_SUSPEND_FUNCTION wolf_service_events_suspend; #ifdef __cplusplus } #endif /** @} */ /* @addtogroup wolf_service */ /** @} */ /* @addtogroup wolf_win32 */ #endif /* ifndef WOLF_SERVICE_H */