summaryrefslogtreecommitdiffstats
path: root/gisi
diff options
context:
space:
mode:
authorPekka Pessi <Pekka.Pessi@nokia.com>2010-09-01 13:47:46 +0200
committerAki Niemi <aki.niemi@nokia.com>2010-09-02 07:50:58 +0300
commit9385ba83ba52ad9957e2f7e51d61678a0e9f34f6 (patch)
tree0d7fe6c44a39a1b6b3f2255b54ef1faec547dcc0 /gisi
parent95fc8bee7282e70db3acffaf3b0ff1a28695645d (diff)
downloadofono-9385ba83ba52ad9957e2f7e51d61678a0e9f34f6.tar.bz2
gisi: added g_isi_send() and g_isi_vsend()
Include a finalize function in GIsiRequest
Diffstat (limited to 'gisi')
-rw-r--r--gisi/client.c81
-rw-r--r--gisi/client.h12
2 files changed, 84 insertions, 9 deletions
diff --git a/gisi/client.c b/gisi/client.c
index e3785a72..24237b29 100644
--- a/gisi/client.c
+++ b/gisi/client.c
@@ -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);
}
diff --git a/gisi/client.h b/gisi/client.h
index 7046f31e..e5ba01d8 100644
--- a/gisi/client.h
+++ b/gisi/client.h
@@ -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,