2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 String ARG_KEY_INSTANCE_ID = L"_InstanceId";
89 const String ARG_KEY_PROVIDER_NAME = L"_ProviderName";
90 const String ARG_KEY_USER_INFO = L"_UserInfo";
91 const String ARG_KEY_WIDTH = L"_Width";
92 const String ARG_KEY_HEIGHT = L"_Height";
95 _AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
98 ,__providerId(providerId)
99 ,__instanceId(instanceId)
102 ,__priority(priority)
103 ,__isForeground(true)
107 ,__providerState(INVALID)
109 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
111 SysLog(NID_APP, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
114 _AppWidgetContextBase::~_AppWidgetContextBase()
116 SysLog(NID_APP, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
122 _AppWidgetContextBase::SetIpcClientId(int clientId)
124 __ipcClientId = clientId;
128 _AppWidgetContextBase::HasValidClientId(void) const
130 SysLog(NID_APP, "%d", __ipcClientId);
131 return (__ipcClientId > -1);
135 _AppWidgetContextBase::IsSharedMemCreated(void) const
137 return ( __buffer_info && __buffer_info);
141 _AppWidgetContextBase::GetSharedMemId(int w, int h)
143 SysLog(NID_APP, "Enter");
145 if( __buffer_info == null)
147 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
148 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
150 __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, this);
151 SysTryReturnResult(NID_APP, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire");
152 SysLog(NID_APP, "provider_buffer_acquire successed");
154 __buffer = provider_buffer_ref(__buffer_info);
155 SysTryReturnResult(NID_APP, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref");
156 SysLog(NID_APP, "provider_buffer_ref successed");
159 int bufferId = __buffer_info->fb->handle;
160 __providerState = RUNNING;
162 SysLog(NID_APP, "(%d) Exit", bufferId);
168 _AppWidgetContextBase::Suspend()
170 __providerState = SUSPENDED;
174 _AppWidgetContextBase::IsRunning() const
176 return (__providerState == RUNNING);
180 _AppWidgetContextBase::ReleaseSharedMem()
182 SysLog(NID_APP, "Enter");
188 ret = provider_buffer_unref(__buffer);
190 SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref");
191 SysLog(NID_APP, "provider_buffer_unref successed");
196 ret = provider_buffer_release(__buffer_info);
197 __buffer_info = null;
198 SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release");
199 SysLog(NID_APP, "provider_buffer_release successed");
202 SysLog(NID_APP, "Exit.");
207 Tizen::Base::Collection::HashMap*
208 _AppWidgetContextBase::CreateRequestArgs(void)
210 HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
212 pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
213 pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
214 pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
215 pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__width)));
216 pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__height)));
222 _AppWidgetContextBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
224 if( __isForeground == false)
226 SysLog(NID_APP, "appWidget isn't foreground, so, message skip");
230 return _AppWidgetRequestHelper::SendRequestToApp(appId, operation, pArgs);
234 _AppWidgetRequestHelper::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
236 SysLog(NID_APP, "appId(%ls), operation(%ls), arg count(%d)", appId.GetPointer(), operation.GetPointer(), pArgs->GetCount() );
239 msg.AddData(OSP_K_APPCONTROL_INTERNAL_OPERATION, L"livebox");
240 Tizen::App::_AppArg::AddStrMap(msg.GetBundle(), pArgs);
242 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId) );
243 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(operation) );
245 return Tizen::App::_AppControlManager::GetInstance()->LaunchPkg(msg, pAppId.get(), pOperation.get(), null, null, null, null);
248 } } } // Tizen::Shell::App {
251 ////////////////////////////////////////////
253 ////////////////////////////////////////////
254 static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
255 double timestamp, double x, double y, void* data)
257 SysLog(NID_APP, "timestamp(%f), x(%f), y(%f)", timestamp, x, y);
259 Tizen::Shell::App::_AppWidgetContextBase *pAppWidgetBase = static_cast<Tizen::Shell::App::_AppWidgetContextBase*>(data);
260 SysTryReturn(NID_APP, pAppWidgetBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetBase is null");
262 // const char *pkgname = provider_buffer_pkgname(info);
263 // const char *id = provider_buffer_id(info);
264 // enum target_type type = provider_buffer_type(info);
266 if( event == BUFFER_EVENT_ENTER)
268 SysLog(NID_APP, "BUFFER_EVENT_ENTER");
270 else if( event == BUFFER_EVENT_LEAVE)
272 SysLog(NID_APP, "BUFFER_EVENT_LEAVE");
274 else if( event == BUFFER_EVENT_DOWN)
276 SysLog(NID_APP, "BUFFER_EVENT_DOWN");
278 else if( event == BUFFER_EVENT_MOVE)
280 SysLog(NID_APP, "BUFFER_EVENT_MOVE");
282 else if( event == BUFFER_EVENT_UP)
284 SysLog(NID_APP, "BUFFER_EVENT_UP");
287 pAppWidgetBase->SendTouchEvent(event, timestamp, x, y);