summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArron Wang <arron.wang@intel.com>2014-10-18 16:50:33 +0800
committerArron Wang <arron.wang@intel.com>2014-11-25 16:17:59 +0800
commit08df46ba86771209df7a9ba41daf142f20ac1dec (patch)
tree7756b3f76642dbfaf57b5fe086fcb0f3f8e828ea
parentfe0fa79c94e9a0f1c2cfa1f58b3acc9bdc7d5e13 (diff)
downloadneardal-08df46ba86771209df7a9ba41daf142f20ac1dec.tar.gz
neardal-08df46ba86771209df7a9ba41daf142f20ac1dec.tar.bz2
neardal-08df46ba86771209df7a9ba41daf142f20ac1dec.zip
Add powered completed callback
Change-Id: I8569a041a9d3f2bfb4c907213f8327d692b2bbcc
-rw-r--r--lib/neardal.c63
-rw-r--r--lib/neardal.h3
-rw-r--r--lib/neardal_prv.h2
3 files changed, 56 insertions, 12 deletions
diff --git a/lib/neardal.c b/lib/neardal.c
index 2c52cd7..11418dd 100644
--- a/lib/neardal.c
+++ b/lib/neardal.c
@@ -245,6 +245,18 @@ errorCode_t neardal_set_cb_record_found(record_cb cb_rcd_found,
return NEARDAL_SUCCESS;
}
+errorCode_t neardal_set_cb_power_completed(power_cb cb_power_completed,
+ void *user_data)
+{
+ neardalMgr.cb.power_completed = cb_power_completed;
+ neardalMgr.cb.power_completed_ud = user_data;
+
+ if (neardalMgr.proxy == NULL)
+ neardal_prv_construct(NULL);
+
+ return NEARDAL_SUCCESS;
+}
+
errorCode_t neardal_free_array(char ***array)
{
if (array == NULL || *array == NULL)
@@ -469,6 +481,40 @@ exit:
return err;
}
+static void power_completed_cb(GObject *source_object,
+ GAsyncResult *res, gpointer user_data)
+{
+ errorCode_t err = NEARDAL_SUCCESS;
+ AdpProp *adpProp = NULL;
+
+ NEARDAL_TRACE("Power Completed!");
+ err = neardal_mgr_prv_get_adapter((gchar *) user_data, &adpProp);
+ if (err != NEARDAL_SUCCESS)
+ goto exit;
+
+ if (adpProp->proxy == NULL) {
+ NEARDAL_TRACE("adapter proxy is null");
+ err = NEARDAL_ERROR_NO_ADAPTER;
+ goto exit;
+ }
+
+ properties_call_set_finish(adpProp->props, res, &neardalMgr.gerror);
+ if (neardalMgr.gerror != NULL) {
+ NEARDAL_TRACE_ERR(
+ "DBUS Error (%d): %s\n",
+ neardalMgr.gerror->code,
+ neardalMgr.gerror->message);
+ err = NEARDAL_ERROR_DBUS;
+ }
+
+exit:
+ if (neardalMgr.cb.power_completed != NULL)
+ neardalMgr.cb.power_completed(err,
+ neardalMgr.cb.power_completed_ud);
+
+ g_free(user_data);
+}
+
/*****************************************************************************
* neardal_set_adapter_property: Set a property on a specific NEARDAL adapter
****************************************************************************/
@@ -480,6 +526,7 @@ errorCode_t neardal_set_adapter_property(const char *adpName,
const gchar *propKey = NULL;
GVariant *propValue = NULL;
GVariant *variantTmp = NULL;
+ gchar *user_data = NULL;
if (neardalMgr.proxy == NULL)
neardal_prv_construct(&err);
@@ -506,18 +553,10 @@ errorCode_t neardal_set_adapter_property(const char *adpName,
NEARDAL_TRACE_LOG("Sending:\n%s=%s\n", propKey,
g_variant_print(propValue, TRUE));
- properties_call_set_sync(adpProp->props, "org.neard.Adapter",
- propKey, propValue, 0, &neardalMgr.gerror);
-
- if (neardalMgr.gerror == NULL)
- err = NEARDAL_SUCCESS;
- else {
- NEARDAL_TRACE_ERR(
- "DBUS Error (%d): %s\n",
- neardalMgr.gerror->code,
- neardalMgr.gerror->message);
- err = NEARDAL_ERROR_DBUS_INVOKE_METHOD_ERROR;
- }
+ user_data = g_strdup(adpName);
+ properties_call_set(adpProp->props, "org.neard.Adapter",
+ propKey, propValue, 0,
+ power_completed_cb, user_data);
exit:
neardal_tools_prv_free_gerror(&neardalMgr.gerror);
diff --git a/lib/neardal.h b/lib/neardal.h
index b2dd243..6968fa8 100644
--- a/lib/neardal.h
+++ b/lib/neardal.h
@@ -189,6 +189,7 @@ typedef void (*dev_cb) (const char *devName, void *user_data);
* @param user_data Client user data
**/
typedef void (*record_cb) (const char *rcdName, void *user_data);
+typedef void (*power_cb) (errorCode_t error, void *user_data);
/**
* @brief Callback prototype for a registered tag type
@@ -572,6 +573,8 @@ void neardal_free_record(neardal_record *record);
errorCode_t neardal_set_cb_record_found(record_cb cb_rcd_found,
void *user_data);
+errorCode_t neardal_set_cb_power_completed(power_cb cb_power_completed,
+ void *user_data);
/*! \fn errorCode_t neardal_agent_set_NDEF_cb(char *tagType, agent_cb cb_agent,
* void *user_data)
* @brief register or unregister a callback to handle a record macthing
diff --git a/lib/neardal_prv.h b/lib/neardal_prv.h
index 2860214..d737ca5 100644
--- a/lib/neardal_prv.h
+++ b/lib/neardal_prv.h
@@ -76,6 +76,8 @@ typedef struct {
void *rcd_found_ud; /* User data for
client callback
'tag record found'*/
+ power_cb power_completed;
+ void *power_completed_ud;
} neardalCb;
/* NEARDAL context */