Add Component Application Structure
[platform/core/uifw/dali-adaptor-legacy.git] / dali / internal / adaptor / tizen-wayland / framework-tizen.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
18 // CLASS HEADER
19 #include <dali/internal/adaptor/common/framework.h>
20
21 // EXTERNAL INCLUDES
22 #include <appcore_ui_base.h>
23 #include <app_control_internal.h>
24 #include <app_common.h>
25 #include <bundle.h>
26 #include <dali/internal/system/linux/dali-ecore.h>
27
28 #include <system_info.h>
29 #include <system_settings.h>
30 #include <bundle_internal.h>
31 #include <widget_base.h>
32 // CONDITIONAL INCLUDES
33 #ifdef APPCORE_WATCH_AVAILABLE
34 #include <appcore-watch/watch_app.h>
35 #endif
36 #ifdef DALI_ELDBUS_AVAILABLE
37 #include <Eldbus.h>
38 #endif // DALI_ELDBUS_AVAILABLE
39
40 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
41 #include <tzplatform_config.h>
42 #endif // TIZEN_PLATFORM_CONFIG_SUPPORTED
43
44 #ifdef COMPONENT_APPLICATION_SUPPORT
45 #include <component_based_app_base.h>
46 #endif
47
48 #include <dali/integration-api/debug.h>
49
50 // INTERNAL INCLUDES
51 #include <dali/internal/system/common/callback-manager.h>
52
53 namespace Dali
54 {
55
56 namespace Internal
57 {
58
59 namespace Adaptor
60 {
61
62 namespace
63 {
64 #if defined(DEBUG_ENABLED)
65 Integration::Log::Filter* gDBusLogging = Integration::Log::Filter::New( Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DBUS" );
66 #endif
67
68 bool IsWidgetFeatureEnabled()
69 {
70   static bool feature = false;
71   static bool retrieved = false;
72   int ret;
73
74   if(retrieved == true)
75   {
76     return feature;
77   }
78
79   ret = system_info_get_platform_bool("http://tizen.org/feature/shell.appwidget", &feature);
80   if(ret != SYSTEM_INFO_ERROR_NONE)
81   {
82     DALI_LOG_ERROR("failed to get system info");
83     return false;
84   }
85
86   retrieved = true;
87   return feature;
88 }
89
90 } // anonymous namespace
91
92 namespace AppCore
93 {
94
95 typedef enum
96 {
97   LOW_MEMORY,                 //< The low memory event
98   LOW_BATTERY,                //< The low battery event
99   LANGUAGE_CHANGED,           //< The system language changed event
100   DEVICE_ORIENTATION_CHANGED, //< The device orientation changed event
101   REGION_FORMAT_CHANGED,      //< The region format changed event
102   SUSPENDED_STATE_CHANGED,    //< The suspended state changed event of the application
103   UPDATE_REQUESTED,           //< The update requested event. This event can occur when an app needs to be updated. It is dependent on target devices.
104 } AppEventType;
105
106 static int AppEventConverter[APPCORE_BASE_EVENT_MAX] =
107 {
108   [LOW_MEMORY] = APPCORE_BASE_EVENT_LOW_MEMORY,
109   [LOW_BATTERY] = APPCORE_BASE_EVENT_LOW_BATTERY,
110   [LANGUAGE_CHANGED] = APPCORE_BASE_EVENT_LANG_CHANGE,
111   [DEVICE_ORIENTATION_CHANGED] = APPCORE_BASE_EVENT_DEVICE_ORIENTATION_CHANGED,
112   [REGION_FORMAT_CHANGED] = APPCORE_BASE_EVENT_REGION_CHANGE,
113   [SUSPENDED_STATE_CHANGED] = APPCORE_BASE_EVENT_SUSPENDED_STATE_CHANGE,
114 };
115
116 struct AppEventInfo
117 {
118   AppEventType type;
119   void *value;
120 };
121
122 typedef struct AppEventInfo *AppEventInfoPtr;
123
124 typedef void (*AppEventCallback)(AppEventInfoPtr eventInfo, void *userData);
125
126 struct AppEventHandler
127 {
128   AppEventType type;
129   AppEventCallback cb;
130   void *data;
131   void *raw;
132 };
133
134 typedef struct AppEventHandler *AppEventHandlerPtr;
135
136 int EventCallback(void *event, void *data)
137 {
138   AppEventHandlerPtr handler = static_cast<AppEventHandlerPtr>(data);
139
140   struct AppEventInfo appEvent;
141
142   appEvent.type = handler->type;
143   appEvent.value = event;
144
145   if (handler->cb)
146     handler->cb(&appEvent, handler->data);
147
148   return 0;
149 }
150
151 int AppAddEventHandler(AppEventHandlerPtr *eventHandler, AppEventType eventType, AppEventCallback callback, void *userData)
152 {
153   AppEventHandlerPtr handler;
154
155   handler = static_cast<AppEventHandlerPtr>( calloc(1, sizeof(struct AppEventHandler)) );
156   if (!handler)
157   {
158     DALI_LOG_ERROR( "failed to create handler" );
159     return TIZEN_ERROR_UNKNOWN;
160   }
161   else
162   {
163     handler->type = eventType;
164     handler->cb = callback;
165     handler->data = userData;
166     handler->raw = appcore_base_add_event( static_cast<appcore_base_event>(AppEventConverter[static_cast<int>(eventType)]), EventCallback, handler);
167
168     *eventHandler = handler;
169
170     return TIZEN_ERROR_NONE;
171   }
172 }
173
174 } // namespace Appcore
175
176 /**
177  * Impl to hide EFL data members
178  */
179 struct Framework::Impl
180 {
181 // Constructor
182   Impl(void* data, Type type )
183   : mAbortCallBack( NULL ),
184     mCallbackManager( NULL )
185 #ifdef APPCORE_WATCH_AVAILABLE
186     , mWatchCallback()
187 #endif
188   {
189     mFramework = static_cast<Framework*>(data);
190
191 #ifndef APPCORE_WATCH_AVAILABLE
192     if ( type == WATCH )
193     {
194       throw Dali::DaliException( "", "Watch Application is not supported." );
195     }
196 #endif
197     mApplicationType = type;
198     mCallbackManager = CallbackManager::New();
199
200     char* region = nullptr;
201     char* language = nullptr;
202     system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &region );
203     system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &language );
204
205     if (region != nullptr)
206     {
207       mRegion = std::string( region );
208     }
209
210     if ( language != nullptr)
211     {
212       mLanguage = std::string( language );
213     }
214   }
215
216   ~Impl()
217   {
218     delete mAbortCallBack;
219
220     // we're quiting the main loop so
221     // mCallbackManager->RemoveAllCallBacks() does not need to be called
222     // to delete our abort handler
223     delete mCallbackManager;
224   }
225
226   int AppMain()
227   {
228     int ret;
229     switch ( mApplicationType )
230     {
231       case NORMAL:
232       {
233         ret = AppNormalMain();
234         break;
235       }
236       case WIDGET:
237       {
238         ret = AppWidgetMain();
239         break;
240       }
241       case WATCH:
242       {
243         ret = AppWatchMain();
244         break;
245       }
246 #ifdef COMPONENT_APPLICATION_SUPPORT
247       case COMPONENT:
248       {
249         ret = AppComponentMain();
250         break;
251       }
252 #endif
253     }
254     return ret;
255   }
256
257   void AppExit()
258   {
259     switch ( mApplicationType )
260     {
261       case NORMAL:
262       {
263         AppNormalExit();
264         break;
265       }
266       case WIDGET:
267       {
268         AppWidgetExit();
269         break;
270       }
271       case WATCH:
272       {
273         AppWatchExit();
274         break;
275       }
276 #ifdef COMPONENT_APPLICATION_SUPPORT
277       case COMPONENT:
278       {
279         AppComponentExit();
280         break;
281       }
282 #endif
283     }
284   }
285
286   void SetLanguage( const std::string& language )
287   {
288     mLanguage = language;
289   }
290
291   void SetRegion( const std::string& region )
292   {
293     mRegion = region;
294   }
295
296   std::string GetLanguage() const
297   {
298     return mLanguage;
299   }
300
301   std::string GetRegion() const
302   {
303     return mRegion;
304   }
305
306   // Data
307   Type mApplicationType;
308   CallbackBase* mAbortCallBack;
309   CallbackManager *mCallbackManager;
310   std::string mLanguage;
311   std::string mRegion;
312
313   Framework* mFramework;
314   AppCore::AppEventHandlerPtr handlers[5];
315 #ifdef APPCORE_WATCH_AVAILABLE
316   watch_app_lifecycle_callback_s mWatchCallback;
317   app_event_handler_h watchHandlers[5];
318 #endif
319
320   static int AppCreate(void *data)
321   {
322     appcore_ui_base_on_create();
323     return static_cast<int>( static_cast<Framework*>(data)->Create() );
324   }
325
326   static int AppTerminate(void *data)
327   {
328     appcore_ui_base_on_terminate();
329     Observer *observer = &static_cast<Framework*>(data)->mObserver;
330
331     observer->OnTerminate();
332
333     return 0;
334   }
335
336   static int AppPause(void *data)
337   {
338     appcore_ui_base_on_pause();
339     Observer *observer = &static_cast<Framework*>(data)->mObserver;
340
341     observer->OnPause();
342
343     return 0;
344   }
345
346   static int AppResume(void *data)
347   {
348     appcore_ui_base_on_resume();
349     Observer *observer = &static_cast<Framework*>(data)->mObserver;
350
351     observer->OnResume();
352
353     return 0;
354   }
355
356   static void ProcessBundle(Framework* framework, bundle *bundleData)
357   {
358     if(bundleData == NULL)
359     {
360       return;
361     }
362
363     // get bundle name
364     char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
365     if(bundleName != NULL)
366     {
367       framework->SetBundleName(bundleName);
368     }
369
370     // get bundle? id
371     char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
372     if(bundleId != NULL)
373     {
374       framework->SetBundleId(bundleId);
375     }
376   }
377
378   /**
379    * Called by AppCore when the application is launched from another module (e.g. homescreen).
380    * @param[in] b the bundle data which the launcher module sent
381    */
382   static int AppControl(bundle* bundleData, void *data)
383   {
384     app_control_h appControl = NULL;
385
386     appcore_ui_base_on_control(bundleData);
387
388     if (bundleData)
389     {
390       if (app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE)
391       {
392         DALI_LOG_ERROR("Failed to create an app_control handle");
393       }
394     }
395     else
396     {
397       if (app_control_create(&appControl) != TIZEN_ERROR_NONE)
398       {
399         DALI_LOG_ERROR("Failed to create an app_control handle");
400       }
401     }
402
403     Framework* framework = static_cast<Framework*>(data);
404     Observer *observer = &framework->mObserver;
405
406     ProcessBundle(framework, bundleData);
407
408     observer->OnReset();
409     observer->OnAppControl(appControl);
410
411     app_control_destroy(appControl);
412
413     return 0;
414   }
415
416   static void AppInit(int argc, char **argv, void *data)
417   {
418 #pragma GCC diagnostic push
419 #pragma GCC diagnostic ignored "-Wold-style-cast"
420
421     ecore_init();
422     ecore_app_args_set( argc, (const char **)argv );
423
424 #pragma GCC diagnostic pop
425   }
426
427   static void AppFinish(void)
428   {
429     ecore_shutdown();
430
431     if(getenv("AUL_LOADER_INIT"))
432     {
433       setenv("AUL_LOADER_INIT", "0", 1);
434       ecore_shutdown();
435     }
436   }
437
438   static void AppRun(void *data)
439   {
440     ecore_main_loop_begin();
441   }
442
443   static void AppExit(void *data)
444   {
445     ecore_main_loop_quit();
446   }
447
448   static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void *data)
449   {
450     Framework* framework = static_cast<Framework*>(data);
451     Observer *observer = &framework->mObserver;
452
453     if( event && event->value )
454     {
455       framework->SetLanguage( std::string( static_cast<const char *>(event->value) ) );
456       observer->OnLanguageChanged();
457     }
458     else
459     {
460       DALI_LOG_ERROR( "NULL pointer in Language changed event\n" );
461     }
462   }
463
464   static void AppDeviceRotated(AppCore::AppEventInfoPtr event_info, void *data)
465   {
466   }
467
468   static void AppRegionChanged(AppCore::AppEventInfoPtr event, void *data)
469   {
470     Framework* framework = static_cast<Framework*>(data);
471     Observer *observer = &framework->mObserver;
472
473     if( event && event->value )
474     {
475       framework->SetRegion( std::string( static_cast<const char *>(event->value) ) );
476       observer->OnRegionChanged();
477     }
478     else
479     {
480       DALI_LOG_ERROR( "NULL pointer in Region changed event\n" );
481     }
482   }
483
484   static void AppBatteryLow(AppCore::AppEventInfoPtr event, void *data)
485   {
486     Observer *observer = &static_cast<Framework*>(data)->mObserver;
487     int status = *static_cast<int *>(event->value);
488     Dali::DeviceStatus::Battery::Status result = Dali::DeviceStatus::Battery::NORMAL;
489
490     // convert to dali battery status
491     switch( status )
492     {
493       case 1:
494       {
495         result = Dali::DeviceStatus::Battery::POWER_OFF;
496         break;
497       }
498       case 2:
499       {
500         result = Dali::DeviceStatus::Battery::CRITICALLY_LOW;
501         break;
502       }
503       default :
504         break;
505     }
506     observer->OnBatteryLow(result);
507   }
508
509   static void AppMemoryLow(AppCore::AppEventInfoPtr event, void *data)
510   {
511     Observer *observer = &static_cast<Framework*>(data)->mObserver;
512     int status = *static_cast<int *>(event->value);
513     Dali::DeviceStatus::Memory::Status result = Dali::DeviceStatus::Memory::NORMAL;
514
515     // convert to dali memmory status
516     switch( status )
517     {
518       case 1:
519       {
520         result = Dali::DeviceStatus::Memory::NORMAL;
521         break;
522       }
523       case 2:
524       {
525         result = Dali::DeviceStatus::Memory::LOW;
526         break;
527       }
528       case 4:
529       {
530         result = Dali::DeviceStatus::Memory::CRITICALLY_LOW;
531         break;
532       }
533       default :
534         break;
535     }
536     observer->OnMemoryLow(result);
537   }
538
539
540   int AppNormalMain()
541   {
542     int ret;
543
544     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
545     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
546     AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
547     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
548     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
549
550     appcore_ui_base_ops ops = appcore_ui_base_get_default_ops();
551
552     /* override methods */
553     ops.base.create = AppCreate;
554     ops.base.control = AppControl;
555     ops.base.terminate = AppTerminate;
556     ops.pause = AppPause;
557     ops.resume = AppResume;
558     ops.base.init = AppInit;
559     ops.base.finish = AppFinish;
560     ops.base.run = AppRun;
561     ops.base.exit = AppExit;
562
563     ret = appcore_ui_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework, APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL |
564                                                                                         APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL |
565                                                                                         APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL |
566                                                                                         APPCORE_UI_BASE_HINT_HW_ACC_CONTROL |
567                                                                                         APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL );
568
569     if (ret != TIZEN_ERROR_NONE)
570       return ret;
571
572     appcore_ui_base_fini();
573
574     return TIZEN_ERROR_NONE;
575   }
576
577   void AppNormalExit()
578   {
579     appcore_ui_base_exit();
580   }
581
582   void AppWidgetExit()
583   {
584     widget_base_exit();
585   }
586
587   static int WidgetAppCreate( void *data )
588   {
589     widget_base_on_create();
590     return static_cast<int>( static_cast<Framework*>(data)->Create() );
591   }
592
593   static int WidgetAppTerminate( void *data )
594   {
595     Observer *observer = &static_cast<Framework*>(data)->mObserver;
596     observer->OnTerminate();
597
598     widget_base_on_terminate();
599     return 0;
600   }
601
602   int AppWidgetMain()
603   {
604     if( !IsWidgetFeatureEnabled() )
605     {
606       DALI_LOG_ERROR("widget feature is not supported");
607       return 0;
608     }
609
610     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
611     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
612     AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
613     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
614     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
615
616     widget_base_ops ops = widget_base_get_default_ops();
617
618     /* override methods */
619     ops.create = WidgetAppCreate;
620     ops.terminate = WidgetAppTerminate;
621     ops.init = AppInit;
622     ops.finish = AppFinish;
623     ops.run = AppRun;
624     ops.exit = AppExit;
625
626     int result = widget_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework);
627
628     widget_base_fini();
629
630     return result;
631   }
632
633 #ifdef APPCORE_WATCH_AVAILABLE
634   static bool WatchAppCreate(int width, int height, void *data)
635   {
636     return static_cast<Framework*>(data)->Create();
637   }
638
639   static void WatchAppTimeTick(watch_time_h time, void *data)
640   {
641     Observer *observer = &static_cast<Framework*>(data)->mObserver;
642     WatchTime curTime(time);
643
644     observer->OnTimeTick(curTime);
645   }
646
647   static void WatchAppAmbientTick(watch_time_h time, void *data)
648   {
649     Observer *observer = &static_cast<Framework*>(data)->mObserver;
650     WatchTime curTime(time);
651
652     observer->OnAmbientTick(curTime);
653   }
654
655   static void WatchAppAmbientChanged(bool ambient, void *data)
656   {
657     Observer *observer = &static_cast<Framework*>(data)->mObserver;
658
659     observer->OnAmbientChanged(ambient);
660   }
661
662   static void WatchAppControl(app_control_h app_control, void *data)
663   {
664     Framework* framework = static_cast<Framework*>(data);
665     Observer *observer = &framework->mObserver;
666     bundle *bundleData = NULL;
667
668     app_control_to_bundle(app_control, &bundleData);
669     ProcessBundle(framework, bundleData);
670
671     observer->OnReset();
672     observer->OnAppControl(app_control);
673   }
674
675   static void WatchAppTerminate(void *data)
676   {
677     Observer *observer = &static_cast<Framework*>(data)->mObserver;
678
679     observer->OnTerminate();
680   }
681
682   static void WatchAppPause(void *data)
683   {
684     Observer *observer = &static_cast<Framework*>(data)->mObserver;
685
686     observer->OnPause();
687   }
688
689   static void WatchAppResume(void *data)
690   {
691     Observer *observer = &static_cast<Framework*>(data)->mObserver;
692
693     observer->OnResume();
694   }
695
696 #endif
697
698   int AppWatchMain()
699   {
700     int ret = true;
701
702 #ifdef APPCORE_WATCH_AVAILABLE
703     mWatchCallback.create = WatchAppCreate;
704     mWatchCallback.app_control = WatchAppControl;
705     mWatchCallback.terminate = WatchAppTerminate;
706     mWatchCallback.pause = WatchAppPause;
707     mWatchCallback.resume = WatchAppResume;
708     mWatchCallback.time_tick = WatchAppTimeTick;
709     mWatchCallback.ambient_tick = WatchAppAmbientTick;
710     mWatchCallback.ambient_changed = WatchAppAmbientChanged;
711
712     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
713     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
714     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
715     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
716
717     ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
718 #endif
719     return ret;
720   }
721
722   void AppWatchExit()
723   {
724 #ifdef APPCORE_WATCH_AVAILABLE
725     watch_app_exit();
726 #endif
727   }
728
729 #ifdef COMPONENT_APPLICATION_SUPPORT
730   int AppComponentMain()
731   {
732     int ret;
733
734     /*Crate component_based_app_base_lifecycle_callback*/
735     component_based_app_base_lifecycle_callback_s callback;
736     callback.init = AppInit;
737     callback.run = AppRun;
738     callback.exit = AppExit;
739     callback.create = ComponentAppCreate;
740     callback.terminate = ComponentAppTerminate;
741     callback.fini = ComponentAppFinish;
742
743     return component_based_app_base_main(*mFramework->mArgc, *mFramework->mArgv, &callback, mFramework);;
744   }
745
746   static void* ComponentAppCreate( void *data )
747   {
748     Framework* framework = static_cast<Framework*>(data);
749     Observer *observer = &framework->mObserver;
750     observer->OnInit();
751
752     return Dali::AnyCast<void*>( observer->OnCreate() );
753   }
754
755   static void ComponentAppTerminate( void *data )
756   {
757     Observer *observer = &static_cast<Framework*>(data)->mObserver;
758     observer->OnTerminate();
759   }
760
761   static void ComponentAppFinish( void *data )
762   {
763     ecore_shutdown();
764
765     if(getenv("AUL_LOADER_INIT"))
766     {
767       setenv("AUL_LOADER_INIT", "0", 1);
768       ecore_shutdown();
769     }
770   }
771
772   void AppComponentExit()
773   {
774     component_based_app_base_exit();
775   }
776
777 #endif
778
779 private:
780   // Undefined
781   Impl( const Impl& impl );
782
783   // Undefined
784   Impl& operator=( const Impl& impl );
785 };
786
787 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
788 : mObserver(observer),
789   mInitialised(false),
790   mPaused(false),
791   mRunning(false),
792   mArgc(argc),
793   mArgv(argv),
794   mBundleName(""),
795   mBundleId(""),
796   mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
797   mImpl(NULL)
798 {
799   bool featureFlag = true;
800   system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
801
802   if( featureFlag == false )
803   {
804     set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
805   }
806 #ifdef DALI_ELDBUS_AVAILABLE
807   // Initialize ElDBus.
808   DALI_LOG_INFO( gDBusLogging, Debug::General, "Starting DBus Initialization\n" );
809   eldbus_init();
810 #endif
811   InitThreads();
812
813   mImpl = new Impl(this, type);
814 }
815
816 Framework::~Framework()
817 {
818   if (mRunning)
819   {
820     Quit();
821   }
822
823 #ifdef DALI_ELDBUS_AVAILABLE
824   // Shutdown ELDBus.
825   DALI_LOG_INFO( gDBusLogging, Debug::General, "Shutting down DBus\n" );
826   eldbus_shutdown();
827 #endif
828
829   delete mImpl;
830 }
831
832 bool Framework::Create()
833 {
834   mInitialised = true;
835   mObserver.OnInit();
836   return true;
837 }
838
839 void Framework::Run()
840 {
841   mRunning = true;
842   int ret;
843
844   ret = mImpl->AppMain();
845   if (ret != APP_ERROR_NONE)
846   {
847     DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
848   }
849   mRunning = false;
850 }
851
852 void Framework::Quit()
853 {
854   mImpl->AppExit();
855 }
856
857 bool Framework::IsMainLoopRunning()
858 {
859   return mRunning;
860 }
861
862 void Framework::AddAbortCallback( CallbackBase* callback )
863 {
864   mImpl->mAbortCallBack = callback;
865 }
866
867 std::string Framework::GetBundleName() const
868 {
869   return mBundleName;
870 }
871
872 void Framework::SetBundleName(const std::string& name)
873 {
874   mBundleName = name;
875 }
876
877 std::string Framework::GetBundleId() const
878 {
879   return mBundleId;
880 }
881
882 std::string Framework::GetResourcePath()
883 {
884   std::string resourcePath = "";
885 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
886   char* app_rsc_path = app_get_resource_path();
887   if (app_rsc_path)
888   {
889     resourcePath = app_rsc_path;
890     free(app_rsc_path);
891   }
892 #else // For backwards compatibility with older Tizen versions
893
894   // "DALI_APPLICATION_PACKAGE" is used to get the already configured Application package path.
895   const char* environmentVariable = "DALI_APPLICATION_PACKAGE";
896   char* value = getenv( environmentVariable );
897   if ( value != NULL )
898   {
899     resourcePath = value;
900   }
901
902   if( resourcePath.back() != '/' )
903   {
904     resourcePath+="/";
905   }
906
907 #endif //TIZEN_PLATFORM_CONFIG_SUPPORTED
908
909   return resourcePath;
910 }
911
912 std::string Framework::GetDataPath()
913 {
914   std::string result;
915   char* dataPath = app_get_data_path();
916   if( dataPath )
917   {
918     result = dataPath;
919     free(dataPath);
920   }
921   return result;
922 }
923
924 void Framework::SetBundleId(const std::string& id)
925 {
926   mBundleId = id;
927 }
928
929 void Framework::AbortCallback( )
930 {
931   // if an abort call back has been installed run it.
932   if (mImpl->mAbortCallBack)
933   {
934     CallbackBase::Execute( *mImpl->mAbortCallBack );
935   }
936   else
937   {
938     Quit();
939   }
940 }
941
942 void Framework::InitThreads()
943 {
944 }
945
946 void Framework::SetLanguage( const std::string& language )
947 {
948   mImpl->SetLanguage( language );
949 }
950
951 void Framework::SetRegion( const std::string& region )
952 {
953   mImpl->SetRegion( region );
954 }
955
956 std::string Framework::GetLanguage() const
957 {
958   return mImpl->GetLanguage();
959 }
960
961 std::string Framework::GetRegion() const
962 {
963   return mImpl->GetRegion();
964 }
965
966 } // namespace Adaptor
967
968 } // namespace Internal
969
970 } // namespace Dali