diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-26 16:45:25 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-26 16:45:25 +0100 |
commit | cbc6aaca6dd7ac57a6115b3512a85045e51303dd (patch) | |
tree | 266097ae9558c6b16a8bd399d7dbcf85c4096e09 /include | |
parent | 3395731667cfd707bfdfacf9b10abf67f7691ffd (diff) | |
download | wolfbones-cbc6aaca6dd7ac57a6115b3512a85045e51303dd.tar.gz wolfbones-cbc6aaca6dd7ac57a6115b3512a85045e51303dd.tar.bz2 |
started with service.c, now the messages in testservicemsg.dll are a mess..
Diffstat (limited to 'include')
-rw-r--r-- | include/wolf/log/log.h | 5 | ||||
-rw-r--r-- | include/wolf/log/messages.h | 21 | ||||
-rw-r--r-- | include/wolf/service/service.h | 90 |
3 files changed, 113 insertions, 3 deletions
diff --git a/include/wolf/log/log.h b/include/wolf/log/log.h index ae91de2..78e2b63 100644 --- a/include/wolf/log/log.h +++ b/include/wolf/log/log.h @@ -18,8 +18,9 @@ #ifndef WOLF_LOG_H #define WOLF_LOG_H -#include "port/stdbool.h" -#include "port/gettext.h" +#include "port/stdbool.h" /* for bool */ +#include "port/gettext.h" /* for _ */ +#include "port/string.h" /* for strlcpy */ /** * @addtogroup wolf_log Logging diff --git a/include/wolf/log/messages.h b/include/wolf/log/messages.h index d04119e..366f5c0 100644 --- a/include/wolf/log/messages.h +++ b/include/wolf/log/messages.h @@ -50,12 +50,13 @@ #define WOLF_CATEGORY_LOGGER 1 #define WOLF_CATEGORY_DAEMON 2 +#define WOLF_CATEGORY_SERVICE 3 /** * Last internally used category. Applications should define their * own categories starting from WOLF_LAST_INTERNAL_CATEGORY+1. */ -#define WOLF_LAST_INTERNAL_CATEGORY 2 +#define WOLF_LAST_INTERNAL_CATEGORY 3 /* * MESSAGES of category LOGGER @@ -159,6 +160,24 @@ /* for users which extend the daemon, for instance when writting a real daemon */ #define WOLF_MSG_DAEMON_USER_BASE WOLF_MSG_DAEMON_BASE+500 +/* + * MESSAGES of category SERVICE + */ + +#define WOLF_MSG_SERVICE_BASE WOLF_CATEGORY_SERVICE * 1000 + +/* service/service.c */ +#define WOLF_MSG_SERVICE_INSTALLING_SERVICE WOLF_MSG_SERVICE_BASE+1 +#define WOLF_MSG_SERVICE_CANT_OPEN_SCM_FOR_INSTALL WOLF_MSG_SERVICE_BASE+2 +#define WOLF_MSG_SERVICE_CANT_GET_PATH_OF_BINARY WOLF_MSG_SERVICE_BASE+3 +#define WOLF_MSG_SERVICE_CANT_CREATE_SERVICE WOLF_MSG_SERVICE_BASE+4 +#define WOLF_MSG_SERVICE_SERVICE_INSTALLED WOLF_MSG_SERVICE_BASE+5 +#define WOLF_MSG_SERVICE_UNINSTALLING_SERVICE WOLF_MSG_SERVICE_BASE+6 +#define WOLF_MSG_SERVICE_CANT_OPEN_SCM_FOR_UNINSTALL WOLF_MSG_SERVICE_BASE+7 +#define WOLF_MSG_SERVICE_CANT_OPEN_SERVICE WOLF_MSG_SERVICE_BASE+8 +#define WOLF_MSG_SERVICE_CANT_DELETE_SERVICE WOLF_MSG_SERVICE_BASE+9 +#define WOLF_MSG_SERVICE_SERVICE_UNINSTALLED WOLF_MSG_SERVICE_BASE+10 + #ifdef __cplusplus extern "C" { #endif diff --git a/include/wolf/service/service.h b/include/wolf/service/service.h new file mode 100644 index 0000000..1d62474 --- /dev/null +++ b/include/wolf/service/service.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com> + + 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 <http://www.gnu.org/licenses/>. +*/ + +#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 <abaumann@yahoo.com> + */ + +#define WIND32_LEAN_AND_MEAN +#include <windows.h> + +#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_name_descr; /**< the descriptive name of the service (for instance + shown in the event log viewer 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 ); + +typedef enum wolf_service_event_t { + 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 + * @param error WOLF_OK if an event occured, WOLF_ERR_TIMEOUT if + * no signal happened after timeout seconds + * @return the event which happened + */ +wolf_service_event_t wolf_service_events_suspend( int timeout, wolf_error_t *error ); + +#ifdef __cplusplus +} +#endif + +/** @} */ /* @addtogroup wolf_service */ + +/** @} */ /* @addtogroup wolf_win32 */ + +#endif /* ifndef WOLF_SERVICE_H */ |