* [PATCH 1/7] Add phonebook request
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 21:07 ` Luiz Augusto von Dentz
2010-11-23 18:11 ` [PATCH 2/7] Add phonebook_req_cancel prototype Dmitriy Paliy
` (5 subsequent siblings)
6 siblings, 1 reply; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook request structure to phonebook-tracker and pointer to
pending call in PBAP object.
---
plugins/pbap.c | 1 +
plugins/phonebook-tracker.c | 4 ++++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 1a7d001..3264e85 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -147,6 +147,7 @@ struct pbap_session {
struct pbap_object {
GString *buffer;
struct pbap_session *session;
+ void *request;
};
static const uint8_t PBAP_TARGET[TARGET_SIZE] = {
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 20053f6..afe0f2f 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1035,6 +1035,10 @@ struct phonebook_index {
int index;
};
+struct phonebook_req {
+ DBusPendingCall *call;
+};
+
static DBusConnection *connection = NULL;
static const char *name2query(const char *name)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/7] Add phonebook request
2010-11-23 18:11 ` [PATCH 1/7] Add " Dmitriy Paliy
@ 2010-11-23 21:07 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2010-11-23 21:07 UTC (permalink / raw)
To: Dmitriy Paliy; +Cc: linux-bluetooth
Hi,
On Tue, Nov 23, 2010 at 8:11 PM, Dmitriy Paliy <dmitriy.paliy@nokia.com> wrote:
> Add phonebook request structure to phonebook-tracker and pointer to
> pending call in PBAP object.
> ---
> plugins/pbap.c | 1 +
> plugins/phonebook-tracker.c | 4 ++++
> 2 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/plugins/pbap.c b/plugins/pbap.c
> index 1a7d001..3264e85 100644
> --- a/plugins/pbap.c
> +++ b/plugins/pbap.c
> @@ -147,6 +147,7 @@ struct pbap_session {
> struct pbap_object {
> GString *buffer;
> struct pbap_session *session;
> + void *request;
> };
>
> static const uint8_t PBAP_TARGET[TARGET_SIZE] = {
> diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
> index 20053f6..afe0f2f 100644
> --- a/plugins/phonebook-tracker.c
> +++ b/plugins/phonebook-tracker.c
> @@ -1035,6 +1035,10 @@ struct phonebook_index {
> int index;
> };
>
> +struct phonebook_req {
> + DBusPendingCall *call;
> +};
No need to create a struct here, you can pass the call since there is
not other members.
--
Luiz Augusto von Dentz
Computer Engineer
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/7] Add phonebook_req_cancel prototype
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 1/7] Add " Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 3/7] Add phonebook_req_cancel to tracker Dmitriy Paliy
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook_req_cancel function prototype to cancel pending request
to backend.
---
plugins/phonebook.h | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/plugins/phonebook.h b/plugins/phonebook.h
index d7cfa46..7ae5ccc 100644
--- a/plugins/phonebook.h
+++ b/plugins/phonebook.h
@@ -107,3 +107,9 @@ int phonebook_get_entry(const char *folder, const char *id,
*/
int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
phonebook_cache_ready_cb ready_cb, void *user_data);
+
+/*
+ * Function used to cancel pending request to backend and free resources
+ * allocated for phonebook request structure.
+ */
+void phonebook_req_cancel(void *request);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/7] Add phonebook_req_cancel to tracker
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 1/7] Add " Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 2/7] Add phonebook_req_cancel prototype Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 4/7] Add update phonebook_pull Dmitriy Paliy
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook_req_cancel function to phonebook_tracker.c that cancels
pending request and deallocates memory of requst object.
---
plugins/phonebook-tracker.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index afe0f2f..6ee5750 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1803,6 +1803,22 @@ done:
return path;
}
+void phonebook_req_cancel(void *request)
+{
+ struct phonebook_req *req = request;
+
+ if (!req)
+ return;
+
+ if (req->call) {
+ dbus_pending_call_cancel(req->call);
+ dbus_pending_call_unref(req->call);
+ }
+
+ g_free(req);
+ req = NULL;
+}
+
int phonebook_pull(const char *name, const struct apparam_field *params,
phonebook_cb cb, void *user_data)
{
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/7] Add update phonebook_pull
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
` (2 preceding siblings ...)
2010-11-23 18:11 ` [PATCH 3/7] Add phonebook_req_cancel to tracker Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 5/7] Add update phonebook_get_entry Dmitriy Paliy
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook_pull function prototype is updated to return void
pointer to backend specific request and error code. All backend
handlers updated accordingly (phonebook-tracker.c,
phonebook-dummy.c, and phonebook-ebook.c).
Phonebook request is created dynamically only for tracker,
therefore, removed appropriately when PBAP object is destroyed,
or IRMC close method invoked.
query_tracker is updated to return pending call request.
IRMC is updated to handle pending request when phonebook is pulled.
---
plugins/irmc.c | 14 +++++++-------
plugins/pbap.c | 19 ++++++++++++++-----
plugins/phonebook-dummy.c | 21 ++++++++++++++++-----
plugins/phonebook-ebook.c | 13 ++++++++++---
plugins/phonebook-tracker.c | 37 ++++++++++++++++++++++++++++---------
plugins/phonebook.h | 4 ++--
6 files changed, 77 insertions(+), 31 deletions(-)
diff --git a/plugins/irmc.c b/plugins/irmc.c
index f7ad33b..4c11933 100644
--- a/plugins/irmc.c
+++ b/plugins/irmc.c
@@ -110,6 +110,7 @@ struct irmc_session {
char did[DID_LEN];
char manu[DID_LEN];
char model[DID_LEN];
+ void *request;
};
#define IRMC_TARGET_SIZE 9
@@ -210,11 +211,8 @@ static void *irmc_connect(struct obex_session *os, int *err)
param->maxlistcount = 0; /* to count the number of vcards... */
param->filter = 0x200085; /* UID TEL N VERSION */
irmc->params = param;
- phonebook_pull("telecom/pb.vcf", irmc->params, phonebook_size_result,
- irmc);
-
- if (err)
- *err = 0;
+ irmc->request = phonebook_pull("telecom/pb.vcf", irmc->params,
+ phonebook_size_result, irmc, err);
return irmc;
}
@@ -298,8 +296,8 @@ static void *irmc_open_pb(const char *name, struct irmc_session *irmc,
if (!g_strcmp0(name, ".vcf")) {
/* how can we tell if the vcard count call already finished? */
- ret = phonebook_pull("telecom/pb.vcf", irmc->params,
- query_result, irmc);
+ irmc->request = phonebook_pull("telecom/pb.vcf", irmc->params,
+ query_result, irmc, &ret);
if (ret < 0) {
DBG("phonebook_pull failed...");
goto fail;
@@ -435,6 +433,8 @@ static int irmc_close(void *object)
irmc->buffer = NULL;
}
+ phonebook_req_cancel(irmc->request);
+
return 0;
}
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 3264e85..0ceaf95 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -698,13 +698,15 @@ static struct obex_service_driver pbap = {
.chkput = pbap_chkput
};
-static struct pbap_object *vobject_create(struct pbap_session *pbap)
+static struct pbap_object *vobject_create(struct pbap_session *pbap,
+ void *request)
{
struct pbap_object *obj;
obj = g_new0(struct pbap_object, 1);
obj->session = pbap;
pbap->obj = obj;
+ obj->request = request;
return obj;
}
@@ -715,6 +717,7 @@ static void *vobject_pull_open(const char *name, int oflag, mode_t mode,
struct pbap_session *pbap = context;
phonebook_cb cb;
int ret;
+ void *request = NULL;
DBG("name %s context %p maxlistcount %d", name, context,
pbap->params->maxlistcount);
@@ -734,11 +737,15 @@ static void *vobject_pull_open(const char *name, int oflag, mode_t mode,
else
cb = query_result;
- ret = phonebook_pull(name, pbap->params, cb, pbap);
+ request = phonebook_pull(name, pbap->params, cb, pbap, &ret);
+
if (ret < 0)
goto fail;
- return vobject_create(pbap);
+ if (err)
+ *err = ret;
+
+ return vobject_create(pbap, request);
fail:
if (err)
@@ -788,7 +795,7 @@ static void *vobject_list_open(const char *name, int oflag, mode_t mode,
goto fail;
done:
- return vobject_create(pbap);
+ return vobject_create(pbap, NULL);
fail:
if (err)
@@ -837,7 +844,7 @@ done:
if (ret < 0)
goto fail;
- return vobject_create(pbap);
+ return vobject_create(pbap, NULL);
fail:
if (err)
@@ -913,6 +920,8 @@ static int vobject_close(void *object)
if (obj->buffer)
g_string_free(obj->buffer, TRUE);
+ phonebook_req_cancel(obj->request);
+
g_free(obj);
return 0;
diff --git a/plugins/phonebook-dummy.c b/plugins/phonebook-dummy.c
index 7c549fa..d9a5a29 100644
--- a/plugins/phonebook-dummy.c
+++ b/plugins/phonebook-dummy.c
@@ -447,8 +447,12 @@ done:
return relative;
}
-int phonebook_pull(const char *name, const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void phonebook_req_cancel(void *request)
+{
+}
+
+void *phonebook_pull(const char *name, const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err)
{
struct dummy_data *dummy;
char *filename, *folder;
@@ -463,14 +467,18 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
if (!g_str_has_suffix(filename, ".vcf")) {
g_free(filename);
- return -EBADR;
+ if (err)
+ *err = -EBADR;
+ return NULL;
}
folder = g_strndup(filename, strlen(filename) - 4);
g_free(filename);
if (!is_dir(folder)) {
g_free(folder);
- return -ENOENT;
+ if (err)
+ *err = -ENOENT;
+ return NULL;
}
dummy = g_new0(struct dummy_data, 1);
@@ -482,7 +490,10 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, read_dir, dummy, dummy_free);
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
int phonebook_get_entry(const char *folder, const char *id,
diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 073ff33..9097a0b 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -408,8 +408,12 @@ done:
return fullname;
}
-int phonebook_pull(const char *name, const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void phonebook_req_cancel(void *request)
+{
+}
+
+void *phonebook_pull(const char *name, const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err)
{
struct contacts_query *data;
EBookQuery *query;
@@ -425,7 +429,10 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
e_book_query_unref(query);
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
int phonebook_get_entry(const char *folder, const char *id,
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 6ee5750..bce60d6 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1203,7 +1203,8 @@ done:
}
static int query_tracker(const char *query, int num_fields,
- reply_list_foreach_t callback, void *user_data)
+ reply_list_foreach_t callback, void *user_data,
+ struct phonebook_req *req)
{
struct pending_reply *pending;
DBusPendingCall *call;
@@ -1232,9 +1233,11 @@ static int query_tracker(const char *query, int num_fields,
pending->num_fields = num_fields;
dbus_pending_call_set_notify(call, query_reply, pending, NULL);
- dbus_pending_call_unref(call);
dbus_message_unref(msg);
+ if (req)
+ req->call = call;
+
return 0;
}
@@ -1819,13 +1822,15 @@ void phonebook_req_cancel(void *request)
req = NULL;
}
-int phonebook_pull(const char *name, const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void *phonebook_pull(const char *name, const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err)
{
struct phonebook_data *data;
const char *query;
reply_list_foreach_t pull_cb;
int col_amount;
+ struct phonebook_req *req;
+ int ret;
DBG("name %s", name);
@@ -1839,15 +1844,28 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
pull_cb = pull_contacts;
}
- if (query == NULL)
- return -ENOENT;
+ if (query == NULL) {
+ if (err)
+ *err = -ENOENT;
+ return NULL;
+ }
data = g_new0(struct phonebook_data, 1);
data->params = params;
data->user_data = user_data;
data->cb = cb;
- return query_tracker(query, col_amount, pull_cb, data);
+ req = g_new0(struct phonebook_req, 1);
+
+ ret = query_tracker(query, col_amount, pull_cb, data, req);
+
+ if (err)
+ *err = ret;
+
+ if (ret < 0)
+ phonebook_req_cancel(req);
+
+ return req;
}
int phonebook_get_entry(const char *folder, const char *id,
@@ -1874,7 +1892,8 @@ int phonebook_get_entry(const char *folder, const char *id,
query = g_strdup_printf(CONTACTS_OTHER_QUERY_FROM_URI,
id, id, id);
- ret = query_tracker(query, PULL_QUERY_COL_AMOUNT, pull_contacts, data);
+ ret = query_tracker(query, PULL_QUERY_COL_AMOUNT, pull_contacts, data,
+ NULL);
g_free(query);
@@ -1898,5 +1917,5 @@ int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
cache->ready_cb = ready_cb;
cache->user_data = user_data;
- return query_tracker(query, 7, add_to_cache, cache);
+ return query_tracker(query, 7, add_to_cache, cache, NULL);
}
diff --git a/plugins/phonebook.h b/plugins/phonebook.h
index 7ae5ccc..951b370 100644
--- a/plugins/phonebook.h
+++ b/plugins/phonebook.h
@@ -86,8 +86,8 @@ char *phonebook_set_folder(const char *current_folder,
* entries of a given folder. The back-end MUST return only the content based
* on the application parameters requested by the client.
*/
-int phonebook_pull(const char *name, const struct apparam_field *params,
- phonebook_cb cb, void *user_data);
+void *phonebook_pull(const char *name, const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err);
/*
* Function used to retrieve a contact from the backend. Only contacts
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/7] Add update phonebook_get_entry
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
` (3 preceding siblings ...)
2010-11-23 18:11 ` [PATCH 4/7] Add update phonebook_pull Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 6/7] Add update phonebook_create_cache Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 7/7] Code clean-up: lines longer 80 symbols removed Dmitriy Paliy
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook_get_entry function prototype update to return void
pointer to backend specific request and error code. All backend
handlers updated accordingly (phonebook-tracker.c,
phonebook-dummy.c, and phonebook-ebook.c).
Phonebook request is created dynamically only for tracker,
therefore, removed appropriately when PBAP object is destroyed.
IRMC does not invoke phonebook_get_entry therefore is not changed.
---
plugins/pbap.c | 11 ++++++-----
plugins/phonebook-dummy.c | 18 +++++++++++-------
plugins/phonebook-ebook.c | 15 ++++++++++-----
plugins/phonebook-tracker.c | 17 ++++++++++++-----
plugins/phonebook.h | 4 ++--
5 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 0ceaf95..2ce580b 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -455,8 +455,8 @@ static void cache_entry_done(void *user_data)
return;
}
- ret = phonebook_get_entry(pbap->folder, id, pbap->params,
- query_result, pbap);
+ pbap->obj->request = phonebook_get_entry(pbap->folder, id,
+ pbap->params, query_result, pbap, &ret);
if (ret < 0)
obex_object_set_io_flags(pbap->obj, G_IO_ERR, ret);
}
@@ -811,6 +811,7 @@ static void *vobject_vcard_open(const char *name, int oflag, mode_t mode,
const char *id;
uint32_t handle;
int ret;
+ void *request = NULL;
DBG("name %s context %p valid %d", name, context, pbap->cache.valid);
@@ -837,14 +838,14 @@ static void *vobject_vcard_open(const char *name, int oflag, mode_t mode,
goto fail;
}
- ret = phonebook_get_entry(pbap->folder, id, pbap->params, query_result,
- pbap);
+ request = phonebook_get_entry(pbap->folder, id, pbap->params,
+ query_result, pbap, &ret);
done:
if (ret < 0)
goto fail;
- return vobject_create(pbap, NULL);
+ return vobject_create(pbap, request);
fail:
if (err)
diff --git a/plugins/phonebook-dummy.c b/plugins/phonebook-dummy.c
index d9a5a29..7a963b6 100644
--- a/plugins/phonebook-dummy.c
+++ b/plugins/phonebook-dummy.c
@@ -496,9 +496,9 @@ void *phonebook_pull(const char *name, const struct apparam_field *params,
return NULL;
}
-int phonebook_get_entry(const char *folder, const char *id,
- const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void *phonebook_get_entry(const char *folder, const char *id,
+ const struct apparam_field *params, phonebook_cb cb,
+ void *user_data, int *err)
{
struct dummy_data *dummy;
char *filename;
@@ -508,9 +508,10 @@ int phonebook_get_entry(const char *folder, const char *id,
fd = open(filename, O_RDONLY);
if (fd < 0) {
- int err = errno;
- DBG("open(): %s(%d)", strerror(err), err);
- return -ENOENT;
+ DBG("open(): %s(%d)", strerror(errno), errno);
+ if (err)
+ *err = -ENOENT;
+ return NULL;
}
dummy = g_new0(struct dummy_data, 1);
@@ -521,7 +522,10 @@ int phonebook_get_entry(const char *folder, const char *id,
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, read_entry, dummy, dummy_free);
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 9097a0b..2515bb0 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -435,9 +435,9 @@ void *phonebook_pull(const char *name, const struct apparam_field *params,
return NULL;
}
-int phonebook_get_entry(const char *folder, const char *id,
- const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void *phonebook_get_entry(const char *folder, const char *id,
+ const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err)
{
struct contacts_query *data;
@@ -448,10 +448,15 @@ int phonebook_get_entry(const char *folder, const char *id,
if (e_book_async_get_contact(ebook, id, ebook_entry_cb, data)) {
g_free(data);
- return -ENOENT;
+ if (err)
+ *err = -ENOENT;
+ return NULL;
}
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index bce60d6..ead583e 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1868,13 +1868,14 @@ void *phonebook_pull(const char *name, const struct apparam_field *params,
return req;
}
-int phonebook_get_entry(const char *folder, const char *id,
- const struct apparam_field *params,
- phonebook_cb cb, void *user_data)
+void *phonebook_get_entry(const char *folder, const char *id,
+ const struct apparam_field *params,
+ phonebook_cb cb, void *user_data, int *err)
{
struct phonebook_data *data;
char *query;
int ret;
+ struct phonebook_req *req = g_new0(struct phonebook_req, 1);
DBG("folder %s id %s", folder, id);
@@ -1893,11 +1894,17 @@ int phonebook_get_entry(const char *folder, const char *id,
id, id, id);
ret = query_tracker(query, PULL_QUERY_COL_AMOUNT, pull_contacts, data,
- NULL);
+ req);
g_free(query);
- return ret;
+ if (ret < 0)
+ phonebook_req_cancel(req);
+
+ if (err)
+ *err = ret;
+
+ return req;
}
int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
diff --git a/plugins/phonebook.h b/plugins/phonebook.h
index 951b370..5342841 100644
--- a/plugins/phonebook.h
+++ b/plugins/phonebook.h
@@ -95,9 +95,9 @@ void *phonebook_pull(const char *name, const struct apparam_field *params,
* return only the content based on the application parameters requested
* by the client.
*/
-int phonebook_get_entry(const char *folder, const char *id,
+void *phonebook_get_entry(const char *folder, const char *id,
const struct apparam_field *params,
- phonebook_cb cb, void *user_data);
+ phonebook_cb cb, void *user_data, int *err);
/*
* PBAP core will keep the contacts cache per folder. SetPhoneBook or
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 6/7] Add update phonebook_create_cache
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
` (4 preceding siblings ...)
2010-11-23 18:11 ` [PATCH 5/7] Add update phonebook_get_entry Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
2010-11-23 18:11 ` [PATCH 7/7] Code clean-up: lines longer 80 symbols removed Dmitriy Paliy
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
Add phonebook_create_cache updated function prototype to return void
pointer to backend specific request and error code. All backend
handlers updated accordingly (phonebook-tracker.c,
phonebook-dummy.c, and phonebook-ebook.c).
In PBAP vobject_list_open and vobject_vcard_open are updated to
store pointer to phonebook request. IRMC is not modified.
Phonebook request is created and stored dynamically only for tracker.
---
plugins/pbap.c | 18 +++++++++++++-----
plugins/phonebook-dummy.c | 16 ++++++++++------
plugins/phonebook-ebook.c | 20 ++++++++++++++------
plugins/phonebook-tracker.c | 25 ++++++++++++++++++++-----
plugins/phonebook.h | 4 ++--
5 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 2ce580b..5137d07 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -455,6 +455,13 @@ static void cache_entry_done(void *user_data)
return;
}
+ /*
+ * If request to create cache succeeded, vobject and phonebook
+ * request were created, then previous request has to be deleted,
+ * even though there is no pending call anymore. In
+ * phonebook_get_entry a new request will be created.
+ */
+ phonebook_req_cancel(pbap->obj->request);
pbap->obj->request = phonebook_get_entry(pbap->folder, id,
pbap->params, query_result, pbap, &ret);
if (ret < 0)
@@ -759,6 +766,7 @@ static void *vobject_list_open(const char *name, int oflag, mode_t mode,
{
struct pbap_session *pbap = context;
int ret;
+ void *request = NULL;
DBG("name %s context %p valid %d", name, context, pbap->cache.valid);
@@ -788,14 +796,14 @@ static void *vobject_list_open(const char *name, int oflag, mode_t mode,
goto done;
}
- ret = phonebook_create_cache(name,
- cache_entry_notify, cache_ready_notify, pbap);
+ request = phonebook_create_cache(name,
+ cache_entry_notify, cache_ready_notify, pbap, &ret);
if (ret < 0)
goto fail;
done:
- return vobject_create(pbap, NULL);
+ return vobject_create(pbap, request);
fail:
if (err)
@@ -827,8 +835,8 @@ static void *vobject_vcard_open(const char *name, int oflag, mode_t mode,
if (pbap->cache.valid == FALSE) {
pbap->find_handle = handle;
- ret = phonebook_create_cache(pbap->folder, cache_entry_notify,
- cache_entry_done, pbap);
+ request = phonebook_create_cache(pbap->folder,
+ cache_entry_notify, cache_entry_done, pbap, &ret);
goto done;
}
diff --git a/plugins/phonebook-dummy.c b/plugins/phonebook-dummy.c
index 7a963b6..a269ea8 100644
--- a/plugins/phonebook-dummy.c
+++ b/plugins/phonebook-dummy.c
@@ -528,8 +528,8 @@ void *phonebook_get_entry(const char *folder, const char *id,
return NULL;
}
-int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
- phonebook_cache_ready_cb ready_cb, void *user_data)
+void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
+ phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
{
struct cache_query *query;
char *foldername;
@@ -540,9 +540,10 @@ int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
g_free(foldername);
if (dp == NULL) {
- int err = errno;
- DBG("opendir(): %s(%d)", strerror(err), err);
- return -ENOENT;
+ DBG("opendir(): %s(%d)", strerror(errno), errno);
+ if (err)
+ *err = -ENOENT;
+ return NULL;
}
query = g_new0(struct cache_query, 1);
@@ -553,5 +554,8 @@ int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, create_cache, query,
query_free);
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
diff --git a/plugins/phonebook-ebook.c b/plugins/phonebook-ebook.c
index 2515bb0..5d7f624 100644
--- a/plugins/phonebook-ebook.c
+++ b/plugins/phonebook-ebook.c
@@ -459,15 +459,18 @@ void *phonebook_get_entry(const char *folder, const char *id,
return NULL;
}
-int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
- phonebook_cache_ready_cb ready_cb, void *user_data)
+void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
+ phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
{
struct cache_query *data;
EBookQuery *query;
gboolean ret;
- if (g_strcmp0("/telecom/pb", name) != 0)
- return -ENOENT;
+ if (g_strcmp0("/telecom/pb", name) != 0) {
+ if (err)
+ *err = -ENOENT;
+ return NULL;
+ }
query = e_book_query_any_field_contains("");
@@ -480,8 +483,13 @@ int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
e_book_query_unref(query);
if (ret != FALSE) {
g_free(data);
- return -EFAULT;
+ if (err)
+ *err = -EFAULT;
+ return NULL;
}
- return 0;
+ if (err)
+ *err = 0;
+
+ return NULL;
}
diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index ead583e..3577212 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -1907,22 +1907,37 @@ void *phonebook_get_entry(const char *folder, const char *id,
return req;
}
-int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
- phonebook_cache_ready_cb ready_cb, void *user_data)
+void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
+ phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
{
struct cache_data *cache;
const char *query;
+ int ret;
+ struct phonebook_req *req;
DBG("name %s", name);
query = folder2query(name);
- if (query == NULL)
- return -ENOENT;
+ if (query == NULL) {
+ if (err)
+ *err = -ENOENT;
+ return NULL;
+ }
cache = g_new0(struct cache_data, 1);
cache->entry_cb = entry_cb;
cache->ready_cb = ready_cb;
cache->user_data = user_data;
- return query_tracker(query, 7, add_to_cache, cache, NULL);
+ req = g_new0(struct phonebook_req, 1);
+
+ ret = query_tracker(query, 7, add_to_cache, cache, req);
+
+ if (ret < 0)
+ phonebook_req_cancel(req);
+
+ if (err)
+ *err = ret;
+
+ return req;
}
diff --git a/plugins/phonebook.h b/plugins/phonebook.h
index 5342841..b6ae5a8 100644
--- a/plugins/phonebook.h
+++ b/plugins/phonebook.h
@@ -105,8 +105,8 @@ void *phonebook_get_entry(const char *folder, const char *id,
* Cache will store only the necessary information required to reply to
* PullvCardListing request and verify if a given contact belongs to the source.
*/
-int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
- phonebook_cache_ready_cb ready_cb, void *user_data);
+void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
+ phonebook_cache_ready_cb ready_cb, void *user_data, int *err);
/*
* Function used to cancel pending request to backend and free resources
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 7/7] Code clean-up: lines longer 80 symbols removed
2010-11-23 18:11 [PATCH 0/7] Cancel pending phonebook request Dmitriy Paliy
` (5 preceding siblings ...)
2010-11-23 18:11 ` [PATCH 6/7] Add update phonebook_create_cache Dmitriy Paliy
@ 2010-11-23 18:11 ` Dmitriy Paliy
6 siblings, 0 replies; 9+ messages in thread
From: Dmitriy Paliy @ 2010-11-23 18:11 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Dmitriy Paliy
---
plugins/pbap.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 5137d07..40a5417 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -263,8 +263,8 @@ static void query_result(const char *buffer, size_t bufsize, int vcards,
if (!pbap->obj->buffer)
pbap->obj->buffer = g_string_new_len(buffer, bufsize);
else
- pbap->obj->buffer = g_string_append_len(pbap->obj->buffer, buffer,
- bufsize);
+ pbap->obj->buffer = g_string_append_len(pbap->obj->buffer,
+ buffer, bufsize);
obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}
@@ -423,11 +423,12 @@ static void cache_ready_notify(void *user_data)
for (; l && max; l = l->next, max--) {
const struct cache_entry *entry = l->data;
- g_string_append_printf(pbap->obj->buffer, VCARD_LISTING_ELEMENT,
- entry->handle, entry->name);
+ g_string_append_printf(pbap->obj->buffer,
+ VCARD_LISTING_ELEMENT, entry->handle, entry->name);
}
- pbap->obj->buffer = g_string_append(pbap->obj->buffer, VCARD_LISTING_END);
+ pbap->obj->buffer = g_string_append(pbap->obj->buffer,
+ VCARD_LISTING_END);
g_slist_free(sorted);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 9+ messages in thread