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