From 73cde24d9690e2b9d4fb588fa8cc54fa50ef0b3e Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 4 Oct 2014 23:19:23 +0200 Subject: client: RIL state update delegation, no client destroy, IPC client boot in open Signed-off-by: Paul Kocialkowski --- client.c | 31 +++++++++++++------------------ ipc.c | 46 +++++++++++++++++++++++++++++----------------- samsung-ril.h | 1 - srs.c | 1 - 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/client.c b/client.c index 1e06554..ab66a40 100644 --- a/client.c +++ b/client.c @@ -146,35 +146,26 @@ void *ril_client_thread(void *data) if (client->failures) { usleep(RIL_CLIENT_RETRY_DELAY); + RIL_LOCK(); + rc = ril_client_close(client); - if (rc < 0) + if (rc < 0) { + RIL_UNLOCK(); goto failure; - - if (client->failures > 1) { - rc = ril_client_destroy(client); - if (rc < 0) - goto failure; - - rc = ril_client_create(client); - if (rc < 0) - goto failure; } rc = ril_client_open(client); - if (rc < 0) + if (rc < 0) { + RIL_UNLOCK(); goto failure; + } + + RIL_UNLOCK(); } rc = client->handlers->loop(client); if (rc < 0) { RIL_LOGE("%s client loop failed", client->name); - - if (client->critical) { - RIL_LOCK(); - ril_radio_state_update(RADIO_STATE_UNAVAILABLE); - RIL_UNLOCK(); - } - goto failure; } else { RIL_LOGE("%s client loop terminated", client->name); @@ -185,9 +176,13 @@ failure: client->failures++; } while (client->failures < RIL_CLIENT_RETRY_COUNT); + RIL_LOCK(); + ril_client_close(client); ril_client_destroy(client); + RIL_UNLOCK(); + RIL_LOGD("Stopped %s client loop", client->name); return NULL; diff --git a/ipc.c b/ipc.c index d8601fa..b31a060 100644 --- a/ipc.c +++ b/ipc.c @@ -153,7 +153,6 @@ int ipc_fmt_create(struct ril_client *client) if (client == NULL) return -1; - RIL_CLIENT_LOCK(client); client->available = 0; @@ -186,12 +185,6 @@ int ipc_fmt_create(struct ril_client *client) goto error; } - rc = ipc_client_boot(ipc_client); - if (rc < 0) { - RIL_LOGE("Booting %s client failed", client->name); - goto error; - } - data->ipc_client = ipc_client; client->data = (void *) data; @@ -273,6 +266,12 @@ int ipc_fmt_open(struct ril_client *client) RIL_CLIENT_LOCK(client); if (client->failures != 1) { + rc = ipc_client_boot(data->ipc_client); + if (rc < 0) { + RIL_LOGE("Booting %s client failed", client->name); + goto error; + } + rc = ipc_client_power_on(data->ipc_client); if (rc < 0) { RIL_LOGE("Powering on %s client failed", client->name); @@ -286,6 +285,9 @@ int ipc_fmt_open(struct ril_client *client) goto error; } + if (client->failures == 1) + ril_radio_state_update(RADIO_STATE_OFF); + eventfd_flush(data->event_fd); client->available = 1; @@ -413,7 +415,7 @@ int ipc_fmt_loop(struct ril_client *client) while (1) { if (!client->available) { RIL_LOGE("%s client is not available", client->name); - return -1; + goto error; } fds_array[0] = data->event_fd; @@ -422,19 +424,20 @@ int ipc_fmt_loop(struct ril_client *client) rc = ipc_client_poll(data->ipc_client, &fds, NULL); if (rc < 0) { RIL_LOGE("Polling %s client failed", client->name); - return -1; + goto error; } if (fds.fds[0] == data->event_fd && fds.count > 0) { rc = eventfd_recv(data->event_fd, &event); if (rc < 0) - return -1; + goto error; switch (event) { case IPC_CLIENT_CLOSE: - return 0; + rc = 0; + goto complete; case IPC_CLIENT_IO_ERROR: - return -1; + goto error; } } @@ -455,7 +458,7 @@ int ipc_fmt_loop(struct ril_client *client) RIL_CLIENT_UNLOCK(client); RIL_UNLOCK(); - return -1; + goto error; } release_wake_lock(RIL_VERSION_STRING); @@ -469,7 +472,7 @@ int ipc_fmt_loop(struct ril_client *client) if (message.data != NULL && message.size > 0) free(message.data); - return -1; + goto error; } if (client->failures) @@ -479,7 +482,18 @@ int ipc_fmt_loop(struct ril_client *client) free(message.data); } - return 0; + rc = 0; + goto complete; + +error: + rc = -1; + + RIL_LOCK(); + ril_radio_state_update(RADIO_STATE_UNAVAILABLE); + RIL_UNLOCK(); + +complete: + return rc; } int ipc_fmt_request_register(struct ril_client *client, int request, @@ -1095,7 +1109,6 @@ struct ril_client_callbacks ipc_rfs_callbacks = { struct ril_client ipc_fmt_client = { .id = RIL_CLIENT_IPC_FMT, .name = "IPC FMT", - .critical = 1, .handlers = &ipc_fmt_handlers, .callbacks = &ipc_fmt_callbacks, }; @@ -1103,7 +1116,6 @@ struct ril_client ipc_fmt_client = { struct ril_client ipc_rfs_client = { .id = RIL_CLIENT_IPC_RFS, .name = "IPC RFS", - .critical = 0, .handlers = &ipc_rfs_handlers, .callbacks = &ipc_rfs_callbacks, }; diff --git a/samsung-ril.h b/samsung-ril.h index 2879782..7c60449 100644 --- a/samsung-ril.h +++ b/samsung-ril.h @@ -103,7 +103,6 @@ struct ril_client_callbacks { struct ril_client { int id; char *name; - int critical; struct ril_client_handlers *handlers; struct ril_client_callbacks *callbacks; diff --git a/srs.c b/srs.c index 5cca71c..38427a2 100644 --- a/srs.c +++ b/srs.c @@ -1172,7 +1172,6 @@ struct ril_client_callbacks srs_callbacks = { struct ril_client srs_client = { .id = RIL_CLIENT_SRS, .name = "SRS", - .critical = 0, .handlers = &srs_handlers, .callbacks = &srs_callbacks, }; -- cgit v1.1