[Replicant] [libsamsung-ipc] [PATCH 06/14] Add ipc_client_type_string

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Wed Sep 1 14:25:27 UTC 2021

When working on applications using libsamsung-ipc, we sometimes
have functions that have an ipc client type argument and that
work for all 3 ipc client types, or want to refactorize the
code to do that in order to make the code more clean and generic.

However in these cases, these functions often needed to output
some error message or tell users what is going on through
logging prints, and the code ends up being way cleaner if there
is a generic function to get the name of the ipc client type.

In many cases it makes sense not to use the full
IPC_CLIENT_TYPE_<type> name but only the <name> type in these
messages, so because it's easier to add IPC_CLIENT_TYPE_ to the
<type> than removing it, it makes sense to only return the string
associated to the type (like "FMT", "RFS" or "DUMMY".

The least significant number of the library version was also
bumped as we are adding a new function, but the applications that
were built against older libsamsung-ipc revisions should still work.

However applications that depends on this ipc_client_type_string
will not work with previous versions of libsamsung-ipc.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
 configure.ac              |  2 +-
 include/samsung-ipc.h     |  1 +
 samsung-ipc/ipc_strings.c | 20 ++++++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index d59ef0f..4246af8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([libsamsung-ipc], [0.6.0], [replicant at osuosl.org], [libsamsung-ipc])
+AC_INIT([libsamsung-ipc], [0.7.0], [replicant at osuosl.org], [libsamsung-ipc])
 AM_INIT_AUTOMAKE([dist-bzip2 dist-xz subdir-objects])
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h
index 53f1f72..d9aa7c7 100644
--- a/include/samsung-ipc.h
+++ b/include/samsung-ipc.h
@@ -138,6 +138,7 @@ const char *ipc_request_type_string(unsigned char type);
 const char *ipc_response_type_string(unsigned char type);
 const char *ipc_command_string(unsigned short command);
 const char *ipc_group_string(unsigned char group);
+const char *ipc_client_type_string(unsigned char client_type);
 int ipc_data_dump(struct ipc_client *client, const void *data, size_t size);
 void ipc_client_log_send(struct ipc_client *client, struct ipc_message *message,
diff --git a/samsung-ipc/ipc_strings.c b/samsung-ipc/ipc_strings.c
index 0922832..4d130b3 100644
--- a/samsung-ipc/ipc_strings.c
+++ b/samsung-ipc/ipc_strings.c
@@ -387,3 +387,23 @@ const char *ipc_group_string(unsigned char group)
 		return group_string;
+const char *ipc_client_type_string(unsigned char client_type)
+	static char client_type_string[5] = { 0 };
+	switch (client_type) {
+		return "FMT";
+		return "RFS";
+		return "DUMMY";
+	default:
+		snprintf((char *) &client_type_string,
+			 sizeof(client_type_string),
+			 "0x%02x",
+			 client_type);
+		return client_type_string;
+	}

More information about the Replicant mailing list