From: Samuel Ortiz Date: Sat, 2 Jul 2011 00:46:22 +0000 (+0200) Subject: adapter: Call target add instead of the other way around X-Git-Tag: 0.1~127 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd6822b2dd2aa9a1cf3bf5ad50f698cf5d6734db;p=platform%2Fupstream%2Fneard.git adapter: Call target add instead of the other way around This is needed for cleaning all targets when a new poll starts. --- diff --git a/src/adapter.c b/src/adapter.c index f63235b..c5f5257 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -165,8 +165,15 @@ static void append_target(DBusMessageIter *iter, void *user_data) &target_path); } -static void target_changed(struct near_adapter *adapter) +void __near_adapter_target_changed(uint32_t adapter_idx) { + struct near_adapter *adapter; + + adapter = g_hash_table_lookup(adapter_hash, + GINT_TO_POINTER(adapter_idx)); + if (adapter == NULL) + return; + near_dbus_property_changed_array(adapter->path, NFC_ADAPTER_INTERFACE, "Target", DBUS_TYPE_OBJECT_PATH, append_target, @@ -343,23 +350,18 @@ void __near_adapter_remove(struct near_adapter *adapter) static void tag_read_cb(uint32_t adapter_idx, int status) { - struct near_adapter *adapter; - - DBG("%d", status); - if (status < 0) return; - adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(adapter_idx)); - if (adapter == NULL) - return; - - target_changed(adapter); + __near_adapter_target_changed(adapter_idx); } -int __near_adapter_add_target(uint32_t idx, struct near_target *target) +int __near_adapter_add_target(uint32_t idx, uint32_t target_idx, + uint32_t protocols, enum near_target_type type, + uint16_t sens_res, uint8_t sel_res) { struct near_adapter *adapter; + struct near_target *target; DBG("idx %d", idx); @@ -367,12 +369,17 @@ int __near_adapter_add_target(uint32_t idx, struct near_target *target) if (adapter == NULL) return -ENODEV; - /* TODO target reference */ - adapter->target = target; adapter->polling = FALSE; - polling_changed(adapter); + /* TODO target reference */ + target = __near_target_add(idx, target_idx, protocols, type, + sens_res, sel_res); + if (target == NULL) + return -ENODEV; + + adapter->target = target; + __near_tag_read(target, tag_read_cb); return 0; @@ -394,6 +401,8 @@ int __near_adapter_remove_target(uint32_t idx, struct near_target *target) adapter->target = NULL; } + __near_target_remove(target); + return 0; } @@ -602,6 +611,8 @@ int __near_adapter_init(void) void __near_adapter_cleanup(void) { + DBG(""); + g_hash_table_destroy(adapter_hash); adapter_hash = NULL; } diff --git a/src/near.h b/src/near.h index 62b4cb0..e663636 100644 --- a/src/near.h +++ b/src/near.h @@ -68,21 +68,6 @@ void __near_manager_adapter_remove(uint32_t idx); int __near_manager_init(DBusConnection *conn); void __near_manager_cleanup(void); -#include - -struct near_adapter * __near_adapter_create(uint32_t idx, - const char *name, uint32_t protocols); -void __near_adapter_destroy(struct near_adapter *adapter); -const char *__near_adapter_get_path(struct near_adapter *adapter); -struct near_adapter *__near_adapter_get(uint32_t idx); -int __near_adapter_add(struct near_adapter *adapter); -void __near_adapter_remove(struct near_adapter *adapter); -int __near_adapter_add_target(uint32_t idx, struct near_target *target); -int __near_adapter_remove_target(uint32_t idx, struct near_target *target); -void __near_adapter_list(DBusMessageIter *iter, void *user_data); -int __near_adapter_init(void); -void __near_adapter_cleanup(void); - #include enum near_target_type { @@ -95,13 +80,31 @@ uint16_t __near_target_get_tag_type(struct near_target *target); uint32_t __near_target_get_idx(struct near_target *target); uint32_t __near_target_get_adapter_idx(struct near_target *target); uint32_t __near_target_get_protocols(struct near_target *target); -int __near_target_add(uint32_t adapter_idx, uint32_t target_idx, - uint32_t protocols, enum near_target_type type, - uint16_t sens_res, uint8_t sel_res); +struct near_target * __near_target_add(uint32_t adapter_idx, uint32_t target_idx, + uint32_t protocols, enum near_target_type type, + uint16_t sens_res, uint8_t sel_res); void __near_target_remove(struct near_target *target); int __near_target_init(void); void __near_target_cleanup(void); +#include + +struct near_adapter * __near_adapter_create(uint32_t idx, + const char *name, uint32_t protocols); +void __near_adapter_destroy(struct near_adapter *adapter); +const char *__near_adapter_get_path(struct near_adapter *adapter); +struct near_adapter *__near_adapter_get(uint32_t idx); +int __near_adapter_add(struct near_adapter *adapter); +void __near_adapter_remove(struct near_adapter *adapter); +int __near_adapter_add_target(uint32_t idx, uint32_t target_idx, + uint32_t protocols, enum near_target_type type, + uint16_t sens_res, uint8_t sel_res); +int __near_adapter_remove_target(uint32_t idx, struct near_target *target); +void __near_adapter_target_changed(uint32_t adapter_idx); +void __near_adapter_list(DBusMessageIter *iter, void *user_data); +int __near_adapter_init(void); +void __near_adapter_cleanup(void); + #include int __near_ndef_init(void); diff --git a/src/netlink.c b/src/netlink.c index 8501761..208a4a9 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -312,7 +312,7 @@ static int get_targets_handler(struct nl_msg *n, void *arg) DBG("target idx %d proto 0x%x sens_res 0x%x sel_res 0x%x", target_idx, protocols, sens_res, sel_res); - __near_target_add(adapter_idx, target_idx, protocols, + __near_adapter_add_target(adapter_idx, target_idx, protocols, NEAR_TARGET_TYPE_TAG, sens_res, sel_res); return 0; diff --git a/src/target.c b/src/target.c index d561ba8..5e74369 100644 --- a/src/target.c +++ b/src/target.c @@ -53,9 +53,10 @@ static void free_target(gpointer data) { struct near_target *target = data; + DBG(""); + if (target->tag != NULL) __near_tag_free(target->tag); - g_free(target->path); g_free(target); } @@ -324,9 +325,9 @@ static void find_tag_type(struct near_target *target, DBG("tag type 0x%x", target->tag_type); } -int __near_target_add(uint32_t adapter_idx, uint32_t target_idx, - uint32_t protocols, enum near_target_type type, - uint16_t sens_res, uint8_t sel_res) +struct near_target *__near_target_add(uint32_t adapter_idx, uint32_t target_idx, + uint32_t protocols, enum near_target_type type, + uint16_t sens_res, uint8_t sel_res) { struct near_target *target; char *path; @@ -335,14 +336,14 @@ int __near_target_add(uint32_t adapter_idx, uint32_t target_idx, adapter_idx, target_idx); if (path == NULL) - return -ENOMEM; + return NULL; if (g_hash_table_lookup(target_hash, path) != NULL) - return -EEXIST; + return NULL; target = g_try_malloc0(sizeof(struct near_target)); if (target == NULL) - return -ENOMEM; + return NULL; target->path = path; target->idx = target_idx; @@ -360,7 +361,7 @@ int __near_target_add(uint32_t adapter_idx, uint32_t target_idx, target_methods, target_signals, NULL, target, NULL); - return __near_adapter_add_target(adapter_idx, target); + return target; } void __near_target_remove(struct near_target *target) @@ -368,8 +369,6 @@ void __near_target_remove(struct near_target *target) if (g_hash_table_lookup(target_hash, target->path) == NULL) return; - __near_adapter_remove_target(target->adapter_idx, target); - g_dbus_unregister_interface(connection, target->path, NFC_TARGET_INTERFACE);