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;
56 enum instance_destroy_type
58 INSTANCE_DESTROY_DEFAULT,
59 INSTANCE_DESTROY_PKGMGR,
60 INSTANCE_DESTROY_TERMINATE,
61 INSTANCE_DESTROY_FAULT,
62 INSTANCE_DESTROY_UNKNOWN,
65 static const char APPNAME_OSP_APPWIDGET_SERVICE[] = "osp-appwidget-service";
66 static const int TIMER_DURATION_PING = 120000;
67 //extern const int UPDATE_PERIOD_MSEC_MIN;
71 AppWidgetManagerService* AppWidgetManagerService::__pTheInstance = null;
73 AppWidgetManagerService::AppWidgetManagerService(void)
78 AppWidgetManagerService::~AppWidgetManagerService(void)
80 SysLog(NID_SHELL, "Enter");
84 DeinitializeCoreDaemonEventReceiver();
86 IMapEnumeratorT<String, _AppContext*>* pMapEnum = __appContextList.GetMapEnumeratorN();
89 while (pMapEnum->MoveNext() == E_SUCCESS)
91 _AppContext* pAppContext = null;
92 pMapEnum->GetValue(pAppContext);
99 SysLog(NID_SHELL, "Exit");
103 AppWidgetManagerService::InitSingleton(void)
105 unique_ptr<AppWidgetManagerService> pInstance(new (nothrow) AppWidgetManagerService());
106 SysTryReturnVoidResult(NID_SHELL, pInstance, E_OUT_OF_MEMORY, "The memory is insufficient.");
108 __pTheInstance = pInstance.release();
109 std::atexit(DestroySingleton);
113 AppWidgetManagerService::DestroySingleton(void)
115 delete __pTheInstance;
118 AppWidgetManagerService*
119 AppWidgetManagerService::GetInstance(void)
121 if (__pTheInstance == null)
123 __pTheInstance = CreateInstance(APPNAME_OSP_APPWIDGET_SERVICE);
125 return __pTheInstance;
128 AppWidgetManagerService*
129 AppWidgetManagerService::CreateInstance(const char* pCoreDaemonId)
133 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
135 if (__pTheInstance == null)
137 pthread_once(&onceBlock, InitSingleton);
138 result r = GetLastResult();
141 onceBlock = PTHREAD_ONCE_INIT;
144 r = __pTheInstance->Construct(pCoreDaemonId);
145 SysAssertf(!IsFailed(r), "Failed to construct AppWidgetManagerService");
146 SysLog(NID_SHELL, "AppWidgetManagerService is created.");
148 return __pTheInstance;
152 AppWidgetManagerService::Construct(const char* pCoreDaemonId)
154 result r = __appContextList.Construct();
155 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct.");
157 _AppWidgetManagerStub::StartIpcServer();
159 SettingInfo::AddSettingEventListener(*this);
161 return InitializeCoreDaemonEventReceiver(pCoreDaemonId);
165 AppWidgetManagerService::OnAppWidgetServiceConnected(struct event_arg *arg, void* data)
168 ret = provider_send_hello();
171 SysLog(NID_SHELL, "Success to be connected with master daemon");
172 AppWidgetManagerService::GetInstance()->StartPingTimer();
177 SysLog(NID_SHELL, "Failed to invoke provider_send_hello()");
183 AppWidgetManagerService::OnAppWidgetServiceCDisconnected(struct event_arg *arg, void* data)
185 SysLog(NID_SHELL, "Disconnected with master daemon");
190 AppWidgetManagerService::StartPingTimer(void)
192 result r = E_SUCCESS;
194 r = __pingTimer.Construct(*this);
195 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
197 r = __pingTimer.StartAsRepeatable(TIMER_DURATION_PING);
198 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
202 AppWidgetManagerService::OnTimerExpired(Timer& timer)
204 provider_send_ping();
208 AppWidgetManagerService::FindAppContext(const Tizen::App::AppId& appId) const
210 _AppContext* pAppContext = null;
211 result r = __appContextList.GetValue(appId, pAppContext);
212 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]");
218 AppWidgetManagerService::RemoveAppContext(const Tizen::App::AppId& appId)
220 return __appContextList.Remove(appId);
224 AppWidgetManagerService::FindAppWidget(const AppId& appId, const String& instanceId) const
226 _AppContext* pAppContext = null;
227 result r = __appContextList.GetValue(appId, pAppContext);
228 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
230 return pAppContext->FindAppWidget(instanceId);
234 AppWidgetManagerService::OnIpcClientConnected(const _IpcServer& server, int clientId)
236 String appId = server.GetClientApplicationId();
237 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
239 _AppContext* pAppContext = null;
240 __appContextList.GetValue(appId, pAppContext);
243 pAppContext->OnIpcConnected(clientId);
248 AppWidgetManagerService::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
250 String appId = server.GetClientApplicationId();
251 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
253 _AppContext* pAppContext = null;
254 __appContextList.GetValue(appId, pAppContext);
257 pAppContext->OnIpcDisconnected();
262 AppWidgetManagerService::OnSettingChanged(Tizen::Base::String& key)
264 // const static wchar_t KEY_SETTING_FONT_SIZE[] = L"http://tizen.org/setting/font.size";
265 const static wchar_t KEY_SETTING_FONT_TYPE[] = L"http://tizen.org/setting/font.type";
266 const static wchar_t KEY_SETTING_LANGUAGE[] = L"http://tizen.org/setting/locale.language";
267 const static wchar_t KEY_SETTING_COUNTRY[] = L"http://tizen.org/setting/locale.country";
269 if( key == KEY_SETTING_FONT_TYPE
270 // || key == KEY_SETTING_FONT_SIZE
271 || key == KEY_SETTING_LANGUAGE
272 || key == KEY_SETTING_COUNTRY )
274 SysLog(NID_SHELL, "'%ls' is changed.", key.GetPointer() );
275 RequestUpdateAllSuspened();
280 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)
284 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, appId, providerName);
286 _AppContext* pAppContext = null;
287 bool containsKey = false;
288 __appContextList.ContainsKey(appId, containsKey);
289 if( containsKey == false)
291 pAppContext = new(std::nothrow) _AppContext(appId);
292 SysTryReturnResult(NID_SHELL, pAppContext, E_OUT_OF_MEMORY, "");
293 __appContextList.Add(appId, pAppContext);
297 __appContextList.GetValue(appId, pAppContext);
300 return pAppContext->AddAppWidget(userInfo, providerId, instanceId, width, height, period, priority);
303 ///////////////////////////////////////////////////////
304 // CoreDaemonEventReceiver implementation
305 ///////////////////////////////////////////////////////
307 AppWidgetManagerService::OnAppWidgetCreate(struct event_arg *arg, int *width, int *height, double *priority, void* data)
309 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_NEW, "The status of data-provider-master is invalid.");
310 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);
312 const int MAX_LENGTH = 0xFFFF;// FUi_Control.h
313 *width = arg->info.lb_create.width;
314 *height= arg->info.lb_create.height;
315 *priority = 1.0f;// Fixed as default
316 SysAssertf(*width >= 0 && *height >= 0 && *width <= MAX_LENGTH && *height <= MAX_LENGTH, "w:%d, h:%d", *width, *height);
318 result r = AppWidgetManagerService::GetInstance()->AddAppWidget(arg->info.lb_create.content, arg->pkgname, arg->id, *width, *height, arg->info.lb_create.period*1000, *priority);
319 SysTryReturn(NID_SHELL, !IsFailed(r), -1, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
325 AppWidgetManagerService::OnAppWidgetUpdate(struct event_arg *arg, void* data)
327 SysAssertf(arg != null && arg->type == event_arg::EVENT_UPDATE_CONTENT, "The status of data-provider-master is invalid.");
329 bool isInstanceIdSpecified = (arg->id == null || strlen(arg->id) < 1) ? false : true;
330 if (isInstanceIdSpecified == false)
334 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(arg->pkgname, appId, providerName);
336 AppWidgetManagerService::GetInstance()->RequestUpdate(appId, providerName, L"");
340 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
341 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
343 result r = pAppContext->UpdateAppWidget(arg->id);
344 SysTryReturn(NID_SHELL, !IsFailed(r), -1, E_OBJ_NOT_FOUND, "Failed to update _AppContext.");
351 AppWidgetManagerService::OnAppWidgetDestroy(struct event_arg *arg, void* data)
353 SysAssertf(arg != null && arg->type == event_arg::EVENT_DELETE, "The status of data-provider-master is invalid.");
354 SysLog(NID_SHELL, "lb_destroy.type (%d)", arg->info.lb_destroy.type);
356 if (arg->info.lb_destroy.type == INSTANCE_DESTROY_PKGMGR)
358 SysLog(NID_SHELL, "INSTANCE_DESTROY_PKGMGR type, ignored.");
362 String appId = _AppWidgetHelper::ExtractAppId(arg->pkgname);
363 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
364 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
366 pAppContext->DestroyAppWidget(arg->id);
368 if (pAppContext->GetProviderCount() == 0)
370 SysLog(NID_SHELL, "The provider count for (%ls) is 0.", appId.GetPointer());
371 AppWidgetManagerService::GetInstance()->RemoveAppContext(appId);
379 AppWidgetManagerService::OnAppWidgetPopupCreate(struct event_arg *arg, void* data)
381 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_CREATE, "The status of data-provider-master is invalid.");
383 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);
385 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
386 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
388 pAppContext->CreateAppWidgetPopup(arg->id, arg->info.pd_create.x, arg->info.pd_create.y, arg->info.pd_create.w, arg->info.pd_create.h);
394 AppWidgetManagerService::OnAppWidgetPopupDestroy(struct event_arg *arg, void* data)
396 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_DESTROY, "The status of data-provider-master is invalid.");
398 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
400 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
401 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
403 pAppContext->DestroyAppWidgetPopup(arg->id);
409 AppWidgetManagerService::OnAppWidgetBackground(struct event_arg *arg, void* data)
411 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_PAUSE, "The status of data-provider-master is invalid.");
413 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
415 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
416 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
418 pAppContext->OnAppWidgetBackground(arg->id);
424 AppWidgetManagerService::OnAppWidgetBackgroundAll(struct event_arg *arg, void* data)
426 SysAssertf(arg != null && arg->type == event_arg::EVENT_PAUSE, "The status of data-provider-master is invalid.");
428 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN());
429 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
431 while (pAppContextEnum->MoveNext() == E_SUCCESS)
433 _AppContext* pAppContext = null;
434 pAppContextEnum->GetValue(pAppContext);
438 pAppContext->OnAppWidgetBackgroundAll();
446 AppWidgetManagerService::OnAppWidgetForeground(struct event_arg *arg, void* data)
448 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_RESUME, "The status of data-provider-master is invalid.");
450 SysTryReturn(NID_SHELL, arg || arg->id || arg->pkgname, 0, E_SUCCESS, "arg is null!");
451 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
453 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
454 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
456 pAppContext->OnAppWidgetForeground(arg->id);
462 AppWidgetManagerService::OnAppWidgetForegroundAll(struct event_arg *arg, void* data)
464 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESUME, "The status of data-provider-master is invalid.");
466 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN());
467 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
469 while (pAppContextEnum->MoveNext() == E_SUCCESS)
471 _AppContext* pAppContext = null;
472 pAppContextEnum->GetValue(pAppContext);
476 pAppContext->OnAppWidgetForegroundAll();
484 AppWidgetManagerService::OnAppWidgetClick(struct event_arg *arg, void* data)
486 SysAssertf(arg != null && arg->type == event_arg::EVENT_CLICKED, "The status of data-provider-master is invalid.");
488 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);
494 AppWidgetManagerService::OnAppWidgetResize(struct event_arg *arg, void* data)
496 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESIZE, "The status of data-provider-master is invalid.");
498 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);
500 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
501 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
503 pAppContext->ResizeAppWidget(arg->id, arg->info.resize.w, arg->info.resize.h);
509 AppWidgetManagerService::OnAppWidgetPeriodChanged(struct event_arg *arg, void* data)
511 SysAssertf(arg != null && arg->type == event_arg::EVENT_SET_PERIOD, "The status of data-provider-master is invalid.");
513 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), width(%d), height(%d), priority(%d)", arg->pkgname, arg->id);
519 AppWidgetManagerService::OnAppWidgetRecreate(struct event_arg *arg, void* data)
521 const int MAX_LENGTH = 0xFF;// FUi_Control.h
522 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_RENEW, "The status of data-provider-master is invalid.");
523 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);
525 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);
527 AppWidgetManagerService* pAppWidgetManagerService = AppWidgetManagerService::GetInstance();
528 SysTryReturn(NID_SHELL, pAppWidgetManagerService != null, -EBUSY, E_SYSTEM, "Failed to get the instance for AppWidgetManagerService.");
530 const double default_priority = 1.0f;
531 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);
532 SysTryReturn(NID_SHELL, !IsFailed(r), -EBUSY, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
538 AppWidgetManagerService::InitializeCoreDaemonEventReceiver(const char *pCoreDaemonId)
540 SysTryReturnResult(NID_SHELL, pCoreDaemonId != null, E_INVALID_ARG, "pCoreDaemonId should not be null!");
542 struct event_handler cbs;
543 memset(&cbs, 0, sizeof(event_handler));
545 cbs.connected = OnAppWidgetServiceConnected,
546 cbs.disconnected = OnAppWidgetServiceCDisconnected,
547 cbs.pause = OnAppWidgetBackgroundAll,
548 cbs.resume = OnAppWidgetForegroundAll,
549 cbs.lb_pause = OnAppWidgetBackground,
550 cbs.lb_resume = OnAppWidgetForeground,
551 cbs.lb_create = OnAppWidgetCreate,
552 cbs.lb_destroy = OnAppWidgetDestroy,
553 cbs.update_content = OnAppWidgetUpdate,
554 cbs.pd_create = OnAppWidgetPopupCreate,
555 cbs.pd_destroy = OnAppWidgetPopupDestroy,
556 cbs.clicked = OnAppWidgetClick,
557 cbs.resize = OnAppWidgetResize,
558 cbs.set_period = OnAppWidgetPeriodChanged;
559 cbs.lb_recreate = OnAppWidgetRecreate;/* Recover from the fault of slave */
560 //cbs.content_event = OnAppWidgetContentEvent,
562 int ret = provider_init(null, pCoreDaemonId, &cbs, this);
563 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "provider_init failed.");
565 SysLog(NID_SHELL, "provider_init is invoked with (%s)", pCoreDaemonId);
570 AppWidgetManagerService::DeinitializeCoreDaemonEventReceiver(void)
576 ///////////////////////////////////////////////////////
577 // stub implementation
578 ///////////////////////////////////////////////////////
580 AppWidgetManagerService::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const
582 _AppContext* pAppContext = null;
583 result r = __appContextList.GetValue(appId, pAppContext);
584 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
586 return pAppContext->RequestUpdate(providerName, argument);
590 AppWidgetManagerService::RequestUpdateAllSuspened(void) const
592 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(__appContextList.GetMapEnumeratorN());
593 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
595 while (pAppContextEnum->MoveNext() == E_SUCCESS)
597 _AppContext* pAppContext = null;
598 pAppContextEnum->GetValue(pAppContext);
600 if ( pAppContext && _AppManagerImpl::GetInstance()->IsRunning(pAppContext->GetAppId()) == false )
602 pAppContext->RequestUpdate(L"", L"");
606 SysLog(NID_SHELL, "Exit.");
611 AppWidgetManagerService::RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument)
613 SysSecureLog(NID_SHELL, "%ls, %ls", instanceId.GetPointer(), argument.GetPointer() );
615 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
616 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
618 result r = pAppContext->RequestUpdateInstance(instanceId, argument);
619 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "Failed to execute RequestUpdateInstance.");
625 AppWidgetManagerService::AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
627 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
628 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
630 pAppContext->AcquireRemoteBuffer(instanceId, width, height, bufferId);
631 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBuffer for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
637 AppWidgetManagerService::AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
639 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
640 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
642 pAppContext->AcquireRemoteBufferForPD(instanceId, width, height, bufferId);
643 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBufferForPD for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
649 AppWidgetManagerService::SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height)
651 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
652 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
654 return pAppContext->SyncRemoteBuffer(instanceId, width, height);
658 AppWidgetManagerService::SyncRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
660 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
661 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
663 return pAppContext->SyncRemoteBufferForPD(instanceId);
667 AppWidgetManagerService::ReleaseRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
673 AppWidgetManagerService::ReleaseRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
679 AppWidgetManagerService::RequestProviderCount(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int& providerCount)
681 SysLog(NID_SHELL, "ENTER");
683 _AppContext* pAppContext = null;
684 result r = __appContextList.GetValue(appId, pAppContext);
685 SysTryReturnResult(NID_SHELL, pAppContext, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
687 providerCount = pAppContext->GetProviderCount();
689 r = pAppContext->DestroyAppWidget(instanceId, false);
690 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute DestroyAppWidget.");
694 pAppContext->SendPendingEvent();
700 AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, bool isSucceeded)
702 _AppContext* pAppContext = null;
703 result r = __appContextList.GetValue(appId, pAppContext);
704 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "appId(%ls) is not found.", appId.GetPointer());
708 r = pAppContext->DestroyAppWidget(instanceId, false);
709 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute RemoveAppWidget.");
711 else // for pending event excluding touch event.
713 SysLog(NID_SHELL, "SendResult is called[true].");
716 pAppContext->SendPendingEvent();
722 AppWidgetManagerService::SendAccessStatus(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int accessStatus)
724 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
725 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
727 return pAppContext->SendAccessStatus(instanceId, accessStatus);
731 AppWidgetManagerService::OnUserEventReceivedN(RequestId reqId, IList* pArgs)
733 SysTryReturnVoidResult(NID_SHELL, pArgs != null, E_INVALID_STATE, "pArgs is null!.");
735 SysLog(NID_SHELL, "Enter.");
739 case LOCAL_EVENT_REQUEST_UPDATE:
741 _AppContext* pAppContext = dynamic_cast<_AppContext*>( pArgs->GetAt(0) );
742 SysTryReturnVoidResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "");
744 pAppContext->HandleUserEvent(pArgs);
752 SysAssertf(false, "Never get here!");
756 SysLog(NID_SHELL, "Exit.");
761 _AppWidgetHelper::ExtractAppId(const String& providerId)
763 int indexOfSecondDot = 0;
764 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
765 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
768 providerId.SubString(0, indexOfSecondDot, appId);
773 _AppWidgetHelper::ExtractProviderName(const String& providerId)
775 int indexOfSecondDot = 0;
776 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
777 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
780 providerId.SubString(indexOfSecondDot + 1, providerName);
784 }}} // Tizen::Shell::App