HomePort
discovery_id.c
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 #include "discovery.h"
29 #include "hpd/common/hpd_common.h"
30 #include "daemon.h"
31 #include "log.h"
32 #include "model.h"
33 
38 {
39  id->hpd = hpd;
40  HPD_STR_CPY(id->aid, aid);
41  return HPD_E_SUCCESS;
42 
43  alloc_error:
45 }
46 
50 hpd_error_t discovery_set_did(hpd_device_id_t *id, hpd_t *hpd, const char *aid, const char *did)
51 {
52  hpd_error_t rc;
53  if ((rc = discovery_set_aid(&id->adapter, hpd, aid))) return rc;
54  HPD_STR_CPY(id->did, did);
55  return HPD_E_SUCCESS;
56 
57  alloc_error:
59 }
60 
64 hpd_error_t discovery_set_sid(hpd_service_id_t *id, hpd_t *hpd, const char *aid, const char *did, const char *sid)
65 {
66  hpd_error_t rc;
67  if ((rc = discovery_set_did(&id->device, hpd, aid, did))) return rc;
68  HPD_STR_CPY(id->sid, sid);
69  return HPD_E_SUCCESS;
70 
71  alloc_error:
73 }
74 
78 hpd_error_t discovery_set_pid(hpd_parameter_id_t *id, hpd_t *hpd, const char *aid, const char *did, const char *sid, const char *pid)
79 {
80  hpd_error_t rc;
81  if ((rc = discovery_set_sid(&id->service, hpd, aid, did, sid))) return rc;
82  HPD_STR_CPY(id->pid, pid);
83  return HPD_E_SUCCESS;
84 
85  alloc_error:
87 }
88 
90 {
91  hpd_error_t rc;
93  if ((rc = discovery_set_aid(*id, hpd, aid))) {
94  discovery_free_aid(*id);
95  (*id) = NULL;
96  return rc;
97  }
98  return HPD_E_SUCCESS;
99 
100  alloc_error:
102 }
103 
104 hpd_error_t discovery_alloc_did(hpd_device_id_t **id, hpd_t *hpd, const char *aid, const char *did)
105 {
106  hpd_error_t rc;
107  HPD_CALLOC(*id, 1, hpd_device_id_t);
108  if ((rc = discovery_set_did(*id, hpd, aid, did))) {
109  discovery_free_did(*id);
110  (*id) = NULL;
111  return rc;
112  }
113  return HPD_E_SUCCESS;
114 
115  alloc_error:
117 }
118 
119 hpd_error_t discovery_alloc_sid(hpd_service_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid)
120 {
121  hpd_error_t rc;
122  HPD_CALLOC(*id, 1, hpd_service_id_t);
123  if ((rc = discovery_set_sid(*id, hpd, aid, did, sid))) {
124  discovery_free_sid(*id);
125  (*id) = NULL;
126  return rc;
127  }
128  return HPD_E_SUCCESS;
129 
130  alloc_error:
132 }
133 
134 hpd_error_t discovery_alloc_pid(hpd_parameter_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid,
135  const char *pid)
136 {
137  hpd_error_t rc;
139  if ((rc = discovery_set_pid(*id, hpd, aid, did, sid, pid))) {
140  discovery_free_pid(*id);
141  (*id) = NULL;
142  return rc;
143  }
144  return HPD_E_SUCCESS;
145 
146  alloc_error:
148 }
149 
151 {
152  return discovery_alloc_aid(dst, src->hpd, src->aid);
153 }
154 
156 {
157  return discovery_alloc_did(dst, src->adapter.hpd, src->adapter.aid, src->did);
158 }
159 
161 {
162  return discovery_alloc_sid(dst, src->device.adapter.hpd, src->device.adapter.aid, src->device.did, src->sid);
163 }
164 
166 {
167  return discovery_alloc_pid(dst, src->service.device.adapter.hpd, src->service.device.adapter.aid, src->service.device.did, src->service.sid, src->pid);
168 }
169 
170 
172 {
173  free(id->aid);
174  free(id);
175  return HPD_E_SUCCESS;
176 }
177 
179 {
180  free(id->adapter.aid);
181  free(id->did);
182  free(id);
183  return HPD_E_SUCCESS;
184 }
185 
187 {
188  free(id->device.adapter.aid);
189  free(id->device.did);
190  free(id->sid);
191  free(id);
192  return HPD_E_SUCCESS;
193 }
194 
196 {
198  free(id->service.device.did);
199  free(id->service.sid);
200  free(id->pid);
201  free(id);
202  return HPD_E_SUCCESS;
203 }
204 
205 #define DISCOVERY_FIND_ADAPTER(ID, ADAPTER) do { \
206  (ADAPTER) = NULL; \
207  TAILQ_FOREACH((ADAPTER), &(ID)->hpd->configuration->adapters, HPD_TAILQ_FIELD) \
208  if (strcmp((ADAPTER)->id, (ID)->aid) == 0) break; \
209  if (!(ADAPTER)) return HPD_E_NOT_FOUND; \
210 } while (0)
211 
212 #define DISCOVERY_FIND_DEVICE(ID, DEVICE) do { \
213  hpd_adapter_t *a = NULL; \
214  DISCOVERY_FIND_ADAPTER(&(ID)->adapter, a); \
215  (DEVICE) = NULL; \
216  TAILQ_FOREACH((DEVICE), a->devices, HPD_TAILQ_FIELD) \
217  if (strcmp((DEVICE)->id, (ID)->did) == 0) break; \
218  if (!(DEVICE)) return HPD_E_NOT_FOUND; \
219 } while (0)
220 
221 #define DISCOVERY_FIND_SERVICE(ID, SERVICE) do { \
222  hpd_device_t *d = NULL; \
223  DISCOVERY_FIND_DEVICE(&(ID)->device, d); \
224  (SERVICE) = NULL; \
225  TAILQ_FOREACH((SERVICE), d->services, HPD_TAILQ_FIELD) \
226  if (strcmp((SERVICE)->id, (ID)->sid) == 0) break; \
227  if (!(SERVICE)) return HPD_E_NOT_FOUND; \
228 } while (0)
229 
230 #define DISCOVERY_FIND_PARAMETER(ID, PARAMETER) do { \
231  hpd_service_t *s = NULL; \
232  DISCOVERY_FIND_SERVICE(&(ID)->service, s); \
233  (PARAMETER) = NULL; \
234  TAILQ_FOREACH((PARAMETER), s->parameters, HPD_TAILQ_FIELD) \
235  if (strcmp((PARAMETER)->id, (ID)->pid) == 0) break; \
236  if (!(PARAMETER)) return HPD_E_NOT_FOUND; \
237 } while (0)
238 
240 {
241  DISCOVERY_FIND_ADAPTER(id, *adapter);
242  return HPD_E_SUCCESS;
243 }
244 
246 {
247  DISCOVERY_FIND_DEVICE(id, *device);
248  return HPD_E_SUCCESS;
249 }
250 
252 {
253  DISCOVERY_FIND_SERVICE(id, *service);
254  return HPD_E_SUCCESS;
255 }
256 
258 {
259  DISCOVERY_FIND_PARAMETER(id, *parameter);
260  return HPD_E_SUCCESS;
261 }
262 
264 {
265  (*hpd) = aid->hpd;
266  return HPD_E_SUCCESS;
267 }
268 
270 {
271  (*hpd) = did->adapter.hpd;
272  return HPD_E_SUCCESS;
273 }
274 
276 {
277  return discovery_alloc_aid(aid, did->adapter.hpd, did->adapter.aid);
278 }
279 
281 {
282  (*hpd) = sid->device.adapter.hpd;
283  return HPD_E_SUCCESS;
284 }
285 
287 {
288  return discovery_alloc_aid(aid, sid->device.adapter.hpd, sid->device.adapter.aid);
289 }
290 
292 {
293  return discovery_alloc_did(did, sid->device.adapter.hpd, sid->device.adapter.aid, sid->device.did);
294 }
295 
297 {
298  (*hpd) = pid->service.device.adapter.hpd;
299  return HPD_E_SUCCESS;
300 }
301 
303 {
305 }
306 
308 {
310 }
311 
313 {
315 }
316 
hpd_error_t discovery_copy_did(hpd_device_id_t **dst, const hpd_device_id_t *src)
Definition: discovery_id.c:155
hpd_device_id_t device
Definition: discovery.h:49
hpd_error_t discovery_copy_sid(hpd_service_id_t **dst, const hpd_service_id_t *src)
Definition: discovery_id.c:160
hpd_error_t discovery_get_parameter_hpd(const hpd_parameter_id_t *pid, hpd_t **hpd)
Definition: discovery_id.c:296
hpd_error_t discovery_get_parameter_adapter(const hpd_parameter_id_t *pid, hpd_adapter_id_t **aid)
Definition: discovery_id.c:302
#define HPD_STR_CPY(DST, SRC)
Definition: hpd_common.h:64
hpd_error_t discovery_find_service(const hpd_service_id_t *id, hpd_service_t **service)
Definition: discovery_id.c:251
hpd_service_id_t service
Definition: discovery.h:54
char * sid
Definition: discovery.h:50
#define LOG_RETURN_E_ALLOC()
Definition: log.h:51
hpd_error_t discovery_set_did(hpd_device_id_t *id, hpd_t *hpd, const char *aid, const char *did)
HPD_E_ALLOC: id might be partially updated.
Definition: discovery_id.c:50
hpd_error_t discovery_get_device_hpd(const hpd_device_id_t *did, hpd_t **hpd)
Definition: discovery_id.c:269
#define DISCOVERY_FIND_SERVICE(ID, SERVICE)
Definition: discovery_id.c:221
free(data.url)
hpd_error_t discovery_alloc_pid(hpd_parameter_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid, const char *pid)
Definition: discovery_id.c:134
hpd_t * hpd
Definition: discovery.h:39
hpd_error_t discovery_get_service_adapter(const hpd_service_id_t *sid, hpd_adapter_id_t **aid)
Definition: discovery_id.c:286
hpd_error_t discovery_free_sid(hpd_service_id_t *id)
Definition: discovery_id.c:186
hpd_error_t discovery_get_service_hpd(const hpd_service_id_t *sid, hpd_t **hpd)
Definition: discovery_id.c:280
char * aid
Definition: discovery.h:40
#define HPD_CALLOC(PTR, NUM, CAST)
Allocates and zeros a structure.
Definition: hpd_common.h:44
#define DISCOVERY_FIND_ADAPTER(ID, ADAPTER)
Definition: discovery_id.c:205
hpd_error_t discovery_copy_pid(hpd_parameter_id_t **dst, const hpd_parameter_id_t *src)
Definition: discovery_id.c:165
hpd_error_t discovery_free_aid(hpd_adapter_id_t *id)
Definition: discovery_id.c:171
hpd_error_t discovery_set_sid(hpd_service_id_t *id, hpd_t *hpd, const char *aid, const char *did, const char *sid)
HPD_E_ALLOC: id might be partially updated.
Definition: discovery_id.c:64
hpd_error_t discovery_find_device(const hpd_device_id_t *id, hpd_device_t **device)
Definition: discovery_id.c:245
#define DISCOVERY_FIND_DEVICE(ID, DEVICE)
Definition: discovery_id.c:212
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
hpd_error_t discovery_get_parameter_device(const hpd_parameter_id_t *pid, hpd_device_id_t **did)
Definition: discovery_id.c:307
hpd_error_t discovery_set_aid(hpd_adapter_id_t *id, hpd_t *hpd, const char *aid)
HPD_E_ALLOC: id might be partially updated.
Definition: discovery_id.c:37
hpd_error_t discovery_find_adapter(const hpd_adapter_id_t *id, hpd_adapter_t **adapter)
Definition: discovery_id.c:239
hpd_error_t discovery_free_did(hpd_device_id_t *id)
Definition: discovery_id.c:178
hpd_error_t discovery_copy_aid(hpd_adapter_id_t **dst, const hpd_adapter_id_t *src)
Definition: discovery_id.c:150
char * did
Definition: discovery.h:45
hpd_error_t discovery_free_pid(hpd_parameter_id_t *id)
Definition: discovery_id.c:195
hpd_error_t discovery_get_adapter_hpd(const hpd_adapter_id_t *aid, hpd_t **hpd)
Definition: discovery_id.c:263
#define DISCOVERY_FIND_PARAMETER(ID, PARAMETER)
Definition: discovery_id.c:230
Definition: daemon.h:50
hpd_error_t discovery_alloc_sid(hpd_service_id_t **id, hpd_t *hpd, const char *aid, const char *did, const char *sid)
Definition: discovery_id.c:119
hpd_error_t discovery_find_parameter(const hpd_parameter_id_t *id, hpd_parameter_t **parameter)
Definition: discovery_id.c:257
hpd_error_t discovery_get_device_adapter(const hpd_device_id_t *did, hpd_adapter_id_t **aid)
Definition: discovery_id.c:275
hpd_error_t discovery_alloc_aid(hpd_adapter_id_t **id, hpd_t *hpd, const char *aid)
Definition: discovery_id.c:89
hpd_error_t discovery_alloc_did(hpd_device_id_t **id, hpd_t *hpd, const char *aid, const char *did)
Definition: discovery_id.c:104
hpd_error_t discovery_get_service_device(const hpd_service_id_t *sid, hpd_device_id_t **did)
Definition: discovery_id.c:291
hpd_adapter_id_t adapter
Definition: discovery.h:44
hpd_error_t discovery_get_parameter_service(const hpd_parameter_id_t *pid, hpd_service_id_t **sid)
Definition: discovery_id.c:312
hpd_error_t discovery_set_pid(hpd_parameter_id_t *id, hpd_t *hpd, const char *aid, const char *did, const char *sid, const char *pid)
HPD_E_ALLOC: id might be partially updated.
Definition: discovery_id.c:78