diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2009-03-27 15:18:58 +0100 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2009-03-27 15:18:58 +0100 |
commit | f83210c88e7376e12b5cf0e86a073c59e4185efb (patch) | |
tree | 43441baf7060b9385cc7b0316551e1aae21c9af0 | |
parent | 1e30a5d2d995ab51cc27c00917cda37ef24295ff (diff) | |
download | wolfbones-f83210c88e7376e12b5cf0e86a073c59e4185efb.tar.gz wolfbones-f83210c88e7376e12b5cf0e86a073c59e4185efb.tar.bz2 |
started to add usefull Windows service documentation, started with wolf_service_start_console
-rw-r--r-- | docs/service/README | 6 | ||||
-rw-r--r-- | include/wolf/service/service.h | 53 | ||||
-rw-r--r-- | src/service/service.c | 10 | ||||
-rw-r--r-- | tests/service/testservice.c | 4 |
4 files changed, 52 insertions, 21 deletions
diff --git a/docs/service/README b/docs/service/README index 22e3384..c3b6c56 100644 --- a/docs/service/README +++ b/docs/service/README @@ -7,4 +7,8 @@ they don't understand (for instance startup groups and order, service dependencies). We should try to get to a set of service functions as for the daemon. -
\ No newline at end of file + +The normal foreground mode in the console should also be possible +and act on events: + +http://www.codeproject.com/KB/winsdk/console_event_handling.aspx diff --git a/include/wolf/service/service.h b/include/wolf/service/service.h index 1275d0b..2033117 100644 --- a/include/wolf/service/service.h +++ b/include/wolf/service/service.h @@ -67,6 +67,38 @@ typedef struct wolf_service_params_t { */ 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 When the main thread terminates after a service shutdown. + * You should not do much after this point in the code.. + */ +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 */ @@ -77,30 +109,15 @@ typedef enum wolf_service_event_t { * we only get the SERVICE_EVENT_TERMINATE event. * * @param timeout wait at most timeout seconds, then return also - * without an event happening + * 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 */ wolf_service_event_t wolf_service_events_suspend( int timeout, wolf_error_t *error ); -/** - * The main service function. - * - * @param argc number of arguments as in main() - * @param argv arguments as in main() - * - * Note: Must be exported as it gets called from the SCM in a service thread/process. - */ -void WINAPI wolf_service_main( DWORD argc, LPTSTR *argv ); - -void wolf_service_register_main( LPSERVICE_MAIN_FUNCTION service_main ); - -int wolf_service_run( LPTSTR service_name, - wolf_error_t *error ); - - - #ifdef __cplusplus } #endif diff --git a/src/service/service.c b/src/service/service.c index b8471ea..bae331a 100644 --- a/src/service/service.c +++ b/src/service/service.c @@ -353,6 +353,16 @@ wolf_service_event_t wolf_service_events_suspend( int timeout, wolf_error_t *err } } + +wolf_error_t wolf_service_start_console( LPTSTR service_name, + LPSERVICE_MAIN_FUNCTION service_main, + DWORD argc, + LPTSTR *argv ) { + service_main( argc, argv ); + + return WOLF_OK; +} + wolf_error_t wolf_service_start( LPTSTR service_name, LPSERVICE_MAIN_FUNCTION service_main ) { BOOL res; diff --git a/tests/service/testservice.c b/tests/service/testservice.c index dd2cddd..896df51 100644 --- a/tests/service/testservice.c +++ b/tests/service/testservice.c @@ -23,7 +23,7 @@ #define SERVICE_NAME "testservice" #define SERVICE_NAME_DESCR "Wolf Test Service" -static void service_main( DWORD argc, LPTSTR *argv ) { +static void WINAPI service_main( DWORD argc, LPTSTR *argv ) { wolf_error_t error; wolf_service_event_t event = WOLF_SERVICE_NO_EVENT; @@ -88,7 +88,7 @@ void __cdecl _tmain( int argc, TCHAR *argv[] ) { } else if( strcasecmp( argv[1], "/remove" ) == 0 ) { (void)wolf_service_remove( SERVICE_NAME ); } else if( strcasecmp( argv[1], "/foreground" ) == 0 ) { - service_main( argc, argv ); + wolf_service_start_console( SERVICE_NAME, &service_main, argc, argv ); } else { fprintf( stderr, "Illegal option '%s'\r\n", argv[1] ); } |