[Tizen] Add codes for Dali Windows Backend
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / windows / framework-win.cpp
1 /*\r
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 // CLASS HEADER\r
19 #include <dali/internal/adaptor/common/framework.h>\r
20 \r
21 // EXTERNAL INCLUDES\r
22 #include <Win32WindowSystem.h>\r
23 \r
24 #include <dali/integration-api/debug.h>\r
25 \r
26 // INTERNAL INCLUDES\r
27 #include <dali/internal/system/common/callback-manager.h>\r
28 \r
29 int64_t counter = 0;\r
30 \r
31 namespace Dali\r
32 {\r
33 \r
34 namespace Internal\r
35 {\r
36 \r
37 namespace Adaptor\r
38 {\r
39 \r
40 namespace\r
41 {\r
42 \r
43 /// Application Status Enum\r
44 enum\r
45 {\r
46   APP_CREATE,\r
47   APP_TERMINATE,\r
48   APP_PAUSE,\r
49   APP_RESUME,\r
50   APP_RESET,\r
51   APP_LANGUAGE_CHANGE,\r
52 };\r
53 \r
54 } // Unnamed namespace\r
55 /**\r
56  * Impl to hide WindowsSystem data members\r
57  */\r
58 struct Framework::Impl\r
59 {\r
60   // Constructor\r
61 \r
62   Impl(void* data)\r
63   : mAbortCallBack( NULL ),\r
64     mCallbackManager( CallbackManager::New() ),\r
65     mLanguage( "NOT_SUPPORTED" ),\r
66     mRegion( "NOT_SUPPORTED" )\r
67   {\r
68   }\r
69 \r
70   ~Impl()\r
71   {\r
72     delete mAbortCallBack;\r
73 \r
74     // we're quiting the main loop so\r
75     // mCallbackManager->RemoveAllCallBacks() does not need to be called\r
76     // to delete our abort handler\r
77     delete mCallbackManager;\r
78   }\r
79 \r
80   std::string GetLanguage() const\r
81   {\r
82     return mLanguage;\r
83   }\r
84 \r
85   std::string GetRegion() const\r
86   {\r
87     return mRegion;\r
88   }\r
89 \r
90   // Data\r
91   CallbackBase* mAbortCallBack;\r
92   CallbackManager *mCallbackManager;\r
93   std::string mLanguage;\r
94   std::string mRegion;\r
95 \r
96   // Static methods\r
97 \r
98   /**\r
99    * Called by AppCore on application creation.\r
100    */\r
101   static bool AppCreate(void *data)\r
102   {\r
103     return static_cast<Framework*>(data)->AppStatusHandler(APP_CREATE, NULL);\r
104   }\r
105 \r
106   /**\r
107    * Called by AppCore when the application should terminate.\r
108    */\r
109   static void AppTerminate(void *data)\r
110   {\r
111     static_cast<Framework*>(data)->AppStatusHandler(APP_TERMINATE, NULL);\r
112   }\r
113 \r
114   /**\r
115    * Called by AppCore when the application is paused.\r
116    */\r
117   static void AppPause(void *data)\r
118   {\r
119     static_cast<Framework*>(data)->AppStatusHandler(APP_PAUSE, NULL);\r
120   }\r
121 \r
122   /**\r
123    * Called by AppCore when the application is resumed.\r
124    */\r
125   static void AppResume(void *data)\r
126   {\r
127     static_cast<Framework*>(data)->AppStatusHandler(APP_RESUME, NULL);\r
128   }\r
129 \r
130   /**\r
131    * Called by AppCore when the language changes on the device.\r
132    */\r
133   static void AppLanguageChange(void* data)\r
134   {\r
135     static_cast<Framework*>(data)->AppStatusHandler(APP_LANGUAGE_CHANGE, NULL);\r
136   }\r
137 \r
138   void Run()\r
139   {\r
140     Win32WindowSystem::RunLoop();\r
141   }\r
142 \r
143   void Quit()\r
144   {\r
145       int temp = 0;\r
146     //uv_stop( mMainLoop );\r
147   }\r
148 \r
149 \r
150 private:\r
151   // Undefined\r
152   Impl( const Impl& impl );\r
153 \r
154   // Undefined\r
155   Impl& operator=( const Impl& impl );\r
156 };\r
157 \r
158 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )\r
159 : mObserver(observer),\r
160   mInitialised(false),\r
161   mRunning(false),\r
162   mArgc(argc),\r
163   mArgv(argv),\r
164   mBundleName(""),\r
165   mBundleId(""),\r
166   mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),\r
167   mImpl(NULL)\r
168 {\r
169     InitThreads();\r
170     mImpl = new Impl(this);\r
171 }\r
172 \r
173 Framework::~Framework()\r
174 {\r
175   if (mRunning)\r
176   {\r
177     Quit();\r
178   }\r
179 \r
180   delete mImpl;\r
181 }\r
182 \r
183 void Framework::Run()\r
184 {\r
185     mRunning = true;\r
186 \r
187     Impl::AppCreate(this);\r
188     mImpl->Run();\r
189     mRunning = false;\r
190 }\r
191 \r
192 void Framework::Quit()\r
193 {\r
194   Impl::AppTerminate(this);\r
195 //  mImpl->Quit();\r
196 }\r
197 \r
198 bool Framework::IsMainLoopRunning()\r
199 {\r
200   return mRunning;\r
201 }\r
202 \r
203 void Framework::AddAbortCallback( CallbackBase* callback )\r
204 {\r
205   mImpl->mAbortCallBack = callback;\r
206 }\r
207 \r
208 std::string Framework::GetBundleName() const\r
209 {\r
210   return mBundleName;\r
211 }\r
212 \r
213 void Framework::SetBundleName(const std::string& name)\r
214 {\r
215   mBundleName = name;\r
216 }\r
217 \r
218 std::string Framework::GetBundleId() const\r
219 {\r
220   return mBundleId;\r
221 }\r
222 \r
223 std::string Framework::GetResourcePath()\r
224 {\r
225   // "DALI_APPLICATION_PACKAGE" is used by Ubuntu specifically to get the already configured Application package path.\r
226   const char* ubuntuEnvironmentVariable = "DALI_APPLICATION_PACKAGE";\r
227   char* value = getenv( ubuntuEnvironmentVariable );\r
228   printf( "DALI_APPLICATION_PACKAGE is %s\n", value );\r
229   std::string resourcePath;\r
230   if ( value != NULL )\r
231   {\r
232     resourcePath = value;\r
233   }\r
234 \r
235   return resourcePath;\r
236 }\r
237 \r
238 void Framework::SetBundleId(const std::string& id)\r
239 {\r
240   mBundleId = id;\r
241 }\r
242 \r
243 void Framework::AbortCallback( )\r
244 {\r
245   // if an abort call back has been installed run it.\r
246   if (mImpl->mAbortCallBack)\r
247   {\r
248     CallbackBase::Execute( *mImpl->mAbortCallBack );\r
249   }\r
250   else\r
251   {\r
252     Quit();\r
253   }\r
254 }\r
255 \r
256 bool Framework::AppStatusHandler(int type, void *bundleData)\r
257 {\r
258   switch (type)\r
259   {\r
260     case APP_CREATE:\r
261     {\r
262       mInitialised = true;\r
263 \r
264       mObserver.OnInit();\r
265       break;\r
266     }\r
267 \r
268     case APP_RESET:\r
269       mObserver.OnReset();\r
270       break;\r
271 \r
272     case APP_RESUME:\r
273       mObserver.OnResume();\r
274       break;\r
275 \r
276     case APP_TERMINATE:\r
277       mObserver.OnTerminate();\r
278       break;\r
279 \r
280     case APP_PAUSE:\r
281       mObserver.OnPause();\r
282       break;\r
283 \r
284     case APP_LANGUAGE_CHANGE:\r
285       mObserver.OnLanguageChanged();\r
286       break;\r
287 \r
288     default:\r
289       break;\r
290   }\r
291 \r
292   return true;\r
293 }\r
294 \r
295 void Framework::InitThreads()\r
296 {\r
297 //  XInitThreads();\r
298 }\r
299 \r
300 std::string Framework::GetLanguage() const\r
301 {\r
302   return mImpl->GetLanguage();\r
303 }\r
304 \r
305 std::string Framework::GetRegion() const\r
306 {\r
307   return mImpl->GetRegion();\r
308 }\r
309 \r
310 } // namespace Adaptor\r
311 \r
312 } // namespace Internal\r
313 \r
314 } // namespace Dali\r