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 "provider_buffer.h"
28 #include <FBaseSysLog.h>
29 #include <FBase_StringConverter.h>
31 #include <FApp_AppMessageImpl.h>
32 #include <FApp_AppArg.h>
33 #include <FApp_AppControlManager.h>
34 #include <FShell_TemplateUtil.h>
35 #include <FShell_AppWidgetManagerImpl.h>
37 #include "FShell_AppWidgetContextBase.h"
50 // provider/inc/provider_buffer_internal.h
51 struct livebox_buffer {
53 BUFFER_CREATED = 0x00beef00,
54 BUFFER_DESTROYED = 0x00dead00,
57 enum target_type type;
60 int fd; /* File handle(descriptor) */
61 int id; /* SHM handle(id) */
72 int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data);
76 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
77 double timestamp, double x, double y, void* data);
79 namespace Tizen { namespace Shell { namespace App
82 using namespace Tizen::App;
83 using namespace Tizen::Base;
84 using namespace Tizen::Base::Collection;
87 const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId";
88 const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName";
89 const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo";
90 const wchar_t ARG_KEY_X[] = L"_X";
91 const wchar_t ARG_KEY_Y[] = L"_Y";
92 const wchar_t ARG_KEY_WIDTH[] = L"_Width";
93 const wchar_t ARG_KEY_HEIGHT[] = L"_Height";
94 const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth";
95 const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight";
96 const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument";
97 const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType";
98 const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp";
101 _AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
103 ,__userInfo(userInfo)
104 ,__providerId(providerId)
105 ,__instanceId(instanceId)
108 ,__priority(priority)
109 ,__isForeground(true)
113 ,__providerState(INVALID)
115 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
117 SysLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
120 _AppWidgetContextBase::~_AppWidgetContextBase()
122 SysLog(NID_SHELL, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
128 _AppWidgetContextBase::SetIpcClientId(int clientId)
130 __ipcClientId = clientId;
134 _AppWidgetContextBase::HasValidClientId(void) const
136 SysLog(NID_SHELL, "%d", __ipcClientId);
137 return (__ipcClientId > -1);
141 _AppWidgetContextBase::IsSharedMemCreated(void) const
143 return ( __buffer_info && __buffer);
147 _AppWidgetContextBase::GetSharedMemId(int w, int h)
149 SysLog(NID_SHELL, "Enter");
151 bool isResized = (__buffer_info != null) && (__buffer_info->width != w || __buffer_info->height != h);
157 if( __buffer_info == null)
159 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
160 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
162 __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, this);
163 SysTryReturnResult(NID_SHELL, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire");
164 SysLog(NID_SHELL, "provider_buffer_acquire successed");
166 __buffer = provider_buffer_ref(__buffer_info);
167 SysTryReturnResult(NID_SHELL, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref");
168 SysLog(NID_SHELL, "provider_buffer_ref successed");
171 int bufferId = __buffer_info->fb->handle;
172 __providerState = RUNNING;
174 SysLog(NID_SHELL, "(%d) Exit", bufferId);
180 _AppWidgetContextBase::Suspend()
182 __providerState = SUSPENDED;
186 _AppWidgetContextBase::IsRunning() const
188 return (__providerState == RUNNING);
192 _AppWidgetContextBase::ReleaseSharedMem()
194 SysLog(NID_SHELL, "Enter");
200 ret = provider_buffer_unref(__buffer);
202 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref");
203 SysLog(NID_SHELL, "provider_buffer_unref successed");
208 ret = provider_buffer_release(__buffer_info);
209 __buffer_info = null;
210 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release");
211 SysLog(NID_SHELL, "provider_buffer_release successed");
214 SysLog(NID_SHELL, "Exit.");
220 _AppWidgetContextBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
222 if( __isForeground == false)
224 SysLog(NID_SHELL, "appWidget isn't foreground, so, message skip");
228 return _AppWidgetRequestHelper::SendRequestToApp(appId, operation, pArgs);
232 _AppWidgetRequestHelper::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
234 SysLog(NID_SHELL, "appId(%ls), operation(%ls), arg count(%d)", appId.GetPointer(), operation.GetPointer(), pArgs->GetCount() );
237 msg.AddData(OSP_K_APPCONTROL_INTERNAL_OPERATION, L"livebox");
238 Tizen::App::_AppArg::AddStrMap(msg.GetBundle(), pArgs);
240 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId) );
241 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(operation) );
243 return Tizen::App::_AppControlManager::GetInstance()->LaunchPkg(msg, pAppId.get(), pOperation.get(), null, null, null, null);
246 } } } // Tizen::Shell::App {
249 ////////////////////////////////////////////
251 ////////////////////////////////////////////
252 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
253 double timestamp, double x, double y, void* data)
255 SysLog(NID_SHELL, "timestamp(%f), x(%f), y(%f)", timestamp, x, y);
257 Tizen::Shell::App::_AppWidgetContextBase *pAppWidgetBase = static_cast<Tizen::Shell::App::_AppWidgetContextBase*>(data);
258 SysTryReturn(NID_SHELL, pAppWidgetBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetBase is null");
260 // const char *pkgname = provider_buffer_pkgname(info);
261 // const char *id = provider_buffer_id(info);
262 // enum target_type type = provider_buffer_type(info);
264 if( event == BUFFER_EVENT_ENTER)
266 SysLog(NID_SHELL, "BUFFER_EVENT_ENTER");
268 else if( event == BUFFER_EVENT_LEAVE)
270 SysLog(NID_SHELL, "BUFFER_EVENT_LEAVE");
272 else if( event == BUFFER_EVENT_DOWN)
274 SysLog(NID_SHELL, "BUFFER_EVENT_DOWN");
276 else if( event == BUFFER_EVENT_MOVE)
278 SysLog(NID_SHELL, "BUFFER_EVENT_MOVE");
280 else if( event == BUFFER_EVENT_UP)
282 SysLog(NID_SHELL, "BUFFER_EVENT_UP");
285 pAppWidgetBase->SendTouchEvent(event, timestamp, x, y);