summaryrefslogtreecommitdiff
path: root/src/ug.c
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:46:42 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-13 01:46:42 +0900
commit7596e199c101a324ac0bbab1be727962fe0ebf07 (patch)
treecc97cc634e3234446670bc6c7d455bd1be5dd806 /src/ug.c
parentc3875cbe2f8e945b837a76ac5f8e6d57bde940bb (diff)
downloadui-gadget-1-7596e199c101a324ac0bbab1be727962fe0ebf07.tar.gz
ui-gadget-1-7596e199c101a324ac0bbab1be727962fe0ebf07.tar.bz2
ui-gadget-1-7596e199c101a324ac0bbab1be727962fe0ebf07.zip
Tizen 2.1 base
Diffstat (limited to 'src/ug.c')
-rwxr-xr-xsrc/ug.c283
1 files changed, 283 insertions, 0 deletions
diff --git a/src/ug.c b/src/ug.c
new file mode 100755
index 0000000..09f4679
--- /dev/null
+++ b/src/ug.c
@@ -0,0 +1,283 @@
+/*
+ * UI Gadget
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "ug.h"
+#include "ug-module.h"
+#include "ug-manager.h"
+#include "ug-dbg.h"
+
+#ifndef UG_API
+#define UG_API __attribute__ ((visibility("default")))
+#endif
+
+ui_gadget_h ug_root_create(void)
+{
+ ui_gadget_h ug;
+
+ ug = calloc(1, sizeof(struct ui_gadget_s));
+ if (!ug) {
+ _ERR("ug root create failed: Memory allocation failed");
+ return NULL;
+ }
+
+ ug->mode = UG_MODE_FULLVIEW;
+ ug->state = UG_STATE_RUNNING;
+ ug->children = NULL;
+
+ return ug;
+}
+
+int ug_free(ui_gadget_h ug)
+{
+ if (!ug) {
+ _ERR("ug free failed: Invalid ug");
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (ug->module) {
+ ug_module_unload(ug->module);
+ }
+ if (ug->name) {
+ free((void *)ug->name);
+ ug->name = NULL;
+ }
+ if (ug->service) {
+ service_destroy(ug->service);
+ ug->service = NULL;
+ }
+ free(ug);
+ ug = NULL;
+ return 0;
+}
+
+UG_API ui_gadget_h ug_create(ui_gadget_h parent,
+ const char *name,
+ enum ug_mode mode,
+ service_h service, struct ug_cbs *cbs)
+{
+ if (!name) {
+ _ERR("ug_create() failed: Invalid name");
+ errno = EINVAL;
+ return NULL;
+ }
+
+ if (mode < UG_MODE_FULLVIEW || mode >= UG_MODE_INVALID) {
+ _ERR("ug_create() failed: Invalid mode");
+ errno = EINVAL;
+ return NULL;
+ }
+
+ return ugman_ug_load(parent, name, mode, service, cbs);
+}
+
+UG_API int ug_init(Display *disp, Window xid, void *win, enum ug_option opt)
+{
+ if (!win || !xid || !disp) {
+ _ERR("ug_init() failed: Invalid arguments");
+ return -1;
+ }
+
+ if (opt < UG_OPT_INDICATOR_ENABLE || opt >= UG_OPT_MAX) {
+ _ERR("ug_init() failed: Invalid option");
+ return -1;
+ }
+
+ return ugman_init(disp, xid, win, opt);
+}
+
+UG_API int ug_pause(void)
+{
+ return ugman_pause();
+}
+
+UG_API int ug_resume(void)
+{
+ return ugman_resume();
+}
+
+UG_API int ug_destroy(ui_gadget_h ug)
+{
+ return ugman_ug_del(ug);
+}
+
+UG_API int ug_destroy_all(void)
+{
+ return ugman_ug_del_all();
+}
+
+UG_API int ug_destroy_me(ui_gadget_h ug)
+{
+ if (!ug || !ugman_ug_exist(ug)) {
+ _ERR("ug_destroy_me() failed: Invalid ug");
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (ug->state == UG_STATE_DESTROYING) {
+ _ERR("ug_destory_me() failed:ug is alreay on destroying");
+ return -1;
+ }
+
+ if (!ug->cbs.destroy_cb) {
+ _ERR("ug_destroy_me() failed: destroy callback does not "
+ "exist");
+ return -1;
+ }
+
+ ug->cbs.destroy_cb(ug, ug->cbs.priv);
+ return 0;
+}
+
+UG_API void *ug_get_layout(ui_gadget_h ug)
+{
+ if (!ug || !ugman_ug_exist(ug)) {
+ _ERR("ug_get_layout() failed: Invalid ug");
+ errno = EINVAL;
+ return NULL;
+ }
+ return ug->layout;
+}
+
+UG_API void *ug_get_parent_layout(ui_gadget_h ug)
+{
+ ui_gadget_h parent;
+ if (!ug || !ugman_ug_exist(ug)) {
+ _ERR("ug_get_parent_layout() failed: Invalid ug");
+ errno = EINVAL;
+ return NULL;
+ }
+
+ parent = ug->parent;
+
+ if (parent)
+ return parent->layout;
+ return NULL;
+}
+
+UG_API enum ug_mode ug_get_mode(ui_gadget_h ug)
+{
+ if (!ug || !ugman_ug_exist(ug)) {
+ _ERR("ug_get_mode() failed: Invalid ug");
+ errno = EINVAL;
+ return UG_MODE_INVALID;
+ }
+
+ return ug->mode;
+}
+
+UG_API void *ug_get_window(void)
+{
+ return ugman_get_window();
+}
+
+UG_API void *ug_get_conformant(void)
+{
+ return ugman_get_conformant();
+}
+
+UG_API int ug_send_event(enum ug_event event)
+{
+ if (event <= UG_EVENT_NONE || event >= UG_EVENT_MAX) {
+ _ERR("ug_send_event() failed: Invalid event");
+ return -1;
+ }
+
+ return ugman_send_event(event);
+}
+
+UG_API int ug_send_key_event(enum ug_key_event event)
+{
+ if (event <= UG_KEY_EVENT_NONE || event >= UG_KEY_EVENT_MAX) {
+ _ERR("ug_send_key_event() failed: Invalid event");
+ return -1;
+ }
+
+ return ugman_send_key_event(event);
+}
+
+UG_API int ug_send_result(ui_gadget_h ug, service_h result)
+{
+ service_h result_dup = NULL;
+
+ if (!ug || !ugman_ug_exist(ug)) {
+ _ERR("ug_send_result() failed: Invalid ug");
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (!ug->cbs.result_cb) {
+ _ERR("ug_send_result() failed: result callback does not exist");
+ return -1;
+ }
+
+ if (result) {
+ service_clone(&result_dup, result);
+ if (!result_dup) {
+ _ERR("ug_send_result() failed: service_destroy failed");
+ return -1;
+ }
+ }
+
+ ug->cbs.result_cb(ug, result_dup, ug->cbs.priv);
+
+ if (result_dup)
+ service_destroy(result_dup);
+
+ return 0;
+}
+
+UG_API int ug_send_message(ui_gadget_h ug, service_h msg)
+{
+ int r;
+
+ service_h msg_dup = NULL;
+ if (msg) {
+ service_clone(&msg_dup, msg);
+ if (!msg_dup) {
+ _ERR("ug_send_message() failed: service_destroy failed");
+ return -1;
+ }
+ }
+
+ r = ugman_send_message(ug, msg_dup);
+
+ if (msg_dup)
+ service_destroy(msg_dup);
+
+ return r;
+}
+
+UG_API int ug_disable_effect(ui_gadget_h ug)
+{
+ if (ug->layout_state != UG_LAYOUT_INIT) {
+ _ERR("ug_disable_effect() failed: ug has already been shown");
+ return -1;
+ }
+ ug->layout_state = UG_LAYOUT_NOEFFECT;
+
+ return 0;
+}