glib_dep = dependency('glib-2.0', required: true)
common_deps += [glib_dep]
+json_dep = dependency('json-glib-1.0', required: true)
+common_deps += [json_dep]
+
subdir('src')
configure_file(output: 'config.h', configuration: conf_data)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(json-glib-1.0)
BuildRequires: pkgconfig(esplusplayer)
%description
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "espp_service_client_priv.h"
+#include <stdarg.h>
+#include <json-glib/json-glib.h>
+
+/* Use g_free() to release the return value. */
+static gchar *get_string_from_json_object(JsonObject *object)
+{
+ g_autoptr(JsonNode) root = NULL;
+ g_autoptr(JsonGenerator) generator = NULL;
+
+ ASSERT(object);
+
+ root = json_node_init_object(json_node_alloc(), object);
+ generator = json_generator_new();
+ json_generator_set_root(generator, root);
+ return json_generator_to_data(generator, NULL);
+}
+
+static JsonObject *make_json_object_params(va_list ap, const char *formats, JsonObject *object)
+{
+ char c;
+ JsonObject *params = json_object_new();
+
+ ASSERT(object);
+
+ while (*formats) {
+ switch ((c = *formats++)) {
+ case 'b':
+ json_object_set_boolean_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_BOOL], (gboolean)va_arg(ap, int));
+ break;
+ case 'i':
+ json_object_set_int_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_INT], (gint64)va_arg(ap, int));
+ break;
+ case 'l':
+ json_object_set_int_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_INT64], (gint64)va_arg(ap, int64_t));
+ break;
+ case 'u':
+ json_object_set_int_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_UINT], (gint64)va_arg(ap, unsigned int));
+ break;
+ case 'k':
+ json_object_set_int_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_UINT64], (gint64)va_arg(ap, uint64_t));
+ break;
+ case 'd':
+ json_object_set_double_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_DOUBLE], (gdouble)va_arg(ap, double));
+ break;
+ case 's':
+ json_object_set_string_member(params,
+ data_type_strs[ESPP_SERVICE_DATA_TYPE_STRING], (const gchar*)va_arg(ap, char *));
+ break;
+ default:
+ LOG_ERROR("not supported format[%c]", c);
+ json_object_unref(params);
+ json_object_unref(object);
+ return NULL;
+ }
+ }
+
+ json_object_set_object_member(object, "params", params);
+
+ return object;
+}
+
+gchar *espp_service_client_msg_params_new(const char *formats, ...)
+{
+ gchar *result = NULL;
+ JsonObject *obj;
+ va_list ap;
+
+ ASSERT(formats);
+
+ obj = json_object_new();
+
+ va_start(ap, formats);
+ obj = make_json_object_params(ap, formats, obj);
+ va_end(ap);
+
+ if (!obj)
+ return NULL;
+
+ result = get_string_from_json_object(obj);
+ json_object_unref(obj);
+
+ LOG_DEBUG("params: %s", result);
+
+ return result;
+}
\ No newline at end of file
int fd;
} espp_s;
+/* message */
+gchar *espp_service_client_msg_params_new(const char *formats, ...);
+
+/* socket */
int espp_service_client_socket_request_create(espp_s *espp);
int espp_service_client_socket_request_destroy(espp_s *espp);
int espp_service_client_socket_request_start(espp_s *espp);
x_dst[x_size - 1] = '\0';\
} while (0) \
-#define FILL_SOCKET_MSG_PARAMS(x_msg, x_params) \
+#define FILL_SOCKET_MSG_PARAMS(x_msg, x_request, ...) \
do { \
+ gchar *params = espp_service_client_msg_params_new(requests[x_request].param_formats, ##__VA_ARGS__); \
memset(&x_msg.params, 0x00, MAX_PARAMS_LEN); \
- STRNCPY(x_msg.params, x_params, MAX_PARAMS_LEN); \
+ if (!params) break; \
+ STRNCPY(x_msg.params, params, MAX_PARAMS_LEN); \
+ g_free(params); \
} while (0) \
-
#define FILL_SOCKET_MSG_REQUEST(x_msg, x_request) \
do { \
x_msg.request = x_request; \
'../common/espp_service_common.c',
'espp_service_client.c',
'espp_service_client_socket.c',
+ 'espp_service_client_msg.c',
])
espp_dep = dependency('esplusplayer', required: true)
#include "espp_service_common.h"
-espp_service_request_s requests[] = { /* str, num_of_params */
- [ESPP_SERVICE_REQUEST_CREATE] = { "Create", 0 },
- [ESPP_SERVICE_REQUEST_DESTROY] = {"Destroy", 0 },
- [ESPP_SERVICE_REQUEST_START] = { "Start", 0 },
+espp_service_request_s requests[] = { /* str, param_formats - 'b':bool, 'i':int, 'l':int64, 'u':uint, 'k':uint64, 'd':double, 's':string) */
+ [ESPP_SERVICE_REQUEST_CREATE] = { "Create", NULL },
+ [ESPP_SERVICE_REQUEST_DESTROY] = {"Destroy", NULL },
+ [ESPP_SERVICE_REQUEST_START] = { "Start", NULL },
+};
+
+const char *data_type_strs[] = {
+ [ESPP_SERVICE_DATA_TYPE_BOOL] = "bool",
+ [ESPP_SERVICE_DATA_TYPE_INT] = "int",
+ [ESPP_SERVICE_DATA_TYPE_INT64] = "int64",
+ [ESPP_SERVICE_DATA_TYPE_UINT] = "uint",
+ [ESPP_SERVICE_DATA_TYPE_UINT64] = "uint64",
+ [ESPP_SERVICE_DATA_TYPE_DOUBLE] = "double",
+ [ESPP_SERVICE_DATA_TYPE_STRING] = "string",
};
\ No newline at end of file
#include <stdlib.h>
#include <glib.h>
#include <stdbool.h>
+#include <stdint.h>
#ifdef USE_DLOG
#include <dlog.h>
#endif
} while (0)
#define ESPP_SERVICE_SOCK ESPP_SVC_SOCK_PATH
-#define MAX_PARAMS_LEN 128
+#define MAX_PARAMS_LEN 256
#define MAX_ERROR_LEN 64
typedef enum {
ESPP_SERVICE_REQUEST_START,
} espp_service_request_e;
+enum {
+ ESPP_SERVICE_DATA_TYPE_BOOL,
+ ESPP_SERVICE_DATA_TYPE_INT,
+ ESPP_SERVICE_DATA_TYPE_INT64,
+ ESPP_SERVICE_DATA_TYPE_UINT,
+ ESPP_SERVICE_DATA_TYPE_UINT64,
+ ESPP_SERVICE_DATA_TYPE_DOUBLE,
+ ESPP_SERVICE_DATA_TYPE_STRING,
+};
+
typedef struct {
espp_service_request_e request;
char params[MAX_PARAMS_LEN];
typedef struct {
const char *str;
- int num_of_params;
+ const char *param_formats;
} espp_service_request_s;
extern espp_service_request_s requests[];
+extern const char *data_type_strs[];
#ifdef __cplusplus
}