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