Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / core / src / application.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  * @file        application.cpp
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of MVC application support
21  */
22 #include <stddef.h>
23 #include <dpl/application.h>
24 #include <dpl/log/log.h>
25
26 namespace // anonymous
27 {
28 static DPL::Application *g_application = NULL;
29 } // namespace anonymous
30
31 namespace DPL {
32 int Application::app_create(void *data)
33 {
34     Application *This = static_cast<Application *>(data);
35     This->OnCreate();
36     return 0;
37 }
38
39 int Application::app_terminate(void *data)
40 {
41     Application *This = static_cast<Application *>(data);
42     This->OnTerminate();
43     return 0;
44 }
45
46 int Application::app_pause(void *data)
47 {
48     Application *This = static_cast<Application *>(data);
49     This->OnPause();
50     return 0;
51 }
52
53 int Application::app_resume(void *data)
54 {
55     Application *This = static_cast<Application *>(data);
56     This->OnResume();
57     return 0;
58 }
59
60 int Application::app_reset(bundle *b, void *data)
61 {
62     Application *This = static_cast<Application *>(data);
63     This->OnReset(b);
64     return 0;
65 }
66
67 Application::Application(int argc, char** argv,
68                          const std::string& applicationName,
69                          bool showMainWindow) :
70     m_argc(argc),
71     m_argv(argv),
72     m_applicationName(applicationName),
73     m_mainWindowVisible(showMainWindow)
74 {
75     if (g_application != NULL) {
76         ThrowMsg(Exception::TooManyInstances,
77                  "Only single instance of Application allowed at one time!");
78     }
79
80     g_application = this;
81 }
82
83 Application::~Application()
84 {
85     g_application = NULL;
86 }
87
88 int Application::Exec()
89 {
90     LogPedantic("Starting application framework...");
91
92     struct appcore_ops ops;
93     ops.create = app_create;
94     ops.terminate = app_terminate;
95     ops.pause = app_pause;
96     ops.resume = app_resume;
97     ops.reset = app_reset;
98     ops.data = this;
99
100     int result = appcore_efl_main(
101             m_applicationName.c_str(), &m_argc, &m_argv, &ops);
102
103     LogPedantic("Exited application framework");
104
105     return result;
106 }
107
108 void Application::OnCreate()
109 {
110     LogPedantic("On application create");
111 }
112
113 void Application::OnStart()
114 {
115     LogPedantic("On application start");
116 }
117
118 void Application::OnStop()
119 {
120     LogPedantic("On application stop");
121 }
122
123 void Application::OnResume()
124 {
125     LogPedantic("On application resume");
126 }
127
128 void Application::OnPause()
129 {
130     LogPedantic("On application pause");
131 }
132
133 void Application::OnRelaunch()
134 {
135     LogPedantic("On application relaunch");
136 }
137
138 void Application::OnReset(bundle *b)
139 {
140     (void)b;
141     LogPedantic("On application reset");
142 }
143
144 void Application::OnTerminate()
145 {
146     LogPedantic("On application terminate");
147 }
148
149 void Application::OnLowMemory()
150 {
151     LogPedantic("On application low memory");
152 }
153
154 void Application::OnLowBattery()
155 {
156     LogPedantic("On application low battery");
157 }
158
159 void Application::OnLanguageChanged()
160 {
161     LogPedantic("On application language changed");
162 }
163
164 void Application::Quit()
165 {
166     elm_exit();
167 }
168
169 DPL::Atomic ApplicationExt::m_useCount(0);
170
171 ApplicationExt::ApplicationExt(int argc,
172                                char** argv,
173                                const std::string& applicationName,
174                                bool showMainWindow) :
175     Application(argc, argv, applicationName, showMainWindow)
176 {}
177
178 ApplicationExt::~ApplicationExt()
179 {}
180
181 int ApplicationExt::Exec()
182 {
183     if (0 == m_useCount.CompareAndExchange(0, 1)) {
184         return Application::Exec();
185     } else {
186         elm_run();
187     }
188     return 0;
189 }
190
191 void ApplicationExt::Quit()
192 {
193     elm_exit();
194 }
195 } // namespace DPL