summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArron Wang <arron.wang@intel.com>2014-10-18 20:29:57 +0800
committerArron Wang <arron.wang@intel.com>2014-11-25 16:20:20 +0800
commit88c1631bfbf639999867261cc13108997dbedc07 (patch)
tree631279d8cf43ae111cac54f16831a1422549752d /lib
parent08df46ba86771209df7a9ba41daf142f20ac1dec (diff)
downloadneardal-88c1631bfbf639999867261cc13108997dbedc07.tar.gz
neardal-88c1631bfbf639999867261cc13108997dbedc07.tar.bz2
neardal-88c1631bfbf639999867261cc13108997dbedc07.zip
Use async call for ndef read/write
Change-Id: Id30e85a1c0069f25268dcb9bab5cffbc46e89e61
Diffstat (limited to 'lib')
-rw-r--r--lib/neardal.c24
-rw-r--r--lib/neardal.h9
-rw-r--r--lib/neardal_prv.h6
-rw-r--r--lib/neardal_record.c16
-rw-r--r--lib/neardal_tag.c76
5 files changed, 125 insertions, 6 deletions
diff --git a/lib/neardal.c b/lib/neardal.c
index 11418dd..f58241f 100644
--- a/lib/neardal.c
+++ b/lib/neardal.c
@@ -257,6 +257,30 @@ errorCode_t neardal_set_cb_power_completed(power_cb cb_power_completed,
return NEARDAL_SUCCESS;
}
+errorCode_t neardal_set_cb_read_completed(read_cb cb_read_completed,
+ void *user_data)
+{
+ neardalMgr.cb.read_completed = cb_read_completed;
+ neardalMgr.cb.read_completed_ud = user_data;
+
+ if (neardalMgr.proxy == NULL)
+ neardal_prv_construct(NULL);
+
+ return NEARDAL_SUCCESS;
+}
+
+errorCode_t neardal_set_cb_write_completed(write_cb cb_write_completed,
+ void *user_data)
+{
+ neardalMgr.cb.write_completed = cb_write_completed;
+ neardalMgr.cb.write_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 6968fa8..127b59f 100644
--- a/lib/neardal.h
+++ b/lib/neardal.h
@@ -129,10 +129,12 @@ typedef struct {
char *authentication; /**< WiFi Authentication. */
char *uri; /**< URI including scheme and resource. */
+ unsigned char *rawNDEF; /**< The raw NDEF type data */
/* Keep uriObjSize first after contiguous array of pointers. */
unsigned int uriObjSize;/**< URI object size. */
+ unsigned int rawNDEFSize; /**< The size of rawNDEF data */
} neardal_record;
/* @}*/
@@ -190,6 +192,8 @@ typedef void (*dev_cb) (const char *devName, void *user_data);
**/
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);
/**
* @brief Callback prototype for a registered tag type
@@ -456,6 +460,7 @@ errorCode_t neardal_get_tag_properties(const char *tagName,
* @return errorCode_t error code
**/
errorCode_t neardal_tag_write(neardal_record *record);
+errorCode_t neardal_tag_get_rawNDEF(const char *tagName);
/*! \fn void neardal_free_tag(neardal_tag *tag)
* @brief Release memory allocated for properties of a tag
@@ -575,6 +580,10 @@ errorCode_t neardal_set_cb_record_found(record_cb cb_rcd_found,
errorCode_t neardal_set_cb_power_completed(power_cb cb_power_completed,
void *user_data);
+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);
/*! \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 d737ca5..92ef89b 100644
--- a/lib/neardal_prv.h
+++ b/lib/neardal_prv.h
@@ -78,6 +78,12 @@ typedef struct {
'tag record found'*/
power_cb power_completed;
void *power_completed_ud;
+
+ read_cb read_completed;
+ void *read_completed_ud;
+
+ write_cb write_completed;
+ void *write_completed_ud;
} neardalCb;
/* NEARDAL context */
diff --git a/lib/neardal_record.c b/lib/neardal_record.c
index 7b93fd2..fcffc1e 100644
--- a/lib/neardal_record.c
+++ b/lib/neardal_record.c
@@ -40,7 +40,9 @@ void neardal_free_record(neardal_record *record) \
GVariant *neardal_record_to_g_variant(neardal_record *in)
{
GVariantBuilder b;
+ GVariantBuilder *tmp, *rawNDEF;
GVariant *out;
+ guint32 count;
g_variant_builder_init(&b, G_VARIANT_TYPE_ARRAY);
@@ -63,6 +65,20 @@ GVariant *neardal_record_to_g_variant(neardal_record *in)
NEARDAL_G_VARIANT_IN(&b, "{'URI', <%s>}", in->uri);
+ if (in->rawNDEF != NULL && in->rawNDEFSize > 0) {
+
+ tmp = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+
+ for (count = 0; count < in->rawNDEFSize; count++)
+ g_variant_builder_add(tmp, "y",
+ in->rawNDEF[count]);
+
+ rawNDEF = g_variant_new("ay", tmp);
+
+ g_variant_builder_add(&b, "{sv}", "NDEF", rawNDEF);
+ g_variant_builder_unref(tmp);
+ }
+
out = g_variant_builder_end(&b);
return out;
diff --git a/lib/neardal_tag.c b/lib/neardal_tag.c
index 9630915..8aa19be 100644
--- a/lib/neardal_tag.c
+++ b/lib/neardal_tag.c
@@ -200,6 +200,75 @@ void neardal_tag_notify_tag_found(TagProp *tagProp)
}
}
+static void read_completed_cb(GObject *source_object,
+ GAsyncResult *res, gpointer user_data)
+{
+ GError *gerror = NULL;
+ GVariant *ret = NULL;
+ NEARDAL_TRACE("Read Completed!");
+
+ ret = g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object),
+ res, &gerror);
+
+ if (gerror != NULL) {
+ NEARDAL_TRACE_ERR(
+ "Unable to read tag's NDEF as a raw bytes stream(%d:%s)\n",
+ gerror->code, gerror->message);
+ g_error_free(gerror);
+ return;
+ }
+
+ if (neardalMgr.cb.read_completed != NULL)
+ neardalMgr.cb.read_completed(ret,
+ neardalMgr.cb.read_completed_ud);
+
+ g_variant_unref(ret);
+}
+
+/*****************************************************************************
+ * neardal_tag_get_rawNDEF: Get tag's NDEF as a raw bytes stream
+ ****************************************************************************/
+errorCode_t neardal_tag_get_rawNDEF(const char *tagName)
+{
+ errorCode_t err = NEARDAL_SUCCESS;
+ TagProp *tag = NULL;
+
+ NEARDAL_ASSERT_RET(tagName != NULL, NEARDAL_ERROR_INVALID_PARAMETER);
+
+ neardal_prv_construct(&err);
+ if (err != NEARDAL_SUCCESS)
+ return err;
+
+ if (!(tag = neardal_mgr_tag_search(tagName)))
+ return NEARDAL_ERROR_NO_TAG;
+
+ org_neard_tag_call_get_raw_ndef(tag->proxy, NULL,
+ read_completed_cb, NULL);
+
+ return err;
+}
+
+static void write_completed_cb(GObject *source_object,
+ GAsyncResult *res, gpointer user_data)
+{
+ errorCode_t err = NEARDAL_SUCCESS;
+ NEARDAL_TRACE("Write Completed!");
+
+ g_dbus_proxy_call_finish(G_DBUS_PROXY(source_object),
+ 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;
+ }
+
+ if (neardalMgr.cb.write_completed != NULL)
+ neardalMgr.cb.write_completed(err,
+ neardalMgr.cb.write_completed_ud);
+}
+
errorCode_t neardal_tag_write(neardal_record *record)
{
GError *gerror = NULL;
@@ -218,12 +287,7 @@ errorCode_t neardal_tag_write(neardal_record *record)
in = neardal_record_to_g_variant(record);
- if (org_neard_tag_call_write_sync(tag->proxy, in, NULL, &gerror)
- == FALSE) {
- NEARDAL_TRACE_ERR("Can't write record: %s\n", gerror->message);
- g_error_free(gerror);
- err = NEARDAL_ERROR_DBUS;
- }
+ org_neard_tag_call_write(tag->proxy, in, NULL, write_completed_cb, NULL);
return err;
}