diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-25 19:12:38 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-25 19:12:38 +0000 |
commit | 8be090b298a02108146d3bf48271f8408ac31917 (patch) | |
tree | 08876e82e0ccdfe74bdb433b898220cb7e1e02eb | |
parent | 2b3d5cfe013c2abf259b86e8dc73bda3d36429c1 (diff) |
Added sdp_create for async searches
-rw-r--r-- | include/sdp_lib.h | 6 | ||||
-rw-r--r-- | src/sdp.c | 73 |
2 files changed, 78 insertions, 1 deletions
diff --git a/include/sdp_lib.h b/include/sdp_lib.h index 8a89ab6e..a4b2cb4b 100644 --- a/include/sdp_lib.h +++ b/include/sdp_lib.h @@ -112,6 +112,12 @@ int sdp_get_socket(const sdp_session_t *session); uint16_t sdp_gen_tid(sdp_session_t *session); /* + * SDP transaction: functions for asynchronous search. + */ +typedef void sdp_callback_t(uint8_t type, sdp_list_t *rsp, void *udata, int err); +sdp_session_t *sdp_create(int sk, uint32_t flags); + +/* * find all devices in the piconet */ int sdp_general_inquiry(inquiry_info *ii, int dev_num, int duration, uint8_t *found); @@ -3033,6 +3033,59 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle, } /* + * SDP transaction structure for asynchronous search + */ +struct sdp_transaction { + sdp_callback_t *cb; + void *udata; + sdp_cstate_t *cstate; + uint8_t *reqbuf; + sdp_buf_t rsp_concat_buf; + uint32_t reqsize; + int cstate_len; + int attr_list_len; +}; + +/* + * Creates a new sdp session for asynchronous search + * INPUT: + * int sk + * non-blocking L2CAP socket + * + * RETURN: + * sdp_session_t * + * NULL - On memory allocation failure + */ +sdp_session_t *sdp_create(int sk, uint32_t flags) +{ + + struct sdp_transaction *t; + sdp_session_t *session = malloc(sizeof(sdp_session_t)); + if (!session) { + errno = ENOMEM; + return NULL; + } + + memset(session, 0, sizeof(*session)); + + session->flags = flags; + session->sock = sk; + + t = malloc(sizeof(struct sdp_transaction)); + if (!t) { + errno = ENOMEM; + free(session); + return NULL; + } + + memset(t, 0, sizeof(*t)); + + session->priv = t; + + return session; +} + +/* * This is a service search request combined with the service * attribute request. First a service class match is done and * for matching service, requested attributes are extracted @@ -3256,7 +3309,25 @@ int sdp_general_inquiry(inquiry_info *ii, int num_dev, int duration, uint8_t *fo int sdp_close(sdp_session_t *session) { - int ret = close(session->sock); + struct sdp_transaction *t; + int ret; + + if (!session) + return -1; + + ret = close(session->sock); + + t = session->priv; + + if (t) { + if (t->reqbuf) + free(t->reqbuf); + + if (t->rsp_concat_buf.data) + free(t->rsp_concat_buf.data); + + free(t); + } free(session); return ret; } |