HomePort
hpd_types.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_TYPES_H
29 #define HOMEPORT_HPD_TYPES_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 typedef char hpd_bool_t;
36 #define HPD_TRUE 1
37 #define HPD_FALSE 0
38 
39 typedef struct hpd hpd_t;
40 typedef struct hpd_module hpd_module_t;
41 typedef struct hpd_action hpd_action_t;
43 typedef struct hpd_adapter hpd_adapter_t;
44 typedef struct hpd_device hpd_device_t;
45 typedef struct hpd_service hpd_service_t;
47 typedef struct hpd_request hpd_request_t;
49 typedef struct hpd_value hpd_value_t;
50 typedef struct hpd_pair hpd_pair_t;
51 typedef struct ev_loop hpd_ev_loop_t;
57 
61 #define HPD_NULL_TERMINATED -1
63 
68 enum hpd_error {
70  HPD_E_SUCCESS = 0, //< The operation was successful.
71  HPD_E_UNKNOWN = 1, //< An unknown error
72  HPD_E_NULL, //< Null pointer error.
73  HPD_E_ALLOC, //< Memory allocation error.
74  HPD_E_STATE, //< An object is in an invalid state.
75  HPD_E_ARGUMENT, //< An argument is invalid.
76  HPD_E_NOT_UNIQUE, //< An argument is not unique.
77  HPD_E_NOT_FOUND, //< The object could not be found.
78 };
80 
85 enum hpd_method {
87  HPD_M_NONE = -1, //< Method that does not exist, must be first below valid methods
88  HPD_M_GET = 0, //< HTTP GET like method
89  HPD_M_PUT, //< HTTP PUT like method
90  HPD_M_COUNT //< Last
91 };
93 
95 
105 #define HPD_HTTP_STATUS_CODE_MAP(XX) \
106  XX(100, Continue) \
107  XX(101, Switching Protocols) \
108  XX(200, OK) \
109  XX(201, Created) \
110  XX(202, Accepted) \
111  XX(203, Non-Authoritative Information) \
112  XX(204, No Content) \
113  XX(205, Reset Content) \
114  XX(206, Partial Content) \
115  XX(300, Multiple Choices) \
116  XX(301, Moved Permanently) \
117  XX(302, Found) \
118  XX(303, See Other) \
119  XX(304, Not Modified) \
120  XX(305, Use Proxy) \
121  XX(306, (Unused)) \
122  XX(307, Temporary Redirect) \
123  XX(400, Bad Request) \
124  XX(401, Unauthorized) \
125  XX(402, Payment Required) \
126  XX(403, Forbidden) \
127  XX(404, Not Found) \
128  XX(405, Method Not Allowed) \
129  XX(406, Not Acceptable) \
130  XX(407, Proxy Authentication Required) \
131  XX(408, Request Timeout) \
132  XX(409, Conflict) \
133  XX(410, Gone) \
134  XX(411, Length Required) \
135  XX(412, Precondition Failed) \
136  XX(413, Request Entity Too Large) \
137  XX(414, Request-URI Too Long) \
138  XX(415, Unsupported Media Type) \
139  XX(416, Requested Range Not Satisfiable) \
140  XX(417, Expectation Failed) \
141  XX(500, Internal Server Error) \
142  XX(501, Not Implemented) \
143  XX(502, Bad Gateway) \
144  XX(503, Service Unavailable) \
145  XX(504, Gateway Timeout) \
146  XX(505, HTTP Version Not Supported)
147 
150 #define XX(num, str) HPD_S_##num = num,
152 #undef XX
153 };
155 
163 };
165 
167 typedef enum hpd_error hpd_error_t;
170 
174 typedef hpd_error_t (*hpd_create_f) (void **data, const hpd_module_t *context);
176 typedef hpd_error_t (*hpd_destroy_f) (void *data);
177 typedef hpd_error_t (*hpd_start_f) (void *data, hpd_t *hpd);
178 typedef hpd_error_t (*hpd_stop_f) (void *data, hpd_t *hpd);
179 typedef hpd_error_t (*hpd_parse_opt_f) (void *data, const char *name, const char *arg);
181 
183 typedef hpd_status_t (*hpd_action_f) (void *data, hpd_request_t *req); //< Action function for handling requests on services.
185 
187 typedef void (*hpd_free_f) (void *data); //< Free function, used to free user supplied data.
189 
192 typedef void (*hpd_response_f) (void *data, const hpd_response_t *res);
194 typedef void (*hpd_value_f) (void *data, const hpd_service_id_t *service, const hpd_value_t *val);
196 typedef void (*hpd_device_f) (void *data, const hpd_device_id_t *device);
198 
205  hpd_parse_opt_f on_parse_opt; //< Should return HPD_E_ARGUMENT if name is not known
206 };
208 
214 static const char * const HPD_ATTR_NETWORK = "network";
216 
222 static const char * const HPD_ATTR_DESC = "description";
223 
229 static const char * const HPD_ATTR_NAME = "name";
230 
236 static const char * const HPD_ATTR_VENDOR = "vendor";
237 
243 static const char * const HPD_ATTR_PRODUCT = "product";
244 
250 static const char * const HPD_ATTR_VERSION = "version";
251 
258 static const char * const HPD_ATTR_LOCATION = "location";
259 
266 static const char * const HPD_ATTR_TYPE = "type";
267 
273 static const char * const HPD_ATTR_UNIT = "unit";
274 
280 static const char * const HPD_ATTR_MAX = "max";
281 
287 static const char * const HPD_ATTR_MIN = "min";
288 
295 static const char * const HPD_ATTR_STEP = "step";
296 
303 static const char * const HPD_ATTR_SCALE = "scale";
304 
310 static const char * const HPD_ATTR_VALUES = "values";
311 
312 static const char * const HPD_ATTR_PROTOCOL = "protocol";
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 
319 #endif //HOMEPORT_HPD_TYPES_H
enum hpd_status hpd_status_t
Definition: hpd_types.h:168
static const char *const HPD_ATTR_UNIT
Default attribute key for units.
Definition: hpd_types.h:273
void(* hpd_free_f)(void *data)
[hpd_action_f]
Definition: hpd_types.h:187
hpd_error_t(* hpd_stop_f)(void *data, hpd_t *hpd)
Definition: hpd_types.h:178
hpd_parse_opt_f on_parse_opt
Definition: hpd_types.h:205
static const char *const HPD_ATTR_LOCATION
Default attribute key for locations.
Definition: hpd_types.h:258
static const char *const HPD_ATTR_MAX
Default attribute key.
Definition: hpd_types.h:280
Definition: map.c:34
static const char *const HPD_ATTR_DESC
Default attribute key for descriptions.
Definition: hpd_types.h:222
enum hpd_log_level hpd_log_level_t
Definition: hpd_types.h:169
static const char *const HPD_ATTR_NETWORK
[hpd_module_def_t]
Definition: hpd_types.h:215
void(* hpd_response_f)(void *data, const hpd_response_t *res)
[hpd_free_f]
Definition: hpd_types.h:192
static const char *const HPD_ATTR_SCALE
Default attribute key.
Definition: hpd_types.h:303
#define HPD_HTTP_STATUS_CODE_MAP(XX)
[hpd_method_t]
Definition: hpd_types.h:105
hpd_error_t(* hpd_start_f)(void *data, hpd_t *hpd)
Definition: hpd_types.h:177
hpd_error
[HPD_NULL_TERMINATED]
Definition: hpd_types.h:69
hpd_error_t(* hpd_parse_opt_f)(void *data, const char *name, const char *arg)
Definition: hpd_types.h:179
static const char *const HPD_ATTR_PROTOCOL
Definition: hpd_types.h:312
static const char *const HPD_ATTR_STEP
Default attribute key.
Definition: hpd_types.h:295
Definition: comm.h:70
static const char *const HPD_ATTR_MIN
Default attribute key.
Definition: hpd_types.h:287
hpd_create_f on_create
Definition: hpd_types.h:201
void(* hpd_device_f)(void *data, const hpd_device_id_t *device)
Device callback for listeners.
Definition: hpd_types.h:196
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
[Application API Callbacks]
Definition: hpd_types.h:200
hpd_status
Definition: hpd_types.h:148
hpd_start_f on_start
Definition: hpd_types.h:203
char hpd_bool_t
Definition: hpd_types.h:35
struct data data
Definition: daemon.h:50
hpd_error_t(* hpd_create_f)(void **data, const hpd_module_t *context)
On failure data should be left as NULL.
Definition: hpd_types.h:175
hpd_status_t(* hpd_action_f)(void *data, hpd_request_t *req)
[hpd_module_def_t functions]
Definition: hpd_types.h:183
static const char *const HPD_ATTR_TYPE
Default attribute key for types.
Definition: hpd_types.h:266
#define XX(num, str)
Definition: hpd_types.h:150
static const char *const HPD_ATTR_VALUES
Default attribute key.
Definition: hpd_types.h:310
hpd_method
[hpd_error_t]
Definition: hpd_types.h:86
void(* hpd_value_f)(void *data, const hpd_service_id_t *service, const hpd_value_t *val)
Value callback for listeners.
Definition: hpd_types.h:194
hpd_error_t(* hpd_destroy_f)(void *data)
Definition: hpd_types.h:176
hpd_log_level
[hpd_status_t]
Definition: hpd_types.h:157
hpd_stop_f on_stop
Definition: hpd_types.h:204
static const char *const HPD_ATTR_VERSION
Default attribute key for versions.
Definition: hpd_types.h:250
struct ev_loop hpd_ev_loop_t
Definition: hpd_types.h:51
static const char *const HPD_ATTR_PRODUCT
Default attribute key for product ids.
Definition: hpd_types.h:243
enum hpd_method hpd_method_t
[hpd_log_level_t]
Definition: hpd_types.h:166
static const char *const HPD_ATTR_NAME
Default attribute key for names.
Definition: hpd_types.h:229
hpd_destroy_f on_destroy
Definition: hpd_types.h:202
static const char *const HPD_ATTR_VENDOR
Default attribute key for vendor ids.
Definition: hpd_types.h:236