Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.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       free( region );
209     }
210
211     if ( language != nullptr)
212     {
213       mLanguage = std::string( language );
214       free( language );
215     }
216   }
217
218   ~Impl()
219   {
220     delete mAbortCallBack;
221
222     // we're quiting the main loop so
223     // mCallbackManager->RemoveAllCallBacks() does not need to be called
224     // to delete our abort handler
225     delete mCallbackManager;
226   }
227
228   int AppMain()
229   {
230     int ret;
231     switch ( mApplicationType )
232     {
233       case NORMAL:
234       {
235         ret = AppNormalMain();
236         break;
237       }
238       case WIDGET:
239       {
240         ret = AppWidgetMain();
241         break;
242       }
243       case WATCH:
244       {
245         ret = AppWatchMain();
246         break;
247       }
248 #ifdef COMPONENT_APPLICATION_SUPPORT
249       case COMPONENT:
250       {
251         ret = AppComponentMain();
252         break;
253       }
254 #endif
255     }
256     return ret;
257   }
258
259   void AppExit()
260   {
261     switch ( mApplicationType )
262     {
263       case NORMAL:
264       {
265         AppNormalExit();
266         break;
267       }
268       case WIDGET:
269       {
270         AppWidgetExit();
271         break;
272       }
273       case WATCH:
274       {
275         AppWatchExit();
276         break;
277       }
278 #ifdef COMPONENT_APPLICATION_SUPPORT
279       case COMPONENT:
280       {
281         AppComponentExit();
282         break;
283       }
284 #endif
285     }
286   }
287
288   void SetLanguage( const std::string& language )
289   {
290     mLanguage = language;
291   }
292
293   void SetRegion( const std::string& region )
294   {
295     mRegion = region;
296   }
297
298   std::string GetLanguage() const
299   {
300     return mLanguage;
301   }
302
303   std::string GetRegion() const
304   {
305     return mRegion;
306   }
307
308   // Data
309   Type mApplicationType;
310   CallbackBase* mAbortCallBack;
311   CallbackManager *mCallbackManager;
312   std::string mLanguage;
313   std::string mRegion;
314
315   Framework* mFramework;
316   AppCore::AppEventHandlerPtr handlers[5];
317 #ifdef APPCORE_WATCH_AVAILABLE
318   watch_app_lifecycle_callback_s mWatchCallback;
319   app_event_handler_h watchHandlers[5];
320 #endif
321
322   static int AppCreate(void *data)
323   {
324     appcore_ui_base_on_create();
325     return static_cast<int>( static_cast<Framework*>(data)->Create() );
326   }
327
328   static int AppTerminate(void *data)
329   {
330     appcore_ui_base_on_terminate();
331     Observer *observer = &static_cast<Framework*>(data)->mObserver;
332
333     observer->OnTerminate();
334
335     return 0;
336   }
337
338   static int AppPause(void *data)
339   {
340     appcore_ui_base_on_pause();
341     Observer *observer = &static_cast<Framework*>(data)->mObserver;
342
343     observer->OnPause();
344
345     return 0;
346   }
347
348   static int AppResume(void *data)
349   {
350     appcore_ui_base_on_resume();
351     Observer *observer = &static_cast<Framework*>(data)->mObserver;
352
353     observer->OnResume();
354
355     return 0;
356   }
357
358   static void ProcessBundle(Framework* framework, bundle *bundleData)
359   {
360     if(bundleData == NULL)
361     {
362       return;
363     }
364
365     // get bundle name
366     char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
367     if(bundleName != NULL)
368     {
369       framework->SetBundleName(bundleName);
370     }
371
372     // get bundle? id
373     char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
374     if(bundleId != NULL)
375     {
376       framework->SetBundleId(bundleId);
377     }
378   }
379
380   /**
381    * Called by AppCore when the application is launched from another module (e.g. homescreen).
382    * @param[in] b the bundle data which the launcher module sent
383    */
384   static int AppControl(bundle* bundleData, void *data)
385   {
386     app_control_h appControl = NULL;
387
388     appcore_ui_base_on_control(bundleData);
389
390     if (bundleData)
391     {
392       if (app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE)
393       {
394         DALI_LOG_ERROR("Failed to create an app_control handle");
395       }
396     }
397     else
398     {
399       if (app_control_create(&appControl) != TIZEN_ERROR_NONE)
400       {
401         DALI_LOG_ERROR("Failed to create an app_control handle");
402       }
403     }
404
405     Framework* framework = static_cast<Framework*>(data);
406     Observer *observer = &framework->mObserver;
407
408     ProcessBundle(framework, bundleData);
409
410     observer->OnReset();
411     observer->OnAppControl(appControl);
412
413     app_control_destroy(appControl);
414
415     return 0;
416   }
417
418   static void AppInit(int argc, char **argv, void *data)
419   {
420 #pragma GCC diagnostic push
421 #pragma GCC diagnostic ignored "-Wold-style-cast"
422
423     ecore_init();
424     ecore_app_args_set( argc, (const char **)argv );
425
426 #pragma GCC diagnostic pop
427   }
428
429   static void AppFinish(void)
430   {
431     ecore_shutdown();
432
433     if(getenv("AUL_LOADER_INIT"))
434     {
435       setenv("AUL_LOADER_INIT", "0", 1);
436       ecore_shutdown();
437     }
438   }
439
440   static void AppRun(void *data)
441   {
442     ecore_main_loop_begin();
443   }
444
445   static void AppExit(void *data)
446   {
447     ecore_main_loop_quit();
448   }
449
450   static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void *data)
451   {
452     Framework* framework = static_cast<Framework*>(data);
453     Observer *observer = &framework->mObserver;
454
455     if( event && event->value )
456     {
457       framework->SetLanguage( std::string( static_cast<const char *>(event->value) ) );
458       observer->OnLanguageChanged();
459     }
460     else
461     {
462       DALI_LOG_ERROR( "NULL pointer in Language changed event\n" );
463     }
464   }
465
466   static void AppDeviceRotated(AppCore::AppEventInfoPtr event_info, void *data)
467   {
468   }
469
470   static void AppRegionChanged(AppCore::AppEventInfoPtr event, void *data)
471   {
472     Framework* framework = static_cast<Framework*>(data);
473     Observer *observer = &framework->mObserver;
474
475     if( event && event->value )
476     {
477       framework->SetRegion( std::string( static_cast<const char *>(event->value) ) );
478       observer->OnRegionChanged();
479     }
480     else
481     {
482       DALI_LOG_ERROR( "NULL pointer in Region changed event\n" );
483     }
484   }
485
486   static void AppBatteryLow(AppCore::AppEventInfoPtr event, void *data)
487   {
488     Observer *observer = &static_cast<Framework*>(data)->mObserver;
489     int status = *static_cast<int *>(event->value);
490     Dali::DeviceStatus::Battery::Status result = Dali::DeviceStatus::Battery::NORMAL;
491
492     // convert to dali battery status
493     switch( status )
494     {
495       case 1:
496       {
497         result = Dali::DeviceStatus::Battery::POWER_OFF;
498         break;
499       }
500       case 2:
501       {
502         result = Dali::DeviceStatus::Battery::CRITICALLY_LOW;
503         break;
504       }
505       default :
506         break;
507     }
508     observer->OnBatteryLow(result);
509   }
510
511   static void AppMemoryLow(AppCore::AppEventInfoPtr event, void *data)
512   {
513     Observer *observer = &static_cast<Framework*>(data)->mObserver;
514     int status = *static_cast<int *>(event->value);
515     Dali::DeviceStatus::Memory::Status result = Dali::DeviceStatus::Memory::NORMAL;
516
517     // convert to dali memmory status
518     switch( status )
519     {
520       case 1:
521       {
522         result = Dali::DeviceStatus::Memory::NORMAL;
523         break;
524       }
525       case 2:
526       {
527         result = Dali::DeviceStatus::Memory::LOW;
528         break;
529       }
530       case 4:
531       {
532         result = Dali::DeviceStatus::Memory::CRITICALLY_LOW;
533         break;
534       }
535       default :
536         break;
537     }
538     observer->OnMemoryLow(result);
539   }
540
541
542   int AppNormalMain()
543   {
544     int ret;
545
546     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
547     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
548     AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
549     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
550     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
551
552     appcore_ui_base_ops ops = appcore_ui_base_get_default_ops();
553
554     /* override methods */
555     ops.base.create = AppCreate;
556     ops.base.control = AppControl;
557     ops.base.terminate = AppTerminate;
558     ops.pause = AppPause;
559     ops.resume = AppResume;
560     ops.base.init = AppInit;
561     ops.base.finish = AppFinish;
562     ops.base.run = AppRun;
563     ops.base.exit = AppExit;
564
565     ret = appcore_ui_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework, APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL |
566                                                                                         APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL |
567                                                                                         APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL |
568                                                                                         APPCORE_UI_BASE_HINT_HW_ACC_CONTROL |
569                                                                                         APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL );
570
571     if (ret != TIZEN_ERROR_NONE)
572       return ret;
573
574     appcore_ui_base_fini();
575
576     return TIZEN_ERROR_NONE;
577   }
578
579   void AppNormalExit()
580   {
581     appcore_ui_base_exit();
582   }
583
584   void AppWidgetExit()
585   {
586     widget_base_exit();
587   }
588
589   static int WidgetAppCreate( void *data )
590   {
591     widget_base_on_create();
592     return static_cast<int>( static_cast<Framework*>(data)->Create() );
593   }
594
595   static int WidgetAppTerminate( void *data )
596   {
597     Observer *observer = &static_cast<Framework*>(data)->mObserver;
598     observer->OnTerminate();
599
600     widget_base_on_terminate();
601     return 0;
602   }
603
604   int AppWidgetMain()
605   {
606     if( !IsWidgetFeatureEnabled() )
607     {
608       DALI_LOG_ERROR("widget feature is not supported");
609       return 0;
610     }
611
612     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
613     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
614     AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework);
615     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
616     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
617
618     widget_base_ops ops = widget_base_get_default_ops();
619
620     /* override methods */
621     ops.create = WidgetAppCreate;
622     ops.terminate = WidgetAppTerminate;
623     ops.init = AppInit;
624     ops.finish = AppFinish;
625     ops.run = AppRun;
626     ops.exit = AppExit;
627
628     int result = widget_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework);
629
630     widget_base_fini();
631
632     return result;
633   }
634
635 #ifdef APPCORE_WATCH_AVAILABLE
636   static bool WatchAppCreate(int width, int height, void *data)
637   {
638     return static_cast<Framework*>(data)->Create();
639   }
640
641   static void WatchAppTimeTick(watch_time_h time, void *data)
642   {
643     Observer *observer = &static_cast<Framework*>(data)->mObserver;
644     WatchTime curTime(time);
645
646     observer->OnTimeTick(curTime);
647   }
648
649   static void WatchAppAmbientTick(watch_time_h time, void *data)
650   {
651     Observer *observer = &static_cast<Framework*>(data)->mObserver;
652     WatchTime curTime(time);
653
654     observer->OnAmbientTick(curTime);
655   }
656
657   static void WatchAppAmbientChanged(bool ambient, void *data)
658   {
659     Observer *observer = &static_cast<Framework*>(data)->mObserver;
660
661     observer->OnAmbientChanged(ambient);
662   }
663
664   static void WatchAppControl(app_control_h app_control, void *data)
665   {
666     Framework* framework = static_cast<Framework*>(data);
667     Observer *observer = &framework->mObserver;
668     bundle *bundleData = NULL;
669
670     app_control_to_bundle(app_control, &bundleData);
671     ProcessBundle(framework, bundleData);
672
673     observer->OnReset();
674     observer->OnAppControl(app_control);
675   }
676
677   static void WatchAppTerminate(void *data)
678   {
679     Observer *observer = &static_cast<Framework*>(data)->mObserver;
680
681     observer->OnTerminate();
682   }
683
684   static void WatchAppPause(void *data)
685   {
686     Observer *observer = &static_cast<Framework*>(data)->mObserver;
687
688     observer->OnPause();
689   }
690
691   static void WatchAppResume(void *data)
692   {
693     Observer *observer = &static_cast<Framework*>(data)->mObserver;
694
695     observer->OnResume();
696   }
697
698 #endif
699
700   int AppWatchMain()
701   {
702     int ret = true;
703
704 #ifdef APPCORE_WATCH_AVAILABLE
705     mWatchCallback.create = WatchAppCreate;
706     mWatchCallback.app_control = WatchAppControl;
707     mWatchCallback.terminate = WatchAppTerminate;
708     mWatchCallback.pause = WatchAppPause;
709     mWatchCallback.resume = WatchAppResume;
710     mWatchCallback.time_tick = WatchAppTimeTick;
711     mWatchCallback.ambient_tick = WatchAppAmbientTick;
712     mWatchCallback.ambient_changed = WatchAppAmbientChanged;
713
714     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework);
715     AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework);
716     AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework);
717     AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework);
718
719     ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework);
720 #endif
721     return ret;
722   }
723
724   void AppWatchExit()
725   {
726 #ifdef APPCORE_WATCH_AVAILABLE
727     watch_app_exit();
728 #endif
729   }
730
731 #ifdef COMPONENT_APPLICATION_SUPPORT
732   int AppComponentMain()
733   {
734     int ret;
735
736     /*Crate component_based_app_base_lifecycle_callback*/
737     component_based_app_base_lifecycle_callback_s callback;
738     callback.init = AppInit;
739     callback.run = AppRun;
740     callback.exit = AppExit;
741     callback.create = ComponentAppCreate;
742     callback.terminate = ComponentAppTerminate;
743     callback.fini = ComponentAppFinish;
744
745     return component_based_app_base_main(*mFramework->mArgc, *mFramework->mArgv, &callback, mFramework);;
746   }
747
748   static void* ComponentAppCreate( void *data )
749   {
750     Framework* framework = static_cast<Framework*>(data);
751     Observer *observer = &framework->mObserver;
752     observer->OnInit();
753
754     return Dali::AnyCast<void*>( observer->OnCreate() );
755   }
756
757   static void ComponentAppTerminate( void *data )
758   {
759     Observer *observer = &static_cast<Framework*>(data)->mObserver;
760     observer->OnTerminate();
761   }
762
763   static void ComponentAppFinish( void *data )
764   {
765     ecore_shutdown();
766
767     if(getenv("AUL_LOADER_INIT"))
768     {
769       setenv("AUL_LOADER_INIT", "0", 1);
770       ecore_shutdown();
771     }
772   }
773
774   void AppComponentExit()
775   {
776     component_based_app_base_exit();
777   }
778
779 #endif
780
781 private:
782   // Undefined
783   Impl( const Impl& impl );
784
785   // Undefined
786   Impl& operator=( const Impl& impl );
787 };
788
789 Framework::Framework( Framework::Observer& observer, int *argc, char ***argv, Type type )
790 : mObserver(observer),
791   mInitialised(false),
792   mPaused(false),
793   mRunning(false),
794   mArgc(argc),
795   mArgv(argv),
796   mBundleName(""),
797   mBundleId(""),
798   mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
799   mImpl(NULL)
800 {
801   bool featureFlag = true;
802   system_info_get_platform_bool( "tizen.org/feature/opengles.version.2_0", &featureFlag );
803
804   if( featureFlag == false )
805   {
806     set_last_result( TIZEN_ERROR_NOT_SUPPORTED );
807   }
808 #ifdef DALI_ELDBUS_AVAILABLE
809   // Initialize ElDBus.
810   DALI_LOG_INFO( gDBusLogging, Debug::General, "Starting DBus Initialization\n" );
811   eldbus_init();
812 #endif
813   InitThreads();
814
815   mImpl = new Impl(this, type);
816 }
817
818 Framework::~Framework()
819 {
820   if (mRunning)
821   {
822     Quit();
823   }
824
825 #ifdef DALI_ELDBUS_AVAILABLE
826   // Shutdown ELDBus.
827   DALI_LOG_INFO( gDBusLogging, Debug::General, "Shutting down DBus\n" );
828   eldbus_shutdown();
829 #endif
830
831   delete mImpl;
832 }
833
834 bool Framework::Create()
835 {
836   mInitialised = true;
837   mObserver.OnInit();
838   return true;
839 }
840
841 void Framework::Run()
842 {
843   mRunning = true;
844   int ret;
845
846   ret = mImpl->AppMain();
847   if (ret != APP_ERROR_NONE)
848   {
849     DALI_LOG_ERROR("Framework::Run(), ui_app_main() is failed. err = %d\n", ret);
850   }
851   mRunning = false;
852 }
853
854 void Framework::Quit()
855 {
856   mImpl->AppExit();
857 }
858
859 bool Framework::IsMainLoopRunning()
860 {
861   return mRunning;
862 }
863
864 void Framework::AddAbortCallback( CallbackBase* callback )
865 {
866   mImpl->mAbortCallBack = callback;
867 }
868
869 std::string Framework::GetBundleName() const
870 {
871   return mBundleName;
872 }
873
874 void Framework::SetBundleName(const std::string& name)
875 {
876   mBundleName = name;
877 }
878
879 std::string Framework::GetBundleId() const
880 {
881   return mBundleId;
882 }
883
884 std::string Framework::GetResourcePath()
885 {
886   std::string resourcePath = "";
887 #if defined( TIZEN_PLATFORM_CONFIG_SUPPORTED ) && TIZEN_PLATFORM_CONFIG_SUPPORTED
888   char* app_rsc_path = app_get_resource_path();
889   if (app_rsc_path)
890   {
891     resourcePath = app_rsc_path;
892     free(app_rsc_path);
893   }
894 #else // For backwards compatibility with older Tizen versions
895
896   // "DALI_APPLICATION_PACKAGE" is used to get the already configured Application package path.
897   const char* environmentVariable = "DALI_APPLICATION_PACKAGE";
898   char* value = getenv( environmentVariable );
899   if ( value != NULL )
900   {
901     resourcePath = value;
902   }
903
904   if( resourcePath.back() != '/' )
905   {
906     resourcePath+="/";
907   }
908
909 #endif //TIZEN_PLATFORM_CONFIG_SUPPORTED
910
911   return resourcePath;
912 }
913
914 std::string Framework::GetDataPath()
915 {
916   std::string result;
917   char* dataPath = app_get_data_path();
918   if( dataPath )
919   {
920     result = dataPath;
921     free(dataPath);
922   }
923   return result;
924 }
925
926 void Framework::SetBundleId(const std::string& id)
927 {
928   mBundleId = id;
929 }
930
931 void Framework::AbortCallback( )
932 {
933   // if an abort call back has been installed run it.
934   if (mImpl->mAbortCallBack)
935   {
936     CallbackBase::Execute( *mImpl->mAbortCallBack );
937   }
938   else
939   {
940     Quit();
941   }
942 }
943
944 void Framework::InitThreads()
945 {
946 }
947
948 void Framework::SetLanguage( const std::string& language )
949 {
950   mImpl->SetLanguage( language );
951 }
952
953 void Framework::SetRegion( const std::string& region )
954 {
955   mImpl->SetRegion( region );
956 }
957
958 std::string Framework::GetLanguage() const
959 {
960   return mImpl->GetLanguage();
961 }
962
963 std::string Framework::GetRegion() const
964 {
965   return mImpl->GetRegion();
966 }
967
968 } // namespace Adaptor
969
970 } // namespace Internal
971
972 } // namespace Dali