YAZ  5.23.1
sc_test.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
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 
29 HANDLE default_stop_event = NULL;
30 
32 static void default_sc_stop(yaz_sc_t s)
33 {
34  SetEvent(default_stop_event);
35 }
36 
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 
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 
int main(int argc, char **argv)
the system main function
Definition: sc_test.c:62
yaz_sc_t yaz_sc_create(const char *service_name, const char *display_name)
creates service handle
Definition: sc.c:44
int argc
Definition: sc.c:35
int yaz_sc_program(yaz_sc_t s, int argc, char **argv, int(*sc_main)(yaz_sc_t s, int argc, char **argv), void(*sc_stop)(yaz_sc_t s))
registers service controlled program
Definition: sc.c:233
Header for Windows Service Control utility.
void yaz_sc_destroy(yaz_sc_t *s)
frees service control handle
Definition: sc.c:371
char ** argv
Definition: sc.c:36
Definition: sc.c:26
Header for memory handling functions.
void yaz_sc_running(yaz_sc_t s)
signals that sc_main applicatio starts running
Definition: sc.c:226
Logging utility.