2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FShell_AppWidgetContextBase.cpp
20 * @brief This is the implementation for the _AppWidgetContextBase class.
24 #include <unique_ptr.h>
26 #include "provider_buffer.h"
29 #include <FBaseSysLog.h>
30 #include <FBase_StringConverter.h>
32 #include <FApp_AppMessageImpl.h>
33 #include <FApp_AppArg.h>
34 #include <FApp_AppControlManager.h>
35 #include <FShell_TemplateUtil.h>
36 #include <FShell_AppWidgetManagerImpl.h>
38 #include "FShell_AppWidgetContextBase.h"
51 // provider/inc/provider_buffer_internal.h
52 struct livebox_buffer {
54 BUFFER_CREATED = 0x00beef00,
55 BUFFER_DESTROYED = 0x00dead00,
58 enum target_type type;
61 int fd; /* File handle(descriptor) */
62 int id; /* SHM handle(id) */
73 int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data);
77 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
78 double timestamp, double x, double y, void* data);
80 namespace Tizen { namespace Shell { namespace App
83 using namespace Tizen::App;
84 using namespace Tizen::Base;
85 using namespace Tizen::Base::Collection;
88 const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId";
89 const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName";
90 const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo";
91 const wchar_t ARG_KEY_X[] = L"_X";
92 const wchar_t ARG_KEY_Y[] = L"_Y";
93 const wchar_t ARG_KEY_WIDTH[] = L"_Width";
94 const wchar_t ARG_KEY_HEIGHT[] = L"_Height";
95 const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth";
96 const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight";
97 const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument";
98 const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType";
99 const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp";
102 _AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
104 ,__userInfo(userInfo)
105 ,__providerId(providerId)
106 ,__instanceId(instanceId)
109 ,__priority(priority)
110 ,__isForeground(true)
114 ,__providerState(INVALID)
116 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
118 SysLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
121 _AppWidgetContextBase::~_AppWidgetContextBase()
123 SysLog(NID_SHELL, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
129 _AppWidgetContextBase::SetIpcClientId(int clientId)
131 __ipcClientId = clientId;
135 _AppWidgetContextBase::HasValidClientId(void) const
137 SysLog(NID_SHELL, "%d", __ipcClientId);
138 return (__ipcClientId > -1);
142 _AppWidgetContextBase::IsSharedMemCreated(void) const
144 return ( __buffer_info && __buffer);
148 _AppWidgetContextBase::GetSharedMemId(int w, int h)
150 SysLog(NID_SHELL, "Enter");
152 bool isResized = (__buffer_info != null) && (__buffer_info->width != w || __buffer_info->height != h);
158 if( __buffer_info == null)
160 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
161 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
163 __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, this);
164 SysTryReturnResult(NID_SHELL, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire");
165 SysLog(NID_SHELL, "provider_buffer_acquire successed");
167 __buffer = provider_buffer_ref(__buffer_info);
168 SysTryReturnResult(NID_SHELL, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref");
169 SysLog(NID_SHELL, "provider_buffer_ref successed");
172 int bufferId = __buffer_info->fb->handle;
173 __providerState = RUNNING;
175 SysLog(NID_SHELL, "(%d) Exit", bufferId);
181 _AppWidgetContextBase::Suspend()
183 __providerState = SUSPENDED;
187 _AppWidgetContextBase::IsRunning() const
189 return (__providerState == RUNNING);
193 _AppWidgetContextBase::ReleaseSharedMem()
195 SysLog(NID_SHELL, "Enter");
201 ret = provider_buffer_unref(__buffer);
203 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref");
204 SysLog(NID_SHELL, "provider_buffer_unref successed");
209 ret = provider_buffer_release(__buffer_info);
210 __buffer_info = null;
211 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release");
212 SysLog(NID_SHELL, "provider_buffer_release successed");
215 SysLog(NID_SHELL, "Exit.");
221 _AppWidgetContextBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
223 if( __isForeground == false)
225 SysLog(NID_SHELL, "appWidget isn't foreground, so, message skip");
229 return _AppWidgetRequestHelper::SendRequestToApp(appId, operation, pArgs);
233 _AppWidgetRequestHelper::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
235 SysLog(NID_SHELL, "appId(%ls), operation(%ls), arg count(%d)", appId.GetPointer(), operation.GetPointer(), pArgs->GetCount() );
238 msg.AddData(OSP_K_APPCONTROL_INTERNAL_OPERATION, L"livebox");
239 Tizen::App::_AppArg::AddStrMap(msg.GetBundle(), pArgs);
241 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId) );
242 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(operation) );
244 return Tizen::App::_AppControlManager::GetInstance()->LaunchPkg(msg, pAppId.get(), pOperation.get(), null, null, null, null);
247 } } } // Tizen::Shell::App {
250 ////////////////////////////////////////////
252 ////////////////////////////////////////////
253 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
254 double timestamp, double x, double y, void* data)
256 SysLog(NID_SHELL, "timestamp(%f), x(%f), y(%f)", timestamp, x, y);
258 Tizen::Shell::App::_AppWidgetContextBase *pAppWidgetBase = static_cast<Tizen::Shell::App::_AppWidgetContextBase*>(data);
259 SysTryReturn(NID_SHELL, pAppWidgetBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetBase is null");
261 // const char *pkgname = provider_buffer_pkgname(info);
262 // const char *id = provider_buffer_id(info);
263 // enum target_type type = provider_buffer_type(info);
265 if( event == BUFFER_EVENT_ENTER)
267 SysLog(NID_SHELL, "BUFFER_EVENT_ENTER");
269 else if( event == BUFFER_EVENT_LEAVE)
271 SysLog(NID_SHELL, "BUFFER_EVENT_LEAVE");
273 else if( event == BUFFER_EVENT_DOWN)
275 SysLog(NID_SHELL, "BUFFER_EVENT_DOWN");
277 else if( event == BUFFER_EVENT_MOVE)
279 SysLog(NID_SHELL, "BUFFER_EVENT_MOVE");
281 else if( event == BUFFER_EVENT_UP)
283 SysLog(NID_SHELL, "BUFFER_EVENT_UP");
286 pAppWidgetBase->SendTouchEvent(event, timestamp, x, y);