HomePort
daemon.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Aalborg University. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY Aalborg University ''AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Aalborg University OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  */
27 
28 #ifndef HOMEPORT_DAEMON_H
29 #define HOMEPORT_DAEMON_H
30 
31 #include "hpd/hpd_types.h"
32 #include "hpd/common/hpd_common.h"
33 #include "hpd/common/hpd_queue.h"
34 #include <ev.h>
35 #include <argp.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
42 typedef struct hpd_modules hpd_modules_t;
43 typedef struct argp_option hpd_argp_option_t;
45 typedef struct hpd_ev_asyncs hpd_ev_asyncs_t;
46 
47 TAILQ_HEAD(hpd_modules, hpd_module);
48 TAILQ_HEAD(hpd_ev_asyncs, hpd_ev_async);
49 
50 struct hpd {
53  ev_signal sigint_watcher;
54  ev_signal sigterm_watcher;
60  const char **option2name;
66  char *argv0;
67 };
68 
69 struct hpd_ev_async {
71  // TODO Using async watches wrongly here, one global watcher (maybe per queue) would be better
72  ev_async watcher;
73  union {
74  hpd_request_t *request;
75  hpd_response_t *response;
76  struct {
77  hpd_t *hpd;
78  union {
79  struct {
80  hpd_service_id_t *service;
82  };
83  hpd_device_id_t *device;
84  };
85  };
86  };
87 };
88 
89 typedef struct hpd_module {
93  char *id;
94  void *data;
95 } hpd_module_t;
96 
99 hpd_error_t daemon_add_module(hpd_t *hpd, const char *id, const hpd_module_def_t *module_def);
100 hpd_error_t daemon_add_option(const hpd_module_t *context, const char *name, const char *arg, int flags,
101  const char *doc);
102 hpd_error_t daemon_start(hpd_t *hpd, int argc, char *argv[]);
103 hpd_error_t daemon_stop(const hpd_t *hpd);
104 hpd_error_t daemon_get_id(const hpd_module_t *context, const char **id);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif //HOMEPORT_DAEMON_H
const hpd_module_t ** option2module
Definition: daemon.h:59
const char ** option2name
Definition: daemon.h:60
hpd_ev_loop_t * loop
Definition: daemon.h:51
TAILQ_ENTRY(hpd_ev_async) HPD_TAILQ_FIELD
hpd_modules_t modules
Definition: daemon.h:55
struct argp_option hpd_argp_option_t
Definition: daemon.h:43
data value
hpd_error_t daemon_start(hpd_t *hpd, int argc, char *argv[])
Definition: daemon.c:446
struct hpd_ev_asyncs hpd_ev_asyncs_t
Definition: daemon.h:45
ev_signal sigterm_watcher
Definition: daemon.h:54
hpd_ev_asyncs_t respond_watchers
Definition: daemon.h:62
#define HPD_TAILQ_FIELD
Definition: hpd_queue.h:37
hpd_argp_option_t * options
Definition: daemon.h:58
int options_count
Definition: daemon.h:57
hpd_error_t daemon_alloc(hpd_t **hpd)
Definition: daemon.c:359
ev_async watcher
Definition: daemon.h:72
hpd_error_t daemon_get_loop(const hpd_t *hpd, hpd_ev_loop_t **loop)
Definition: daemon.c:504
struct hpd_modules hpd_modules_t
Definition: daemon.h:42
hpd_configuration_t * configuration
Definition: daemon.h:52
Definition: comm.h:70
hpd_ev_asyncs_t request_watchers
Definition: daemon.h:61
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
[Application API Callbacks]
Definition: hpd_types.h:200
ev_signal sigint_watcher
Definition: daemon.h:53
hpd_error_t daemon_get_id(const hpd_module_t *context, const char **id)
Definition: daemon.c:498
Definition: daemon.h:50
hpd_error_t daemon_stop(const hpd_t *hpd)
Definition: daemon.c:492
static struct ev_loop * loop
hpd_ev_asyncs_t changed_watchers
Definition: daemon.h:63
hpd_t * hpd
Definition: daemon.h:90
hpd_error_t daemon_add_module(hpd_t *hpd, const char *id, const hpd_module_def_t *module_def)
Definition: daemon.c:394
TAILQ_HEAD(hpd_modules, hpd_module)
hpd_ev_asyncs_t detached_watchers
Definition: daemon.h:65
hpd_ev_asyncs_t attached_watchers
Definition: daemon.h:64
TAILQ_ENTRY(hpd_module) HPD_TAILQ_FIELD
struct ev_loop hpd_ev_loop_t
Definition: hpd_types.h:51
char * argv0
Definition: daemon.h:66
hpd_error_t daemon_free(hpd_t *hpd)
Definition: daemon.c:382
hpd_error_t daemon_add_option(const hpd_module_t *context, const char *name, const char *arg, int flags, const char *doc)
Definition: daemon.c:409
int module_options_count
Definition: daemon.h:56
hpd_module_def_t def
Definition: daemon.h:92