tizen beta release
[framework/web/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 <dpl/application.h>
23 #include <dpl/log/log.h>
24
25 namespace // anonymous
26 {
27 static DPL::Application *g_application = NULL;
28 } // namespace anonymous
29
30 namespace DPL
31 {
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, "Only single instance of Application allowed at one time!");
77
78     g_application = this;
79 }
80
81 Application::~Application()
82 {
83     g_application = NULL;
84 }
85
86 int Application::Exec()
87 {
88     LogPedantic("Starting application framework...");
89
90     struct appcore_ops ops;
91     ops.create = app_create;
92     ops.terminate = app_terminate;
93     ops.pause = app_pause;
94     ops.resume = app_resume;
95     ops.reset = app_reset;
96     ops.data=this;
97
98     int result = appcore_efl_main(m_applicationName.c_str(), &m_argc, &m_argv, &ops);
99
100     LogPedantic("Exited application framework");
101
102     return result;
103 }
104
105 void Application::OnCreate()
106 {
107     LogPedantic("On application create");
108 }
109
110 void Application::OnStart()
111 {
112     LogPedantic("On application start");
113 }
114
115 void Application::OnStop()
116 {
117     LogPedantic("On application stop");
118 }
119
120 void Application::OnResume()
121 {
122     LogPedantic("On application resume");
123 }
124
125 void Application::OnPause()
126 {
127     LogPedantic("On application pause");
128 }
129
130 void Application::OnRelaunch()
131 {
132     LogPedantic("On application relaunch");
133 }
134
135 void Application::OnReset(bundle *b)
136 {
137     (void)b;
138     LogPedantic("On application reset");
139 }
140
141 void Application::OnTerminate()
142 {
143     LogPedantic("On application terminate");
144 }
145
146 void Application::OnLowMemory()
147 {
148     LogPedantic("On application low memory");
149 }
150
151 void Application::OnLowBattery()
152 {
153     LogPedantic("On application low battery");
154 }
155
156 void Application::OnLanguageChanged()
157 {
158     LogPedantic("On application language changed");
159 }
160
161 void Application::Quit()
162 {
163     elm_exit();
164 }
165
166 DPL::Atomic ApplicationExt::m_useCount(0);
167
168 ApplicationExt::ApplicationExt(int argc, char** argv, const std::string& applicationName, bool showMainWindow) :
169     Application(argc, argv, applicationName, showMainWindow)
170 {
171 }
172
173 ApplicationExt::~ApplicationExt()
174 {
175 }
176
177 int ApplicationExt::Exec()
178 {
179     if (0 == m_useCount.CompareAndExchange(0, 1))
180     {
181         return Application::Exec();
182     }
183     else
184     {
185         elm_run();
186     }
187     return 0;
188 }
189
190 void ApplicationExt::Quit()
191 {
192     elm_exit();
193 }
194 } // namespace DPL