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;
71 #ifdef UNDER_TIZEN_2_3_CAPI
72 mEventCallback.service = AppService;
74 mEventCallback.app_control = AppControl;
77 mEventCallback.low_memory = NULL;
78 mEventCallback.low_battery = NULL;
79 mEventCallback.device_orientation = DeviceRotated;
80 mEventCallback.language_changed = AppLanguageChange;
81 mEventCallback.region_format_changed = NULL;
83 mCallbackManager = CallbackManager::New();
88 // we're quiting the main loop so
89 // mCallbackManager->RemoveAllCallBacks() does not need to be called
90 // to delete our abort handler
91 delete mCallbackManager;
96 boost::function<void(void)> mAbortCallBack;
97 app_event_callback_s mEventCallback;
98 CallbackManager *mCallbackManager;
102 * Called by AppCore on application creation.
104 static bool AppCreate(void *data)
106 return static_cast<Framework*>(data)->SlpAppStatusHandler(APP_CREATE);
110 * Called by AppCore when the application should terminate.
112 static void AppTerminate(void *data)
114 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_TERMINATE);
118 * Called by AppCore when the application is paused.
120 static void AppPause(void *data)
122 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_PAUSE);
126 * Called by AppCore when the application is resumed.
128 static void AppResume(void *data)
130 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_RESUME);
134 * Called by AppCore when the application is launched from another module (e.g. homescreen).
135 * @param[in] b the bundle data which the launcher module sent
137 #ifdef UNDER_TIZEN_2_3_CAPI
138 static void AppService(service_h service, void *data)
140 static void AppControl(app_control_h app_control, void *data)
143 Framework* framework = static_cast<Framework*>(data);
147 bundle *bundleData = NULL;
149 #ifdef UNDER_TIZEN_2_3_CAPI
150 service_to_bundle(service, &bundleData);
152 app_control_to_bundle(app_control, &bundleData);
158 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
159 if(bundleName != NULL)
161 framework->SetBundleName(bundleName);
165 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
168 framework->SetBundleId(bundleId);
171 framework->SlpAppStatusHandler(APP_RESET);
176 * Called by AppCore when the language changes on the device.
178 static void AppLanguageChange(void* data)
180 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_LANGUAGE_CHANGE);
183 static void DeviceRotated(app_device_orientation_e orientation, void *user_data)
187 case APP_DEVICE_ORIENTATION_0:
189 case APP_DEVICE_ORIENTATION_90:
191 case APP_DEVICE_ORIENTATION_180:
193 case APP_DEVICE_ORIENTATION_270:
200 Framework::Framework(Framework::Observer& observer, int *argc, char ***argv, const std::string& name)
201 : mObserver(observer),
209 mAbortHandler(boost::bind(&Framework::AbortCallback, this)),
213 mImpl = new Impl(this);
216 Framework::~Framework()
226 void Framework::Run()
230 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
235 void Framework::Quit()
240 bool Framework::IsMainLoopRunning()
245 void Framework::AddAbortCallback(boost::function<void(void)> callBack)
247 mImpl->mAbortCallBack = callBack;
250 std::string Framework::GetBundleName() const
255 void Framework::SetBundleName(const std::string& name)
260 std::string Framework::GetBundleId() const
265 void Framework::SetBundleId(const std::string& id)
270 void Framework::AbortCallback( )
272 // if an abort call back has been installed run it.
273 if (mImpl->mAbortCallBack)
275 mImpl->mAbortCallBack();
283 bool Framework::SlpAppStatusHandler(int type)
291 // Connect to abnormal exit signals
292 mAbortHandler.AbortOnSignal( SIGINT );
293 mAbortHandler.AbortOnSignal( SIGQUIT );
294 mAbortHandler.AbortOnSignal( SIGKILL );
305 mObserver.OnResume();
309 mObserver.OnTerminate();
316 case APP_LANGUAGE_CHANGE:
317 mObserver.OnLanguageChanged();
327 } // namespace Adaptor
329 } // namespace Internal