HomePort
hpd_shared_api.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_HPD_SHARED_API_H
29 #define HOMEPORT_HPD_SHARED_API_H
30 
31 #include <hpd/hpd_types.h>
32 
33 #include <stddef.h>
34 #include <stdarg.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
41 hpd_error_t hpd_module_add_option(const hpd_module_t *context, const char *name, const char *arg, int flags,
42  const char *doc);
43 hpd_error_t hpd_module_get_id(const hpd_module_t *context, const char **id);
46 
48 hpd_error_t hpd_logf(const hpd_module_t *context, hpd_log_level_t level, const char *file, int line, const char *fmt, ...);
49 hpd_error_t hpd_vlogf(const hpd_module_t *context, hpd_log_level_t level, const char *file, int line, const char *fmt, va_list vp);
50 #define HPD_LOG_ERROR(CONTEXT, FMT, ...) hpd_logf((CONTEXT), HPD_L_ERROR, __FILE__, __LINE__, (FMT), ##__VA_ARGS__)
51 #define HPD_LOG_WARN(CONTEXT, FMT, ...) hpd_logf((CONTEXT), HPD_L_WARN , __FILE__, __LINE__, (FMT), ##__VA_ARGS__)
52 #define HPD_LOG_INFO(CONTEXT, FMT, ...) hpd_logf((CONTEXT), HPD_L_INFO , __FILE__, __LINE__, (FMT), ##__VA_ARGS__)
53 #define HPD_LOG_DEBUG(CONTEXT, FMT, ...) hpd_logf((CONTEXT), HPD_L_DEBUG, __FILE__, __LINE__, (FMT), ##__VA_ARGS__)
54 #define HPD_LOG_VERBOSE(CONTEXT, FMT, ...) hpd_logf((CONTEXT), HPD_L_VERBOSE, __FILE__, __LINE__, (FMT), ##__VA_ARGS__)
55 
56 #define HPD_LOG_RETURN(CONTEXT, E, FMT, ...) do { HPD_LOG_DEBUG((CONTEXT), (FMT), ##__VA_ARGS__); return (E); } while(0)
57 #define HPD_LOG_RETURN_E_NULL(CONTEXT) HPD_LOG_RETURN((CONTEXT), HPD_E_NULL, "Unexpected null pointer.")
58 #define HPD_LOG_RETURN_E_ALLOC(CONTEXT) HPD_LOG_RETURN((CONTEXT), HPD_E_ALLOC, "Unable to allocate memory.")
59 // TODO New function, check if it can be used elsewhere
60 #define HPD_LOG_RETURN_E_SNPRINTF(CONTEXT) HPD_LOG_RETURN((CONTEXT), HPD_E_UNKNOWN, "snprintf failed.")
61 
67 
68 hpd_error_t hpd_device_id_alloc(hpd_device_id_t **id, hpd_t *hpd, const char *aid, const char *did);
71 
72 hpd_error_t hpd_service_id_alloc(hpd_service_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid);
75 
76 hpd_error_t hpd_parameter_id_alloc(hpd_parameter_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid, const char *pid);
80 
82 hpd_error_t hpd_adapter_get_id(const hpd_adapter_id_t *aid, const char **id);
83 hpd_error_t hpd_adapter_get_attr(const hpd_adapter_id_t *id, const char *key, const char **val);
88 
90 hpd_error_t hpd_device_get_id(const hpd_device_id_t *did, const char **id);
91 hpd_error_t hpd_device_get_attr(const hpd_device_id_t *id, const char *key, const char **val);
96 
98 hpd_error_t hpd_service_get_id(const hpd_service_id_t *sid, const char **id);
99 hpd_error_t hpd_service_get_attr(const hpd_service_id_t *id, const char *key, const char **val);
107 
109 hpd_error_t hpd_parameter_get_id(const hpd_parameter_id_t *pid, const char **id);
110 hpd_error_t hpd_parameter_get_attr(const hpd_parameter_id_t *id, const char *key, const char **val);
115 
117 #define hpd_service_foreach_action(RC, ACTION, ID) for ( \
118  (RC) = hpd_service_first_action((ID), &(ACTION)); \
119  !(RC) && (ACTION); \
120  (RC) = hpd_service_next_action(&(ACTION)))
121 #define hpd_adapter_foreach_attr(RC, PAIR, ID) for ( \
122  (RC) = hpd_adapter_first_attr((ID), &(PAIR)); \
123  !(RC) && (PAIR); \
124  (RC) = hpd_adapter_next_attr(&(PAIR)))
125 #define hpd_device_foreach_attr(RC, PAIR, ID) for ( \
126  (RC) = hpd_device_first_attr((ID), &(PAIR)); \
127  !(RC) && (PAIR); \
128  (RC) = hpd_device_next_attr(&(PAIR)))
129 #define hpd_service_foreach_attr(RC, PAIR, ID) for ( \
130  (RC) = hpd_service_first_attr((ID), &(PAIR)); \
131  !(RC) && (PAIR); \
132  (RC) = hpd_service_next_attr(&(PAIR)))
133 #define hpd_parameter_foreach_attr(RC, PAIR, ID) for ( \
134  (RC) = hpd_parameter_first_attr((ID), &(PAIR)); \
135  !(RC) && (PAIR); \
136  (RC) = hpd_parameter_next_attr(&(PAIR)))
137 
142 
144 hpd_error_t hpd_pair_get(const hpd_pair_t *pair, const char **key, const char **value);
146 
147 // TODO Rename get functions to get_alloc ?
159 
167 
176 
178 #define hpd_foreach_adapter(RC, ADAPTER, HPD) for ( \
179  (RC) = hpd_first_adapter((HPD), &(ADAPTER)); \
180  !(RC) && (ADAPTER); \
181  (RC) = hpd_next_adapter(&(ADAPTER)))
182 #define hpd_foreach_device(RC, DEVICE, HPD) for ( \
183  (RC) = hpd_first_device((HPD), &(DEVICE)); \
184  !(RC) && (DEVICE); \
185  (RC) = hpd_next_device(&(DEVICE)))
186 #define hpd_foreach_service(RC, SERVICE, HPD) for ( \
187  (RC) = hpd_first_service((HPD), &(SERVICE)); \
188  !(RC) && (SERVICE); \
189  (RC) = hpd_next_service(&(SERVICE)))
190 #define hpd_adapter_foreach_device(RC, DEVICE, ADAPTER) for ( \
191  (RC) = hpd_adapter_first_device((ADAPTER), &(DEVICE)); \
192  !(RC) && (DEVICE); \
193  (RC) = hpd_adapter_next_device(&(DEVICE)))
194 #define hpd_adapter_foreach_service(RC, SERVICE, ADAPTER) for ( \
195  (RC) = hpd_adapter_first_service((ADAPTER), &(SERVICE)); \
196  !(RC) && (SERVICE); \
197  (RC) = hpd_adapter_next_service(&(SERVICE)))
198 #define hpd_device_foreach_service(RC, SERVICE, DEVICE) for ( \
199  (RC) = hpd_device_first_service((DEVICE), &(SERVICE)); \
200  !(RC) && (SERVICE); \
201  (RC) = hpd_device_next_service(&(SERVICE)))
202 #define hpd_service_foreach_parameter(RC, PARAMETER, SERVICE) for ( \
203  (RC) = hpd_service_first_parameter((SERVICE), &(PARAMETER)); \
204  !(RC) && (PARAMETER); \
205  (RC) = hpd_service_next_parameter(&(PARAMETER)))
206 
209 hpd_error_t hpd_value_alloc(hpd_value_t **value, const char *body, int len);
210 // TODO New function, check if it can be used elsewhere
211 hpd_error_t hpd_value_allocf(hpd_value_t **value, const char *fmt, ...);
212 hpd_error_t hpd_value_vallocf(hpd_value_t **value, const char *fmt, va_list vp);
215 hpd_error_t hpd_value_set_header(hpd_value_t *value, const char *key, const char *val);
217 hpd_error_t hpd_value_get_body(const hpd_value_t *value, const char **body, size_t *len);
218 hpd_error_t hpd_value_get_header(const hpd_value_t *value, const char *key, const char **val);
223 
225 #define hpd_value_foreach_header(RC, PAIR, VALUE) for ( \
226  (RC) = hpd_value_first_header((VALUE), &(PAIR)); \
227  !(RC) && (PAIR); \
228  (RC) = hpd_value_next_header(&(PAIR)))
229 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif //HOMEPORT_HPD_SHARED_API_H
hpd_error_t hpd_adapter_first_device(const hpd_adapter_id_t *adapter_id, hpd_device_id_t **device_id)
hpd_error_t hpd_adapter_first_service(const hpd_adapter_id_t *adapter_id, hpd_service_id_t **service_id)
hpd_error_t hpd_value_set_headers(hpd_value_t *value,...)
Definition: value_api.c:75
hpd_error_t hpd_device_next_attr(hpd_pair_t **pair)
hpd_error_t hpd_next_device(hpd_device_id_t **device_id)
hpd_error_t hpd_service_get_attr(const hpd_service_id_t *id, const char *key, const char **val)
hpd_error_t hpd_adapter_get_attrs(const hpd_adapter_id_t *id,...)
hpd_error_t hpd_service_next_parameter(hpd_parameter_id_t **parameter_id)
hpd_error_t hpd_service_get_adapter(const hpd_service_id_t *sid, hpd_adapter_id_t **aid)
hpd_error_t hpd_adapter_first_attr(const hpd_adapter_id_t *id, hpd_pair_t **pair)
hpd_error_t hpd_service_id_alloc(hpd_service_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid)
Definition: discovery_api.c:70
hpd_error_t hpd_adapter_next_device(hpd_device_id_t **device_id)
hpd_error_t hpd_parameter_id_free(hpd_parameter_id_t *id)
hpd_error_t hpd_parameter_next_attr(hpd_pair_t **pair)
hpd_error_t hpd_value_alloc(hpd_value_t **value, const char *body, int len)
[Browsing foreach loops]
Definition: value_api.c:33
data value
Definition: map.c:34
hpd_error_t hpd_module_add_option(const hpd_module_t *context, const char *name, const char *arg, int flags, const char *doc)
[hpd_t functions]
Definition: daemon_api.c:65
hpd_error_t hpd_value_vallocf(hpd_value_t **value, const char *fmt, va_list vp)
Definition: value_api.c:50
hpd_error_t hpd_value_get_body(const hpd_value_t *value, const char **body, size_t *len)
Definition: value_api.c:87
hpd_error_t hpd_parameter_get_service(const hpd_parameter_id_t *pid, hpd_service_id_t **sid)
hpd_error_t hpd_device_next_service(hpd_service_id_t **service_id)
enum hpd_log_level hpd_log_level_t
Definition: hpd_types.h:169
hpd_error_t hpd_device_id_alloc(hpd_device_id_t **id, hpd_t *hpd, const char *aid, const char *did)
Definition: discovery_api.c:52
hpd_error_t hpd_parameter_get_attr(const hpd_parameter_id_t *id, const char *key, const char **val)
hpd_error_t hpd_vlogf(const hpd_module_t *context, hpd_log_level_t level, const char *file, int line, const char *fmt, va_list vp)
Definition: log_api.c:42
hpd_error_t hpd_adapter_get_attr(const hpd_adapter_id_t *id, const char *key, const char **val)
hpd_error_t hpd_parameter_get_device(const hpd_parameter_id_t *pid, hpd_device_id_t **did)
hpd_error_t hpd_service_first_attr(const hpd_service_id_t *id, hpd_pair_t **pair)
hpd_error_t hpd_value_copy(hpd_value_t **dst, const hpd_value_t *src)
Definition: value_api.c:56
hpd_error_t hpd_adapter_id_alloc(hpd_adapter_id_t **id, hpd_t *hpd, const char *aid)
[log functions]
Definition: discovery_api.c:34
hpd_error_t hpd_pair_get(const hpd_pair_t *pair, const char **key, const char **value)
[hpd_action_t functions]
Definition: map.c:229
hpd_error_t hpd_service_next_action(hpd_action_t **action)
hpd_error_t hpd_adapter_next_service(hpd_service_id_t **service_id)
hpd_error_t hpd_parameter_get_adapter(const hpd_parameter_id_t *pid, hpd_adapter_id_t **aid)
hpd_error_t hpd_value_get_headers(const hpd_value_t *value,...)
Definition: value_api.c:99
hpd_error_t hpd_device_id_copy(hpd_device_id_t **dst, const hpd_device_id_t *src)
Definition: discovery_api.c:58
hpd_error_t hpd_adapter_get_id(const hpd_adapter_id_t *aid, const char **id)
[id_t functions]
hpd_error_t hpd_parameter_get_hpd(const hpd_parameter_id_t *pid, hpd_t **hpd)
hpd_error_t hpd_parameter_get_id(const hpd_parameter_id_t *pid, const char **id)
[hpd_service_t functions]
hpd_error_t hpd_service_id_copy(hpd_service_id_t **dst, const hpd_service_id_t *src)
Definition: discovery_api.c:76
hpd_error_t hpd_service_first_action(const hpd_service_id_t *id, hpd_action_t **action)
hpd_error_t hpd_parameter_first_attr(const hpd_parameter_id_t *id, hpd_pair_t **pair)
hpd_error_t hpd_device_get_id(const hpd_device_id_t *did, const char **id)
[hpd_adapter_t functions]
hpd_error_t hpd_module_get_id(const hpd_module_t *context, const char **id)
Definition: daemon_api.c:79
data key
Definition: comm.h:70
hpd_error_t hpd_service_get_id(const hpd_service_id_t *sid, const char **id)
[hpd_device_t functions]
hpd_error_t hpd_service_next_attr(hpd_pair_t **pair)
hpd_error_t hpd_service_has_action(const hpd_service_id_t *id, const hpd_method_t method, hpd_bool_t *boolean)
hpd_error_t hpd_parameter_get_attrs(const hpd_parameter_id_t *id,...)
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
hpd_error_t hpd_device_get_hpd(const hpd_device_id_t *did, hpd_t **hpd)
hpd_error_t hpd_parameter_id_alloc(hpd_parameter_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid, const char *pid)
Definition: discovery_api.c:89
hpd_error_t hpd_service_get_hpd(const hpd_service_id_t *sid, hpd_t **hpd)
hpd_error_t hpd_adapter_id_copy(hpd_adapter_id_t **dst, const hpd_adapter_id_t *src)
Definition: discovery_api.c:40
hpd_error_t hpd_adapter_next_attr(hpd_pair_t **pair)
hpd_error_t hpd_device_id_free(hpd_device_id_t *id)
Definition: discovery_api.c:64
hpd_error_t hpd_device_first_service(const hpd_device_id_t *device_id, hpd_service_id_t **service_id)
char hpd_bool_t
Definition: hpd_types.h:35
Definition: daemon.h:50
hpd_error_t hpd_first_service(hpd_t *hpd, hpd_service_id_t **service_id)
hpd_error_t hpd_logf(const hpd_module_t *context, hpd_log_level_t level, const char *file, int line, const char *fmt,...)
[hpd_t functions]
Definition: log_api.c:31
static struct ev_loop * loop
hpd_error_t hpd_service_get_device(const hpd_service_id_t *sid, hpd_device_id_t **did)
hpd_error_t hpd_value_next_header(hpd_pair_t **pair)
Definition: value_api.c:117
hpd_error_t hpd_value_free(hpd_value_t *value)
Definition: value_api.c:62
hpd_error_t hpd_device_get_attr(const hpd_device_id_t *id, const char *key, const char **val)
hpd_error_t hpd_action_get_method(const hpd_action_t *action, hpd_method_t *method)
[model foreach loops]
hpd_error_t hpd_first_adapter(hpd_t *hpd, hpd_adapter_id_t **adapter_id)
hpd_error_t hpd_parameter_id_copy(hpd_parameter_id_t **dst, const hpd_parameter_id_t *src)
Definition: discovery_api.c:96
hpd_error_t hpd_value_get_header(const hpd_value_t *value, const char *key, const char **val)
Definition: value_api.c:93
hpd_error_t hpd_first_device(hpd_t *hpd, hpd_device_id_t **device_id)
hpd_error_t hpd_device_first_attr(const hpd_device_id_t *id, hpd_pair_t **pair)
hpd_error_t hpd_adapter_id_free(hpd_adapter_id_t *id)
Definition: discovery_api.c:46
hpd_error_t hpd_device_get_attrs(const hpd_device_id_t *id,...)
hpd_error_t hpd_next_adapter(hpd_adapter_id_t **adapter_id)
hpd_error_t hpd_next_service(hpd_service_id_t **service_id)
hpd_error_t hpd_service_first_parameter(const hpd_service_id_t *service_id, hpd_parameter_id_t **parameter_id)
hpd_error_t hpd_service_get_attrs(const hpd_service_id_t *id,...)
hpd_error_t hpd_value_set_header(hpd_value_t *value, const char *key, const char *val)
Definition: value_api.c:68
hpd_error_t hpd_value_allocf(hpd_value_t **value, const char *fmt,...)
Definition: value_api.c:41
hpd_error_t hpd_service_id_free(hpd_service_id_t *id)
Definition: discovery_api.c:82
struct ev_loop hpd_ev_loop_t
Definition: hpd_types.h:51
hpd_error_t hpd_value_first_header(const hpd_value_t *value, hpd_pair_t **pair)
Definition: value_api.c:111
enum hpd_method hpd_method_t
[hpd_log_level_t]
Definition: hpd_types.h:166
hpd_error_t hpd_device_get_adapter(const hpd_device_id_t *did, hpd_adapter_id_t **aid)
hpd_error_t hpd_get_loop(hpd_t *hpd, hpd_ev_loop_t **loop)
Definition: daemon_api.c:44
hpd_error_t hpd_adapter_get_hpd(const hpd_adapter_id_t *aid, hpd_t **hpd)
[hpd_pair_t functions]