2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "framework.h"
25 #include <boost/bind.hpp>
27 #include <dali/integration-api/debug.h>
30 #include <callback-manager.h>
44 /// Application Status Enum
55 } // Unnamed namespace
58 * Impl to hide EFL data members
60 struct Framework::Impl
66 mEventCallback.create = AppCreate;
67 mEventCallback.terminate = AppTerminate;
68 mEventCallback.pause = AppPause;
69 mEventCallback.resume = AppResume;
70 #if defined(TIZEN_SDK_2_3)
71 mEventCallback.app_control = AppControl;
73 mEventCallback.service = AppService;
75 mEventCallback.low_memory = NULL;
76 mEventCallback.low_battery = NULL;
77 mEventCallback.device_orientation = DeviceRotated;
78 mEventCallback.language_changed = AppLanguageChange;
79 mEventCallback.region_format_changed = NULL;
81 mCallbackManager = CallbackManager::New();
86 // we're quiting the main loop so
87 // mCallbackManager->RemoveAllCallBacks() does not need to be called
88 // to delete our abort handler
89 delete mCallbackManager;
94 boost::function<void(void)> mAbortCallBack;
95 app_event_callback_s mEventCallback;
96 CallbackManager *mCallbackManager;
100 * Called by AppCore on application creation.
102 static bool AppCreate(void *data)
104 return static_cast<Framework*>(data)->SlpAppStatusHandler(APP_CREATE);
108 * Called by AppCore when the application should terminate.
110 static void AppTerminate(void *data)
112 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_TERMINATE);
116 * Called by AppCore when the application is paused.
118 static void AppPause(void *data)
120 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_PAUSE);
124 * Called by AppCore when the application is resumed.
126 static void AppResume(void *data)
128 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_RESUME);
132 * Called by AppCore when the application is launched from another module (e.g. homescreen).
133 * @param[in] b the bundle data which the launcher module sent
136 #if defined(TIZEN_SDK_2_3)
137 static void AppControl(app_control_h app_control, void *data)
139 static void AppService(service_h service, void *data)
142 Framework* framework = static_cast<Framework*>(data);
146 bundle *bundleData = NULL;
147 #if defined(TIZEN_SDK_2_3)
148 app_control_to_bundle(app_control, &bundleData);
150 service_to_bundle(service, &bundleData);
156 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
157 if(bundleName != NULL)
159 framework->SetBundleName(bundleName);
163 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
166 framework->SetBundleId(bundleId);
169 framework->SlpAppStatusHandler(APP_RESET);
174 * Called by AppCore when the language changes on the device.
176 static void AppLanguageChange(void* data)
178 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_LANGUAGE_CHANGE);
181 static void DeviceRotated(app_device_orientation_e orientation, void *user_data)
185 case APP_DEVICE_ORIENTATION_0:
187 case APP_DEVICE_ORIENTATION_90:
189 case APP_DEVICE_ORIENTATION_180:
191 case APP_DEVICE_ORIENTATION_270:
198 Framework::Framework(Framework::Observer& observer, int *argc, char ***argv, const std::string& name)
199 : mObserver(observer),
207 mAbortHandler(boost::bind(&Framework::AbortCallback, this)),
211 mImpl = new Impl(this);
214 Framework::~Framework()
224 void Framework::Run()
228 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
233 void Framework::Quit()
238 bool Framework::IsMainLoopRunning()
243 void Framework::AddAbortCallback(boost::function<void(void)> callBack)
245 mImpl->mAbortCallBack = callBack;
248 std::string Framework::GetBundleName() const
253 void Framework::SetBundleName(const std::string& name)
258 std::string Framework::GetBundleId() const
263 void Framework::SetBundleId(const std::string& id)
268 void Framework::AbortCallback( )
270 // if an abort call back has been installed run it.
271 if (mImpl->mAbortCallBack)
273 mImpl->mAbortCallBack();
281 bool Framework::SlpAppStatusHandler(int type)
289 // Connect to abnormal exit signals
290 mAbortHandler.AbortOnSignal( SIGINT );
291 mAbortHandler.AbortOnSignal( SIGQUIT );
292 mAbortHandler.AbortOnSignal( SIGKILL );
303 mObserver.OnResume();
307 mObserver.OnTerminate();
314 case APP_LANGUAGE_CHANGE:
315 mObserver.OnLanguageChanged();
325 } // namespace Adaptor
327 } // namespace Internal