aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-08-31 14:51:35 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-08-31 15:12:55 +0200
commit9b9813cda1e3bb1c2376c284ee4e4f2f30738ce8 (patch)
tree8074df1ce80aff0219aaae2654ce00b68c7844ef
parent0dc570f10a5028949581d433ab8a52dcdf014936 (diff)
downloadhardware_replicant_libsamsung-ipc-history/12-09-2022/replicant-11-i9300-modem.tar.gz
hardware_replicant_libsamsung-ipc-history/12-09-2022/replicant-11-i9300-modem.tar.bz2
hardware_replicant_libsamsung-ipc-history/12-09-2022/replicant-11-i9300-modem.zip
Try to make the threading code workhistory/12-09-2022/replicant-11-i9300-modem
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tools/ipc-modem.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/tools/ipc-modem.c b/tools/ipc-modem.c
index d84c6ef..46871cc 100644
--- a/tools/ipc-modem.c
+++ b/tools/ipc-modem.c
@@ -448,6 +448,14 @@ void modem_read_loop(struct ipc_modem_client *modem_client)
}
}
+void modem_dummy_read_loop(struct ipc_modem_client *modem_client)
+{
+ for(;;) {
+ printf("%s for the %s channel\n", __FUNCTION__, modem_client->name);
+ sleep(1);
+ }
+}
+
void modem_log_handler(__attribute__((unused)) void *user_data,
const char *msg)
{
@@ -476,7 +484,8 @@ void modem_log_handler_quiet(__attribute__((unused)) void *user_data,
{
}
-int modem_start(struct ipc_client *client_fmt, struct ipc_client *client_rfs)
+int modem_start(struct ipc_client *client_fmt, struct ipc_client *client_rfs,
+ bool dry_run)
{
int rc = -1;
@@ -527,13 +536,17 @@ int modem_stop(struct ipc_client *client_fmt, struct ipc_client *client_rfs)
return 0;
}
-int modem_create_channel_thread(struct ipc_client *client, const char* name)
+int modem_create_channel_thread(struct ipc_client *client, const char* name,
+ bool dry_run)
{
int rc;
struct ipc_modem_client modem_client;
- printf("[2] Starting modem_read_loop on %s client\n", name);
+ if (dry_run)
+ printf("[2] Starting modem_dummy_read_loop on %s client\n", name);
+ else
+ printf("[2] Starting modem_read_loop on %s client\n", name);
modem_client.client = client;
modem_client.name = name;
@@ -553,10 +566,16 @@ int modem_create_channel_thread(struct ipc_client *client, const char* name)
return rc;
}
- rc = pthread_create(&modem_client.thread,
- &modem_client.attr,
- (void *) modem_read_loop,
- (void *) &modem_client);
+ if (dry_run)
+ rc = pthread_create(&modem_client.thread,
+ &modem_client.attr,
+ (void *) modem_dummy_read_loop,
+ (void *) &modem_client);
+ else
+ rc = pthread_create(&modem_client.thread,
+ &modem_client.attr,
+ (void *) modem_read_loop,
+ (void *) &modem_client);
if (rc) {
printf("[E] %s pthread_create failed with error %d\n",
name, rc);
@@ -583,8 +602,11 @@ void print_help(void)
printf("\t--rfs enable RFS client in addition to FMT client\n");
}
-int create_client(struct ipc_client **client, int client_type, bool debug)
+int create_client(struct ipc_client **client, int client_type, bool debug,
+ bool dry_run)
{
+ if (dry_run)
+ client_type = IPC_CLIENT_TYPE_DUMMY;
*client = ipc_client_create(client_type);
if (*client == 0) {
@@ -602,18 +624,19 @@ int create_client(struct ipc_client **client, int client_type, bool debug)
return 0;
}
-int handle_command(enum command cmd, bool debug, bool rfs)
+int handle_command(enum command cmd, bool debug, bool rfs, bool dry_run)
{
struct ipc_client *client_fmt = 0;
struct ipc_client *client_rfs = 0;
int rc = 0;
- rc = create_client(&client_fmt, IPC_CLIENT_TYPE_FMT, debug);
+ rc = create_client(&client_fmt, IPC_CLIENT_TYPE_FMT, debug, dry_run);
if (rc)
goto modem_quit;
if (rfs)
- rc = create_client(&client_rfs, IPC_CLIENT_TYPE_RFS, debug);
+ rc = create_client(&client_rfs, IPC_CLIENT_TYPE_RFS, debug,
+ dry_run);
switch (cmd) {
case CMD_POWER_ON:
@@ -636,32 +659,37 @@ int handle_command(enum command cmd, bool debug, bool rfs)
break;
case CMD_START:
printf("[0] Starting modem FMT client\n");
- rc = modem_start(client_fmt, client_rfs);
- if (rc < 0) {
- printf("[E] Something went wrong "
- "starting FMT client\n");
- modem_stop(client_fmt, client_rfs);
- return 1;
+ if (!dry_run) {
+ rc = modem_start(client_fmt, client_rfs, dry_run);
+ if (rc < 0) {
+ printf("[E] Something went wrong "
+ "starting FMT client\n");
+ modem_stop(client_fmt, client_rfs);
+ return 1;
+ }
}
if (rfs) {
printf("[1] Starting modem RFS client\n");
rc = modem_create_channel_thread(client_rfs,
- "RFS");
+ "RFS",
+ dry_run);
if (rc)
return rc;
} else {
printf("[1] Skipping modem RFS client start\n");
}
- rc = modem_create_channel_thread(client_fmt, "FMT");
- return rc;
+ rc = modem_create_channel_thread(client_fmt, "FMT", dry_run);
+ break;
default:
printf("ERROR: unknown CMD %d\n", cmd);
/* We should handle all commands */
assert(false);
}
+ while(1) {}
+
modem_quit:
if (client_fmt != 0)
ipc_client_destroy(client_fmt);
@@ -679,6 +707,7 @@ int main(int argc, char *argv[])
int rc = -1;
bool debug = false;
bool rfs = false;
+ bool dry_run = false;
struct option opt_l[] = {
{"call", required_argument, 0, 0 },
@@ -723,6 +752,9 @@ int main(int argc, char *argv[])
} else if (strcmp(opt_l[opt_i].name, "rfs") == 0) {
rfs = true;
printf("[I] RFS enabled\n");
+ } else if (strcmp(opt_l[opt_i].name, "dry-run") == 0) {
+ dry_run = true;
+ printf("[I] dry-run mode\n");
} else if (strcmp(opt_l[opt_i].name, "call") == 0) {
if (optarg) {
if (strlen(optarg) < 14) {
@@ -766,5 +798,5 @@ int main(int argc, char *argv[])
optind++;
}
- return handle_command(command, debug, rfs);
+ return handle_command(command, debug, rfs, dry_run);
}