mirror of git://git.sysmocom.de/ofono
gisi: Add sendto methods to GIsiClient
Add g_isi_vsendto() and g_isi_sendto() methods for sending messages to an arbitrary Phonet address.
This commit is contained in:
parent
79e23355a4
commit
6462450059
|
@ -353,6 +353,42 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov,
|
|||
return g_isi_vsend(client, iov, iovlen, timeout, func, opaque, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an ISI request to a specific Phonet address and register a callback
|
||||
* to process the response(s) to the resulting transaction.
|
||||
*
|
||||
* @param client ISI client (from g_isi_client_create())
|
||||
* @param dst Phonet destination address
|
||||
* @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_sendto(GIsiClient *client,
|
||||
struct sockaddr_pn *dst,
|
||||
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,
|
||||
};
|
||||
|
||||
return g_isi_vsendto(client, dst, &iov, 1, timeout, cb, opaque, notify);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an ISI request and register a callback to process the response(s) to
|
||||
* the resulting transaction.
|
||||
|
@ -388,10 +424,11 @@ GIsiRequest *g_isi_send(GIsiClient *client,
|
|||
|
||||
|
||||
/**
|
||||
* Send an ISI request and register a callback to process the response(s) to
|
||||
* the resulting transaction.
|
||||
* Send an ISI request to a specific Phonet address and register a callback
|
||||
* to process the response(s) to the resulting transaction.
|
||||
*
|
||||
* @param cl ISI client (from g_isi_client_create())
|
||||
* @param client ISI client (from g_isi_client_create())
|
||||
* @param dst Phonet destination address
|
||||
* @param iov scatter-gather array to the request payload
|
||||
* @param iovlen number of vectors in the scatter-gather array
|
||||
* @param timeout timeout in seconds
|
||||
|
@ -406,19 +443,17 @@ GIsiRequest *g_isi_send(GIsiClient *client,
|
|||
* If an error occurs, @a errno is set accordingly and a NULL pointer is
|
||||
* returned.
|
||||
*/
|
||||
GIsiRequest *g_isi_vsend(GIsiClient *client,
|
||||
GIsiRequest *g_isi_vsendto(GIsiClient *client,
|
||||
struct sockaddr_pn *dst,
|
||||
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 = {
|
||||
.spn_family = AF_PHONET,
|
||||
};
|
||||
struct msghdr msg = {
|
||||
.msg_name = (void *)&dst,
|
||||
.msg_namelen = sizeof(dst),
|
||||
.msg_name = (void *)dst,
|
||||
.msg_namelen = sizeof(*dst),
|
||||
.msg_iov = _iov,
|
||||
.msg_iovlen = 1 + iovlen,
|
||||
.msg_control = NULL,
|
||||
|
@ -465,8 +500,6 @@ GIsiRequest *g_isi_vsend(GIsiClient *client,
|
|||
goto error;
|
||||
}
|
||||
|
||||
dst.spn_resource = client->resource,
|
||||
|
||||
id = req->id;
|
||||
_iov[0].iov_base = &id;
|
||||
_iov[0].iov_len = 1;
|
||||
|
@ -500,6 +533,46 @@ error:
|
|||
return 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 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_vsend(GIsiClient *client,
|
||||
const struct iovec *__restrict iov,
|
||||
size_t iovlen, unsigned timeout,
|
||||
GIsiResponseFunc cb, void *opaque,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
struct sockaddr_pn dst = {
|
||||
.spn_family = AF_PHONET,
|
||||
};
|
||||
|
||||
if (!client) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dst.spn_resource = client->resource;
|
||||
|
||||
return g_isi_vsendto(client, &dst, iov, iovlen, timeout,
|
||||
cb, opaque, notify);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a pending request, i.e. stop waiting for responses and cancels the
|
||||
* timeout.
|
||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <gisi/modem.h>
|
||||
#include "phonet.h"
|
||||
|
||||
struct _GIsiClient;
|
||||
typedef struct _GIsiClient GIsiClient;
|
||||
|
@ -73,11 +74,25 @@ GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov,
|
|||
size_t iovlen, unsigned timeout,
|
||||
GIsiResponseFunc func, void *opaque);
|
||||
|
||||
GIsiRequest *g_isi_sendto(GIsiClient *client,
|
||||
struct sockaddr_pn *dst,
|
||||
const void *data, size_t len,
|
||||
unsigned timeout,
|
||||
GIsiResponseFunc func, void *opaque,
|
||||
GDestroyNotify notify);
|
||||
|
||||
GIsiRequest *g_isi_send(GIsiClient *client, const void *data, size_t len,
|
||||
unsigned timeout,
|
||||
GIsiResponseFunc func, void *opaque,
|
||||
GDestroyNotify notify);
|
||||
|
||||
GIsiRequest *g_isi_vsendto(GIsiClient *client,
|
||||
struct sockaddr_pn *dst,
|
||||
const struct iovec *iov, size_t iovlen,
|
||||
unsigned timeout,
|
||||
GIsiResponseFunc func, void *opaque,
|
||||
GDestroyNotify notify);
|
||||
|
||||
GIsiRequest *g_isi_vsend(GIsiClient *client,
|
||||
const struct iovec *iov, size_t iovlen,
|
||||
unsigned timeout,
|
||||
|
|
Loading…
Reference in New Issue