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