2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
18 * @file FShell_AppWidgetContextBase.cpp
19 * @brief This is the implementation for the _AppWidgetContextBase class.
23 #include <unique_ptr.h>
25 #include <FBaseColHashMap.h>
26 #include <FBaseSysLog.h>
27 #include <FBase_StringConverter.h>
28 #include <FApp_AppMessageImpl.h>
29 #include <FApp_AppArg.h>
30 #include <FApp_AppControlManager.h>
31 #include "FShell_AppWidgetManagerImpl.h"
32 #include "FShell_AppWidgetContextBase.h"
45 // provider/inc/provider_buffer_internal.h
46 struct livebox_buffer {
48 BUFFER_CREATED = 0x00beef00,
49 BUFFER_DESTROYED = 0x00dead00,
52 enum target_type type;
55 int fd; /* File handle(descriptor) */
56 int id; /* SHM handle(id) */
67 int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data);
71 static int AppWidgetHandleBufferEventCallback(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data);
73 namespace Tizen { namespace Shell { namespace App
76 using namespace Tizen::App;
77 using namespace Tizen::Base;
78 using namespace Tizen::Base::Collection;
80 const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId";
81 const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName";
82 const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo";
83 const wchar_t ARG_KEY_X[] = L"_X";
84 const wchar_t ARG_KEY_Y[] = L"_Y";
85 const wchar_t ARG_KEY_WIDTH[] = L"_Width";
86 const wchar_t ARG_KEY_HEIGHT[] = L"_Height";
87 const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth";
88 const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight";
89 const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument";
90 const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType";
91 const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp";
93 _AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
96 ,__providerId(providerId)
97 ,__instanceId(instanceId)
100 ,__priority(priority)
101 ,__isForeground(true)
105 ,__providerState(INVALID)
107 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
109 SysLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
112 _AppWidgetContextBase::~_AppWidgetContextBase(void)
114 SysLog(NID_SHELL, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
119 _AppWidgetContextBase::SetIpcClientId(int clientId)
121 __ipcClientId = clientId;
125 _AppWidgetContextBase::HasValidClientId(void) const
127 SysLog(NID_SHELL, "%d", __ipcClientId);
128 return (__ipcClientId > -1);
132 _AppWidgetContextBase::IsSharedMemCreated(void) const
134 return ( __buffer_info && __buffer);
138 _AppWidgetContextBase::GetSharedMemId(int w, int h)
140 SysLog(NID_SHELL, "Enter");
142 bool isResized = (__buffer_info != null) && (__buffer_info->width != w || __buffer_info->height != h);
148 if( __buffer_info == null)
150 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
151 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
153 __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, this);
154 SysTryReturnResult(NID_SHELL, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire");
155 SysLog(NID_SHELL, "provider_buffer_acquire successed");
157 __buffer = provider_buffer_ref(__buffer_info);
158 SysTryReturnResult(NID_SHELL, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref");
159 SysLog(NID_SHELL, "provider_buffer_ref successed");
162 int bufferId = __buffer_info->fb->handle;
163 __providerState = RUNNING;
165 SysLog(NID_SHELL, "(%d) Exit", bufferId);
171 _AppWidgetContextBase::Suspend(void)
173 __providerState = SUSPENDED;
177 _AppWidgetContextBase::IsRunning(void) const
179 return (__providerState == RUNNING);
183 _AppWidgetContextBase::ReleaseSharedMem(void)
185 SysLog(NID_SHELL, "Enter");
191 ret = provider_buffer_unref(__buffer);
193 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref");
194 SysLog(NID_SHELL, "provider_buffer_unref successed");
199 ret = provider_buffer_release(__buffer_info);
200 __buffer_info = null;
201 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release");
202 SysLog(NID_SHELL, "provider_buffer_release successed");
205 SysLog(NID_SHELL, "Exit.");
211 _AppWidgetContextBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
213 return _AppWidgetRequestHelper::SendRequestToApp(appId, operation, pArgs);
217 _AppWidgetContextBase::GetAppId(void) const
223 _AppWidgetContextBase::GetProviderName(void) const
225 return __providerName;
229 _AppWidgetContextBase::GetUserInfo(void) const
235 _AppWidgetContextBase::SetForeground(bool foreground)
237 __isForeground = foreground;
241 _AppWidgetContextBase::IsForeground(void) const
243 return __isForeground;
247 _AppWidgetContextBase::GetClientId(void) const
249 return __ipcClientId;
253 _AppWidgetContextBase::GetWidth(void) const
259 _AppWidgetContextBase::GetHeight(void) const
265 _AppWidgetContextBase::GetInstanceId(void) const
271 _AppWidgetContextBase::GetProviderId(void) const
277 _AppWidgetContextBase::GetPriority(void) const
283 _AppWidgetContextBase::SetWidth(int width)
289 _AppWidgetContextBase::SetHeight(int height)
295 _AppWidgetRequestHelper::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
297 SysLog(NID_SHELL, "appId(%ls), operation(%ls), arg count(%d)", appId.GetPointer(), operation.GetPointer(), pArgs->GetCount() );
300 msg.AddData(OSP_K_APPCONTROL_INTERNAL_OPERATION, L"appwidget");
301 Tizen::App::_AppArg::AddStrMap(msg.GetBundle(), pArgs);
303 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId) );
304 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(operation) );
306 result r = Tizen::App::_AppControlManager::GetInstance()->LaunchPkg(msg, pAppId.get(), pOperation.get(), null, null, null, null);
307 SysLog(NID_SHELL, "The result of SendRequestToApp [%s]", GetErrorMessage(r));
312 }}} // Tizen::Shell::App
314 ////////////////////////////////////////////
316 ////////////////////////////////////////////
317 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data)
319 SysLog(NID_SHELL, "timestamp(%f), x(%f), y(%f)", timestamp, x, y);
321 Tizen::Shell::App::_AppWidgetContextBase *pAppWidgetBase = static_cast<Tizen::Shell::App::_AppWidgetContextBase*>(data);
322 SysTryReturn(NID_SHELL, pAppWidgetBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetBase is null");
324 if (event == BUFFER_EVENT_ENTER)
326 SysLog(NID_SHELL, "BUFFER_EVENT_ENTER");
328 else if (event == BUFFER_EVENT_LEAVE)
330 SysLog(NID_SHELL, "BUFFER_EVENT_LEAVE");
332 else if (event == BUFFER_EVENT_DOWN)
334 SysLog(NID_SHELL, "BUFFER_EVENT_DOWN");
336 else if (event == BUFFER_EVENT_MOVE)
338 SysLog(NID_SHELL, "BUFFER_EVENT_MOVE");
340 else if(event == BUFFER_EVENT_UP)
342 SysLog(NID_SHELL, "BUFFER_EVENT_UP");
345 pAppWidgetBase->SendTouchEvent(event, timestamp, x, y);