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 mEventCallback.service = AppService;
71 mEventCallback.low_memory = NULL;
72 mEventCallback.low_battery = NULL;
73 mEventCallback.device_orientation = DeviceRotated;
74 mEventCallback.language_changed = AppLanguageChange;
75 mEventCallback.region_format_changed = NULL;
77 mCallbackManager = CallbackManager::New();
82 // we're quiting the main loop so
83 // mCallbackManager->RemoveAllCallBacks() does not need to be called
84 // to delete our abort handler
85 delete mCallbackManager;
90 boost::function<void(void)> mAbortCallBack;
91 app_event_callback_s mEventCallback;
92 CallbackManager *mCallbackManager;
96 * Called by AppCore on application creation.
98 static bool AppCreate(void *data)
100 return static_cast<Framework*>(data)->SlpAppStatusHandler(APP_CREATE);
104 * Called by AppCore when the application should terminate.
106 static void AppTerminate(void *data)
108 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_TERMINATE);
112 * Called by AppCore when the application is paused.
114 static void AppPause(void *data)
116 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_PAUSE);
120 * Called by AppCore when the application is resumed.
122 static void AppResume(void *data)
124 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_RESUME);
128 * Called by AppCore when the application is launched from another module (e.g. homescreen).
129 * @param[in] b the bundle data which the launcher module sent
131 static void AppService(service_h service, void *data)
133 Framework* framework = static_cast<Framework*>(data);
137 bundle *bundleData = NULL;
138 service_to_bundle(service, &bundleData);
143 char* bundleName = const_cast<char*>(bundle_get_val(bundleData, "name"));
144 if(bundleName != NULL)
146 framework->SetBundleName(bundleName);
150 char* bundleId = const_cast<char*>(bundle_get_val(bundleData, "id"));
153 framework->SetBundleId(bundleId);
156 framework->SlpAppStatusHandler(APP_RESET);
161 * Called by AppCore when the language changes on the device.
163 static void AppLanguageChange(void* data)
165 static_cast<Framework*>(data)->SlpAppStatusHandler(APP_LANGUAGE_CHANGE);
168 static void DeviceRotated(app_device_orientation_e orientation, void *user_data)
172 case APP_DEVICE_ORIENTATION_0:
174 case APP_DEVICE_ORIENTATION_90:
176 case APP_DEVICE_ORIENTATION_180:
178 case APP_DEVICE_ORIENTATION_270:
185 Framework::Framework(Framework::Observer& observer, int *argc, char ***argv, const std::string& name)
186 : mObserver(observer),
194 mAbortHandler(boost::bind(&Framework::AbortCallback, this)),
198 mImpl = new Impl(this);
201 Framework::~Framework()
211 void Framework::Run()
215 app_efl_main(mArgc, mArgv, &mImpl->mEventCallback, this);
220 void Framework::Quit()
225 bool Framework::IsMainLoopRunning()
230 void Framework::AddAbortCallback(boost::function<void(void)> callBack)
232 mImpl->mAbortCallBack = callBack;
235 std::string Framework::GetBundleName() const
240 void Framework::SetBundleName(const std::string& name)
245 std::string Framework::GetBundleId() const
250 void Framework::SetBundleId(const std::string& id)
255 void Framework::AbortCallback( )
257 // if an abort call back has been installed run it.
258 if (mImpl->mAbortCallBack)
260 mImpl->mAbortCallBack();
268 bool Framework::SlpAppStatusHandler(int type)
276 // Connect to abnormal exit signals
277 mAbortHandler.AbortOnSignal( SIGINT );
278 mAbortHandler.AbortOnSignal( SIGQUIT );
279 mAbortHandler.AbortOnSignal( SIGKILL );
290 mObserver.OnResume();
294 mObserver.OnTerminate();
301 case APP_LANGUAGE_CHANGE:
302 mObserver.OnLanguageChanged();
312 } // namespace Adaptor
314 } // namespace Internal