Add Ubuntu Vivid 15.04
[yaz-moved-to-github.git] / src / sc_test.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file sc_test.c
7  * \brief Small test for the Windows Service Control utility
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #ifdef WIN32
14 #include <windows.h>
15 #include <tchar.h>
16 #include <direct.h>
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <yaz/xmalloc.h>
23 #include <yaz/log.h>
24 #include <yaz/sc.h>
25
26 #ifdef WIN32
27
28 /** \brief handle that is used to stop that service should be stopped */
29 HANDLE    default_stop_event = NULL;
30
31 /** \brief stop handler which just signals "stop" */
32 static void default_sc_stop(yaz_sc_t s)
33 {
34     SetEvent(default_stop_event);
35 }
36
37 /** \brief service control main
38     This does not read argc and argv.
39     Real applications would typically do that. It is very important that
40     yaz_sc_running is called before the application starts to operate .
41 */
42 static int default_sc_main(yaz_sc_t s, int argc, char **argv)
43 {
44     default_stop_event = CreateEvent(
45         NULL,    // default security attributes
46         TRUE,    // manual reset event
47         FALSE,   // not signaled
48         NULL);   // no name
49
50     if (default_stop_event == NULL)
51     {
52         return 1;
53     }
54     yaz_sc_running(s);
55     WaitForSingleObject(default_stop_event, INFINITE);
56     return 0;
57 }
58
59 #endif
60
61 /** \brief the system main function */
62 int main(int argc, char **argv)
63 {
64 #ifdef WIN32
65     yaz_sc_t s = yaz_sc_create("yaz_sc_test", "YAZ Service Control Test");
66
67     yaz_sc_program(s, argc, argv, default_sc_main, default_sc_stop);
68
69     yaz_sc_destroy(&s);
70 #else
71     printf("Only on Windows\n");
72 #endif
73     exit(0);
74 }
75 /*
76  * Local variables:
77  * c-basic-offset: 4
78  * c-file-style: "Stroustrup"
79  * indent-tabs-mode: nil
80  * End:
81  * vim: shiftwidth=4 tabstop=8 expandtab
82  */
83