Re: [gisi-notify-fix PATCH 2/4] gisi: simplify handling of pending

2011-01-18 Thread Aki Niemi
Hi Pekka,

2011/1/12  pekka.pe...@nokia.com:
 diff --git a/gisi/modem.h b/gisi/modem.h
 index fff1338..91fe3d0 100644
 --- a/gisi/modem.h
 +++ b/gisi/modem.h
 @@ -109,7 +109,9 @@ int g_isi_response_vsend(GIsiModem *modem, const 
 GIsiMessage *req,

  GIsiPending *g_isi_pending_from_msg(const GIsiMessage *msg);

 -void g_isi_pending_remove(GIsiPending *operation);
 +void g_isi_pending_own(GIsiPending *op, gpointer owner);
 +void g_isi_remove_all_my_pending(GIsiModem *modem, uint8_t resource,
 +                                       gpointer owner);

Overall, I like the idea.

But how about naming these a bit better? Something like
g_isi_pending_set_owner() and g_isi_pending_remove_by_owner()?

Cheers,
Aki
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [gisi-notify-fix PATCH 2/4] gisi: simplify handling of pending

2011-01-18 Thread Pekka Pessi
Hi,

2011/1/18 Aki Niemi a...@protocolpolice.com:
 -void g_isi_pending_remove(GIsiPending *operation);
 +void g_isi_pending_own(GIsiPending *op, gpointer owner);
 +void g_isi_remove_all_my_pending(GIsiModem *modem, uint8_t resource,
 +                                       gpointer owner);

 Overall, I like the idea.

 But how about naming these a bit better? Something like
 g_isi_pending_set_owner() and g_isi_pending_remove_by_owner()?

Sounds better. I'll do that, and I think I also leave the
g_isi_pending_remove() as an added bonus. Just in case.

-- 
Pekka.Pessi mail at nokia.com
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[gisi-notify-fix PATCH 2/4] gisi: simplify handling of pending

2011-01-12 Thread Pekka . Pessi
From: Pekka Pessi pekka.pe...@nokia.com

Client or server mark their pending objects with g_isi_pending_own().

The g_isi_remove_all_my_pending() is used to remove pending objects by
client or server when they get destroyed or reset.
---
 gisi/client.c |  199 ++---
 gisi/modem.c  |   52 +--
 gisi/modem.h  |4 +-
 gisi/server.c |   73 ++---
 4 files changed, 88 insertions(+), 240 deletions(-)

diff --git a/gisi/client.c b/gisi/client.c
index 85e1fa7..58fe0f3 100644
--- a/gisi/client.c
+++ b/gisi/client.c
@@ -32,58 +32,12 @@
 
 #include client.h
 
-struct pending_data {
-   GIsiClient *client;
-   GIsiNotifyFunc notify;
-   void *data;
-   GDestroyNotify destroy;
-};
-
 struct _GIsiClient {
GIsiModem *modem;
unsigned timeout;
uint8_t resource;
-   GSList *pending;
 };
 
-static void pending_destroy(gpointer data)
-{
-   struct pending_data *pd = data;
-
-   if (pd == NULL)
-   return;
-
-   if (pd-destroy != NULL)
-   pd-destroy(pd-data);
-
-   g_free(pd);
-}
-
-static void pending_resp_notify(const GIsiMessage *msg, void *data)
-{
-   struct pending_data *pd = data;
-
-   if (pd == NULL)
-   return;
-
-   pd-client-pending = g_slist_remove(pd-client-pending,
-   g_isi_pending_from_msg(msg));
-
-   if (pd-notify != NULL)
-   pd-notify(msg, pd-data);
-}
-
-static void pending_notify(const GIsiMessage *msg, void *data)
-{
-   struct pending_data *pd = data;
-
-   if (pd == NULL)
-   return;
-
-   if (pd-notify != NULL)
-   pd-notify(msg, pd-data);
-}
-
 uint8_t g_isi_client_resource(GIsiClient *client)
 {
return client != NULL ? client-resource : 0;
@@ -112,31 +66,13 @@ GIsiClient *g_isi_client_create(GIsiModem *modem, uint8_t 
resource)
client-timeout = G_ISI_CLIENT_DEFAULT_TIMEOUT;
client-resource = resource;
client-modem = modem;
-   client-pending = NULL;
 
return client;
 }
 
-static void foreach_destroy(gpointer value, gpointer user)
-{
-   GIsiPending *op = value;
-   GIsiClient *client = user;
-
-   if (op == NULL || client == NULL)
-   return;
-
-   client-pending = g_slist_remove(client-pending, op);
-   g_isi_pending_remove(op);
-}
-
 void g_isi_client_reset(GIsiClient *client)
 {
-   if (client == NULL || client-pending == NULL)
-   return;
-
-   g_slist_foreach(client-pending, foreach_destroy, client);
-   g_slist_free(client-pending);
-   client-pending = NULL;
+   g_isi_remove_all_my_pending(client-modem, client-resource, client);
 };
 
 void g_isi_client_destroy(GIsiClient *client)
@@ -156,43 +92,19 @@ void g_isi_client_set_timeout(GIsiClient *client, unsigned 
timeout)
client-timeout = timeout;
 }
 
-static struct pending_data *pending_data_create(GIsiClient *client,
-   GIsiNotifyFunc notify,
-   void *data,
-   GDestroyNotify destroy)
-{
-   struct pending_data *pd;
-
-   if (client == NULL) {
-   errno = EINVAL;
-   return NULL;
-   }
-
-   pd = g_try_new0(struct pending_data, 1);
-   if (pd == NULL) {
-   errno = ENOMEM;
-   return NULL;
-   }
-
-   pd-client = client;
-   pd-notify = notify;
-   pd-data = data;
-   pd-destroy = destroy;
-
-   return pd;
-}
-
 gboolean g_isi_client_send(GIsiClient *client,
const void *__restrict msg, size_t len,
GIsiNotifyFunc notify, void *data,
GDestroyNotify destroy)
 {
-   if (client == NULL)
-   return FALSE;
+   GIsiPending *op;
+
+   op = g_isi_request_send(client-modem, client-resource, msg, len,
+   client-timeout, notify, data, destroy);
 
-   return g_isi_client_send_with_timeout(client, msg, len,
-   client-timeout,
-   notify, data, destroy);
+   g_isi_pending_own(op, client);
+
+   return op != NULL;
 }
 
 gboolean g_isi_client_send_with_timeout(GIsiClient *client,
@@ -201,23 +113,14 @@ gboolean g_isi_client_send_with_timeout(GIsiClient 
*client,
GIsiNotifyFunc notify, void *data,
GDestroyNotify destroy)
 {
-   struct pending_data *pd;
GIsiPending *op;
 
-   pd = pending_data_create(client, notify, data, destroy);
-   if (pd == NULL)
-   return FALSE;
-
op = g_isi_request_send(client-modem, client-resource, buf, len,
-   timeout, pending_resp_notify, pd,
-