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_AppWidgetManagerService.cpp
19 * @brief This is the implementation for the AppWidgetManagerService class.
22 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseColIList.h>
31 #include <FBaseComparerT.h>
32 #include <FApp_AppManagerImpl.h>
33 #include <FShell_AppWidgetManagerImpl.h>
34 #include <FIo_IpcServer.h>
35 #include <FBase_StringConverter.h>
37 #include "FShell_AppContext.h"
38 #include "FShell_AppWidgetPopupContext.h"
39 #include "FShell_AppWidgetManagerService.h"
40 #include "FShell_TemplateUtil.h"
42 namespace Tizen { namespace Shell { namespace App {
45 using namespace Tizen::App;
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Base::Runtime;
49 using namespace Tizen::Io;
50 using namespace Tizen::System;
51 using namespace Tizen::Shell::App;
55 static const char APPNAME_OSP_APPWIDGET_SERVICE[] = "osp-appwidget-service";
56 static const int TIMER_DURATION_PING = 120000;
57 //extern const int UPDATE_PERIOD_MSEC_MIN;
60 AppWidgetManagerService* AppWidgetManagerService::__pTheInstance = null;
62 AppWidgetManagerService::AppWidgetManagerService(void)
67 AppWidgetManagerService::~AppWidgetManagerService(void)
69 SysLog(NID_SHELL, "Enter");
73 DeinitializeCoreDaemonEventReceiver();
75 IMapEnumeratorT<String, _AppContext*>* pMapEnum = __appContextList.GetMapEnumeratorN();
78 while (pMapEnum->MoveNext() == E_SUCCESS)
80 _AppContext* pAppContext = null;
81 pMapEnum->GetValue(pAppContext);
88 SysLog(NID_SHELL, "Exit");
92 AppWidgetManagerService::InitSingleton(void)
94 unique_ptr<AppWidgetManagerService> pInstance(new (nothrow) AppWidgetManagerService());
95 SysTryReturnVoidResult(NID_SHELL, pInstance, E_OUT_OF_MEMORY, "The memory is insufficient.");
97 __pTheInstance = pInstance.release();
98 std::atexit(DestroySingleton);
102 AppWidgetManagerService::DestroySingleton(void)
104 delete __pTheInstance;
107 AppWidgetManagerService*
108 AppWidgetManagerService::GetInstance(void)
110 if (__pTheInstance == null)
112 __pTheInstance = CreateInstance(APPNAME_OSP_APPWIDGET_SERVICE);
114 return __pTheInstance;
117 AppWidgetManagerService*
118 AppWidgetManagerService::CreateInstance(const char* pCoreDaemonId)
122 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
124 if (__pTheInstance == null)
126 pthread_once(&onceBlock, InitSingleton);
127 result r = GetLastResult();
130 onceBlock = PTHREAD_ONCE_INIT;
133 r = __pTheInstance->Construct(pCoreDaemonId);
134 SysAssertf(!IsFailed(r), "Failed to construct AppWidgetManagerService");
135 SysLog(NID_SHELL, "AppWidgetManagerService is created.");
137 return __pTheInstance;
141 AppWidgetManagerService::Construct(const char* pCoreDaemonId)
143 result r = __appContextList.Construct();
144 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct.");
146 _AppWidgetManagerStub::StartIpcServer();
147 InitializeCoreDaemonEventReceiver(pCoreDaemonId);
149 SetSettingEventListener(*this);
155 AppWidgetManagerService::SetSettingEventListener(Tizen::System::ISettingEventListener& listener)
157 const int MAX_TRY_COUNT = 10;
158 const int TRY_SLEEP_TIME = 250;
163 result r = SettingInfo::AddSettingEventListener(listener);
166 SysLog(NID_APP, "Succeeded to invoke AddSettingEventListener");
170 if (count >= MAX_TRY_COUNT)
172 SysLog(NID_APP, "Failed to invoke AddSettingEventListener");
177 Thread::Sleep(TRY_SLEEP_TIME);
178 SysLog(NID_APP, "%d th retry...", count);
184 AppWidgetManagerService::OnAppWidgetServiceConnected(struct event_arg *arg, void* data)
187 ret = provider_send_hello();
190 SysLog(NID_SHELL, "Success to be connected with master daemon");
191 AppWidgetManagerService::GetInstance()->StartPingTimer();
196 SysLog(NID_SHELL, "Failed to invoke provider_send_hello()");
202 AppWidgetManagerService::OnAppWidgetServiceCDisconnected(struct event_arg *arg, void* data)
204 SysLog(NID_SHELL, "Disconnected with master daemon");
209 AppWidgetManagerService::StartPingTimer(void)
211 result r = E_SUCCESS;
213 r = __pingTimer.Construct(*this);
214 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
216 r = __pingTimer.StartAsRepeatable(TIMER_DURATION_PING);
217 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
221 AppWidgetManagerService::OnTimerExpired(Timer& timer)
223 provider_send_ping();
227 AppWidgetManagerService::FindAppContext(const Tizen::App::AppId& appId) const
229 _AppContext* pAppContext = null;
230 result r = __appContextList.GetValue(appId, pAppContext);
231 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]");
237 AppWidgetManagerService::RemoveAppContext(const Tizen::App::AppId& appId)
239 return __appContextList.Remove(appId);
243 AppWidgetManagerService::FindAppWidget(const AppId& appId, const String& instanceId) const
245 _AppContext* pAppContext = null;
246 result r = __appContextList.GetValue(appId, pAppContext);
247 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
249 return pAppContext->FindAppWidget(instanceId);
253 AppWidgetManagerService::OnIpcClientConnected(const _IpcServer& server, int clientId)
255 String appId = server.GetClientApplicationId();
256 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
258 _AppContext* pAppContext = null;
259 __appContextList.GetValue(appId, pAppContext);
262 pAppContext->OnIpcConnected(clientId);
267 AppWidgetManagerService::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
269 String appId = server.GetClientApplicationId();
270 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
272 _AppContext* pAppContext = null;
273 __appContextList.GetValue(appId, pAppContext);
276 pAppContext->OnIpcDisconnected();
281 AppWidgetManagerService::OnSettingChanged(Tizen::Base::String& key)
283 // const static wchar_t KEY_SETTING_FONT_SIZE[] = L"http://tizen.org/setting/font.size";
284 const static wchar_t KEY_SETTING_FONT_TYPE[] = L"http://tizen.org/setting/font.type";
285 const static wchar_t KEY_SETTING_LANGUAGE[] = L"http://tizen.org/setting/locale.language";
286 const static wchar_t KEY_SETTING_COUNTRY[] = L"http://tizen.org/setting/locale.country";
288 if( key == KEY_SETTING_FONT_TYPE
289 // || key == KEY_SETTING_FONT_SIZE
290 || key == KEY_SETTING_LANGUAGE
291 || key == KEY_SETTING_COUNTRY )
293 SysLog(NID_SHELL, "'%ls' is changed.", key.GetPointer() );
294 RequestUpdateAllSuspened();
299 AppWidgetManagerService::AddAppWidget(const Tizen::Base::String& userInfo, const Tizen::Base::String& providerId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority)
303 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, appId, providerName);
305 _AppContext* pAppContext = null;
306 bool containsKey = false;
307 __appContextList.ContainsKey(appId, containsKey);
308 if( containsKey == false)
310 pAppContext = new(std::nothrow) _AppContext(appId);
311 SysTryReturnResult(NID_SHELL, pAppContext, E_OUT_OF_MEMORY, "");
312 __appContextList.Add(appId, pAppContext);
316 __appContextList.GetValue(appId, pAppContext);
319 return pAppContext->AddAppWidget(userInfo, providerId, instanceId, width, height, period, priority);
322 ///////////////////////////////////////////////////////
323 // CoreDaemonEventReceiver implementation
324 ///////////////////////////////////////////////////////
326 AppWidgetManagerService::OnAppWidgetCreate(struct event_arg *arg, int *width, int *height, double *priority, void* data)
328 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_NEW, "The status of data-provider-master is invalid.");
329 SysSecureLog(NID_SHELL, "providerId(%s) id(%s) content(%s) cluster(%s) category(%s)", arg->pkgname, arg->id, arg->info.lb_create.content, arg->info.lb_create.cluster, arg->info.lb_create.category);
331 const int MAX_LENGTH = 0xFFFF;// FUi_Control.h
332 *width = arg->info.lb_create.width;
333 *height= arg->info.lb_create.height;
334 *priority = 1.0f;// Fixed as default
335 SysAssertf(*width >= 0 && *height >= 0 && *width <= MAX_LENGTH && *height <= MAX_LENGTH, "w:%d, h:%d", *width, *height);
337 result r = AppWidgetManagerService::GetInstance()->AddAppWidget(arg->info.lb_create.content, arg->pkgname, arg->id, *width, *height, arg->info.lb_create.period*1000, *priority);
338 SysTryReturn(NID_SHELL, !IsFailed(r), -1, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
344 AppWidgetManagerService::OnAppWidgetUpdate(struct event_arg *arg, void* data)
346 SysAssertf(arg != null && arg->type == event_arg::EVENT_UPDATE_CONTENT, "The status of data-provider-master is invalid.");
348 bool isInstanceIdSpecified = (arg->id == null || strlen(arg->id) < 1) ? false : true;
349 if (isInstanceIdSpecified == false)
353 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(arg->pkgname, appId, providerName);
355 AppWidgetManagerService::GetInstance()->RequestUpdate(appId, providerName, L"");
359 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
360 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
362 result r = pAppContext->UpdateAppWidget(arg->id);
363 SysTryReturn(NID_SHELL, !IsFailed(r), -1, E_OBJ_NOT_FOUND, "Failed to update _AppContext.");
370 AppWidgetManagerService::OnAppWidgetDestroy(struct event_arg *arg, void* data)
372 SysAssertf(arg != null && arg->type == event_arg::EVENT_DELETE, "The status of data-provider-master is invalid.");
373 SysLog(NID_SHELL, "lb_destroy.type (%d)", arg->info.lb_destroy.type);
375 if (arg->info.lb_destroy.type == event_arg::event_data::lb_destroy::INSTANCE_DESTROY_PKGMGR)
377 SysLog(NID_SHELL, "INSTANCE_DESTROY_PKGMGR type, ignored.");
381 String appId = _AppWidgetHelper::ExtractAppId(arg->pkgname);
382 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
383 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
385 pAppContext->DestroyAppWidget(arg->id);
387 if (pAppContext->GetProviderCount() == 0)
389 SysLog(NID_SHELL, "The provider count for (%ls) is 0.", appId.GetPointer());
390 AppWidgetManagerService::GetInstance()->RemoveAppContext(appId);
398 AppWidgetManagerService::OnAppWidgetPopupCreate(struct event_arg *arg, void* data)
400 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_CREATE, "The status of data-provider-master is invalid.");
402 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), x(%d), y(%d), width(%f), height(%f), priority(%d)", arg->pkgname, arg->id, arg->info.pd_create.x, arg->info.pd_create.y, arg->info.pd_create.w, arg->info.pd_create.h);
404 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
405 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
407 pAppContext->CreateAppWidgetPopup(arg->id, arg->info.pd_create.x, arg->info.pd_create.y, arg->info.pd_create.w, arg->info.pd_create.h);
413 AppWidgetManagerService::OnAppWidgetPopupDestroy(struct event_arg *arg, void* data)
415 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_DESTROY, "The status of data-provider-master is invalid.");
417 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
419 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
420 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
422 pAppContext->DestroyAppWidgetPopup(arg->id);
428 AppWidgetManagerService::OnAppWidgetBackground(struct event_arg *arg, void* data)
430 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_PAUSE, "The status of data-provider-master is invalid.");
432 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
434 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
435 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
437 pAppContext->OnAppWidgetBackground(arg->id);
443 AppWidgetManagerService::OnAppWidgetBackgroundAll(struct event_arg *arg, void* data)
445 SysAssertf(arg != null && arg->type == event_arg::EVENT_PAUSE, "The status of data-provider-master is invalid.");
447 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN());
448 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
450 while (pAppContextEnum->MoveNext() == E_SUCCESS)
452 _AppContext* pAppContext = null;
453 pAppContextEnum->GetValue(pAppContext);
457 pAppContext->OnAppWidgetBackgroundAll();
465 AppWidgetManagerService::OnAppWidgetForeground(struct event_arg *arg, void* data)
467 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_RESUME, "The status of data-provider-master is invalid.");
469 SysTryReturn(NID_SHELL, arg || arg->id || arg->pkgname, 0, E_SUCCESS, "arg is null!");
470 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
472 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
473 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
475 pAppContext->OnAppWidgetForeground(arg->id);
481 AppWidgetManagerService::OnAppWidgetForegroundAll(struct event_arg *arg, void* data)
483 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESUME, "The status of data-provider-master is invalid.");
485 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN());
486 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
488 while (pAppContextEnum->MoveNext() == E_SUCCESS)
490 _AppContext* pAppContext = null;
491 pAppContextEnum->GetValue(pAppContext);
495 pAppContext->OnAppWidgetForegroundAll();
503 AppWidgetManagerService::OnAppWidgetClick(struct event_arg *arg, void* data)
505 SysAssertf(arg != null && arg->type == event_arg::EVENT_CLICKED, "The status of data-provider-master is invalid.");
507 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), clicked.event(%s), clicked.x(%f), clicked.y(%f)", arg->pkgname, arg->id, arg->info.clicked.event, arg->info.clicked.x, arg->info.clicked.y);
513 AppWidgetManagerService::OnAppWidgetResize(struct event_arg *arg, void* data)
515 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESIZE, "The status of data-provider-master is invalid.");
517 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), resize.w(%d), resize.h(%d)", arg->pkgname, arg->id, arg->info.resize.w, arg->info.resize.h);
519 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
520 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
522 pAppContext->ResizeAppWidget(arg->id, arg->info.resize.w, arg->info.resize.h);
528 AppWidgetManagerService::OnAppWidgetPeriodChanged(struct event_arg *arg, void* data)
530 SysAssertf(arg != null && arg->type == event_arg::EVENT_SET_PERIOD, "The status of data-provider-master is invalid.");
532 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), width(%d), height(%d), priority(%d)", arg->pkgname, arg->id);
538 AppWidgetManagerService::OnAppWidgetRecreate(struct event_arg *arg, void* data)
540 const int MAX_LENGTH = 0xFF;// FUi_Control.h
541 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_RENEW, "The status of data-provider-master is invalid.");
542 SysAssertf(arg->info.lb_recreate.width >= 0 && arg->info.lb_recreate.height >= 0 && arg->info.lb_recreate.width <= MAX_LENGTH && arg->info.lb_recreate.height <= MAX_LENGTH, "w:%d, h:%d", arg->info.lb_recreate.width, arg->info.lb_recreate.height);
544 SysSecureLog(NID_SHELL, "providerId(%s) id(%s) content(%s) cluster(%s) category(%s)", arg->pkgname, arg->id, arg->info.lb_recreate.content, arg->info.lb_recreate.cluster, arg->info.lb_recreate.category);
546 AppWidgetManagerService* pAppWidgetManagerService = AppWidgetManagerService::GetInstance();
547 SysTryReturn(NID_SHELL, pAppWidgetManagerService != null, -EBUSY, E_SYSTEM, "Failed to get the instance for AppWidgetManagerService.");
549 const double default_priority = 1.0f;
550 result r = pAppWidgetManagerService->AddAppWidget(arg->info.lb_recreate.content, arg->pkgname, arg->id, arg->info.lb_recreate.width, arg->info.lb_recreate.height, arg->info.lb_recreate.period * 1000, default_priority);
551 SysTryReturn(NID_SHELL, !IsFailed(r), -EBUSY, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
557 AppWidgetManagerService::InitializeCoreDaemonEventReceiver(const char *pCoreDaemonId)
559 SysTryReturnResult(NID_SHELL, pCoreDaemonId != null, E_INVALID_ARG, "pCoreDaemonId should not be null!");
561 struct event_handler cbs;
562 memset(&cbs, 0, sizeof(event_handler));
564 cbs.connected = OnAppWidgetServiceConnected,
565 cbs.disconnected = OnAppWidgetServiceCDisconnected,
566 cbs.pause = OnAppWidgetBackgroundAll,
567 cbs.resume = OnAppWidgetForegroundAll,
568 cbs.lb_pause = OnAppWidgetBackground,
569 cbs.lb_resume = OnAppWidgetForeground,
570 cbs.lb_create = OnAppWidgetCreate,
571 cbs.lb_destroy = OnAppWidgetDestroy,
572 cbs.update_content = OnAppWidgetUpdate,
573 cbs.pd_create = OnAppWidgetPopupCreate,
574 cbs.pd_destroy = OnAppWidgetPopupDestroy,
575 cbs.clicked = OnAppWidgetClick,
576 cbs.resize = OnAppWidgetResize,
577 cbs.set_period = OnAppWidgetPeriodChanged;
578 cbs.lb_recreate = OnAppWidgetRecreate;/* Recover from the fault of slave */
579 //cbs.content_event = OnAppWidgetContentEvent,
581 int ret = provider_init(null, pCoreDaemonId, &cbs, this);
582 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "provider_init failed.");
584 SysLog(NID_SHELL, "provider_init is invoked with (%s)", pCoreDaemonId);
589 AppWidgetManagerService::DeinitializeCoreDaemonEventReceiver(void)
595 ///////////////////////////////////////////////////////
596 // stub implementation
597 ///////////////////////////////////////////////////////
599 AppWidgetManagerService::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const
601 _AppContext* pAppContext = null;
602 result r = __appContextList.GetValue(appId, pAppContext);
603 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
605 return pAppContext->RequestUpdate(providerName, argument);
609 AppWidgetManagerService::RequestUpdateAllSuspened(void) const
611 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(__appContextList.GetMapEnumeratorN());
612 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
614 while (pAppContextEnum->MoveNext() == E_SUCCESS)
616 _AppContext* pAppContext = null;
617 pAppContextEnum->GetValue(pAppContext);
619 if ( pAppContext && _AppManagerImpl::GetInstance()->IsRunning(pAppContext->GetAppId()) == false )
621 pAppContext->RequestUpdate(L"", L"");
625 SysLog(NID_SHELL, "Exit.");
630 AppWidgetManagerService::RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument)
632 SysSecureLog(NID_SHELL, "%ls, %ls", instanceId.GetPointer(), argument.GetPointer() );
634 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
635 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
637 result r = pAppContext->RequestUpdateInstance(instanceId, argument);
638 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "Failed to execute RequestUpdateInstance.");
644 AppWidgetManagerService::AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
646 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
647 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
649 pAppContext->AcquireRemoteBuffer(instanceId, width, height, bufferId);
650 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBuffer for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
656 AppWidgetManagerService::AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
658 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
659 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
661 pAppContext->AcquireRemoteBufferForPD(instanceId, width, height, bufferId);
662 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBufferForPD for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
668 AppWidgetManagerService::SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height)
670 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
671 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
673 return pAppContext->SyncRemoteBuffer(instanceId, width, height);
677 AppWidgetManagerService::SyncRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
679 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
680 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
682 return pAppContext->SyncRemoteBufferForPD(instanceId);
686 AppWidgetManagerService::ReleaseRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
692 AppWidgetManagerService::ReleaseRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
698 AppWidgetManagerService::RequestProviderCount(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int& providerCount)
700 SysLog(NID_SHELL, "ENTER");
702 _AppContext* pAppContext = null;
703 result r = __appContextList.GetValue(appId, pAppContext);
704 SysTryReturnResult(NID_SHELL, pAppContext, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
706 providerCount = pAppContext->GetProviderCount();
708 r = pAppContext->DestroyAppWidget(instanceId, false);
709 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute DestroyAppWidget.");
713 pAppContext->SendPendingEvent();
719 AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, bool isSucceeded)
721 _AppContext* pAppContext = null;
722 result r = __appContextList.GetValue(appId, pAppContext);
723 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "appId(%ls) is not found.", appId.GetPointer());
727 r = pAppContext->DestroyAppWidget(instanceId, false);
728 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute RemoveAppWidget.");
730 else // for pending event excluding touch event.
732 SysLog(NID_SHELL, "SendResult is called[true].");
735 pAppContext->SendPendingEvent();
741 AppWidgetManagerService::SendAccessStatus(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int accessStatus)
743 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
744 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
746 return pAppContext->SendAccessStatus(instanceId, accessStatus);
750 AppWidgetManagerService::OnUserEventReceivedN(RequestId reqId, IList* pArgs)
752 SysTryReturnVoidResult(NID_SHELL, pArgs != null, E_INVALID_STATE, "pArgs is null!.");
754 SysLog(NID_SHELL, "Enter.");
758 case LOCAL_EVENT_REQUEST_UPDATE:
760 _AppContext* pAppContext = dynamic_cast<_AppContext*>( pArgs->GetAt(0) );
761 SysTryReturnVoidResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "");
763 pAppContext->HandleUserEvent(pArgs);
771 SysAssertf(false, "Never get here!");
775 SysLog(NID_SHELL, "Exit.");
780 _AppWidgetHelper::ExtractAppId(const String& providerId)
782 int indexOfSecondDot = 0;
783 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
784 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
787 providerId.SubString(0, indexOfSecondDot, appId);
792 _AppWidgetHelper::ExtractProviderName(const String& providerId)
794 int indexOfSecondDot = 0;
795 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
796 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
799 providerId.SubString(indexOfSecondDot + 1, providerName);
803 }}} // Tizen::Shell::App