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_AppWidgetContext.cpp
19 * @brief This is the implementation for the _AppWidgetContext class.
23 #include <unique_ptr.h>
26 //#include <FBaseColIList.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseInteger.h>
29 #include <FBaseDouble.h>
30 #include <FBaseColHashMap.h>
31 #include <FBaseColAllElementsDeleter.h>
32 #include <FSysSystemTime.h>
34 #include <FAppAppManager.h>
35 #include <FBaseComparerT.h>
37 #include <FBase_StringConverter.h>
38 #include "FShell_AppWidgetManagerImpl.h"
39 #include "FShell_AppWidgetManagerService.h"
40 #include "FShell_AppWidgetPopupContext.h"
41 #include "FShell_AppWidgetContext.h"
42 #include "FShell_AppWidgetContextHelper.h"
43 #include "FShell_AppWidgetRemoteBuffer.h"
44 #include "FShell_TemplateUtil.h"
46 namespace Tizen { namespace Shell { namespace App
50 using namespace Tizen::App;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::System;
55 const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId";
56 const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName";
57 const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo";
58 const wchar_t ARG_KEY_X[] = L"_X";
59 const wchar_t ARG_KEY_Y[] = L"_Y";
60 const wchar_t ARG_KEY_WIDTH[] = L"_Width";
61 const wchar_t ARG_KEY_HEIGHT[] = L"_Height";
62 const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth";
63 const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight";
64 const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument";
65 const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType";
66 const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp";
68 const wchar_t APPWIDGET_ON_ADD[] = L"http://tizen.org/appcontrol/appwidget/add";
69 const wchar_t APPWIDGET_ON_REMOVE[] = L"http://tizen.org/appcontrol/appwidget/remove";
70 const wchar_t APPWIDGET_ON_UPDATE[] = L"http://tizen.org/appcontrol/appwidget/update";
71 const wchar_t APPWIDGET_ON_RESIZE[] = L"http://tizen.org/appcontrol/appwidget/resize";
72 const wchar_t APPWIDGET_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidget/touch";
74 const int UPDATE_PERIOD_MSEC_MIN = 1800000; // 30min
76 static const wchar_t INVALID_INSTANCE[] = L"file://invalid instance id";
78 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 _AppContext::_AppContext(const AppId& appId)
83 ,__isWaitingResult(false)
85 ,__connectionState(CONNECTION_STATE_NONE)
86 ,__pPendingEventList(null)
89 __pPendingEventList = new (nothrow) ArrayListT<PendingEvent*>();
90 SysTryReturnVoidResult(NID_SHELL, __pPendingEventList, E_OUT_OF_MEMORY, "");
92 result r = __pPendingEventList->Construct();
93 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct.");
95 static __HashMapDefaultProviderT <String> strHashCodeProvider;
96 static ComparerT <String> strComparer;
97 r = __appWidgetContextList.Construct(0, 0, strHashCodeProvider, strComparer);
98 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct.");
101 _AppContext::~_AppContext(void)
103 if (__pPendingEventList)
105 for (int i = 0; i < __pPendingEventList->GetCount(); i++)
107 PendingEvent* pEvent = null;
108 __pPendingEventList->GetAt(i, pEvent);
111 __pPendingEventList->RemoveAll();
112 delete __pPendingEventList;
117 _AppContext::AddAppWidget(const Tizen::Base::String& userInfo, const Tizen::Base::String& providerId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority)
119 _AppWidgetContext* pAppWidgetContext = new (std::nothrow)_AppWidgetContext(this, userInfo, providerId, instanceId, width, height, period, priority);
120 SysTryReturn(NID_SHELL, pAppWidgetContext, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
122 __appWidgetContextList.Add(pAppWidgetContext->GetInstanceId(), pAppWidgetContext);
123 pAppWidgetContext->OnAdded();
125 SysSecureLog(NID_SHELL, "%ls, %ls, count(%d)", pAppWidgetContext->GetProviderId().GetPointer(), pAppWidgetContext->GetInstanceId().GetPointer(), __appWidgetContextList.GetCount());
126 return pAppWidgetContext;
130 _AppContext::RemoveAppWidget(const Tizen::Base::String& instanceId, bool isTriggeredByViewer)
132 _AppWidgetContext* pAppWidgetContext = FindAppWidget(instanceId);
133 SysTryReturnResult(NID_SHELL, pAppWidgetContext, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]");
135 __appWidgetContextList.Remove(instanceId);
137 result r = pAppWidgetContext->OnRemoved(isTriggeredByViewer);
138 SysTryLog(NID_SHELL, !IsFailed(r), "Failed to execute OnRemoved.");
140 delete pAppWidgetContext;
142 SysLog(NID_SHELL, "AppWidget(%ls, %ls) is removed. remain count(%d)", pAppWidgetContext->GetProviderId().GetPointer(), instanceId.GetPointer(), __appWidgetContextList.GetCount());
147 _AppContext::GetConnectionState(void) const
149 return __connectionState;
153 _AppContext::SetConnectionState(_ConnectionState state)
155 __connectionState = state;
159 _AppContext::GetAppId(void) const
165 _AppContext::GetClientId(void) const
167 return __ipcClientId;
171 _AppContext::OnIpcConnected(int clientId)
173 __ipcClientId = clientId;
174 SetConnectionState(CONNECTION_STATE_CONNECTED);
178 _AppContext::OnIpcDisconnected(void)
181 SetConnectionState(CONNECTION_STATE_DISCONNECTED);
183 unique_ptr< IMapEnumeratorT<String, _AppWidgetContext*> > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN());
184 SysTryReturnVoidResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "");
186 _AppWidgetContext* pAppWidgetContext = null;
187 while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS)
189 pAppWidgetContextEnum->GetValue(pAppWidgetContext);
190 if (pAppWidgetContext)
192 pAppWidgetContext->OnDisconnected();
198 _AppContext::SetWaitingStatus(bool status)
200 __isWaitingResult = status;
204 _AppContext::GetWaitingStatus(void) const
206 return __isWaitingResult;
210 _AppContext::SendRequestToApp(const AppId& providerAppId, const String& operation, HashMap* pArgs)
212 result r = E_SUCCESS;
214 if (GetConnectionState() == CONNECTION_STATE_NONE || GetConnectionState() == CONNECTION_STATE_DISCONNECTED)
216 SysLog(NID_SHELL, "The application is not running.");
217 result r = _AppWidgetRequestHelper::SendAppControlRequest(providerAppId, operation, pArgs);
218 SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Failed to SendRequestToApp", GetErrorMessage(r));
220 SetWaitingStatus(true);
221 SetConnectionState(CONNECTION_STATE_CONNECTING);
225 if (GetConnectionState() == CONNECTION_STATE_CONNECTING || GetWaitingStatus() == true)
227 SysLog(NID_SHELL, "The application is running but IPC is not connected yet.");
228 __pPendingEventList->Add(new (nothrow) PendingEvent(operation, pArgs));
232 SysLog(NID_SHELL, "The application is running and IPC is connected.");
233 r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), operation, pArgs);
235 pArgs->RemoveAll(true);
237 SetWaitingStatus(true);
245 _AppContext::SendPendingEvent(void)
247 SetWaitingStatus(false);
248 TryReturn(__pPendingEventList->GetCount() > 0, E_DATA_NOT_FOUND, "This context has no pending event. Please find next pending event context.");
250 PendingEvent* pEvent = null;
251 __pPendingEventList->GetAt(0, pEvent);
252 SysTryReturnResult(NID_SHELL, pEvent != null, E_SYSTEM, "__pPendingEventList has (%d) items, but failed to GetAt(0)", __pPendingEventList->GetCount());
254 __pPendingEventList->RemoveAt(0);
255 SysLog(NID_SHELL, "(%d) Remains in __pPendingEventList.", __pPendingEventList->GetCount());
257 result r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), pEvent->operation, pEvent->pArg);
259 SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "SendIpcRequest failed.");
265 _AppContext::FindAppWidget(const String& instanceId) const
267 _AppWidgetContext* pAppWidgetContext = null;
269 if (instanceId == INVALID_INSTANCE)
271 pAppWidgetContext = FindInvalidAppWidget();
275 result r = __appWidgetContextList.GetValue(instanceId, pAppWidgetContext);
276 SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "instanceId(%ls) is not found", instanceId.GetPointer() );
278 return pAppWidgetContext;
282 _AppContext::FindInvalidAppWidget(void) const
284 SysTryReturn(NID_SHELL, GetConnectionState() == CONNECTION_STATE_NONE, null, E_INVALID_STATE, "[E_INVALID_STATE] connectionState(%d)", GetConnectionState());
286 _AppWidgetContext* pAppWidgetContext = null;
287 unique_ptr< IMapEnumeratorT<String, _AppWidgetContext*> > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN());
288 SysTryReturn(NID_SHELL, pAppWidgetContextEnum, null, E_SYSTEM, "");
290 while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS)
292 pAppWidgetContextEnum->GetValue(pAppWidgetContext);
293 if (pAppWidgetContext)
295 //TODO: check whether this app context has only one instance of _AppWidgetContext
296 return pAppWidgetContext;
303 _AppContext::GetProviderCount(const String& appId) const
305 return __appWidgetContextList.GetCount();
309 _AppContext::RequestUpdate(const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const
312 bool requestToAll = providerName.IsEmpty();
314 unique_ptr< IMapEnumeratorT<String, _AppWidgetContext*> > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN());
315 SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke __appWidgetContextList.GetMapEnumeratorN()");
317 while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS)
319 _AppWidgetContext* pAppWidgetContext = null;
320 pAppWidgetContextEnum->GetValue(pAppWidgetContext);
322 if (pAppWidgetContext->GetProviderName() == providerName || requestToAll == true)
324 pAppWidgetContext->RequestUpdate(argument);
329 SysLog(NID_SHELL, "Exit.");
330 return (found) ? E_SUCCESS : E_OBJ_NOT_FOUND;
334 _AppContext::OnAppWidgetBackgroundAll(void) const
336 unique_ptr< IMapEnumeratorT<String, _AppWidgetContext*> > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN());
337 SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke GetMapEnumeratorN()");
339 while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS)
341 _AppWidgetContext* pAppWidgetContext = null;
342 pAppWidgetContextEnum->GetValue(pAppWidgetContext);
343 if (pAppWidgetContext)
345 pAppWidgetContext->OnBackground();
353 _AppContext::OnAppWidgetForegroundAll(void) const
355 unique_ptr< IMapEnumeratorT<String, _AppWidgetContext*> > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN());
356 SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke GetMapEnumeratorN()");
358 while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS)
360 _AppWidgetContext* pAppWidgetContext = null;
361 pAppWidgetContextEnum->GetValue(pAppWidgetContext);
362 if (pAppWidgetContext)
364 pAppWidgetContext->OnForeground();
373 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
374 // _AppWidgetContext class
375 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
376 _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int period, int priority)
377 :__isRemoteBufferProxyCreated(false)
378 ,__hasPendingRequest(false)
379 ,__isForeground(true)
382 ,__priority(priority)
384 ,__updateMillis( (period > UPDATE_PERIOD_MSEC_MIN) ? period : UPDATE_PERIOD_MSEC_MIN )
385 ,__lastUpdatedTime(0)
386 ,__userInfo(userInfo)
387 ,__providerId(providerId)
388 ,__instanceId(instanceId)
389 ,__pAppContext(pAppContext)
390 ,__pAppWidgetPopup(null)
391 ,__pAppWidgetRemoteBuffer(null)
392 ,__pPendingTouchEventList(null)
394 _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);//TODO: extract this line to outside
395 SysSecureLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d), period(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority, __updateMillis);
397 // for updating period
398 if (__updateMillis > 0)
400 SystemTime::GetTicks(this->__lastUpdatedTime);
402 result r = __updateTimer.Construct(*this);
403 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
405 r = __updateTimer.StartAsRepeatable(__updateMillis);
406 SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
409 __pPendingTouchEventList = new (nothrow) ArrayListT<PendingTouchEvent*>();
410 SysTryReturnVoidResult(NID_SHELL, __pPendingTouchEventList, E_OUT_OF_MEMORY, "");
411 __pPendingTouchEventList->Construct();
413 __pAppWidgetRemoteBuffer = new (nothrow) _AppWidgetRemoteBuffer(providerId, instanceId, TYPE_LB, this);
414 SysTryReturnVoidResult(NID_SHELL, __pAppWidgetRemoteBuffer, E_OUT_OF_MEMORY, "");
417 _AppWidgetContext::~_AppWidgetContext(void)
419 SysSecureLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight(), GetPriority());
421 __updateTimer.Cancel();
423 if (__pAppWidgetPopup)
425 SysLog(NID_SHELL, "Destroying dangling AppWidgetPopup instance..");
426 delete __pAppWidgetPopup;
429 if (__pPendingTouchEventList)
431 for (int i = 0; i < __pPendingTouchEventList->GetCount(); i++)
433 PendingTouchEvent* pTouchEvent = null;
434 __pPendingTouchEventList->GetAt(i, pTouchEvent);
437 __pPendingTouchEventList->RemoveAll();
438 delete __pPendingTouchEventList;
441 if (__pAppWidgetRemoteBuffer)
443 delete __pAppWidgetRemoteBuffer;
448 _AppWidgetContext::GetAppContext(void) const
450 return __pAppContext;
453 _AppWidgetPopupContext*
454 _AppWidgetContext::GetAppWidgetPopup(void) const
456 return __pAppWidgetPopup;
460 _AppWidgetContext::OnAdded(void)
462 SendAddRequest(GetWidth(), GetHeight());
466 _AppWidgetContext::OnRemoved(bool isTriggeredByViewer)
468 if (isTriggeredByViewer)
470 return SendRemoveRequest();
474 std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
475 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
477 int ret = provider_send_deleted(providerId.get(), id.get());
478 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_send_deleted.");
484 _AppWidgetContext::OnUpdate(const String& argument)
486 SysLog(NID_SHELL, "argument(%ls)", argument.GetPointer());
489 // Queueing the pointer of background context.
490 if (!this->IsForeground())
493 if (!argument.IsEmpty())
495 __pendingArgument = argument;
498 __hasPendingRequest = true;
499 SysLog(NID_SHELL, "Update is requested but the %ls is background.", (this->GetAppId()).GetPointer());
503 result r = this->SendUpdateRequest(GetWidth(), GetHeight(), argument);
504 SysTryLog(NID_SHELL, !IsFailed(r), "Failed to execute SendUpdateRequest.");
506 SystemTime::GetTicks(this->__lastUpdatedTime);
507 SysLog(NID_SHELL, "The last updated time is %lld.", this->__lastUpdatedTime);
509 __hasPendingRequest = false;
510 __pendingArgument.Clear();
515 _AppWidgetContext::OnResize(int width, int height)
517 SysSecureLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight(), GetPriority());
522 SendResizeRequest(width, height);
526 _AppWidgetContext::RequestUpdate(const String& argument)
528 ArrayList* pArray = new (std::nothrow) ArrayList();
529 SysTryReturnResult(NID_SHELL, pArray, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
533 pArray->Add(new String(argument));
535 result r = Tizen::App::App::GetInstance()->SendUserEvent(LOCAL_EVENT_REQUEST_UPDATE, pArray);
536 SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
537 SysLog(NID_SHELL, "UserEvent(%d) is sent for '%ls.%ls'.", LOCAL_EVENT_REQUEST_UPDATE, GetAppId().GetPointer(), GetProviderName().GetPointer() );
543 _AppWidgetContext::OnForeground(void)
547 SysLog(NID_SHELL, "%ls is already foreground.", (this->GetAppId()).GetPointer());
551 this->SetForeground(true);
553 if (__hasPendingRequest == true)
555 SysLog(NID_SHELL, "There is pending update request.");
556 // RequestUpdate(__pendingArgument);
557 OnUpdate(__pendingArgument);
561 if (IsUpdatePeriodExpired() == true)
563 SysLog(NID_SHELL, "The period is expired.");
564 // RequestUpdate(L"");
571 _AppWidgetContext::IsUpdatePeriodExpired(void) const
573 if (this->GetPeriod() <= 0)
578 long long currentTicks = 0;
579 SystemTime::GetTicks(currentTicks);
581 SysLog(NID_SHELL, "current[%lld] - last updated time[%lld] = [%lld], period[%d]",
582 currentTicks, this->GetLastUpdatedTime(), currentTicks - this->GetLastUpdatedTime(), this->GetPeriod());
584 bool isPeriodExpired = (currentTicks - this->GetLastUpdatedTime()) >= (this->GetPeriod());
585 return isPeriodExpired;
589 _AppWidgetContext::OnBackground(void)
593 SysLog(NID_SHELL, "%ls is already background.", (this->GetAppId()).GetPointer());
597 SysLog(NID_SHELL, "OnBackground");
598 SetForeground(false);
602 _AppWidgetContext::OnPopupCreated(double x, double y, int width, int height)
604 __pAppWidgetPopup = new (nothrow) _AppWidgetPopupContext(this);
605 SysTryReturnVoidResult(NID_SHELL, __pAppWidgetPopup, E_OUT_OF_MEMORY, "");
607 __pAppWidgetPopup->OnPopupCreated(x, y, width, height);
611 _AppWidgetContext::OnPopupDestoyed(void)
613 SysLog(NID_SHELL, "");
615 if (__pAppWidgetPopup)
617 // __pAppWidgetPopup->OnPopupDestoyed();
618 delete __pAppWidgetPopup;
619 __pAppWidgetPopup = null;
624 _AppWidgetContext::SendAddRequest(int width, int height) const
626 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
628 return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_ADD, pArgs.release());
632 _AppWidgetContext::SendUpdateRequest(int width, int height, const String& argument) const
634 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
636 pArgs->Add(new (nothrow) String(ARG_KEY_ARGUMENT), new (nothrow) String(argument));
638 return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_UPDATE, pArgs.release());
642 _AppWidgetContext::SendResizeRequest(int width, int height) const
644 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
646 return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_RESIZE, pArgs.release());
650 _AppWidgetContext::SendRemoveRequest(void) const
652 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
654 return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_REMOVE, pArgs.release());
658 _AppWidgetContext::SendPendingTouchEvent(void)
660 for (int i =0; i< __pPendingTouchEventList->GetCount(); i++)
662 PendingTouchEvent* pTouchEvent = null;
663 __pPendingTouchEventList->GetAt(i, pTouchEvent);
664 AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), pTouchEvent->eventType, pTouchEvent->timeStamp, pTouchEvent->x, pTouchEvent->y);
667 __pPendingTouchEventList->RemoveAll();
671 _AppWidgetContext::OnTouchEventReceived(buffer_event event, double timestamp, double x, double y)
673 if (__pAppContext->GetConnectionState() == CONNECTION_STATE_CONNECTED && __isRemoteBufferProxyCreated)
675 SysLog(NID_SHELL, "%d, %f, %f", event, x, y);
676 AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), event, timestamp, x, y);
680 __pPendingTouchEventList->Add(new (nothrow) PendingTouchEvent(event, timestamp, x, y));
682 if( AppManager::GetInstance()->IsRunning(this->GetAppId() ) == false ||
683 ( __pAppContext->GetConnectionState() == CONNECTION_STATE_CONNECTED && __isRemoteBufferProxyCreated == false))
685 SysLog(NID_SHELL, "request to start AppControl");
686 std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
688 // TODO: consider to remove these unused args.
689 pArgs->Add(new (nothrow) String(ARG_KEY_EVENT_TYPE), new (nothrow) String(Integer::ToString(event)));
690 pArgs->Add(new (nothrow) String(ARG_KEY_TIME_STAMP), new (nothrow) String(Double::ToString(timestamp)));
691 pArgs->Add(new (nothrow) String(ARG_KEY_X), new (nothrow) String(Double::ToString(x)));
692 pArgs->Add(new (nothrow) String(ARG_KEY_Y), new (nothrow) String(Double::ToString(y)));
694 _AppWidgetRequestHelper::SendAppControlRequest(GetAppId(), APPWIDGET_ON_TOUCH, pArgs.get());
700 _AppWidgetContext::SyncRemoteBuffer(int width, int height)
702 std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
703 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
704 std::unique_ptr<char[]> content_info(_StringConverter::CopyToCharArrayN(GetUserInfo()));
706 int ret = provider_send_updated(providerId.get(), id.get(), width, height, GetPriority(), content_info.get(), null);
707 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
709 SendPendingTouchEvent();
710 SysLog(NID_SHELL, "Done");
715 _AppWidgetContext::SendAccessStatus(int accessStatus) const
717 std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
718 std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
720 int ret = provider_send_access_status(providerId.get(), id.get(), accessStatus);
721 SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_access_status");
726 Tizen::Base::Collection::HashMap*
727 _AppWidgetContext::CreateRequestArgsN(void) const
729 HashMap* pArgs = new (nothrow) HashMap(SingleObjectDeleter);
732 pArgs->Add(new (nothrow) String(ARG_KEY_INSTANCE_ID), new (nothrow) String(GetInstanceId()));
733 pArgs->Add(new (nothrow) String(ARG_KEY_PROVIDER_NAME), new (nothrow) String(GetProviderName()));
734 pArgs->Add(new (nothrow) String(ARG_KEY_USER_INFO), new (nothrow) String(GetUserInfo()));
735 pArgs->Add(new (nothrow) String(ARG_KEY_WIDTH), new (nothrow) String(Integer::ToString(GetWidth())));
736 pArgs->Add(new (nothrow) String(ARG_KEY_HEIGHT), new (nothrow) String(Integer::ToString(GetHeight())));
742 _AppWidgetContext::GetPeriod(void) const
744 return __updateMillis;
748 _AppWidgetContext::GetLastUpdatedTime(void) const
750 return __lastUpdatedTime;
754 _AppWidgetContext::GetClientId(void) const
756 return GetAppContext()->GetClientId();
760 _AppWidgetContext::GetWidth(void) const
766 _AppWidgetContext::SetWidth(int width)
772 _AppWidgetContext::GetHeight(void) const
778 _AppWidgetContext::SetHeight(int height)
784 _AppWidgetContext::GetProviderId(void) const
790 _AppWidgetContext::SetProviderId(const String& providerId)
792 __providerId = providerId;
796 _AppWidgetContext::GetAppId(void) const
802 _AppWidgetContext::GetPriority(void) const
808 _AppWidgetContext::SetPriority(int priority)
810 __priority = priority;
814 _AppWidgetContext::GetProviderName(void) const
816 return __providerName;
820 _AppWidgetContext::SetForeground(bool foreground)
822 __isForeground = foreground;
826 _AppWidgetContext::IsForeground(void) const
828 return __isForeground;
832 _AppWidgetContext::GetUserInfo(void) const
838 _AppWidgetContext::SetUserInfo(const String& userInfo)
840 __userInfo = userInfo;
844 _AppWidgetContext::GetInstanceId(void) const
850 _AppWidgetContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
852 if (&timer == &__updateTimer)
854 SysLog(NID_SHELL, "update timer is expired for appWidget app(%ls).", GetProviderId().GetPointer());
860 _AppWidgetContext::OnDisconnected(void)
862 SysSecureLog(NID_SHELL, "%ls, %ls", GetInstanceId().GetPointer(), GetProviderId().GetPointer());
864 __isRemoteBufferProxyCreated = false;
865 if (GetAppWidgetPopup())
872 _AppWidgetContext::AcquireRemoteBuffer(int w, int h) const
874 int id = __pAppWidgetRemoteBuffer->Acquire(w, h);
877 __isRemoteBufferProxyCreated = true;
882 }}} // Tizen::Shell::App