diff mbox series

[04/27] qmi: Add qmi_qrtr_node_get_service

Message ID 20240614185300.1086701-4-denkenz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [01/27] qmi: Remove qmi_free() | expand

Commit Message

Denis Kenzior June 14, 2024, 6:52 p.m. UTC
Introduce a new method that will return a qmi_service object handle
immediately, if possible.  This allows the lightweight service handles
to be obtained without requiring the caller to provide a callback
function and waiting for the event loop to invoke it.  On QRTR, the
underlying socket can access all services directly without needing to
exchange any messages to allocate a client for that service first, as
done by QMUX using QMI_CTL_GET_CLIENT_ID.
---
 drivers/qmimodem/qmi.c | 26 ++++++++++++++++++++++++++
 drivers/qmimodem/qmi.h |  7 ++++---
 2 files changed, 30 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index c5a4a37b917d..c3b1f7fef64f 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -2332,6 +2332,32 @@  struct qmi_device *qmi_device_new_qrtr(void)
 	return &qrtr->super;
 }
 
+struct qmi_service *qmi_qrtr_node_get_service(struct qmi_device *device,
+						uint32_t type)
+{
+	struct service_family *family;
+	const struct qmi_service_info *info;
+
+	if (!device)
+		return NULL;
+
+	if (type == QMI_SERVICE_CONTROL)
+		return NULL;
+
+	family = l_hashmap_lookup(device->family_list, L_UINT_TO_PTR(type));
+	if (family)
+		goto done;
+
+	info = __find_service_info_by_type(device, type);
+	if (!info)
+		return NULL;
+
+	family = service_family_create(device, info, 0);
+	l_hashmap_insert(device->family_list, L_UINT_TO_PTR(type), family);
+done:
+	return service_create(family);
+}
+
 struct qmi_param *qmi_param_new(void)
 {
 	return l_new(struct qmi_param, 1);
diff --git a/drivers/qmimodem/qmi.h b/drivers/qmimodem/qmi.h
index 3e532ec25abd..604e4e7e8659 100644
--- a/drivers/qmimodem/qmi.h
+++ b/drivers/qmimodem/qmi.h
@@ -58,9 +58,9 @@  enum qmi_data_endpoint_type {
 
 typedef void (*qmi_destroy_func_t)(void *user_data);
 
-
 struct qmi_device;
 struct qmi_result;
+struct qmi_service;
 
 typedef void (*qmi_debug_func_t)(const char *str, void *user_data);
 typedef void (*qmi_shutdown_func_t)(void *user_data);
@@ -90,6 +90,9 @@  bool qmi_device_set_expected_data_format(struct qmi_device *device,
 struct qmi_device *qmi_device_new_qmux(const char *device);
 struct qmi_device *qmi_device_new_qrtr(void);
 
+struct qmi_service *qmi_qrtr_node_get_service(struct qmi_device *device,
+						uint32_t type);
+
 struct qmi_param;
 
 struct qmi_param *qmi_param_new(void);
@@ -128,8 +131,6 @@  void qmi_result_print_tlvs(struct qmi_result *result);
 
 int qmi_error_to_ofono_cme(int qmi_error);
 
-struct qmi_service;
-
 typedef void (*qmi_create_func_t)(struct qmi_service *service, void *user_data);
 
 bool qmi_service_create_shared(struct qmi_device *device,