HomePort
event_api.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 "daemon.h"
30 #include "hpd/hpd_api.h"
31 #include "event.h"
32 #include "log.h"
33 #include "comm.h"
34 
36 {
37  if (!id || !val) LOG_RETURN_E_NULL();
39  return event_changed(id, val);
40 }
41 
43 {
44  if (!listener || !hpd) LOG_RETURN_E_NULL();
45  return event_alloc_listener(listener, hpd);
46 }
47 
49 {
50  if (!listener) LOG_RETURN_E_NULL();
51  return event_set_listener_data(listener, data, on_free);
52 }
53 
55 {
56  if (!listener) LOG_RETURN_E_NULL();
57  return event_set_value_callback(listener, on_change);
58 }
60 {
61  if (!listener) LOG_RETURN_E_NULL();
62  return event_set_device_callback(listener, on_attach, on_detach);
63 }
64 
66 {
67  if (!listener) LOG_RETURN_E_NULL();
68  if (!listener->on_change && !listener->on_attach && !listener->on_detach)
69  LOG_RETURN(HPD_E_ARGUMENT, "Listener do not contain any callbacks.");
70  if (!listener->hpd->configuration) LOG_RETURN_HPD_STOPPED();
71  return event_subscribe(listener);
72 }
73 
75 {
76  if (!listener) LOG_RETURN_E_NULL();
77  return event_unsubscribe(listener);
78 }
79 
81 {
82  if (!listener || !data) LOG_RETURN_E_NULL();
83  return event_get_listener_data(listener, data);
84 }
85 
87 {
88  if (!listener) LOG_RETURN_E_NULL();
89  if (!listener->on_attach)
90  LOG_RETURN(HPD_E_ARGUMENT, "Listener do not contain an on_attach callback.");
91  return event_foreach_attached(listener);
92 }
hpd_device_id_t device
Definition: discovery.h:49
hpd_error_t event_set_device_callback(hpd_listener_t *listener, hpd_device_f on_attach, hpd_device_f on_detach)
Definition: event.c:67
void(* hpd_free_f)(void *data)
[hpd_action_f]
Definition: hpd_types.h:187
#define LOG_RETURN_E_NULL()
Definition: log.h:50
hpd_ev_loop_t * loop
Definition: daemon.h:51
hpd_device_f on_attach
Definition: comm.h:47
#define LOG_RETURN_HPD_STOPPED()
Definition: log.h:53
hpd_error_t hpd_listener_set_device_callback(hpd_listener_t *listener, hpd_device_f on_attach, hpd_device_f on_detach)
Definition: event_api.c:59
hpd_error_t hpd_changed(const hpd_service_id_t *id, hpd_value_t *val)
[hpd_response_t functions]
Definition: event_api.c:35
hpd_error_t hpd_foreach_attached(const hpd_listener_t *listener)
Definition: event_api.c:86
hpd_t * hpd
Definition: discovery.h:39
hpd_error_t hpd_listener_free(hpd_listener_t *listener)
Definition: event_api.c:74
hpd_t * hpd
Definition: comm.h:44
hpd_error_t hpd_listener_alloc(hpd_listener_t **listener, hpd_t *hpd)
[hpd_response_t functions]
Definition: event_api.c:42
hpd_error_t event_foreach_attached(const hpd_listener_t *listener)
Definition: event.c:96
hpd_error_t event_subscribe(hpd_listener_t *listener)
Definition: event.c:74
hpd_configuration_t * configuration
Definition: daemon.h:52
Definition: comm.h:70
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
hpd_value_f on_change
Definition: comm.h:46
#define LOG_RETURN(E, FMT,...)
Definition: log.h:48
hpd_error_t hpd_subscribe(hpd_listener_t *listener)
Definition: event_api.c:65
Definition: daemon.h:50
hpd_error_t event_unsubscribe(hpd_listener_t *listener)
Definition: event.c:80
hpd_error_t hpd_listener_set_data(hpd_listener_t *listener, void *data, hpd_free_f on_free)
Definition: event_api.c:48
hpd_error_t hpd_listener_set_value_callback(hpd_listener_t *listener, hpd_value_f on_change)
Definition: event_api.c:54
hpd_error_t hpd_listener_get_data(const hpd_listener_t *listener, void **data)
Definition: event_api.c:80
hpd_error_t event_get_listener_data(const hpd_listener_t *listener, void **data)
Definition: event.c:90
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_device_f on_detach
Definition: comm.h:48
hpd_error_t event_set_listener_data(hpd_listener_t *listener, void *data, hpd_free_f on_free)
Definition: event.c:53
hpd_adapter_id_t adapter
Definition: discovery.h:44
hpd_error_t event_set_value_callback(hpd_listener_t *listener, hpd_value_f on_change)
Definition: event.c:61
hpd_error_t event_changed(const hpd_service_id_t *id, hpd_value_t *val)
Definition: event.c:182
hpd_error_t event_alloc_listener(hpd_listener_t **listener, hpd_t *hpd)
Definition: event.c:36