--- /dev/null
+/* Code generated by cmd/cgo; DO NOT EDIT. */
+
+/* package interface */
+
+
+#line 1 "cgo-builtin-prolog"
+
+#include <stddef.h> /* for ptrdiff_t below */
+
+#ifndef GO_CGO_EXPORT_PROLOGUE_H
+#define GO_CGO_EXPORT_PROLOGUE_H
+
+typedef struct { const char *p; ptrdiff_t n; } _GoString_;
+
+#endif
+
+/* Start of preamble from import "C" comments. */
+
+
+
+
+/* End of preamble from import "C" comments. */
+
+
+/* Start of boilerplate cgo prologue. */
+#line 1 "cgo-gcc-export-header-prolog"
+
+#ifndef GO_CGO_PROLOGUE_H
+#define GO_CGO_PROLOGUE_H
+
+typedef signed char GoInt8;
+typedef unsigned char GoUint8;
+typedef short GoInt16;
+typedef unsigned short GoUint16;
+typedef int GoInt32;
+typedef unsigned int GoUint32;
+typedef long long GoInt64;
+typedef unsigned long long GoUint64;
+typedef GoInt64 GoInt;
+typedef GoUint64 GoUint;
+typedef __SIZE_TYPE__ GoUintptr;
+typedef float GoFloat32;
+typedef double GoFloat64;
+typedef float _Complex GoComplex64;
+typedef double _Complex GoComplex128;
+
+/*
+ static assertion to make sure the file is being used on architecture
+ at least with matching size of GoInt.
+*/
+typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
+
+typedef _GoString_ GoString;
+typedef void *GoMap;
+typedef void *GoChan;
+typedef struct { void *t; void *v; } GoInterface;
+typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
+
+#endif
+
+/* End of boilerplate cgo prologue. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern int OrchestrationInit();
+
+extern int OrchestrationRequestService();
+
+#ifdef __cplusplus
+}
+#endif
+++ /dev/null
-/* Code generated by cmd/cgo; DO NOT EDIT. */
-
-/* package interface */
-
-
-#line 1 "cgo-builtin-prolog"
-
-#include <stddef.h> /* for ptrdiff_t below */
-
-#ifndef GO_CGO_EXPORT_PROLOGUE_H
-#define GO_CGO_EXPORT_PROLOGUE_H
-
-typedef struct { const char *p; ptrdiff_t n; } _GoString_;
-
-#endif
-
-/* Start of preamble from import "C" comments. */
-
-
-
-
-/* End of preamble from import "C" comments. */
-
-
-/* Start of boilerplate cgo prologue. */
-#line 1 "cgo-gcc-export-header-prolog"
-
-#ifndef GO_CGO_PROLOGUE_H
-#define GO_CGO_PROLOGUE_H
-
-typedef signed char GoInt8;
-typedef unsigned char GoUint8;
-typedef short GoInt16;
-typedef unsigned short GoUint16;
-typedef int GoInt32;
-typedef unsigned int GoUint32;
-typedef long long GoInt64;
-typedef unsigned long long GoUint64;
-typedef GoInt64 GoInt;
-typedef GoUint64 GoUint;
-typedef __SIZE_TYPE__ GoUintptr;
-typedef float GoFloat32;
-typedef double GoFloat64;
-typedef float _Complex GoComplex64;
-typedef double _Complex GoComplex128;
-
-/*
- static assertion to make sure the file is being used on architecture
- at least with matching size of GoInt.
-*/
-typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
-
-typedef _GoString_ GoString;
-typedef void *GoMap;
-typedef void *GoChan;
-typedef struct { void *t; void *v; } GoInterface;
-typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
-
-#endif
-
-/* End of boilerplate cgo prologue. */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-extern int OrchestrationInit();
-
-extern int OrchestrationRequestService();
-
-#ifdef __cplusplus
-}
-#endif
--- /dev/null
+#include <gio/gio.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <dbus_interface.h>
+
+/* ---------------------------------------------------------------------------------------------------- */
+static guint owner_id;
+static GDBusConnection *_gdbus_conn;
+static GDBusNodeInfo *introspection_data = NULL;
+
+request_service_cb _request_service_cb = NULL;
+
+#define _ORCHESTRATION_BUS_NAME "org.tizen.orchestration"
+#define _ORCHESTRATION_OBJECT_PATH "/org/tizen/orchestration"
+#define _ORCHESTRATION_SVC_ERROR_DOMAIN "orchestration"
+
+GDBusErrorEntry _orchestration_svc_errors[] = {
+ {ORCH_ERROR_NONE, "NoError"},
+ {ORCH_ERROR_INVALID_PARAMETER, "Invalid parameter"},
+ {ORCH_ERROR_FAULT, "Orchestration Failed"},
+};
+
+/* Introspection data for the service we are exporting */
+static gchar introspection_xml[] =
+ " <node>"
+ " <interface name='org.tizen.orchestration.agent'>"
+ " <method name='request_service'>"
+ " <arg type='s' name='app_name' direction='in'/>"
+ " <arg type='s' name='service_info' direction='in'/>"
+ " </method>"
+ " </interface>"
+ " </node>";
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GQuark _ORCHESTRATION_ERROR_quark(void)
+{
+ static volatile gsize quark_volatile = 0;
+ g_dbus_error_register_error_domain(_ORCHESTRATION_SVC_ERROR_DOMAIN,
+ &quark_volatile,
+ _orchestration_svc_errors,
+ G_N_ELEMENTS(_orchestration_svc_errors));
+ return (GQuark)quark_volatile;
+}
+
+int _request_service(GVariant *parameters, GVariant **reply_body)
+{
+ char *app_name, *service_info;
+
+ g_variant_get(parameters, "(&ss)", &app_name, &service_info);
+
+ if (app_name == NULL)
+ return ORCH_ERROR_INVALID_PARAMETER;
+ if (service_info == NULL)
+ return ORCH_ERROR_INVALID_PARAMETER;
+
+ _request_service_cb(app_name, service_info);
+
+ return ORCH_ERROR_NONE;
+}
+
+static void _handle_method_call(
+ GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ int ret = ORCH_ERROR_NONE;
+ GVariant *reply_body = NULL;
+
+ if (g_strcmp0(method_name, "request_service") == 0)
+ {
+ ret = _request_service(parameters, &reply_body);
+ }
+ if (ret == ORCH_ERROR_NONE)
+ {
+ printf("Orchestration service Success, method name : %s\n", method_name);
+ g_dbus_method_invocation_return_value(invocation, reply_body);
+ }
+ else
+ {
+ printf("Orchestration service fail, method name : %s\n", method_name);
+
+ GError *error = g_error_new(_ORCHESTRATION_ERROR_quark(), ret, "request service failed");
+ g_dbus_method_invocation_return_gerror(invocation, error);
+ g_error_free(error);
+ }
+}
+
+static const GDBusInterfaceVTable _interface_vtable =
+{
+ _handle_method_call,
+ NULL,
+ NULL
+};
+
+static int _dbus_init(void)
+{
+ GError *error = NULL;
+
+ if (_gdbus_conn == NULL)
+ {
+ _gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (_gdbus_conn == NULL)
+ {
+ if (error != NULL)
+ {
+ printf("Failed to get dbus [%s]", error->message);
+ g_error_free(error);
+ }
+ return ORCH_ERROR_FAULT;
+ }
+ }
+
+ return ORCH_ERROR_NONE;
+}
+
+void orch_dbus_finish(void)
+{
+ g_bus_unown_name(owner_id);
+ g_dbus_node_info_unref(introspection_data);
+}
+
+ORCH_DBUS_ERROR orch_dbus_initialize(request_service_cb cb)
+{
+ int result;
+ guint orch_registration_id;
+
+ GError *error = NULL;
+
+ if (cb == NULL)
+ {
+ result = ORCH_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+ _request_service_cb = cb;
+
+ result = _dbus_init();
+ if (result != ORCH_ERROR_NONE)
+ {
+ printf("Can't init dbus [%d]", result);
+ goto out;
+ }
+ owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ _ORCHESTRATION_BUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL,
+ NULL,
+ NULL,
+ NULL, NULL);
+ if (!owner_id)
+ {
+ printf("Failed to own name");
+ result = ORCH_ERROR_FAULT;
+ goto out;
+ }
+
+ introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error);
+ if (!introspection_data)
+ {
+ printf("g_dbus_node_info_new_for_xml is failed.");
+ if (error != NULL)
+ {
+ printf("g_dbus_node_info_new_for_xml err [%s]", error->message);
+ g_error_free(error);
+ }
+ result = ORCH_ERROR_FAULT;
+ goto out;
+ }
+
+ orch_registration_id = g_dbus_connection_register_object(_gdbus_conn,
+ _ORCHESTRATION_OBJECT_PATH, introspection_data->interfaces[0],
+ &_interface_vtable, NULL, NULL, NULL);
+
+ if (orch_registration_id == 0)
+ {
+ printf("Failed to g_dbus_connection_register_object");
+ result = ORCH_ERROR_FAULT;
+ goto out;
+ }
+
+out:
+ if (introspection_data)
+ {
+ g_dbus_node_info_unref(introspection_data);
+ }
+
+ return result;
+}
\ No newline at end of file