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