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 <FSys_SettingInfoImpl.h>
34 #include <FShell_AppWidgetManagerImpl.h>
35 #include <FIo_IpcServer.h>
36 #include <FBase_StringConverter.h>
38 #include "FShell_AppContext.h"
39 #include "FShell_AppWidgetPopupContext.h"
40 #include "FShell_AppWidgetManagerService.h"
41 #include "FShell_TemplateUtil.h"
43 namespace Tizen { namespace Shell { namespace App {
46 using namespace Tizen::App;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Runtime;
50 using namespace Tizen::Io;
51 using namespace Tizen::System;
52 using namespace Tizen::Shell::App;
56 static const char APPNAME_OSP_APPWIDGET_SERVICE[] = "osp-appwidget-service";
57 static const int TIMER_DURATION_PING = 120000;
58 //extern const int UPDATE_PERIOD_MSEC_MIN;
61 AppWidgetManagerService* AppWidgetManagerService::__pTheInstance = null;
63 AppWidgetManagerService::AppWidgetManagerService(void)
68 AppWidgetManagerService::~AppWidgetManagerService(void)
70 SysLog(NID_SHELL, "Enter");
74 DeinitializeCoreDaemonEventReceiver();
75 _AppManagerImpl::GetInstance()->RemoveAppEventListener(*this);
76 _SettingInfoImpl::RemoveSettingEventListener(*this);
78 IMapEnumeratorT<String, _AppContext*>* pMapEnum = __appContextList.GetMapEnumeratorN();
81 while (pMapEnum->MoveNext() == E_SUCCESS)
83 _AppContext* pAppContext = null;
84 pMapEnum->GetValue(pAppContext);
91 SysLog(NID_SHELL, "Exit");
95 AppWidgetManagerService::InitSingleton(void)
97 unique_ptr<AppWidgetManagerService> pInstance(new (nothrow) AppWidgetManagerService());
98 SysTryReturnVoidResult(NID_SHELL, pInstance, E_OUT_OF_MEMORY, "The memory is insufficient.");
100 __pTheInstance = pInstance.release();
101 std::atexit(DestroySingleton);
105 AppWidgetManagerService::DestroySingleton(void)
107 delete __pTheInstance;
110 AppWidgetManagerService*
111 AppWidgetManagerService::GetInstance(void)
113 if (__pTheInstance == null)
115 __pTheInstance = CreateInstance(APPNAME_OSP_APPWIDGET_SERVICE);
117 return __pTheInstance;
120 AppWidgetManagerService*
121 AppWidgetManagerService::CreateInstance(const char* pCoreDaemonId)
125 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
127 if (__pTheInstance == null)
129 pthread_once(&onceBlock, InitSingleton);
130 result r = GetLastResult();
133 onceBlock = PTHREAD_ONCE_INIT;
136 r = __pTheInstance->Construct(pCoreDaemonId);
137 SysAssertf(!IsFailed(r), "Failed to construct AppWidgetManagerService");
138 SysLog(NID_SHELL, "AppWidgetManagerService is created.");
140 return __pTheInstance;
144 AppWidgetManagerService::Construct(const char* pCoreDaemonId)
146 result r = __appContextList.Construct();
147 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct.");
149 _AppWidgetManagerStub::StartIpcServer();
150 InitializeCoreDaemonEventReceiver(pCoreDaemonId);
152 SetSettingEventListener(*this);
153 _AppManagerImpl::GetInstance()->AddAppEventListener(*this);
159 AppWidgetManagerService::SetSettingEventListener(Tizen::System::ISettingEventListener& listener)
161 const int MAX_TRY_COUNT = 10;
162 const int TRY_SLEEP_TIME = 250;
167 result r = _SettingInfoImpl::AddSettingEventListener(listener);
170 SysLog(NID_APP, "Succeeded to invoke AddSettingEventListener");
174 if (count >= MAX_TRY_COUNT)
176 SysLog(NID_APP, "Failed to invoke AddSettingEventListener");
181 Thread::Sleep(TRY_SLEEP_TIME);
182 SysLog(NID_APP, "%d th retry...", count);
188 AppWidgetManagerService::OnAppWidgetServiceConnected(struct event_arg *arg, void* data)
191 ret = provider_send_hello();
194 SysLog(NID_SHELL, "Success to be connected with master daemon");
195 AppWidgetManagerService::GetInstance()->StartPingTimer();
200 SysLog(NID_SHELL, "Failed to invoke provider_send_hello()");
206 AppWidgetManagerService::OnAppWidgetServiceDisconnected(struct event_arg *arg, void* data)
208 SysLog(NID_SHELL, "Disconnected with master daemon");
213 AppWidgetManagerService::StartPingTimer(void)
215 result r = E_SUCCESS;
217 r = __pingTimer.Construct(*this);
218 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
220 r = __pingTimer.StartAsRepeatable(TIMER_DURATION_PING);
221 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
225 AppWidgetManagerService::OnTimerExpired(Timer& timer)
227 provider_send_ping();
231 AppWidgetManagerService::FindAppContext(const Tizen::App::AppId& appId) const
233 _AppContext* pAppContext = null;
234 result r = __appContextList.GetValue(appId, pAppContext);
235 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]");
241 AppWidgetManagerService::RemoveAppContext(const Tizen::App::AppId& appId)
243 return __appContextList.Remove(appId);
247 AppWidgetManagerService::FindAppWidget(const AppId& appId, const String& instanceId) const
249 _AppContext* pAppContext = null;
250 result r = __appContextList.GetValue(appId, pAppContext);
251 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
253 return pAppContext->FindAppWidget(instanceId);
257 AppWidgetManagerService::OnApplicationLaunched(const AppId& appId, int pid)
263 AppWidgetManagerService::OnApplicationTerminated(const AppId& appId, int pid)
265 _AppContext* pAppContext = null;
266 __appContextList.GetValue(appId, pAppContext);
269 pAppContext->OnApplicationTerminated();
274 AppWidgetManagerService::OnIpcClientConnected(const AppId& appId, int clientId)
276 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
278 _AppContext* pAppContext = null;
279 __appContextList.GetValue(appId, pAppContext);
282 pAppContext->OnIpcConnected(clientId);
287 AppWidgetManagerService::OnIpcClientDisconnected(const AppId& appId, int clientId)
289 SysLog(NID_SHELL, "appId(%ls)", appId.GetPointer());
291 _AppContext* pAppContext = null;
292 __appContextList.GetValue(appId, pAppContext);
295 pAppContext->OnIpcDisconnected();
300 AppWidgetManagerService::OnSettingChanged(Tizen::Base::String& key)
302 // const static wchar_t KEY_SETTING_FONT_SIZE[] = L"http://tizen.org/setting/font.size";
303 const static wchar_t KEY_SETTING_FONT_TYPE[] = L"http://tizen.org/setting/font.type";
304 const static wchar_t KEY_SETTING_LANGUAGE[] = L"http://tizen.org/setting/locale.language";
305 const static wchar_t KEY_SETTING_COUNTRY[] = L"http://tizen.org/setting/locale.country";
307 if( key == KEY_SETTING_FONT_TYPE
308 // || key == KEY_SETTING_FONT_SIZE
309 || key == KEY_SETTING_LANGUAGE
310 || key == KEY_SETTING_COUNTRY )
312 SysLog(NID_SHELL, "'%ls' is changed.", key.GetPointer() );
313 RequestUpdateAllInactiveted();
318 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)
322 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, appId, providerName);
324 _AppContext* pAppContext = null;
325 bool containsKey = false;
326 __appContextList.ContainsKey(appId, containsKey);
327 if( containsKey == false)
329 pAppContext = new(std::nothrow) _AppContext(appId);
330 SysTryReturnResult(NID_SHELL, pAppContext, E_OUT_OF_MEMORY, "");
331 __appContextList.Add(appId, pAppContext);
335 __appContextList.GetValue(appId, pAppContext);
338 return pAppContext->AddAppWidget(userInfo, providerId, instanceId, width, height, period, priority);
341 ///////////////////////////////////////////////////////
342 // CoreDaemonEventReceiver implementation
343 ///////////////////////////////////////////////////////
345 AppWidgetManagerService::OnAppWidgetCreate(struct event_arg *arg, int *width, int *height, double *priority, void* data)
347 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_NEW, "The status of data-provider-master is invalid.");
348 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);
350 const int MAX_LENGTH = 0xFFFF;// FUi_Control.h
351 *width = arg->info.lb_create.width;
352 *height= arg->info.lb_create.height;
353 *priority = 1.0f;// Fixed as default
354 SysAssertf(*width >= 0 && *height >= 0 && *width <= MAX_LENGTH && *height <= MAX_LENGTH, "w:%d, h:%d", *width, *height);
356 result r = AppWidgetManagerService::GetInstance()->AddAppWidget(arg->info.lb_create.content, arg->pkgname, arg->id, *width, *height, arg->info.lb_create.period*1000, *priority);
357 SysTryReturn(NID_SHELL, !IsFailed(r), -1, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
363 AppWidgetManagerService::OnAppWidgetUpdate(struct event_arg *arg, void* data)
365 SysAssertf(arg != null && arg->type == event_arg::EVENT_UPDATE_CONTENT, "The status of data-provider-master is invalid.");
367 bool isInstanceIdSpecified = (arg->id == null || strlen(arg->id) < 1) ? false : true;
368 if (isInstanceIdSpecified == false)
372 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(arg->pkgname, appId, providerName);
374 AppWidgetManagerService::GetInstance()->RequestUpdate(appId, providerName, L"");
378 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
379 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
381 result r = pAppContext->UpdateAppWidget(arg->id);
382 SysTryReturn(NID_SHELL, !IsFailed(r), -1, E_OBJ_NOT_FOUND, "Failed to update _AppContext.");
389 AppWidgetManagerService::OnAppWidgetDestroy(struct event_arg *arg, void* data)
391 SysAssertf(arg != null && arg->type == event_arg::EVENT_DELETE, "The status of data-provider-master is invalid.");
392 SysLog(NID_SHELL, "lb_destroy.type (%d)", arg->info.lb_destroy.type);
394 if (arg->info.lb_destroy.type == event_arg::event_data::lb_destroy::INSTANCE_DESTROY_PKGMGR)
396 SysLog(NID_SHELL, "INSTANCE_DESTROY_PKGMGR type, ignored.");
400 String appId = _AppWidgetHelper::ExtractAppId(arg->pkgname);
401 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
402 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
404 pAppContext->DestroyAppWidget(arg->id);
406 if (pAppContext->GetProviderCount() == 0)
408 SysLog(NID_SHELL, "The provider count for (%ls) is 0.", appId.GetPointer());
409 AppWidgetManagerService::GetInstance()->RemoveAppContext(appId);
417 AppWidgetManagerService::OnAppWidgetPopupCreate(struct event_arg *arg, void* data)
419 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_CREATE, "The status of data-provider-master is invalid.");
421 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);
423 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
424 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
426 pAppContext->CreateAppWidgetPopup(arg->id, arg->info.pd_create.x, arg->info.pd_create.y, arg->info.pd_create.w, arg->info.pd_create.h);
432 AppWidgetManagerService::OnAppWidgetPopupDestroy(struct event_arg *arg, void* data)
434 SysAssertf(arg != null && arg->type == event_arg::EVENT_PD_DESTROY, "The status of data-provider-master is invalid.");
436 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
438 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
439 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
441 pAppContext->DestroyAppWidgetPopup(arg->id);
447 AppWidgetManagerService::OnAppWidgetBackground(struct event_arg *arg, void* data)
449 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_PAUSE, "The status of data-provider-master is invalid.");
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->OnAppWidgetBackground(arg->id);
462 AppWidgetManagerService::OnAppWidgetBackgroundAll(struct event_arg *arg, void* data)
464 SysAssertf(arg != null && arg->type == event_arg::EVENT_PAUSE, "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->OnAppWidgetBackgroundAll();
484 AppWidgetManagerService::OnAppWidgetForeground(struct event_arg *arg, void* data)
486 SysAssertf(arg != null && arg->type == event_arg::EVENT_LB_RESUME, "The status of data-provider-master is invalid.");
488 SysTryReturn(NID_SHELL, arg || arg->id || arg->pkgname, 0, E_SUCCESS, "arg is null!");
489 SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id);
491 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
492 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
494 pAppContext->OnAppWidgetForeground(arg->id);
500 AppWidgetManagerService::OnAppWidgetForegroundAll(struct event_arg *arg, void* data)
502 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESUME, "The status of data-provider-master is invalid.");
504 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN());
505 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
507 while (pAppContextEnum->MoveNext() == E_SUCCESS)
509 _AppContext* pAppContext = null;
510 pAppContextEnum->GetValue(pAppContext);
514 pAppContext->OnAppWidgetForegroundAll();
522 AppWidgetManagerService::OnAppWidgetClick(struct event_arg *arg, void* data)
524 SysAssertf(arg != null && arg->type == event_arg::EVENT_CLICKED, "The status of data-provider-master is invalid.");
526 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);
532 AppWidgetManagerService::OnAppWidgetResize(struct event_arg *arg, void* data)
534 SysAssertf(arg != null && arg->type == event_arg::EVENT_RESIZE, "The status of data-provider-master is invalid.");
536 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);
538 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(_AppWidgetHelper::ExtractAppId(arg->pkgname));
539 SysTryReturn(NID_SHELL, pAppContext != null, -1, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Failed to find _AppContext.");
541 pAppContext->ResizeAppWidget(arg->id, arg->info.resize.w, arg->info.resize.h);
547 AppWidgetManagerService::OnAppWidgetPeriodChanged(struct event_arg *arg, void* data)
549 SysAssertf(arg != null && arg->type == event_arg::EVENT_SET_PERIOD, "The status of data-provider-master is invalid.");
551 SysSecureLog(NID_SHELL, "providerId(%s), id(%s), width(%d), height(%d), priority(%d)", arg->pkgname, arg->id);
557 AppWidgetManagerService::OnAppWidgetRecreate(struct event_arg *arg, void* data)
559 const int MAX_LENGTH = 0xFFFF;// FUi_Control.h
560 SysAssertf(arg != null && arg->pkgname != null && arg->id != null && arg->type == event_arg::EVENT_RENEW, "The status of data-provider-master is invalid.");
561 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);
563 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);
565 AppWidgetManagerService* pAppWidgetManagerService = AppWidgetManagerService::GetInstance();
566 SysTryReturn(NID_SHELL, pAppWidgetManagerService != null, -EBUSY, E_SYSTEM, "Failed to get the instance for AppWidgetManagerService.");
568 const double default_priority = 1.0f;
569 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);
570 SysTryReturn(NID_SHELL, !IsFailed(r), -EBUSY, r, "[%s] Failed to execute AddAppWidget.", GetErrorMessage(r));
576 AppWidgetManagerService::InitializeCoreDaemonEventReceiver(const char *pCoreDaemonId)
578 SysTryReturnResult(NID_SHELL, pCoreDaemonId != null, E_INVALID_ARG, "pCoreDaemonId should not be null!");
580 struct event_handler cbs;
581 memset(&cbs, 0, sizeof(event_handler));
583 cbs.connected = OnAppWidgetServiceConnected,
584 cbs.disconnected = OnAppWidgetServiceDisconnected,
585 cbs.pause = OnAppWidgetBackgroundAll,
586 cbs.resume = OnAppWidgetForegroundAll,
587 cbs.lb_pause = OnAppWidgetBackground,
588 cbs.lb_resume = OnAppWidgetForeground,
589 cbs.lb_create = OnAppWidgetCreate,
590 cbs.lb_destroy = OnAppWidgetDestroy,
591 cbs.update_content = OnAppWidgetUpdate,
592 cbs.pd_create = OnAppWidgetPopupCreate,
593 cbs.pd_destroy = OnAppWidgetPopupDestroy,
594 cbs.clicked = OnAppWidgetClick,
595 cbs.resize = OnAppWidgetResize,
596 cbs.set_period = OnAppWidgetPeriodChanged;
597 cbs.lb_recreate = OnAppWidgetRecreate;/* Recover from the fault of slave */
598 //cbs.content_event = OnAppWidgetContentEvent,
600 int ret = provider_init(null, pCoreDaemonId, &cbs, this);
601 SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "provider_init failed.");
603 SysLog(NID_SHELL, "provider_init is invoked with (%s)", pCoreDaemonId);
608 AppWidgetManagerService::DeinitializeCoreDaemonEventReceiver(void)
614 ///////////////////////////////////////////////////////
615 // stub implementation
616 ///////////////////////////////////////////////////////
618 AppWidgetManagerService::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const
620 _AppContext* pAppContext = null;
621 result r = __appContextList.GetValue(appId, pAppContext);
622 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() );
624 return pAppContext->RequestUpdate(providerName, argument);
628 AppWidgetManagerService::RequestUpdateAllInactiveted(void) const
630 SysLog(NID_SHELL, "Enter.");
631 unique_ptr< IMapEnumeratorT<String, _AppContext*> > pAppContextEnum(__appContextList.GetMapEnumeratorN());
632 SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()");
634 while (pAppContextEnum->MoveNext() == E_SUCCESS)
636 _AppContext* pAppContext = null;
637 pAppContextEnum->GetValue(pAppContext);
641 pAppContext->RequestUpdateAllInactiveted();
645 SysLog(NID_SHELL, "Exit.");
650 AppWidgetManagerService::RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument)
652 SysSecureLog(NID_SHELL, "%ls, %ls", instanceId.GetPointer(), argument.GetPointer() );
654 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
655 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
657 result r = pAppContext->RequestUpdateInstance(instanceId, argument);
658 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "Failed to execute RequestUpdateInstance.");
664 AppWidgetManagerService::AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
666 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
667 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
669 pAppContext->AcquireRemoteBuffer(instanceId, width, height, bufferId);
670 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBuffer for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
676 AppWidgetManagerService::AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId)
678 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
679 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
681 pAppContext->AcquireRemoteBufferForPD(instanceId, width, height, bufferId);
682 SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to execute AcquireRemoteBufferForPD for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
688 AppWidgetManagerService::SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height)
690 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
691 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
693 return pAppContext->SyncRemoteBuffer(instanceId, width, height);
697 AppWidgetManagerService::SyncRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
699 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
700 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
702 return pAppContext->SyncRemoteBufferForPD(instanceId);
706 AppWidgetManagerService::ReleaseRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
712 AppWidgetManagerService::ReleaseRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
718 AppWidgetManagerService::RequestProviderCount(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int& providerCount)
720 SysLog(NID_SHELL, "ENTER");
722 _AppContext* pAppContext = null;
723 result r = __appContextList.GetValue(appId, pAppContext);
724 SysTryReturnResult(NID_SHELL, pAppContext, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
726 providerCount = pAppContext->GetProviderCount();
728 r = pAppContext->DestroyAppWidget(instanceId, false);
729 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute DestroyAppWidget.");
733 pAppContext->SendPendingEvent();
739 AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, bool isSucceeded)
741 _AppContext* pAppContext = null;
742 result r = __appContextList.GetValue(appId, pAppContext);
743 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_OBJ_NOT_FOUND, "appId(%ls) is not found.", appId.GetPointer());
747 r = pAppContext->DestroyAppWidget(instanceId, false);
748 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute RemoveAppWidget.");
750 else // for pending event excluding touch event.
752 SysLog(NID_SHELL, "SendResult is called[true].");
755 pAppContext->SendPendingEvent();
761 AppWidgetManagerService::SendAccessStatus(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int accessStatus)
763 _AppContext* pAppContext = AppWidgetManagerService::GetInstance()->FindAppContext(appId);
764 SysTryReturnResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "Failed to find _AppContext.");
766 return pAppContext->SendAccessStatus(instanceId, accessStatus);
770 AppWidgetManagerService::OnUserEventReceivedN(RequestId reqId, IList* pArgs)
772 SysTryReturnVoidResult(NID_SHELL, pArgs != null, E_INVALID_STATE, "pArgs is null!.");
774 SysLog(NID_SHELL, "Enter.");
778 case LOCAL_EVENT_REQUEST_UPDATE:
780 _AppContext* pAppContext = dynamic_cast<_AppContext*>( pArgs->GetAt(0) );
781 SysTryReturnVoidResult(NID_SHELL, pAppContext != null, E_OBJ_NOT_FOUND, "");
783 pAppContext->HandleUserEvent(pArgs);
791 SysAssertf(false, "Never get here!");
795 SysLog(NID_SHELL, "Exit.");
800 _AppWidgetHelper::ExtractAppId(const String& providerId)
802 int indexOfSecondDot = 0;
803 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
804 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
807 providerId.SubString(0, indexOfSecondDot, appId);
812 _AppWidgetHelper::ExtractProviderName(const String& providerId)
814 int indexOfSecondDot = 0;
815 result r = providerId.IndexOf(".", 12, indexOfSecondDot);//"1234567890._"
816 SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() );
819 providerId.SubString(indexOfSecondDot + 1, providerName);
823 }}} // Tizen::Shell::App