From dbeb7482ce14f9a439ffd052fd18dc8b3f60f822 Mon Sep 17 00:00:00 2001 From: heewon Park Date: Fri, 29 Mar 2019 18:26:56 +0900 Subject: [PATCH] Add orchestration client sdk. Signed-off-by: heewon Park --- src/libedge-orchestration/Makefile | 27 ++++++++ src/libedge-orchestration/inc/dbus_consumer.h | 27 ++++++++ .../inc/orchestration_client.h | 39 ++++++++++++ src/libedge-orchestration/sample/main.c | 14 +++++ src/libedge-orchestration/src/dbus_consumer.c | 62 +++++++++++++++++++ .../src/orchestration_client.c | 55 ++++++++++++++++ 6 files changed, 224 insertions(+) create mode 100644 src/libedge-orchestration/Makefile create mode 100644 src/libedge-orchestration/inc/dbus_consumer.h create mode 100644 src/libedge-orchestration/inc/orchestration_client.h create mode 100644 src/libedge-orchestration/sample/main.c create mode 100644 src/libedge-orchestration/src/dbus_consumer.c create mode 100644 src/libedge-orchestration/src/orchestration_client.c diff --git a/src/libedge-orchestration/Makefile b/src/libedge-orchestration/Makefile new file mode 100644 index 0000000..2dee550 --- /dev/null +++ b/src/libedge-orchestration/Makefile @@ -0,0 +1,27 @@ +# +# Makefile +# + +CC=gcc +all: orchestration-client main + +# %.o: %.c +# $(CC) -Wall -c `pkg-config --cflags dbus-1` +# lt; -o $@ + +main: ./sample/main.c + $(CC) -Wall ./sample/main.c -o ./sample/main -I ./inc -L ./ -lorchestration-client `pkg-config --libs --cflags gio-2.0 gio-unix-2.0 glib-2.0 dbus-glib-1 dbus-1` + +orchestration-client: orchestration_client.o dbus_consumer.o + $(CC) -shared -g -Wall -Werror ./src/orchestration_client.o ./src/dbus_consumer.o -o liborchestration-client.so -I ./inc + +orchestration_client.o: ./src/orchestration_client.c + $(CC) -fPIC -Wall ./src/orchestration_client.c -c -o ./src/orchestration_client.o -I ./inc + +dbus_consumer.o: ./src/dbus_consumer.c + $(CC) -fPIC -Wall ./src/dbus_consumer.c -c -o ./src/dbus_consumer.o -I ./inc `pkg-config --libs --cflags gio-2.0 gio-unix-2.0 glib-2.0 dbus-glib-1 dbus-1` + + +.PHONY: clean +clean: + rm ./src/*.o liborchestration-client.so ./sample/main \ No newline at end of file diff --git a/src/libedge-orchestration/inc/dbus_consumer.h b/src/libedge-orchestration/inc/dbus_consumer.h new file mode 100644 index 0000000..c2d3f24 --- /dev/null +++ b/src/libedge-orchestration/inc/dbus_consumer.h @@ -0,0 +1,27 @@ +#ifndef __ORCHESTRATION_DBUS_CONSUMER_H__ +#define __ORCHESTRATION_DBUS_CONSUMER_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum { + ORCH_DBUS_DISCONNECTED = 0, + ORCH_DBUS_CONNECTED = 1, +} ORCH_DBUS_STATUS; + +typedef enum { + ORCH_DBUS_ERROR_NONE = 0, + ORCH_DBUS_ERROR_INVALID_PARAMETER = -1, + ORCH_DBUS_ERROR_FAULT = -2, +} ORCH_DBUS_ERROR; + +int dbus_consumer_initailze(); +int request_service_execute(char* app_name, char* exec_param); + +#ifdef __cplusplus +} +#endif + +#endif /* __ORCHESTRATION_DBUS_CONSUMER_H__ */ \ No newline at end of file diff --git a/src/libedge-orchestration/inc/orchestration_client.h b/src/libedge-orchestration/inc/orchestration_client.h new file mode 100644 index 0000000..65077de --- /dev/null +++ b/src/libedge-orchestration/inc/orchestration_client.h @@ -0,0 +1,39 @@ +#ifndef __ORCHESTRATION_CLIENT_H__ +#define __ORCHESTRATION_CLIENT_H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum { + ORCH_CLIENT_ERROR_NONE = 0, + ORCH_CLIENT_ERROR_INVALID_PARAMETER = -1, + ORCH_CLIENT_ERROR_FAULT = -2, +} ORCH_CLIENT_ERROR; + +typedef enum { + ORCHESTRATION_SERVICE_STATUS_STARTED = 0, + ORCHESTRATION_SERVICE_STATUS_COMPLETED, + ORCHESTRATION_SERVICE_STATUS_FAILED, + ORCHESTRATION_SERVICE_STATUS_UNDEFINED_ERROR, +} orchestration_service_status_e; + +typedef struct +{ + char* exec_parameter; +} orchestration_service_info_s; + +typedef void (*orchestration_changed_service_status_cb) + (orchestration_service_status_e staus, void* user_data); + +ORCH_CLIENT_ERROR orchestration_request_service(char* app_name, + orchestration_service_info_s service_info, + orchestration_changed_service_status_cb cb, + void* user_data); + +#ifdef __cplusplus +} +#endif + +#endif /* __ORCHESTRATION_CLIENT_H__ */ \ No newline at end of file diff --git a/src/libedge-orchestration/sample/main.c b/src/libedge-orchestration/sample/main.c new file mode 100644 index 0000000..d5e9c36 --- /dev/null +++ b/src/libedge-orchestration/sample/main.c @@ -0,0 +1,14 @@ +#include +#include + +void status_cb(orchestration_service_status_e staus, void* user_data) +{ + +} + +int main() { + orchestration_service_info_s service_info; + service_info.exec_parameter = "param"; + orchestration_request_service("app_name12312313", service_info, status_cb, NULL); + return 0; +} \ No newline at end of file diff --git a/src/libedge-orchestration/src/dbus_consumer.c b/src/libedge-orchestration/src/dbus_consumer.c new file mode 100644 index 0000000..56d6e82 --- /dev/null +++ b/src/libedge-orchestration/src/dbus_consumer.c @@ -0,0 +1,62 @@ +#include +#include +#include + +#include + +/* ---------------------------------------------------------------------------------------------------- */ +GDBusConnection *_gdbus_conn; +gchar* _name_owner; + +#define _ORCHESTRATION_BUS_NAME "org.tizen.orchestration" +#define _ORCHESTRATION_OBJECT_PATH "/org/tizen/orchestration" +#define _ORCHESTRATION_INTERFACE "org.tizen.orchestration.agent" +#define _ORCHESTRATION_REQUEST_SERVICE_METHOD "request_service" + +/* ---------------------------------------------------------------------------------------------------- */ + +int dbus_consumer_initailze() +{ + GError *error = NULL; + + _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) + { + printf ("Failed to get bus access - %i : %s\n", error->code, error->message); + g_error_free (error); + error = NULL; + return ORCH_DBUS_ERROR_FAULT; + } + return ORCH_DBUS_ERROR_NONE; +} + +int request_service_execute(char* app_name, char* exec_param) +{ + GError *error = NULL; + + GVariant *result = + g_dbus_connection_call_sync (_gdbus_conn, + _ORCHESTRATION_BUS_NAME, + _ORCHESTRATION_OBJECT_PATH, + _ORCHESTRATION_INTERFACE, + _ORCHESTRATION_REQUEST_SERVICE_METHOD, + g_variant_new ("(ss)", app_name, exec_param), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (result) + g_variant_unref (result); + + if (error) + { + printf("Failed to call remote method - %i : %s\n", error->code, error->message); + g_error_free (error); + error = NULL; + g_object_unref (_gdbus_conn); + return ORCH_DBUS_ERROR_FAULT; + } + + return ORCH_DBUS_ERROR_NONE; +} \ No newline at end of file diff --git a/src/libedge-orchestration/src/orchestration_client.c b/src/libedge-orchestration/src/orchestration_client.c new file mode 100644 index 0000000..4d4d95f --- /dev/null +++ b/src/libedge-orchestration/src/orchestration_client.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +/* ---------------------------------------------------------------------------------------------------- */ +orchestration_changed_service_status_cb _changed_service_status_cb; + +#define _ORCHESTRATION_BUS_NAME "org.tizen.orchestration" +#define _ORCHESTRATION_OBJECT_PATH "/org/tizen/orchestration" +#define _ORCHESTRATION_INTERFACE "org.tizen.orchestration.agent" +#define _ORCHESTRATION_REQUEST_SERVICE_METHOD "request_service" + +ORCH_CLIENT_ERROR orchestration_request_service(char* app_name, + orchestration_service_info_s service_info, + orchestration_changed_service_status_cb cb, + void* user_data) +{ + int result = 0; + int ret = 0; + + if (app_name == NULL) + { + printf("app_name is null\n"); + return ORCH_CLIENT_ERROR_INVALID_PARAMETER; + } + if (service_info.exec_parameter == NULL) + { + printf("service_info is null\n"); + return ORCH_CLIENT_ERROR_INVALID_PARAMETER; + } + if (cb == NULL) + { + printf("orchestration_changed_service_status_cb is null\n"); + return ORCH_CLIENT_ERROR_INVALID_PARAMETER; + } + _changed_service_status_cb = cb; + + result = dbus_consumer_initailze(); + if (result != ORCH_DBUS_ERROR_NONE) + { + printf("dbus_consumer_initailze failed\n"); + return ORCH_CLIENT_ERROR_FAULT; + } + + result = request_service_execute(app_name, service_info.exec_parameter); + if (ret != ORCH_DBUS_ERROR_NONE) + { + printf("request_service_execute failed\n"); + return ORCH_CLIENT_ERROR_FAULT; + } + + return result; +} + -- 2.34.1