[PATCH i-g-t v2 22/39] lib/chamelium/v3: Implement Chamelium configuration parsing
Louis Chauvet
louis.chauvet at bootlin.com
Tue Jul 9 15:34:38 UTC 2024
The mapping between DRM connectors and Chamelium ports can differ among
setups. To avoid using a time-consuming algorithm for auto-detecting the
configuration, this commit introduces parsing of the port mapping from a
configuration file. The format used is the same as in Chamelium v2.
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
lib/chamelium/v3/igt_chamelium.c | 72 ++++++++++++++++++++++++++++++++++++++++
lib/chamelium/v3/igt_chamelium.h | 2 ++
2 files changed, 74 insertions(+)
diff --git a/lib/chamelium/v3/igt_chamelium.c b/lib/chamelium/v3/igt_chamelium.c
index 767dfcfcb182..e5a6a438924d 100644
--- a/lib/chamelium/v3/igt_chamelium.c
+++ b/lib/chamelium/v3/igt_chamelium.c
@@ -10,6 +10,9 @@
#define CHAMELIUM_CONFIG_SECTION "Chameliumv3"
#define CHAMELIUM_CONFIG_URL "URL"
+#define CHAMELIUM_V2_CONFIG_PREFIX "Chamelium"
+#define CHAMELIUM_V2_CONFIG_PORT_ID "ChameliumPortID"
+
struct igt_chamelium_v3 {
xmlrpc_env env;
xmlrpc_client *client;
@@ -126,6 +129,75 @@ struct igt_chamelium_v3 *chamelium_v3_init_from_config(void)
return chamelium;
}
+/**
+ * chamelium_v3_fill_port_mapping_from_config_v2() - Read the configuration file using the chamelium
+ * v2 format
+ *
+ * @chamelium: chamelium to store the port mapping into
+ *
+ * Read the configuration file to search a chamelium configuration, using the Cv2 format. It will
+ * ignore any malformed entry.
+ */
+static void chamelium_v3_fill_port_mapping_from_config_v2(struct igt_chamelium_v3 *chamelium)
+{
+ char **group_list;
+
+ igt_assert(igt_key_file);
+
+ group_list = g_key_file_get_groups(igt_key_file, NULL);
+ for (int group_idx = 0; group_list[group_idx]; group_idx++) {
+ if (strstr(group_list[group_idx], CHAMELIUM_V2_CONFIG_PREFIX ":")) {
+ struct chamelium_v3_port_mapping *port_mapping = NULL;
+ GError *error = NULL;
+ char *port_name_str =
+ group_list[group_idx] + (sizeof(CHAMELIUM_V2_CONFIG_PREFIX ":") - 1);
+
+ errno = 0;
+
+ port_mapping = chamelium_v3_port_mapping_alloc();
+ port_mapping->connector_name = strdup(port_name_str);
+
+ if (g_key_file_has_key(igt_key_file, group_list[group_idx],
+ CHAMELIUM_V2_CONFIG_PORT_ID, NULL)) {
+ port_mapping->port_id = g_key_file_get_integer(igt_key_file,
+ group_list[group_idx],
+ CHAMELIUM_V2_CONFIG_PORT_ID,
+ &error);
+ if (error) {
+ igt_info("Skipping malformed entry %s: %s\n",
+ group_list[group_idx], error->message);
+ chamelium_v3_port_mapping_free(port_mapping);
+ } else {
+ igt_list_add(&port_mapping->link, &chamelium->port_mapping);
+ }
+ } else {
+ igt_warn("Skipping malformed entry %s: Missing "
+ CHAMELIUM_V2_CONFIG_PORT_ID "\n",
+ group_list[group_idx]);
+ chamelium_v3_port_mapping_free(port_mapping);
+ }
+
+ if (error)
+ free(error);
+ }
+
+ free(group_list[group_idx]);
+ }
+ free(group_list);
+}
+
+/**
+ * chamelium_v3_fill_port_mapping() - Read the configuration file and fill the port_mapping
+ * structure.
+ *
+ * @chamelium: chamelium to store the port mapping into
+ */
+void chamelium_v3_fill_port_mapping(struct igt_chamelium_v3 *chamelium)
+{
+ if (igt_key_file)
+ chamelium_v3_fill_port_mapping_from_config_v2(chamelium);
+}
+
/**
* chamelium_v3_uninit() - Free the resources used by a chamelium
*
diff --git a/lib/chamelium/v3/igt_chamelium.h b/lib/chamelium/v3/igt_chamelium.h
index cab33e43aadd..3aaf51dd38db 100644
--- a/lib/chamelium/v3/igt_chamelium.h
+++ b/lib/chamelium/v3/igt_chamelium.h
@@ -44,6 +44,8 @@ struct chamelium_v3_port_mapping {
struct igt_chamelium_v3 *chamelium_v3_init(char *url);
struct igt_chamelium_v3 *chamelium_v3_init_from_config(void);
+void chamelium_v3_fill_port_mapping(struct igt_chamelium_v3 *chamelium);
+
void chamelium_v3_uninit(struct igt_chamelium_v3 *chamelium);
void chamelium_v3_reset(struct igt_chamelium_v3 *chamelium);
--
2.44.2
More information about the igt-dev
mailing list