Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 260b86b5 authored by Ayush Singh's avatar Ayush Singh
Browse files

Some small code improvements


- Having a wrapper around greybus message is proving more difficult that
  initial assumption

Signed-off-by: default avatarAyush Singh <ayushdevel1325@gmail.com>
parent 95a27c1b
Branches
1 merge request!3Single Socket Multiplex
......@@ -19,6 +19,7 @@ static uint8_t gb_connection_process(struct gb_connection *conn)
uint8_t count = 0;
struct gb_message *msg;
LOG_DBG("Trying to read from Intf %u, Cport %u", conn->inf_ap->id, conn->ap_cport_id);
msg = conn->inf_ap->controller.read(&conn->inf_ap->controller, conn->ap_cport_id);
if (msg) {
conn->inf_peer->controller.write(&conn->inf_peer->controller, msg,
......@@ -29,6 +30,7 @@ static uint8_t gb_connection_process(struct gb_connection *conn)
conn->peer_cport_id);
}
LOG_DBG("Trying to read from Intf %u, Cport %u", conn->inf_peer->id, conn->peer_cport_id);
msg = conn->inf_peer->controller.read(&conn->inf_peer->controller, conn->peer_cport_id);
if (msg) {
conn->inf_ap->controller.write(&conn->inf_ap->controller, msg, conn->ap_cport_id);
......@@ -49,6 +51,7 @@ static void gb_flush_connection(struct gb_connection *conn)
static void gb_connection_dealloc(struct gb_connection *conn)
{
LOG_DBG("Possible point 3");
sys_dlist_remove(&conn->node);
k_mem_slab_free(&gb_connection_slab, (void **)&conn);
}
......
......@@ -40,6 +40,7 @@ struct gb_message *gb_message_alloc(size_t payload_len, uint8_t message_type, ui
msg->header.id = operation_id;
msg->header.type = message_type;
msg->header.status = status;
sys_dnode_init(&msg->node);
return msg;
}
......
......@@ -20,12 +20,12 @@ LOG_MODULE_DECLARE(cc1352_greybus, CONFIG_BEAGLEPLAY_GREYBUS_LOG_LEVEL);
struct node_control_data {
struct in6_addr addr;
int sock;
sys_dlist_t msgs;
int sock;
};
K_MEM_SLAB_DEFINE_STATIC(node_control_data_slab, sizeof(struct node_control_data),
MAX_GREYBUS_NODES, 8);
MAX_GREYBUS_NODES, 4);
static sys_dlist_t node_interface_list = SYS_DLIST_STATIC_INIT(&node_interface_list);
static struct in6_addr node_addr_cache[MAX_GREYBUS_NODES];
......@@ -288,7 +288,6 @@ static struct gb_message *node_inf_read(struct gb_controller *ctrl, uint16_t cpo
/* return any pending message */
if ((msg = msgs_find(&ctrl_data->msgs, cport_id))) {
LOG_DBG("Return Point 1");
return msg;
}
......@@ -304,7 +303,6 @@ static struct gb_message *node_inf_read(struct gb_controller *ctrl, uint16_t cpo
/* Add to queue if the message is of different cport */
if (gb_message_pad_read(msg) == cport_id) {
LOG_DBG("Return Point 2");
return msg;
}
......
......@@ -58,6 +58,8 @@ static int svc_inf_create_connection(struct gb_controller *ctrl, uint16_t cport_
static void svc_inf_destroy_connection(struct gb_controller *ctrl, uint16_t cport_id)
{
struct gb_message *msg;
ARG_UNUSED(ctrl);
if (cport_id != 0) {
......@@ -65,13 +67,10 @@ static void svc_inf_destroy_connection(struct gb_controller *ctrl, uint16_t cpor
return;
}
struct gb_message *msg;
/* Set svc to uninitialized */
atomic_set_bit_to(svc_is_read_flag, 0, false);
msg = k_fifo_get(&svc_ctrl_data.pending_read, K_NO_WAIT);
while (msg) {
while ((msg = k_fifo_get(&svc_ctrl_data.pending_read, K_NO_WAIT))) {
/* Free all pending messages */
gb_message_dealloc(msg);
msg = k_fifo_get(&svc_ctrl_data.pending_read, K_NO_WAIT);
......@@ -321,6 +320,11 @@ static void svc_connection_create_handler(struct gb_message *msg)
struct gb_interface *intf_1, *intf_2;
struct gb_connection *conn;
if (req->intf1_id == req->intf2_id && req->cport1_id == req->cport2_id) {
LOG_ERR("Cannot create loop connection");
goto fail;
}
intf_1 = gb_interface_find_by_id(req->intf1_id);
if (!intf_1) {
LOG_DBG("Unknown Interface 1: %u", req->intf1_id);
......@@ -338,6 +342,9 @@ static void svc_connection_create_handler(struct gb_message *msg)
goto fail;
}
LOG_DBG("Created connection between Intf %u, Cport %u and Intf %u, Cport %u", req->intf1_id,
req->cport1_id, req->intf2_id, req->cport2_id);
svc_response_helper(msg, NULL, 0, GB_SVC_OP_SUCCESS);
return;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment