adapter: Get the device powered status
authorSamuel Ortiz <sameo@linux.intel.com>
Tue, 31 Jan 2012 12:09:35 +0000 (13:09 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Tue, 31 Jan 2012 12:09:35 +0000 (13:09 +0100)
src/adapter.c
src/manager.c
src/near.h
src/netlink.c

index d0bd329..06ed957 100644 (file)
@@ -439,7 +439,7 @@ static GDBusSignalTable adapter_signals[] = {
 };
 
 struct near_adapter * __near_adapter_create(uint32_t idx,
-                                       const char *name, uint32_t protocols)
+               const char *name, uint32_t protocols, near_bool_t powered)
 {
        struct near_adapter *adapter;
 
@@ -454,7 +454,7 @@ struct near_adapter * __near_adapter_create(uint32_t idx,
        }
        adapter->idx = idx;
        adapter->protocols = protocols;
-       adapter->powered = TRUE;
+       adapter->powered = powered;
        adapter->targets = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                                        NULL, free_target);
        adapter->sock = -1;
index f662851..d5ea970 100644 (file)
@@ -67,7 +67,8 @@ static DBusMessage *set_property(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
-int __near_manager_adapter_add(uint32_t idx, const char *name, uint32_t protocols)
+int __near_manager_adapter_add(uint32_t idx, const char *name,
+                               uint32_t protocols, near_bool_t powered)
 {
        struct near_adapter *adapter;
        const char *path;
@@ -75,7 +76,7 @@ int __near_manager_adapter_add(uint32_t idx, const char *name, uint32_t protocol
 
        DBG("idx %d", idx);
 
-       adapter = __near_adapter_create(idx, name, protocols);
+       adapter = __near_adapter_create(idx, name, protocols, powered);
        if (adapter == NULL)
                return -ENOMEM;
 
index c504fb4..153091b 100644 (file)
@@ -63,7 +63,8 @@ DBusMessage *__near_error_operation_timeout(DBusMessage *msg);
 DBusMessage *__near_error_invalid_service(DBusMessage *msg);
 DBusMessage *__near_error_invalid_property(DBusMessage *msg);
 
-int __near_manager_adapter_add(uint32_t idx, const char *name, uint32_t protocols);
+int __near_manager_adapter_add(uint32_t idx, const char *name,
+                       uint32_t protocols, near_bool_t powered);
 void __near_manager_adapter_remove(uint32_t idx);
 int __near_manager_init(DBusConnection *conn);
 void __near_manager_cleanup(void);
@@ -90,7 +91,7 @@ void __near_target_cleanup(void);
 #include <near/adapter.h>
 
 struct near_adapter * __near_adapter_create(uint32_t idx,
-                               const char *name, uint32_t protocols);
+               const char *name, uint32_t protocols, near_bool_t powered);
 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);
index 74d4d64..8b50c43 100644 (file)
@@ -157,6 +157,7 @@ static int get_devices_handler(struct nl_msg *n, void *arg)
        struct nlattr *attrs[NFC_ATTR_MAX + 1];
        char *name;
        uint32_t idx, protocols;
+       near_bool_t powered;
 
        DBG("");
 
@@ -167,11 +168,17 @@ static int get_devices_handler(struct nl_msg *n, void *arg)
                return NL_STOP;
        }
 
+
        idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
        name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
        protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
 
-       __near_manager_adapter_add(idx, name, protocols);
+       if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL)
+               powered = FALSE;
+       else
+               powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
+
+       __near_manager_adapter_add(idx, name, protocols, powered);
 
        return NL_SKIP;
 }
@@ -371,11 +378,17 @@ static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, near_bool_t add)
        if (add == TRUE) {
                char *name;
                uint32_t protocols;
+               near_bool_t powered;
 
                name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
                protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
+               if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL)
+                       powered = FALSE;
+               else
+                       powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
 
-               return __near_manager_adapter_add(idx, name, protocols);
+               return __near_manager_adapter_add(idx, name,
+                                               protocols, powered);
        } else {
                __near_manager_adapter_remove(idx);
        }