diff options
author | Olivier Guiter <olivier.guiter@linux.intel.com> | 2013-09-02 12:32:14 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-09-02 14:30:22 +0200 |
commit | b3c63774d4a2b528f6f46392a0f711a650b52a4d (patch) | |
tree | 75ea3bfbf0ac68f2b87a0458cb357493a5dd083e | |
parent | f226b625c8c94fc9be82bdfec14ebdf848c344d6 (diff) | |
download | neard-b3c63774d4a2b528f6f46392a0f711a650b52a4d.tar.gz neard-b3c63774d4a2b528f6f46392a0f711a650b52a4d.tar.bz2 neard-b3c63774d4a2b528f6f46392a0f711a650b52a4d.zip |
p2p: Add a user_data pointer to p2p struct
user_data pointer is added to p2p internal structure and is sent
(as param) in every p2p functions (read, push, close,...).
-rw-r--r-- | include/snep.h | 8 | ||||
-rw-r--r-- | plugins/handover.c | 16 | ||||
-rw-r--r-- | plugins/llcp-validation.c | 8 | ||||
-rw-r--r-- | plugins/npp.c | 2 | ||||
-rw-r--r-- | plugins/p2p.c | 15 | ||||
-rw-r--r-- | plugins/p2p.h | 14 | ||||
-rw-r--r-- | plugins/snep-validation.c | 10 | ||||
-rw-r--r-- | plugins/snep.c | 6 | ||||
-rw-r--r-- | src/snep.c | 8 | ||||
-rw-r--r-- | unit/test-snep-read.c | 10 |
10 files changed, 60 insertions, 37 deletions
diff --git a/include/snep.h b/include/snep.h index c908387..5392c58 100644 --- a/include/snep.h +++ b/include/snep.h @@ -83,13 +83,15 @@ bool near_snep_core_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb, near_server_io req_get, - near_server_io req_put); + near_server_io req_put, + gpointer data); int near_snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx, struct near_ndef_message *ndef, - near_device_io_cb cb); + near_device_io_cb cb, + gpointer data); -void near_snep_core_close(int client_fd, int err); +void near_snep_core_close(int client_fd, int err, gpointer data); void near_snep_core_response_noinfo(int client_fd, uint8_t response); void near_snep_core_response_with_info(int client_fd, uint8_t response, diff --git a/plugins/handover.c b/plugins/handover.c index dcca9ab..5e46087 100644 --- a/plugins/handover.c +++ b/plugins/handover.c @@ -95,7 +95,7 @@ static void free_hr_ndef(gpointer data) g_free(ndef); } -static void handover_close(int client_fd, int err) +static void handover_close(int client_fd, int err, gpointer data) { struct hr_ndef *ndef; @@ -147,7 +147,7 @@ static int handover_ndef_parse(int client_fd, struct hr_ndef *ndef) fail: near_error("ndef parsing failed %d", err); - handover_close(client_fd, 0); + handover_close(client_fd, 0, NULL); return err; } @@ -240,7 +240,7 @@ static bool handover_read_cfg_records(int client_fd, err = handover_ndef_parse(client_fd, ndef); if (err > 0) { /* clean memory */ - handover_close(client_fd, 0); + handover_close(client_fd, 0, NULL); return true; } @@ -380,7 +380,8 @@ fail: */ static bool handover_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, + gpointer data) { struct hr_ndef *ndef; @@ -403,7 +404,7 @@ static void free_hr_push_client(struct hr_push_client *client, int status) { DBG(""); - handover_close(client->fd, 0); + handover_close(client->fd, 0, NULL); if (client->cb) client->cb(client->adapter_idx, client->target_idx, status); @@ -432,7 +433,7 @@ static gboolean handover_push_event(GIOChannel *channel, ret = handover_read(client->fd, client->adapter_idx, client->target_idx, - client->cb); + client->cb, data); if (!ret) free_hr_push_client(client, 0); @@ -443,7 +444,8 @@ static gboolean handover_push_event(GIOChannel *channel, static int handover_push(int client_fd, uint32_t adapter_idx, uint32_t target_idx, struct near_ndef_message *ndef, - near_device_io_cb cb) + near_device_io_cb cb, + gpointer data) { int err; struct hr_push_client *client; diff --git a/plugins/llcp-validation.c b/plugins/llcp-validation.c index 814584e..853e2ab 100644 --- a/plugins/llcp-validation.c +++ b/plugins/llcp-validation.c @@ -270,7 +270,7 @@ error: } /* clean on close */ -static void llcp_validation_close(int client_fd, int err) +static void llcp_validation_close(int client_fd, int err, gpointer data) { DBG(""); @@ -281,7 +281,8 @@ static void llcp_validation_close(int client_fd, int err) /* Connection Oriented: Wrapper for read function */ static bool llcp_validation_read_co(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, + gpointer data) { DBG("CO client with fd: %d", client_fd); return llcp_common_read(client_fd, adapter_idx, target_idx, cb, @@ -291,7 +292,8 @@ static bool llcp_validation_read_co(int client_fd, uint32_t adapter_idx, /* Connection less: Wrapper for read function */ static bool llcp_validation_read_cl(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, + gpointer data) { DBG("CL client with fd: %d", client_fd); return llcp_common_read(client_fd, adapter_idx, target_idx, cb, diff --git a/plugins/npp.c b/plugins/npp.c index 3df49eb..eac17a6 100644 --- a/plugins/npp.c +++ b/plugins/npp.c @@ -56,7 +56,7 @@ struct p2p_npp_frame { static bool npp_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, gpointer data) { struct near_device *device; struct p2p_npp_frame frame; diff --git a/plugins/p2p.c b/plugins/p2p.c index a3904a7..bf6ee8b 100644 --- a/plugins/p2p.c +++ b/plugins/p2p.c @@ -147,7 +147,8 @@ static gboolean p2p_client_event(GIOChannel *channel, GIOCondition condition, err = 0; if (client_data->driver->close) - client_data->driver->close(client_data->fd, err); + client_data->driver->close(client_data->fd, err, + client_data->driver->user_data); near_error("%s client channel closed", client_data->driver->name); @@ -173,7 +174,8 @@ static gboolean p2p_client_event(GIOChannel *channel, GIOCondition condition, more = client_data->driver->read(client_data->fd, client_data->adapter_idx, client_data->target_idx, - client_data->cb); + client_data->cb, + client_data->driver->user_data); return more; } @@ -187,7 +189,8 @@ static void free_client_data(gpointer data) client_data = (struct p2p_data *) data; if (client_data->driver->close) - client_data->driver->close(client_data->fd, 0); + client_data->driver->close(client_data->fd, 0, + client_data->driver->user_data); if (client_data->watch > 0) g_source_remove(client_data->watch); @@ -346,7 +349,8 @@ static gboolean p2p_push_blocking(gpointer user_data) } err = conn->driver->push(fd, conn->adapter_idx, conn->target_idx, - conn->ndef, conn->cb); + conn->ndef, conn->cb, + conn->driver->user_data); out: if (err < 0) @@ -418,7 +422,8 @@ static gboolean p2p_connect_event(GIOChannel *channel, GIOCondition condition, } err = conn->driver->push(fd, conn->adapter_idx, conn->target_idx, - conn->ndef, conn->cb); + conn->ndef, conn->cb, + conn->driver->user_data); out: if (err < 0) diff --git a/plugins/p2p.h b/plugins/p2p.h index a7c0c51..9616cd6 100644 --- a/plugins/p2p.h +++ b/plugins/p2p.h @@ -35,12 +35,16 @@ struct near_p2p_driver { const char *fallback_service_name; bool single_connection; int sock_type; - bool (*read)(int client_fd, - uint32_t adapter_idx, uint32_t target_idx, - near_device_io_cb cb); + gpointer user_data; + + bool (*read)(int client_fd, uint32_t adapter_idx, uint32_t target_idx, + near_device_io_cb cb, + gpointer data); int (*push)(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - struct near_ndef_message *ndef, near_device_io_cb cb); - void (*close)(int client_fd, int err); + struct near_ndef_message *ndef, + near_device_io_cb cb, + gpointer data); + void (*close)(int client_fd, int err, gpointer data); }; int npp_init(void); diff --git a/plugins/snep-validation.c b/plugins/snep-validation.c index 86c8905..2261938 100644 --- a/plugins/snep-validation.c +++ b/plugins/snep-validation.c @@ -211,24 +211,26 @@ error: /* This function is a wrapper to push post processing read functions */ static bool snep_validation_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, + gpointer data) { DBG(""); return near_snep_core_read(client_fd, adapter_idx, target_idx, cb, snep_validation_server_req_get, - snep_validation_server_req_put); + snep_validation_server_req_put, + data); } -static void snep_validation_close(int client_fd, int err) +static void snep_validation_close(int client_fd, int err, gpointer data) { DBG(""); g_hash_table_remove(snep_validation_hash, GINT_TO_POINTER(client_fd)); /* Call core server close */ - near_snep_core_close(client_fd, err); + near_snep_core_close(client_fd, err, data); } struct near_p2p_driver validation_snep_driver = { diff --git a/plugins/snep.c b/plugins/snep.c index f77c0a3..7557f78 100644 --- a/plugins/snep.c +++ b/plugins/snep.c @@ -117,13 +117,15 @@ static bool snep_default_server_req_get(int client_fd, void *data) /* This function is a wrapper to push post processing read functions */ static bool snep_default_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, - near_tag_io_cb cb) + near_tag_io_cb cb, + gpointer data) { DBG(""); return near_snep_core_read(client_fd, adapter_idx, target_idx, cb, snep_default_server_req_get, - snep_default_server_req_put); + snep_default_server_req_put, + data); } @@ -514,7 +514,8 @@ bool near_snep_core_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb, near_server_io req_get, - near_server_io req_put) + near_server_io req_put, + gpointer data) { struct p2p_snep_data *snep_data; struct p2p_snep_req_frame frame; @@ -794,7 +795,8 @@ done: /* SNEP Core: on P2P push */ int near_snep_core_push(int fd, uint32_t adapter_idx, uint32_t target_idx, struct near_ndef_message *ndef, - near_device_io_cb cb) + near_device_io_cb cb, + gpointer data) { struct p2p_snep_put_req_data *req; GIOChannel *channel; @@ -837,7 +839,7 @@ error: } /* SNEP core functions: close */ -void near_snep_core_close(int client_fd, int err) +void near_snep_core_close(int client_fd, int err, gpointer data) { struct p2p_snep_data *snep_data; diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c index 1f88b56..03c916a 100644 --- a/unit/test-snep-read.c +++ b/unit/test-snep-read.c @@ -344,7 +344,8 @@ static bool test_snep_read_req_common( TEST_SNEP_LOG("sent 0x%02X request\n", req->request); - ret = near_snep_core_read(sockfd[server], 0, 0, NULL, req_get, req_put); + ret = near_snep_core_read(sockfd[server], 0, 0, NULL, req_get, req_put, + NULL); return ret; } @@ -369,7 +370,8 @@ static bool test_snep_read_send_fragment(size_t frag_len, g_assert(nbytes == frag_len); near_snep_core_read(sockfd[server], 0, 0, NULL, - test_snep_dummy_req_get, test_snep_dummy_req_put); + test_snep_dummy_req_get, test_snep_dummy_req_put, + NULL); return true; } @@ -857,7 +859,7 @@ static void test_snep_response_put_get_ndef(gpointer context, /* UUT */ ret = near_snep_core_read(sockfd[client], 0, 0, NULL, - test_snep_dummy_req_get, test_snep_dummy_req_put); + test_snep_dummy_req_get, test_snep_dummy_req_put, NULL); g_assert(ret); resp = g_try_malloc0(frame_len); @@ -876,7 +878,7 @@ static void test_snep_response_put_get_ndef(gpointer context, /* UUT */ ret = near_snep_core_read(sockfd[client], 0, 0, NULL, - test_snep_dummy_req_get, test_snep_dummy_req_put); + test_snep_dummy_req_get, test_snep_dummy_req_put, NULL); g_assert(ret); /* Get response and verify */ |