summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:37:44 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:37:44 +0900
commit07eb0c3cb8e30e74db35671045b42676f94e4a28 (patch)
treebdfd14b110afb51544b48fb9e478aab546cb2a9b /src
parent96c080d65747c89d1b3a0c78460e0f0a7ad08a2f (diff)
downloadminicontrol-07eb0c3cb8e30e74db35671045b42676f94e4a28.tar.gz
minicontrol-07eb0c3cb8e30e74db35671045b42676f94e4a28.tar.bz2
minicontrol-07eb0c3cb8e30e74db35671045b42676f94e4a28.zip
Tizen 2.1 base
Diffstat (limited to 'src')
-rwxr-xr-xsrc/minicontrol-internal.c301
-rwxr-xr-xsrc/minicontrol-monitor.c276
-rwxr-xr-xsrc/minicontrol-provider.c338
-rwxr-xr-xsrc/minicontrol-viewer.c98
4 files changed, 1013 insertions, 0 deletions
diff --git a/src/minicontrol-internal.c b/src/minicontrol-internal.c
new file mode 100755
index 0000000..9dde33a
--- /dev/null
+++ b/src/minicontrol-internal.c
@@ -0,0 +1,301 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * 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 <stdlib.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "minicontrol-error.h"
+#include "minicontrol-type.h"
+#include "minicontrol-internal.h"
+#include "minicontrol-log.h"
+
+#define MINICTRL_DBUS_PATH "/org/tizen/minicontrol"
+#define MINICTRL_DBUS_INTERFACE "org.tizen.minicontrol.signal"
+
+struct _minictrl_sig_handle {
+ DBusConnection *conn;
+ void (*callback) (void *data, DBusMessage *msg);
+ void *user_data;
+ char *signal;
+};
+
+int _minictrl_viewer_req_message_send(void)
+{
+ DBusConnection *connection = NULL;
+ DBusMessage *message = NULL;
+ DBusError err;
+ dbus_bool_t dbus_ret;
+ int ret = MINICONTROL_ERROR_NONE;
+
+ dbus_error_init(&err);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ if (!connection) {
+ ERR("Fail to dbus_bus_get : %s", err.message);
+ ret = MINICONTROL_ERROR_DBUS;
+ goto release_n_return;
+ }
+
+ message = dbus_message_new_signal(MINICTRL_DBUS_PATH,
+ MINICTRL_DBUS_INTERFACE,
+ MINICTRL_DBUS_SIG_RUNNING_REQ);
+ if (!message) {
+ ERR("fail to create dbus message");
+ ret = MINICONTROL_ERROR_OUT_OF_MEMORY;
+ goto release_n_return;
+ }
+
+ dbus_ret = dbus_connection_send(connection, message, NULL);
+ if (!dbus_ret) {
+ ERR("fail to send dbus viewer req message");
+ ret = MINICONTROL_ERROR_DBUS;
+ goto release_n_return;
+ }
+
+ dbus_connection_flush(connection);
+
+release_n_return:
+ dbus_error_free(&err);
+
+ if (message)
+ dbus_message_unref(message);
+
+ if (connection)
+ dbus_connection_unref(connection);
+
+ return ret;
+}
+
+int _minictrl_provider_message_send(const char *sig_name, const char *svr_name,
+ unsigned int witdh, unsigned int height,
+ minicontrol_priority_e priority)
+{
+ DBusConnection *connection = NULL;
+ DBusMessage *message = NULL;
+ DBusError err;
+ dbus_bool_t dbus_ret;
+ int ret = MINICONTROL_ERROR_NONE;
+
+ if (!sig_name) {
+ ERR("sig_name is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!svr_name) {
+ ERR("svr_name is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ dbus_error_init(&err);
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ if (!connection) {
+ ERR("Fail to dbus_bus_get : %s", err.message);
+ ret = MINICONTROL_ERROR_DBUS;
+ goto release_n_return;
+ }
+
+ message = dbus_message_new_signal(MINICTRL_DBUS_PATH,
+ MINICTRL_DBUS_INTERFACE,
+ sig_name);
+
+ if (!message) {
+ ERR("fail to create dbus message");
+ ret = MINICONTROL_ERROR_OUT_OF_MEMORY;
+ goto release_n_return;
+ }
+
+ dbus_ret = dbus_message_append_args(message,
+ DBUS_TYPE_STRING, &svr_name,
+ DBUS_TYPE_UINT32, &witdh,
+ DBUS_TYPE_UINT32, &height,
+ DBUS_TYPE_UINT32, &priority,
+ DBUS_TYPE_INVALID);
+ if (!dbus_ret) {
+ ERR("fail to append name to dbus message : %s", svr_name);
+ ret = MINICONTROL_ERROR_OUT_OF_MEMORY;
+ goto release_n_return;
+ }
+
+ dbus_ret = dbus_connection_send(connection, message, NULL);
+ if (!dbus_ret) {
+ ERR("fail to send dbus message : %s", svr_name);
+ ret = MINICONTROL_ERROR_DBUS;
+ goto release_n_return;
+ }
+
+ dbus_connection_flush(connection);
+ INFO("[%s][%s] size-[%ux%u] priority[%u]",
+ sig_name, svr_name, witdh, height, priority);
+
+release_n_return:
+ dbus_error_free(&err);
+
+ if (message)
+ dbus_message_unref(message);
+
+ if (connection)
+ dbus_connection_unref(connection);
+
+ return ret;
+}
+
+static DBusHandlerResult _minictrl_signal_filter(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ minictrl_sig_handle *handle = NULL;
+ const char *interface;
+ DBusError error;
+ dbus_bool_t ret;
+
+ if (!user_data)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ handle = user_data;
+
+ dbus_error_init(&error);
+
+ interface = dbus_message_get_interface(msg);
+ if (!interface)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (strcmp(MINICTRL_DBUS_INTERFACE, interface))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ ret = dbus_message_is_signal(msg, interface, handle->signal);
+ if (!ret) {
+ DBG("this msg is not signal");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (handle->callback)
+ handle->callback(handle->user_data, msg);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+
+minictrl_sig_handle *_minictrl_dbus_sig_handle_attach(const char *signal,
+ void (*callback) (void *data, DBusMessage *msg),
+ void *data)
+{
+ minictrl_sig_handle *handle = NULL;
+ DBusError err;
+ DBusConnection *conn = NULL;
+ char rule[1024] = {'\0', };
+
+ if (!signal) {
+ ERR("signal is NULL");
+ return NULL;
+ }
+
+ if (!callback) {
+ ERR("call is NULL");
+ return NULL;
+ }
+
+ handle = malloc(sizeof(minictrl_sig_handle));
+ if (!handle) {
+ ERR("fail to alloc handle");
+ return NULL;
+ }
+
+ dbus_error_init(&err);
+ conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
+ if (!conn) {
+ ERR("fail to get bus : %s", err.message);
+ goto error_n_return;
+ }
+
+ dbus_connection_setup_with_g_main(conn, NULL);
+ snprintf(rule, 1024,
+ "path='%s',type='signal',interface='%s',member='%s'",
+ MINICTRL_DBUS_PATH,
+ MINICTRL_DBUS_INTERFACE,
+ signal);
+
+ dbus_bus_add_match(conn, rule, &err);
+ if (dbus_error_is_set(&err)) {
+ ERR("fail to dbus_bus_remove_match : %s",
+ err.message);
+ goto error_n_return;
+ }
+
+ if (dbus_connection_add_filter(conn, _minictrl_signal_filter,
+ handle, NULL) == FALSE) {
+ ERR("fail to dbus_connection_add_filter : %s",
+ err.message);
+ goto error_n_return;
+ }
+
+ dbus_connection_set_exit_on_disconnect(conn, FALSE);
+
+ handle->conn = conn;
+ handle->callback = callback;
+ handle->user_data = data;
+ handle->signal = strdup(signal);
+
+ INFO("success to attach signal[%s]-[%p, %p]", signal, callback, data);
+
+ return handle;
+
+
+error_n_return:
+ if (handle)
+ free(handle);
+
+ dbus_error_free(&err);
+
+ if (conn)
+ dbus_connection_close(conn);
+
+ return NULL;
+}
+
+void _minictrl_dbus_sig_handle_dettach(minictrl_sig_handle *handle)
+{
+ DBusError err;
+ char rule[1024] = {'\0', };
+
+ if (!handle) {
+ ERR("handle is NULL");
+ return;
+ }
+
+ dbus_error_init(&err);
+
+ dbus_connection_remove_filter(handle->conn,
+ _minictrl_signal_filter, handle);
+
+ snprintf(rule, 1024,
+ "path='%s',type='signal',interface='%s',member='%s'",
+ MINICTRL_DBUS_PATH,
+ MINICTRL_DBUS_INTERFACE,
+ handle->signal);
+
+ dbus_bus_remove_match(handle->conn, rule, &err);
+ if (dbus_error_is_set(&err)) {
+ ERR("fail to dbus_bus_remove_match : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ dbus_connection_close(handle->conn);
+
+ free(handle->signal);
+ free(handle);
+
+ return;
+}
+
diff --git a/src/minicontrol-monitor.c b/src/minicontrol-monitor.c
new file mode 100755
index 0000000..d6520e7
--- /dev/null
+++ b/src/minicontrol-monitor.c
@@ -0,0 +1,276 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * 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 <stdlib.h>
+#include <dbus/dbus.h>
+
+#include "minicontrol-error.h"
+#include "minicontrol-internal.h"
+#include "minicontrol-monitor.h"
+#include "minicontrol-log.h"
+
+struct _minicontrol_monitor {
+ minictrl_sig_handle *start_sh;
+ minictrl_sig_handle *stop_sh;
+ minictrl_sig_handle *resize_sh;
+ minictrl_sig_handle *request_sh;
+ minicontrol_monitor_cb callback;
+ void *user_data;
+};
+
+static struct _minicontrol_monitor *g_monitor_h;
+
+static minicontrol_priority_e _int_to_priority(unsigned int value)
+{
+ minicontrol_priority_e priority = MINICONTROL_PRIORITY_LOW;
+ switch (value) {
+ case MINICONTROL_PRIORITY_TOP:
+ priority = MINICONTROL_PRIORITY_TOP;
+ break;
+ case MINICONTROL_PRIORITY_MIDDLE:
+ priority = MINICONTROL_PRIORITY_MIDDLE;
+ break;
+ case MINICONTROL_PRIORITY_LOW:
+ default:
+ priority = MINICONTROL_PRIORITY_LOW;
+ break;
+ }
+ return priority;
+}
+
+static void _provider_start_cb(void *data, DBusMessage *msg)
+{
+ DBusError err;
+ char *svr_name = NULL;
+ unsigned int w = 0;
+ unsigned int h = 0;
+ unsigned int pri = 0;
+ minicontrol_priority_e priority;
+ dbus_bool_t dbus_ret;
+
+ dbus_error_init(&err);
+
+ dbus_ret = dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &svr_name,
+ DBUS_TYPE_UINT32, &w,
+ DBUS_TYPE_UINT32, &h,
+ DBUS_TYPE_UINT32, &pri,
+ DBUS_TYPE_INVALID);
+ if (!dbus_ret) {
+ ERR("fail to get args : %s", err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ priority = _int_to_priority(pri);
+
+ if (g_monitor_h->callback)
+ g_monitor_h->callback(MINICONTROL_ACTION_START,
+ svr_name, w, h, priority,
+ g_monitor_h->user_data);
+
+ dbus_error_free(&err);
+}
+
+static void _provider_stop_cb(void *data, DBusMessage *msg)
+{
+ DBusError err;
+ char *svr_name = NULL;
+ dbus_bool_t dbus_ret;
+
+ dbus_error_init(&err);
+
+ dbus_ret = dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &svr_name,
+ DBUS_TYPE_INVALID);
+ if (!dbus_ret) {
+ ERR("fail to get args : %s", err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ if (g_monitor_h->callback)
+ g_monitor_h->callback(MINICONTROL_ACTION_STOP,
+ svr_name, 0, 0, MINICONTROL_PRIORITY_LOW,
+ g_monitor_h->user_data);
+
+ dbus_error_free(&err);
+}
+
+static void _provider_resize_cb(void *data, DBusMessage *msg)
+{
+ DBusError err;
+ char *svr_name = NULL;
+ unsigned int w = 0;
+ unsigned int h = 0;
+ unsigned int pri = 0;
+ minicontrol_priority_e priority;
+ dbus_bool_t dbus_ret;
+
+ dbus_error_init(&err);
+
+ dbus_ret = dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &svr_name,
+ DBUS_TYPE_UINT32, &w,
+ DBUS_TYPE_UINT32, &h,
+ DBUS_TYPE_UINT32, &pri,
+ DBUS_TYPE_INVALID);
+ if (!dbus_ret) {
+ ERR("fail to get args : %s", err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ priority = _int_to_priority(pri);
+
+ if (g_monitor_h->callback)
+ g_monitor_h->callback(MINICONTROL_ACTION_RESIZE,
+ svr_name, w, h, priority,
+ g_monitor_h->user_data);
+
+ dbus_error_free(&err);
+}
+
+static void _provider_request_cb(void *data, DBusMessage *msg)
+{
+ DBusError err;
+ char *svr_name = NULL;
+ unsigned int w = 0;
+ unsigned int h = 0;
+ unsigned int pri = 0;
+ minicontrol_priority_e priority;
+ dbus_bool_t dbus_ret;
+
+ dbus_error_init(&err);
+
+ dbus_ret = dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &svr_name,
+ DBUS_TYPE_UINT32, &w,
+ DBUS_TYPE_UINT32, &h,
+ DBUS_TYPE_UINT32, &pri,
+ DBUS_TYPE_INVALID);
+ if (!dbus_ret) {
+ ERR("fail to get args : %s", err.message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ priority = _int_to_priority(pri);
+
+ if (g_monitor_h->callback)
+ g_monitor_h->callback(MINICONTROL_ACTION_REQUEST,
+ svr_name, w, h, priority,
+ g_monitor_h->user_data);
+
+ dbus_error_free(&err);
+}
+
+EXPORT_API minicontrol_error_e minicontrol_monitor_start(
+ minicontrol_monitor_cb callback, void *data)
+{
+ if (!callback)
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+
+ if (!g_monitor_h) {
+ minictrl_sig_handle *start_sh;
+ minictrl_sig_handle *stop_sh;
+ minictrl_sig_handle *resize_sh;
+ minictrl_sig_handle *request_sh;
+ struct _minicontrol_monitor *monitor_h;
+
+ start_sh = _minictrl_dbus_sig_handle_attach(
+ MINICTRL_DBUS_SIG_START,
+ _provider_start_cb, NULL);
+ if (!start_sh) {
+ ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
+ MINICTRL_DBUS_SIG_START);
+ return MINICONTROL_ERROR_DBUS;
+ }
+
+ stop_sh = _minictrl_dbus_sig_handle_attach(
+ MINICTRL_DBUS_SIG_STOP,
+ _provider_stop_cb, NULL);
+ if (!stop_sh) {
+ ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
+ MINICTRL_DBUS_SIG_STOP);
+ return MINICONTROL_ERROR_DBUS;
+ }
+
+ resize_sh = _minictrl_dbus_sig_handle_attach(
+ MINICTRL_DBUS_SIG_RESIZE,
+ _provider_resize_cb, NULL);
+ if (!resize_sh) {
+ ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
+ MINICTRL_DBUS_SIG_RESIZE);
+ return MINICONTROL_ERROR_DBUS;
+ }
+
+ request_sh = _minictrl_dbus_sig_handle_attach(
+ MINICTRL_DBUS_SIG_REQUEST,
+ _provider_request_cb, NULL);
+ if (!request_sh) {
+ ERR("fail to _minictrl_dbus_sig_handle_attach - %s",
+ MINICTRL_DBUS_SIG_REQUEST);
+ return MINICONTROL_ERROR_DBUS;
+ }
+
+ monitor_h = malloc(sizeof(struct _minicontrol_monitor));
+ if (!monitor_h) {
+ ERR("fail to alloc monitor_h");
+ _minictrl_dbus_sig_handle_dettach(start_sh);
+ _minictrl_dbus_sig_handle_dettach(stop_sh);
+ _minictrl_dbus_sig_handle_dettach(resize_sh);
+ _minictrl_dbus_sig_handle_dettach(request_sh);
+ return MINICONTROL_ERROR_OUT_OF_MEMORY;
+ }
+
+ monitor_h->start_sh = start_sh;
+ monitor_h->stop_sh = stop_sh;
+ monitor_h->resize_sh = resize_sh;
+ monitor_h->request_sh = request_sh;
+ g_monitor_h = monitor_h;
+ }
+
+ g_monitor_h->callback = callback;
+ g_monitor_h->user_data = data;
+ INFO("callback[%p], data[%p]", callback, data);
+
+ return _minictrl_viewer_req_message_send();
+}
+
+EXPORT_API minicontrol_error_e minicontrol_monitor_stop(void)
+{
+ if (!g_monitor_h)
+ return MINICONTROL_ERROR_NONE;
+
+ if (g_monitor_h->start_sh)
+ _minictrl_dbus_sig_handle_dettach(g_monitor_h->start_sh);
+
+ if (g_monitor_h->stop_sh)
+ _minictrl_dbus_sig_handle_dettach(g_monitor_h->stop_sh);
+
+ if (g_monitor_h->resize_sh)
+ _minictrl_dbus_sig_handle_dettach(g_monitor_h->resize_sh);
+
+ if (g_monitor_h->request_sh)
+ _minictrl_dbus_sig_handle_dettach(g_monitor_h->request_sh);
+
+ free(g_monitor_h);
+ g_monitor_h = NULL;
+
+ return MINICONTROL_ERROR_NONE;
+}
+
diff --git a/src/minicontrol-provider.c b/src/minicontrol-provider.c
new file mode 100755
index 0000000..cc4e034
--- /dev/null
+++ b/src/minicontrol-provider.c
@@ -0,0 +1,338 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * 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 <Elementary.h>
+
+#include "minicontrol-error.h"
+#include "minicontrol-type.h"
+#include "minicontrol-internal.h"
+#include "minicontrol-provider.h"
+#include "minicontrol-log.h"
+
+#define MINICTRL_PRIORITY_SUFFIX_TOP "__minicontrol_top"
+#define MINICTRL_PRIORITY_SUFFIX_LOW "__minicontrol_low"
+#define MINICTRL_DATA_KEY "__minictrl_data_internal"
+
+enum {
+ MINICTRL_STATE_READY =0,
+ MINICTRL_STATE_RUNNING,
+};
+
+struct _provider_data {
+ char *name;
+ int state;
+ minicontrol_priority_e priority;
+ Evas_Object *obj;
+ minictrl_sig_handle *sh;
+};
+
+static void __provider_data_free(struct _provider_data *pd)
+{
+ if (pd) {
+ if (pd->name)
+ free(pd->name);
+
+ if (pd->sh)
+ _minictrl_dbus_sig_handle_dettach(pd->sh);
+
+ free(pd);
+ }
+}
+
+static int __str_has_suffix(const char *str, const char *suffix)
+{
+ int str_len;
+ int suffix_len;
+
+ if (!str)
+ return -1;
+
+ if (!suffix)
+ return -1;
+
+ str_len = strlen (str);
+ suffix_len = strlen (suffix);
+
+ if (str_len < suffix_len)
+ return -1;
+
+ return strcmp(str + str_len - suffix_len, suffix);
+}
+
+static void _running_req_cb(void *data, DBusMessage *msg)
+{
+ struct _provider_data *pd;
+
+ if (!data) {
+ ERR("data is NULL");
+ return;
+ }
+ pd = data;
+
+ if (pd->state == MINICTRL_STATE_RUNNING) {
+ Evas_Coord w = 0;
+ Evas_Coord h = 0;
+ evas_object_geometry_get(pd->obj, NULL, NULL, &w, &h);
+ _minictrl_provider_message_send(MINICTRL_DBUS_SIG_START,
+ pd->name, w, h, pd->priority);
+ }
+}
+
+static int minicontrol_win_start(Evas_Object *mincontrol)
+{
+ struct _provider_data *pd;
+ int ret = MINICONTROL_ERROR_NONE;
+
+ if (!mincontrol) {
+ ERR("mincontrol is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ pd = evas_object_data_get(mincontrol, MINICTRL_DATA_KEY);
+ if (!pd) {
+ ERR("pd is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!pd->name) {
+ ERR("pd name is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pd->state != MINICTRL_STATE_RUNNING) {
+ Evas_Coord w = 0;
+ Evas_Coord h = 0;
+ pd->state = MINICTRL_STATE_RUNNING;
+
+ evas_object_geometry_get(mincontrol, NULL, NULL, &w, &h);
+ ret = _minictrl_provider_message_send(MINICTRL_DBUS_SIG_START,
+ pd->name, w, h, pd->priority);
+ }
+
+ return ret;
+}
+
+static int minicontrol_win_stop(Evas_Object *mincontrol)
+{
+ struct _provider_data *pd;
+ int ret = MINICONTROL_ERROR_NONE;
+
+ if (!mincontrol) {
+ ERR("mincontrol is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ pd = evas_object_data_get(mincontrol, MINICTRL_DATA_KEY);
+ if (!pd) {
+ ERR("pd is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!pd->name) {
+ ERR("pd name is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+ if (pd->state != MINICTRL_STATE_READY) {
+ pd->state = MINICTRL_STATE_READY;
+ ret = _minictrl_provider_message_send(MINICTRL_DBUS_SIG_STOP,
+ pd->name, 0, 0, pd->priority);
+ }
+
+ return ret;
+}
+
+static void _minictrl_win_del(void *data, Evas *e,
+ Evas_Object *obj, void *event_info)
+{
+ struct _provider_data *pd = NULL;
+
+ minicontrol_win_stop(obj);
+
+ pd = evas_object_data_get(obj, MINICTRL_DATA_KEY);
+ __provider_data_free(pd);
+
+ evas_object_data_set(obj, MINICTRL_DATA_KEY, NULL);
+}
+
+static void _minictrl_win_hide(void *data, Evas *e,
+ Evas_Object *obj, void *event_info)
+{
+ minicontrol_win_stop(obj);
+}
+
+static void _minictrl_win_show(void *data, Evas *e,
+ Evas_Object *obj, void *event_info)
+{
+ minicontrol_win_start(obj);
+}
+
+static void _minictrl_win_resize(void *data, Evas *e,
+ Evas_Object *obj, void *event_info)
+{
+ struct _provider_data *pd;
+
+ if (!data) {
+ ERR("data is NULL, invaild parameter");
+ return;
+ }
+ pd = data;
+
+ if (pd->state == MINICTRL_STATE_RUNNING) {
+ Evas_Coord w = 0;
+ Evas_Coord h = 0;
+
+ evas_object_geometry_get(obj, NULL, NULL, &w, &h);
+ _minictrl_provider_message_send(MINICTRL_DBUS_SIG_RESIZE,
+ pd->name, w, h, pd->priority);
+ }
+}
+
+static char *_minictrl_create_name(const char *name)
+{
+ time_t now;
+ struct tm *now_tm;
+ char time_buf[20]; /* 18 chars to represent time */
+ char *buf;
+ int size = 0;
+
+ if (!name) {
+ ERR("name is NULL, invaild parameter");
+ return NULL;
+ }
+
+ now = time(NULL);
+ now_tm = localtime(&now);
+ strftime(time_buf, sizeof(time_buf), "%y-%m-%d-%H:%M:%S", now_tm);
+
+ size = snprintf(NULL, 0, "[%s]-[%s]", name, time_buf) + 1;
+ buf = (char *)malloc(sizeof(char) * size);
+ if (!buf) {
+ ERR("fail to alloc buf");
+ return NULL;
+ }
+
+ snprintf(buf, size, "[%s]-[%s]", name, time_buf);
+
+ return buf;
+}
+
+static minicontrol_priority_e _minictrl_get_priroty_by_name(const char *name)
+{
+ minicontrol_priority_e priority = MINICONTROL_PRIORITY_MIDDLE;
+
+ if (!__str_has_suffix(name, MINICTRL_PRIORITY_SUFFIX_TOP))
+ priority = MINICONTROL_PRIORITY_TOP;
+ else if (!__str_has_suffix(name, MINICTRL_PRIORITY_SUFFIX_LOW))
+ priority = MINICONTROL_PRIORITY_LOW;
+
+ return priority;
+}
+
+EXPORT_API Evas_Object *minicontrol_win_add(const char *name)
+{
+ Evas_Object *win = NULL;
+ char *name_inter = NULL;
+ struct _provider_data *pd;
+
+ if (!name)
+ return NULL;
+
+ win = elm_win_add(NULL, "minicontrol", ELM_WIN_SOCKET_IMAGE);
+ if (!win)
+ return NULL;
+
+ name_inter = _minictrl_create_name(name);
+ if (!name_inter) {
+
+ ERR("Fail to create name_inter for : %s", name);
+ evas_object_del(win);
+ return NULL;
+
+ }
+
+ if (!elm_win_socket_listen(win, name_inter, 0, EINA_FALSE)) {
+ ERR("Fail to elm win socket listen");
+ evas_object_del(win);
+ return NULL;
+ }
+
+ pd = malloc(sizeof(struct _provider_data));
+ if (!pd) {
+ ERR("Fail to alloc memory");
+ evas_object_del(win);
+ free(name_inter);
+ return NULL;
+
+ }
+ memset(pd, 0x00, sizeof(struct _provider_data));
+ pd->name = name_inter;
+ pd->state = MINICTRL_STATE_READY;
+ pd->obj = win;
+ pd->priority = _minictrl_get_priroty_by_name(name);
+
+ evas_object_data_set(win ,MINICTRL_DATA_KEY,pd);
+
+ elm_win_autodel_set(win, EINA_TRUE);
+
+ evas_object_event_callback_add(win, EVAS_CALLBACK_DEL,
+ _minictrl_win_del, pd);
+
+ evas_object_event_callback_add(win, EVAS_CALLBACK_SHOW,
+ _minictrl_win_show, pd);
+
+ evas_object_event_callback_add(win, EVAS_CALLBACK_HIDE,
+ _minictrl_win_hide, pd);
+
+ evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE,
+ _minictrl_win_resize, pd);
+
+ pd->sh = _minictrl_dbus_sig_handle_attach(MINICTRL_DBUS_SIG_RUNNING_REQ,
+ _running_req_cb, pd);
+
+ INFO("new minicontrol win[%p] created - %s, priority[%d]",
+ win, pd->name, pd->priority);
+
+ return win;
+}
+
+EXPORT_API minicontrol_error_e minicontrol_request(Evas_Object *mincontrol, minicontrol_request_e request)
+{
+ struct _provider_data *pd;
+ int ret = MINICONTROL_ERROR_NONE;
+
+ if (!mincontrol) {
+ ERR("mincontrol is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ pd = evas_object_data_get(mincontrol, MINICTRL_DATA_KEY);
+ if (!pd) {
+ ERR("pd is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!pd->name) {
+ ERR("pd name is NULL, invaild parameter");
+ return MINICONTROL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (pd->state == MINICTRL_STATE_RUNNING) {
+ ret = _minictrl_provider_message_send(MINICTRL_DBUS_SIG_REQUEST,
+ pd->name, request, request, pd->priority);
+ }
+
+ return ret;
+}
diff --git a/src/minicontrol-viewer.c b/src/minicontrol-viewer.c
new file mode 100755
index 0000000..6a346eb
--- /dev/null
+++ b/src/minicontrol-viewer.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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://floralicense.org/license/
+ *
+ * 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 <Elementary.h>
+#include <Ecore_Evas.h>
+
+#include "minicontrol-internal.h"
+#include "minicontrol-type.h"
+#include "minicontrol-viewer.h"
+#include "minicontrol-log.h"
+
+#define MINICTRL_PLUG_DATA_KEY "__minictrl_plug_name"
+
+static void _minictrl_plug_server_del(Ecore_Evas *ee)
+{
+ char *svr_name = NULL;
+
+ svr_name = ecore_evas_data_get(ee, MINICTRL_PLUG_DATA_KEY);
+ if (!svr_name) {
+ ERR("fail to get svr_name");
+ return;
+ }
+
+ INFO("server - %s is deleted", svr_name);
+
+ /* send message to remve plug */
+ _minictrl_provider_message_send(MINICTRL_DBUS_SIG_STOP,
+ svr_name, 0, 0,
+ MINICONTROL_PRIORITY_LOW);
+}
+
+static void _minictrl_plug_del(void *data, Evas *e,
+ Evas_Object *obj, void *event_info)
+{
+ Ecore_Evas *ee = NULL;
+ char *svr_name = NULL;
+
+ ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
+ if (!ee)
+ return;
+
+ svr_name = ecore_evas_data_get(ee, MINICTRL_PLUG_DATA_KEY);
+ if (svr_name)
+ free(svr_name);
+
+ ecore_evas_data_set(ee, MINICTRL_PLUG_DATA_KEY, NULL);
+}
+
+EXPORT_API
+Evas_Object *minicontrol_viewer_image_object_get(const Evas_Object *obj)
+{
+ return elm_plug_image_object_get(obj);
+}
+
+EXPORT_API Evas_Object *minicontrol_viewer_add(Evas_Object *parent,
+ const char *svr_name)
+{
+ Evas_Object *plug = NULL;
+ Evas_Object *plug_img = NULL;
+ Ecore_Evas *ee = NULL;
+
+ plug = elm_plug_add(parent);
+ if (!plug) {
+ ERR("fail to create plug");
+ return NULL;
+ }
+
+ if (!elm_plug_connect(plug, svr_name, 0, EINA_FALSE)) {
+ ERR("Cannot connect plug[%s]", svr_name);
+ evas_object_del(plug);
+ return NULL;
+ }
+
+ plug_img = elm_plug_image_object_get(plug);
+
+ ee = ecore_evas_object_ecore_evas_get(plug_img);
+ ecore_evas_data_set(ee, MINICTRL_PLUG_DATA_KEY, strdup(svr_name));
+ ecore_evas_callback_delete_request_set(ee, _minictrl_plug_server_del);
+
+ evas_object_event_callback_add(plug, EVAS_CALLBACK_DEL,
+ _minictrl_plug_del, plug);
+
+ return plug;
+}
+