gisi: added g_isi_send() and g_isi_vsend()
authorPekka Pessi <Pekka.Pessi@nokia.com>
Wed, 1 Sep 2010 11:47:46 +0000 (13:47 +0200)
committerAki Niemi <aki.niemi@nokia.com>
Thu, 2 Sep 2010 04:50:58 +0000 (07:50 +0300)
Include a finalize function in GIsiRequest

gisi/client.c
gisi/client.h

index e3785a7..24237b2 100644 (file)
@@ -52,6 +52,7 @@ struct _GIsiRequest {
        guint timeout;
        GIsiResponseFunc func;
        void *data;
+       GDestroyNotify notify;
 };
 
 struct _GIsiIndication {
@@ -240,6 +241,9 @@ static void g_isi_cleanup_req(void *data)
                req->func(req->client, NULL, 0, 0, req->data);
        req->client->error = 0;
 
+       if (req->notify)
+               req->notify(req->data);
+
        if (req->timeout > 0)
                g_source_remove(req->timeout);
 
@@ -329,31 +333,84 @@ GIsiRequest *g_isi_request_make(GIsiClient *client, const void *__restrict buf,
                                size_t len, unsigned timeout,
                                GIsiResponseFunc cb, void *opaque)
 {
+       return g_isi_send(client, buf, len, timeout, cb, opaque, NULL);
+}
+
+/**
+ * Make an ISI request and register a callback to process the response(s) to
+ * the resulting transaction.
+ * @param cl ISI client (from g_isi_client_create())
+ * @param iov scatter-gather array to the request payload
+ * @param iovlen number of vectors in the scatter-gather array
+ * @param timeout timeout in seconds
+ * @param cb callback to process response(s)
+ * @param opaque data for the callback
+ */
+GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov,
+                                       size_t iovlen, unsigned timeout,
+                                       GIsiResponseFunc func, void *opaque)
+{
+       return g_isi_vsend(client, iov, iovlen, timeout, func, opaque, NULL);
+}
+
+/**
+ * Send an ISI request and register a callback to process the response(s) to
+ * the resulting transaction.
+ *
+ * @param cl ISI client (from g_isi_client_create())
+ * @param buf pointer to request payload
+ * @param len request payload byte length
+ * @param timeout timeout in seconds
+ * @param cb callback to process response(s)
+ * @param opaque data for the callback
+ * @param notify finalizer function for the @a opaque data (may be NULL)
+ *
+ * @return
+ * A pointer to a newly created GIsiRequest.
+ *
+ * @errors
+ * If an error occurs, @a errno is set accordingly and a NULL pointer is
+ * returned.
+ */
+GIsiRequest *g_isi_send(GIsiClient *client,
+                       const void *__restrict buf, size_t len,
+                       unsigned timeout,
+                       GIsiResponseFunc cb, void *opaque,
+                       GDestroyNotify notify)
+{
        const struct iovec iov = {
                .iov_base = (void *)buf,
                .iov_len = len,
        };
 
-       if (!client)
-               return NULL;
-
-       return g_isi_request_vmake(client, &iov, 1, timeout, cb, opaque);
+       return g_isi_vsend(client, &iov, 1, timeout, cb, opaque, notify);
 }
 
+
 /**
- * Make an ISI request and register a callback to process the response(s) to
+ * Send an ISI request and register a callback to process the response(s) to
  * the resulting transaction.
+ *
  * @param cl ISI client (from g_isi_client_create())
  * @param iov scatter-gather array to the request payload
  * @param iovlen number of vectors in the scatter-gather array
  * @param timeout timeout in seconds
  * @param cb callback to process response(s)
  * @param opaque data for the callback
+ * @param notify finalizer function for the @a opaque data (may be NULL)
+ *
+ * @return
+ * A pointer to a newly created GIsiRequest.
+ *
+ * @errors
+ * If an error occurs, @a errno is set accordingly and a NULL pointer is
+ * returned.
  */
-GIsiRequest *g_isi_request_vmake(GIsiClient *client,
-                                       const struct iovec *__restrict iov,
-                                       size_t iovlen, unsigned timeout,
-                                       GIsiResponseFunc cb, void *opaque)
+GIsiRequest *g_isi_vsend(GIsiClient *client,
+                               const struct iovec *__restrict iov,
+                               size_t iovlen, unsigned timeout,
+                               GIsiResponseFunc cb, void *opaque,
+                               GDestroyNotify notify)
 {
        struct iovec _iov[1 + iovlen];
        struct sockaddr_pn dst = {
@@ -390,6 +447,7 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client,
        req->id = (client->reqs.last + 1) % 255;
        req->func = cb;
        req->data = opaque;
+       req->notify = notify;
 
        old = tsearch(req, &client->reqs.pending, g_isi_cmp);
        if (!old) {
@@ -438,6 +496,7 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client,
 error:
        tdelete(req, &client->reqs.pending, g_isi_cmp);
        g_free(req);
+
        return NULL;
 }
 
@@ -455,6 +514,10 @@ void g_isi_request_cancel(GIsiRequest *req)
                g_source_remove(req->timeout);
 
        tdelete(req, &req->client->reqs.pending, g_isi_cmp);
+
+       if (req->notify)
+               req->notify(req->data);
+
        g_free(req);
 }
 
index 7046f31..e5ba01d 100644 (file)
@@ -27,6 +27,7 @@ extern "C" {
 #endif
 
 #include <stdint.h>
+#include <glib/gtypes.h>
 #include <gisi/modem.h>
 
 struct _GIsiClient;
@@ -72,6 +73,17 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov,
                                        size_t iovlen, unsigned timeout,
                                        GIsiResponseFunc func, void *opaque);
 
+GIsiRequest *g_isi_send(GIsiClient *client, const void *data, size_t len,
+                       unsigned timeout,
+                       GIsiResponseFunc func, void *opaque,
+                       GDestroyNotify notify);
+
+GIsiRequest *g_isi_vsend(GIsiClient *client,
+                               const struct iovec *iov, size_t iovlen,
+                               unsigned timeout,
+                               GIsiResponseFunc func, void *opaque,
+                               GDestroyNotify notify);
+
 void g_isi_request_cancel(GIsiRequest *req);
 
 int g_isi_subscribe(GIsiClient *client, uint8_t type,