44d12dd7378d7c124001b333ede0f9beff6fc919
[apps/home/wrt-setting.git] / webapp-detail / ug.cpp
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://floralicense.org/license/
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include <malloc.h>
18 #include <ui-gadget.h>
19 #include <ui-gadget-module.h>
20 #include <string.h>
21 #include <Elementary.h>
22 #include <bundle.h>
23
24 #undef None
25 #include <dpl/wrt-dao-ro/WrtDatabase.h>
26 #include <dpl/wrt-dao-ro/common_dao_types.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28
29 #include "mainview.h"
30
31 #define EXPORT_SYMBOL extern "C" __attribute__((visibility("default")))
32
33 struct priv {
34     WebAppDetailSetting::MainView *mainView;
35 };
36
37 static void *onCreate(ui_gadget_h ug,
38                       enum ug_mode /*mode*/,
39                       service_h service,
40                       void *user_data)
41 {
42     struct priv *priv;
43     WrtDB::TizenAppId appID;
44     char *pkgname = NULL;
45
46     Assert(ug && user_data);
47     priv = static_cast<struct priv *>(user_data);
48
49     service_get_extra_data(service, "pkg_name", &pkgname);
50     if (!pkgname)
51         return NULL;
52
53     appID = WrtDB::WidgetDAOReadOnly::getTzAppId((DPL::FromASCIIString
54                                                  (std::string(pkgname))));
55
56     /* Create MainView */
57     try {
58         priv->mainView = new WebAppDetailSetting::MainView(ug, appID);
59         return priv->mainView->loadView();
60     } catch (const std::bad_alloc &) {
61         return NULL;
62     }
63 }
64
65 static void onDestroy(ui_gadget_h /*ug*/,
66                       service_h /*service*/,
67                       void *user_data)
68 {
69     struct priv *priv;
70
71     Assert(user_data);
72     priv = static_cast<struct priv *>(user_data);
73     delete priv->mainView;
74     priv->mainView = NULL;
75 }
76
77 EXPORT_SYMBOL int UG_MODULE_INIT(struct ug_module_ops *ops)
78 {
79     struct priv *priv;
80
81     Assert(ops);
82     priv = static_cast<struct priv *>(calloc(1, sizeof(*priv)));
83     if (!priv)
84         return -1;
85
86     WrtDB::WrtDatabase::attachToThreadRW();
87     //AceDB::AceDAOReadOnly::attachToThreadRW();
88
89     memset(ops, 0x00, sizeof(*ops));
90     ops->priv = priv;
91     ops->create = onCreate;
92     ops->destroy = onDestroy;
93     ops->opt = UG_OPT_INDICATOR_ENABLE;
94
95     return 0;
96 }
97
98 EXPORT_SYMBOL void UG_MODULE_EXIT(struct ug_module_ops *ops)
99 {
100     struct priv *priv;
101
102     Assert(ops);
103     priv = static_cast<struct priv *>(ops->priv);
104     if (priv->mainView)
105         delete priv->mainView;
106     free(priv);
107
108     //AceDB::AceDAOReadOnly::detachFromThread();
109     WrtDB::WrtDatabase::detachFromThread();
110 }