diff options
author | Arron Wang <arron.wang@intel.com> | 2014-11-02 10:26:07 +0800 |
---|---|---|
committer | Arron Wang <arron.wang@intel.com> | 2014-11-25 16:20:57 +0800 |
commit | 5c8e58cef16a6707efcd195ec1e8cf7fdb05c46f (patch) | |
tree | f764a3a532c29a62fe7250c6b8357aaaec6bb0ee | |
parent | 88c1631bfbf639999867261cc13108997dbedc07 (diff) | |
download | neardal-5c8e58cef16a6707efcd195ec1e8cf7fdb05c46f.tar.gz neardal-5c8e58cef16a6707efcd195ec1e8cf7fdb05c46f.tar.bz2 neardal-5c8e58cef16a6707efcd195ec1e8cf7fdb05c46f.zip |
Add raw data push async callback support
Change-Id: I31e99be13f4e2b60903a1a7698e4e105888baa4e
-rw-r--r-- | lib/neardal.c | 12 | ||||
-rw-r--r-- | lib/neardal.h | 3 | ||||
-rw-r--r-- | lib/neardal_device.c | 35 | ||||
-rw-r--r-- | lib/neardal_prv.h | 3 |
4 files changed, 45 insertions, 8 deletions
diff --git a/lib/neardal.c b/lib/neardal.c index f58241f..6e552db 100644 --- a/lib/neardal.c +++ b/lib/neardal.c @@ -281,6 +281,18 @@ errorCode_t neardal_set_cb_write_completed(write_cb cb_write_completed, return NEARDAL_SUCCESS; } +errorCode_t neardal_set_cb_push_completed(push_cb cb_push_completed, + void *user_data) +{ + neardalMgr.cb.push_completed = cb_push_completed; + neardalMgr.cb.push_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) diff --git a/lib/neardal.h b/lib/neardal.h index 127b59f..0d2a8f8 100644 --- a/lib/neardal.h +++ b/lib/neardal.h @@ -194,6 +194,7 @@ typedef void (*record_cb) (const char *rcdName, void *user_data); typedef void (*power_cb) (errorCode_t error, void *user_data); typedef void (*read_cb) (GVariant *ret, void *user_data); typedef void (*write_cb) (errorCode_t error, void *user_data); +typedef void (*push_cb) (errorCode_t error, void *user_data); /** * @brief Callback prototype for a registered tag type @@ -584,6 +585,8 @@ errorCode_t neardal_set_cb_read_completed(read_cb cb_read_completed, void *user_data); errorCode_t neardal_set_cb_write_completed(write_cb cb_write_completed, void *user_data); +errorCode_t neardal_set_cb_push_completed(push_cb cb_push_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_device.c b/lib/neardal_device.c index 253cee4..cad6869 100644 --- a/lib/neardal_device.c +++ b/lib/neardal_device.c @@ -63,9 +63,32 @@ void neardal_dev_notify_dev_found(DevProp *devProp) } } +static void push_completed_cb(GObject *source_object, + GAsyncResult *res, gpointer user_data) +{ + GError *gerror = NULL; + errorCode_t err = NEARDAL_SUCCESS; + + NEARDAL_TRACE("Push Completed!"); + + g_dbus_connection_call_finish(neardalMgr.conn, + res, &gerror); + + if (gerror != NULL) { + NEARDAL_TRACE_ERR( + "Unable to write device NDEF as a raw bytes stream(%d:%s)\n", + gerror->code, gerror->message); + g_error_free(gerror); + err = NEARDAL_ERROR_DBUS; + } + + if (neardalMgr.cb.push_completed != NULL) + neardalMgr.cb.push_completed(err, + neardalMgr.cb.push_completed_ud); +} + errorCode_t neardal_dev_push(neardal_record *record) { - GError *gerror = NULL; errorCode_t err; GVariant *in; @@ -75,7 +98,7 @@ errorCode_t neardal_dev_push(neardal_record *record) in = neardal_record_to_g_variant(record); - g_dbus_connection_call_sync(neardalMgr.conn, + g_dbus_connection_call(neardalMgr.conn, "org.neard", record->name, "org.neard.Device", @@ -85,12 +108,8 @@ errorCode_t neardal_dev_push(neardal_record *record) G_DBUS_CALL_FLAGS_NONE, 3000, /* 3 secs */ NULL, - &gerror); - if (gerror) { - NEARDAL_TRACE_ERR("Can't push record: %s\n", gerror->message); - g_error_free(gerror); - err = NEARDAL_ERROR_DBUS_CANNOT_INVOKE_METHOD; - } + push_completed_cb, + NULL); exit: return err; } diff --git a/lib/neardal_prv.h b/lib/neardal_prv.h index 92ef89b..99f348d 100644 --- a/lib/neardal_prv.h +++ b/lib/neardal_prv.h @@ -84,6 +84,9 @@ typedef struct { write_cb write_completed; void *write_completed_ud; + + push_cb push_completed; + void *push_completed_ud; } neardalCb; /* NEARDAL context */ |