tizen 2.3.1 release
[framework/web/wearable/wrt-commons.git] / modules / 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 bool Application::app_create(void *data)
33 {
34     Application *This = static_cast<Application *>(data);
35     This->OnCreate();
36     return true;
37 }
38
39 void Application::app_terminate(void *data)
40 {
41     Application *This = static_cast<Application *>(data);
42     This->OnTerminate();
43 }
44
45 void Application::app_pause(void *data)
46 {
47     Application *This = static_cast<Application *>(data);
48     This->OnPause();
49 }
50
51 void Application::app_resume(void *data)
52 {
53     Application *This = static_cast<Application *>(data);
54     This->OnResume();
55 }
56
57 void Application::app_control(app_control_h app_control, void *data)
58 {
59     Application *This = static_cast<Application *>(data);
60
61     // convert app_control to bundle
62     bundle *b;
63     app_control_to_bundle(app_control, &b);
64
65     This->OnReset(b);
66 }
67
68 Application::Application(int argc, char** argv,
69                          const std::string& applicationName,
70                          bool showMainWindow) :
71     m_argc(argc),
72     m_argv(argv),
73     m_applicationName(applicationName),
74     m_mainWindowVisible(showMainWindow)
75 {
76     if (g_application != NULL) {
77         ThrowMsg(Exception::TooManyInstances,
78                  "Only single instance of Application allowed at one time!");
79     }
80
81     g_application = this;
82 }
83
84 Application::~Application()
85 {
86     g_application = NULL;
87 }
88
89 int Application::Exec()
90 {
91     LogPedantic("Starting application framework...");
92
93     ui_app_lifecycle_callback_s callback;
94     callback.create = app_create;
95     callback.terminate = app_terminate;
96     callback.pause = app_pause;
97     callback.resume = app_resume;
98     callback.app_control = app_control;
99
100     int result = ui_app_main(m_argc, m_argv, &callback, this);
101
102     LogPedantic("Exited application framework");
103
104     return result;
105 }
106
107 void Application::OnCreate()
108 {
109     LogPedantic("On application create");
110 }
111
112 void Application::OnStart()
113 {
114     LogPedantic("On application start");
115 }
116
117 void Application::OnStop()
118 {
119     LogPedantic("On application stop");
120 }
121
122 void Application::OnResume()
123 {
124     LogPedantic("On application resume");
125 }
126
127 void Application::OnPause()
128 {
129     LogPedantic("On application pause");
130 }
131
132 void Application::OnRelaunch()
133 {
134     LogPedantic("On application relaunch");
135 }
136
137 void Application::OnReset(bundle *b)
138 {
139     (void)b;
140     LogPedantic("On application reset");
141 }
142
143 void Application::OnTerminate()
144 {
145     LogPedantic("On application terminate");
146 }
147
148 void Application::OnLowMemory()
149 {
150     LogPedantic("On application low memory");
151 }
152
153 void Application::OnLowBattery()
154 {
155     LogPedantic("On application low battery");
156 }
157
158 void Application::OnLanguageChanged()
159 {
160     LogPedantic("On application language changed");
161 }
162
163 void Application::Quit()
164 {
165     elm_exit();
166 }
167
168 DPL::Atomic ApplicationExt::m_useCount(0);
169
170 ApplicationExt::ApplicationExt(int argc,
171                                char** argv,
172                                const std::string& applicationName,
173                                bool showMainWindow) :
174     Application(argc, argv, applicationName, showMainWindow)
175 {}
176
177 ApplicationExt::~ApplicationExt()
178 {}
179
180 int ApplicationExt::Exec()
181 {
182     if (0 == m_useCount.CompareAndExchange(0, 1)) {
183         return Application::Exec();
184     } else {
185         elm_run();
186     }
187     return 0;
188 }
189
190 void ApplicationExt::Quit()
191 {
192     elm_exit();
193 }
194 } // namespace DPL