2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // All rights reserved.
6 // This software contains confidential and proprietary information
7 // of Samsung Electronics Co., Ltd.
8 // The user of this software agrees not to disclose, disseminate or copy such
9 // Confidential Information and shall use the software only in accordance with
10 // the terms of the license agreement the user entered into with Samsung.
14 * @file FShell_LiveboxBase.cpp
15 * @brief This is the implementation for the Livebox class.
19 #include <unique_ptr.h>
21 #include "provider_buffer.h"
24 #include <FBaseSysLog.h>
25 #include <FBase_StringConverter.h>
27 #include <FApp_AppMessageImpl.h>
28 #include <FApp_AppArg.h>
29 #include <FApp_AppControlManager.h>
30 #include <FShell_TemplateUtil.h>
31 #include <FShell_LiveboxManagerImpl.h>
33 #include "FShell_LiveboxBase.h"
46 // provider/inc/provider_buffer_internal.h
47 struct livebox_buffer {
49 BUFFER_CREATED = 0x00beef00,
50 BUFFER_DESTROYED = 0x00dead00,
53 enum target_type type;
56 int fd; /* File handle(descriptor) */
57 int id; /* SHM handle(id) */
68 int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data);
72 static int LiveboxHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
73 double timestamp, double x, double y, void* data);
75 namespace Tizen { namespace Shell { namespace App
78 using namespace Tizen::App;
79 using namespace Tizen::Base;
80 using namespace Tizen::Base::Collection;
83 const String LIVEBOX_ON_ADD(L"Livebox='event=add'");
84 const String LIVEBOX_ON_REMOVE(L"Livebox='event=remove'");
85 const String LIVEBOX_ON_UPDATE(L"Livebox='event=update'");
86 const String LIVEBOX_ON_RESIZE(L"Livebox='event=resize'");
87 const String LIVEBOX_ON_TOUCH(L"Livebox='event=touch'");
88 const String LIVEBOX_TRAY_ON_CREATE(L"LiveboxTray='event=create'");
89 const String LIVEBOX_TRAY_ON_DESTROY(L"LiveboxTray='event=destroy'");
90 const String LIVEBOX_TRAY_ON_TOUCH(L"LiveboxTray='event=touch'");
92 const String ARG_KEY_INSTANCE_ID = L"_InstanceId";
93 const String ARG_KEY_PROVIDER_NAME = L"_ProviderName";
94 const String ARG_KEY_USER_INFO = L"_UserInfo";
97 _LiveboxBase::_LiveboxBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
100 ,__providerId(providerId)
101 ,__instanceId(instanceId)
104 ,__priority(priority)
106 ,__buffer(null) // __pEcoreEvas(null), __pEvas(null), __current(0)
107 ,__isForeground(true)
110 _LiveboxManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
112 SysLog(NID_APP, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
115 _LiveboxBase::~_LiveboxBase()
117 SysLog(NID_APP, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
122 _LiveboxBase::SetClientId(int clientId)
124 __ipcClientId = clientId;
128 _LiveboxBase::HasValidClientId() const
130 SysLog(NID_APP, "%d", __ipcClientId);
131 return (__ipcClientId > -1);
135 _LiveboxBase::GetSharedMemId(int w, int h)
137 SysLog(NID_APP, "Enter");
139 if( __buffer_info == null)
141 std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
142 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
144 __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), LiveboxHandleBufferEventCallback, this);
145 SysTryReturnResult(NID_APP, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire");
146 SysLog(NID_APP, "provider_buffer_acquire successed");
148 __buffer = provider_buffer_ref(__buffer_info);
149 SysTryReturnResult(NID_APP, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref");
150 SysLog(NID_APP, "provider_buffer_ref successed");
153 int bufferId = __buffer_info->fb->handle;
155 SysLog(NID_APP, "(%d) Exit", bufferId);
160 _LiveboxBase::ReleaseSharedMem()
162 SysLog(NID_APP, "Enter");
167 ret = provider_buffer_unref(__buffer);
169 SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref");
170 SysLog(NID_APP, "provider_buffer_unref successed");
175 ret = provider_buffer_release(__buffer_info);
176 __buffer_info = null;
177 SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release");
178 SysLog(NID_APP, "provider_buffer_release successed");
181 SysLog(NID_APP, "Exit.");
186 Tizen::Base::Collection::HashMap*
187 _LiveboxBase::CreateRequestArgs(void)
189 HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
191 pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
192 pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
193 pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
199 _LiveboxBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
201 if( __isForeground == false)
203 SysLog(NID_APP, "livebox isn't foreground, so, message skip");
207 return _LiveboxRequestHelper::SendRequestToApp(appId, operation, pArgs);
211 _LiveboxRequestHelper::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
213 SysLog(NID_APP, "appId(%ls), operation(%ls), arg count(%d)", appId.GetPointer(), operation.GetPointer(), pArgs->GetCount() );
215 /* std::unique_ptr<IMapEnumerator> pMapEnum(pArgs->GetMapEnumeratorN());
216 SysTryReturnResult(NID_APP, pMapEnum.get(), E_SYSTEM, "failed to get GetMapEnumeratorN");
218 while( pMapEnum->MoveNext() == E_SUCCESS)
220 const String* pKey = dynamic_cast<const String*>(pMapEnum->GetKey());
221 const String* pValue = dynamic_cast<const String*>(pMapEnum->GetValue());
225 SysLog(NID_APP, "key is null");
230 SysLog(NID_APP, "pValue is null");
234 SysLog(NID_APP, "key(%ls), value(%ls)", pKey->GetPointer(), pValue->GetPointer() );
240 msg.AddData(OSP_K_APPCONTROL_INTERNAL_OPERATION, L"livebox");
241 // AddStrArrayToBundle(msg.GetBundle(), OSP_K_ARG, pArgs);
242 Tizen::App::_AppArg::AddStrMap(msg.GetBundle(), pArgs);
243 std::unique_ptr<char[]> pAppId(_StringConverter::CopyToCharArrayN(appId) );
244 std::unique_ptr<char[]> pOperation(_StringConverter::CopyToCharArrayN(operation) );
246 return Tizen::App::_AppControlManager::GetInstance()->LaunchPkg(msg, pAppId.get(), pOperation.get(), null, null, null, null);
250 _LiveboxRequestHelper::ExtractPackageIdAndExecutableName(AppId appId, AppId& outPackageId, String& outExecutableName)
252 const int APP_ID_LEN = 10;
254 if (appId.GetLength() > APP_ID_LEN)
256 result r = appId.SubString(APP_ID_LEN + 1, appId.GetLength() - (APP_ID_LEN + 1), outExecutableName);
257 SysTryReturnResult(NID_APP, !IsFailed(r), E_INVALID_ARG, "invalid AppId(%ls)", appId.GetPointer());
259 r = appId.SubString(0, APP_ID_LEN, outPackageId);
260 SysTryReturnResult(NID_APP, !IsFailed(r), E_INVALID_ARG, "invalid AppId(%ls)", appId.GetPointer());
270 _LiveboxRequestHelper::AddStrArrayToBundle(bundle* b, const char* key, const IList* pList)
273 SysTryReturnResult(NID_APP, pb != NULL, E_INVALID_ARG, "Empty bundle.");
275 if (pList == null || pList->GetCount() == 0)
277 SysLog(NID_APP, "No element added for bundle.");
282 const int count = pList->GetCount();
284 const char** pSa = new (std::nothrow) const char*[count];
285 SysTryReturnResult(NID_APP, pSa != null, E_OUT_OF_MEMORY, "Memory allocation failure with cound %d.", count);
287 for (i = 0; i < count; i++)
291 const String* pStr = static_cast<const String*>(pList->GetAt(i));
294 pSa[i] = _StringConverter::CopyToCharArrayN(*pStr);
298 result r = E_SUCCESS;
300 int ret = bundle_add_str_array(pb, key, pSa, count);
301 SysTryReturnResult(NID_APP, ret >= 0, E_SYSTEM, "Bundle add failre with %d.", strerror(errno));
304 for (i = 0; i < count; i++)
315 } } } // Tizen::Shell::App {
318 ////////////////////////////////////////////
320 ////////////////////////////////////////////
321 static int LiveboxHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event,
322 double timestamp, double x, double y, void* data)
324 SysLog(NID_APP, "timestamp(%f), x(%f), y(%f)", timestamp, x, y);
326 Tizen::Shell::App::_LiveboxBase *pLiveboxBase = static_cast<Tizen::Shell::App::_LiveboxBase*>(data);
327 SysTryReturn(NID_APP, pLiveboxBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pLiveboxBase is null");
329 // const char *pkgname = provider_buffer_pkgname(info);
330 // const char *id = provider_buffer_id(info);
331 // enum target_type type = provider_buffer_type(info);
333 if( event == BUFFER_EVENT_ENTER)
335 SysLog(NID_APP, "BUFFER_EVENT_ENTER");
337 else if( event == BUFFER_EVENT_LEAVE)
339 SysLog(NID_APP, "BUFFER_EVENT_LEAVE");
341 else if( event == BUFFER_EVENT_DOWN)
343 SysLog(NID_APP, "BUFFER_EVENT_DOWN");
345 else if( event == BUFFER_EVENT_MOVE)
347 SysLog(NID_APP, "BUFFER_EVENT_MOVE");
349 else if( event == BUFFER_EVENT_UP)
351 SysLog(NID_APP, "BUFFER_EVENT_UP");
354 pLiveboxBase->SendTouchEvent(event, timestamp, x, y);