Implemented new Windows Service wrapper (sc).
[yaz-moved-to-github.git] / src / sc_test.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data
3  * See the file LICENSE for details.
4  */
5
6 #ifdef WIN32
7 #include <windows.h>
8 #include <tchar.h>
9 #include <direct.h>
10 #endif
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <yaz/xmalloc.h>
15 #include <yaz/log.h>
16 #include <yaz/sc.h>
17
18 HANDLE    default_stop_event = NULL;
19 static void default_sc_stop(yaz_sc_t s)
20 {
21     SetEvent(default_stop_event);
22 }
23
24 static int default_sc_main(yaz_sc_t s, int argc, char **argv)
25 {
26     default_stop_event = CreateEvent(
27         NULL,    // default security attributes
28         TRUE,    // manual reset event
29         FALSE,   // not signaled
30         NULL);   // no name
31
32     if (default_stop_event == NULL)
33     {
34         return 1;
35     }
36     yaz_sc_running(s);
37     WaitForSingleObject(default_stop_event, INFINITE);
38     return 0;
39 }
40
41
42 int main(int argc, char **argv)
43 {
44     yaz_sc_t s = yaz_sc_create("yaz_sc_test", "YAZ Service Control Test");
45
46     yaz_sc_program(s, argc, argv, default_sc_main, default_sc_stop);
47
48     yaz_sc_destroy(&s);
49     exit(0);
50 }
51 /*
52  * Local variables:
53  * c-basic-offset: 4
54  * indent-tabs-mode: nil
55  * End:
56  * vim: shiftwidth=4 tabstop=8 expandtab
57  */
58