From 8ebc670e98c78524be50eae09b181d4f0a5d79bc Mon Sep 17 00:00:00 2001 From: "jungmin76.park" Date: Fri, 2 Aug 2013 17:16:34 +0900 Subject: [PATCH] refactoring (now _AppContext manages list of _AppWidgetContext, IpcConnection state, request toward app, pending request.) Change-Id: Id3ee4bb16c18916808b42995c280479408d1a746 Signed-off-by: jungmin76.park --- inc/FShell_AppWidgetContext.h | 108 ++++---- inc/FShell_AppWidgetManagerService.h | 35 ++- inc/FShell_AppWidgetManagerStub.h | 9 +- inc/FShell_AppWidgetPopupContext.h | 8 +- inc/FShell_AppWidgetRemoteBuffer.h | 5 + inc/OspAppWidgetService.h | 6 +- src/FShell_AppWidgetContext.cpp | 437 ++++++++++++++++++++++++--------- src/FShell_AppWidgetManagerService.cpp | 368 ++++++++------------------- src/FShell_AppWidgetManagerStub.cpp | 24 +- src/FShell_AppWidgetPopupContext.cpp | 8 +- src/OspAppWidgetService.cpp | 6 + 11 files changed, 544 insertions(+), 470 deletions(-) diff --git a/inc/FShell_AppWidgetContext.h b/inc/FShell_AppWidgetContext.h index 3dc6758..8d56634 100644 --- a/inc/FShell_AppWidgetContext.h +++ b/inc/FShell_AppWidgetContext.h @@ -52,8 +52,7 @@ extern const wchar_t ARG_KEY_EVENT_TYPE[]; extern const wchar_t ARG_KEY_TIME_STAMP[]; extern const int UPDATE_PERIOD_MSEC_MIN; -class _AppWidgetContext; -class _AppWidgetPopupContext; + enum _ConnectionState { @@ -63,34 +62,71 @@ enum _ConnectionState CONNECTION_STATE_DISCONNECTED }; -//////////////////////////////////////////////// -// _AppContext -//////////////////////////////////////////////// +class _AppWidgetContext; + +/** + * @class _AppContext + * @brief Context of a AppWidget provider application. + */ class _AppContext :public Tizen::Base::Object { public: - _AppContext(void); + _AppContext(const Tizen::App::AppId& appId); ~_AppContext(void); + _AppWidgetContext* AddAppWidget(const Tizen::Base::String& userInfo, const Tizen::Base::String& providerId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority); + result RemoveAppWidget(const Tizen::Base::String& instanceId, bool isTriggeredByViewer = true); + result RequestUpdate(const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const; + result OnAppWidgetBackgroundAll(void) const; + result OnAppWidgetForegroundAll(void) const; + + result SendRequestToApp(const Tizen::App::AppId& providerAppId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs); + result SendPendingEvent(void); + + void OnIpcConnected(int clientId); + void OnIpcDisconnected(void); + + Tizen::App::AppId GetAppId(void) const; + int GetClientId(void) const; _ConnectionState GetConnectionState(void) const; + bool GetWaitingStatus(void) const; + + _AppWidgetContext* FindAppWidget(const Tizen::Base::String& instanceId) const; + int GetProviderCount(const Tizen::Base::String& appId) const; + +private: void SetConnectionState(_ConnectionState state); - int GetClientId(void) const; - void SetClientId(int clientId); void SetWaitingStatus(bool status); - bool GetWaitingStatus(void) const; + _AppWidgetContext* FindInvalidAppWidget(void) const; private: + + struct PendingEvent + { + PendingEvent(const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pHashMap) + : operation(operation), pArg(pHashMap) { } + + Tizen::Base::String operation; + Tizen::Base::Collection::HashMap* pArg; + }; + + Tizen::App::AppId __appId; bool __isWaitingResult; int __ipcClientId; _ConnectionState __connectionState; - Tizen::Base::Collection::ArrayListT<_AppWidgetContext*> __appWidetContextList; + Tizen::Base::Collection::HashMapT __appWidgetContextList; + Tizen::Base::Collection::ArrayListT* __pPendingEventList; }; -//////////////////////////////////////////////// -// _AppWidgetContext -//////////////////////////////////////////////// + +class _AppWidgetPopupContext; + +/** + * @class _AppWidgetContext + * @brief Context of a AppWidget provider and it's AppWidgetFrame + */ class _AppWidgetContext : public Tizen::Base::Runtime::ITimerEventListener , public _IAppWidgetRemoteBufferEventListener @@ -104,13 +140,13 @@ public: void OnAdded(void); void OnUpdate(const Tizen::Base::String& argument); void OnResize(int width, int height); - result OnRemoved(void); - virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y); - + result OnRemoved(bool isTriggeredByViewer = true); // dynamic box state void OnForeground(void); void OnBackground(void); + result RequestUpdate(const Tizen::Base::String& argument); + // handle request from dynamic box int AcquireRemoteBuffer(int w, int h) const; result SyncRemoteBuffer(int width, int height); @@ -120,12 +156,10 @@ public: void OnPopupCreated(double x, double y, int width, int height); void OnPopupDestoyed(void); _AppWidgetPopupContext* GetAppWidgetPopup(void) const; - result SendPopupRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs) const; Tizen::Base::Collection::HashMap* CreateRequestArgsN(void) const; _AppContext* GetAppContext(void) const; void OnDisconnected(void); - result SendPendingEvent(void); Tizen::Base::String GetAppId(void) const; Tizen::Base::String GetProviderName(void) const; @@ -142,14 +176,13 @@ public: // void SetPriority(int priority); private: - result SendAddRequest(int width, int height); - result SendUpdateRequest(int width, int height, const Tizen::Base::String& argument); - result SendResizeRequest(int width, int height); - result SendRemoveRequest(void); + result SendAddRequest(int width, int height) const; + result SendUpdateRequest(int width, int height, const Tizen::Base::String& argument) const; + result SendResizeRequest(int width, int height) const; + result SendRemoveRequest(void) const; void SendPendingTouchEvent(void); - result RequestUpdate(const Tizen::Base::String& argument); - result SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs); + virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y); virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer); void SetForeground(bool forground); @@ -160,6 +193,7 @@ private: int GetClientId(void) const; bool IsForeground(void) const; long long GetLastUpdatedTime(void) const; + bool IsUpdatePeriodExpired(void) const; private: struct PendingTouchEvent @@ -173,15 +207,6 @@ private: double y; }; - struct PendingEvent - { - PendingEvent(const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pHashMap) - : operation(operation), pArg(pHashMap) { } - - Tizen::Base::String operation; - Tizen::Base::Collection::HashMap* pArg; - }; - mutable bool __isRemoteBufferProxyCreated; bool __hasPendingRequest; bool __isForeground; @@ -189,14 +214,14 @@ private: int __height; int __priority; int __ipcClientId; - int __updateMillis; + const int __updateMillis; long long __lastUpdatedTime; - Tizen::Base::String __userInfo; - Tizen::Base::String __providerId; - Tizen::Base::String __instanceId; - Tizen::Base::String __appId; - Tizen::Base::String __providerName; + const Tizen::Base::String __userInfo; + const Tizen::Base::String __providerId; + const Tizen::Base::String __instanceId; + Tizen::Base::String __appId;//TODO: const + Tizen::Base::String __providerName;//TODO: const Tizen::Base::String __pendingArgument; Tizen::Base::Runtime::Timer __updateTimer; @@ -205,10 +230,11 @@ private: _AppWidgetRemoteBuffer* __pAppWidgetRemoteBuffer; Tizen::Base::Collection::ArrayListT* __pPendingTouchEventList; - Tizen::Base::Collection::ArrayListT* __pPendingEventList; - }; // class _AppWidgetContext + +static const RequestId LOCAL_EVENT_REQUEST_UPDATE = 0; + }}} // Tizen::Shell::App #endif // _FSHELL_INTERNAL_APPWIDGET_CONTEXT_H_ diff --git a/inc/FShell_AppWidgetManagerService.h b/inc/FShell_AppWidgetManagerService.h index 0af5429..467a24a 100644 --- a/inc/FShell_AppWidgetManagerService.h +++ b/inc/FShell_AppWidgetManagerService.h @@ -38,6 +38,10 @@ class IList; namespace Tizen { namespace Shell { namespace App { +/** + * @class AppWidgetManagerService + * @brief The AppWidgetManagerService class handles request from viewer and provider applications, and manages context of connected application. + */ class AppWidgetManagerService :public Tizen::Shell::App::_AppWidgetManagerStub ,public Tizen::Base::Runtime::ITimerEventListener @@ -47,9 +51,8 @@ public: static AppWidgetManagerService* GetInstance(void); static AppWidgetManagerService* CreateInstance(const char* pServiceIdForCoreDaemon); _AppWidgetContext* AddAppWidget(const Tizen::Base::String& userInfo, const Tizen::Base::String& appId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority); - result RemoveAppWidget(const char* pProviderId, const char* pId); - result RequestUpdate(_AppWidgetContext* pAppWidgetContext, const Tizen::Base::String& argument); - int GetProviderCount(const Tizen::Base::String& appId) const; + result RequestUpdate(_AppWidgetContext* pAppWidgetContext, const Tizen::Base::String& argument) const; + void OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs); private: result Construct(const char* pServiceIdForCoreDaemon); @@ -57,8 +60,8 @@ private: result DeinitializeCoreDaemonEventReceiver(void); // core daemon callbacks - static int AppWidgetConnected(struct event_arg *arg, void* data); - static int AppWidgetDisconnected(struct event_arg *arg, void* data); + static int OnAppWidgetServiceConnected(struct event_arg *arg, void* data); + static int OnAppWidgetServiceCDisconnected(struct event_arg *arg, void* data); static int OnAppWidgetCreate(struct event_arg *arg, int *width, int *height, double *priority, void* data); static int OnAppWidgetDestroy(struct event_arg *arg, void* data); static int OnAppWidgetUpdate(struct event_arg *arg, void* data); @@ -74,8 +77,8 @@ private: static int OnAppWidgetRecreate(struct event_arg *arg, void* data); // stub implementations - virtual result RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument); - virtual result RequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument); + virtual result RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const; + virtual result RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument); virtual result AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int w, int h, int& bufferId); virtual result AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int w, int h, int& bufferId); virtual result SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height); @@ -98,28 +101,20 @@ private: virtual void OnSettingChanged(Tizen::Base::String & key); // helpers - _AppWidgetContext* Find(const Tizen::Base::String& instanceId) const; - int UpdateAppWidgetsByProviderId(const Tizen::Base::String& appId); - result RequestPendingEvent(void); + _AppWidgetContext* FindAppWidget(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId) const; + int UpdateAppWidgetsByProviderId(const Tizen::Base::String& providerId); +// result RequestPendingEvent(void); void StartPingTimer(void); virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer); + static Tizen::App::AppId ExtractAppId(const Tizen::Base::String& providerId); + result RequestUpdateAllSuspened(void) const; private: - class _TaskHandlerThread - : public Tizen::Base::Runtime::Thread - { - public: - virtual ~_TaskHandlerThread(void); - virtual void OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs); - - }; static AppWidgetManagerService* __pTheInstance; - Tizen::Base::Collection::HashMapT __appWidgetContextList; Tizen::Base::Collection::HashMapT __appContextList; Tizen::Base::Runtime::Timer __pingTimer; - _TaskHandlerThread __handlerThread; }; // class AppWidgetManagerService }}} // Tizen::Shell::App diff --git a/inc/FShell_AppWidgetManagerStub.h b/inc/FShell_AppWidgetManagerStub.h index 7b3641c..df3411d 100644 --- a/inc/FShell_AppWidgetManagerStub.h +++ b/inc/FShell_AppWidgetManagerStub.h @@ -37,7 +37,6 @@ namespace Tizen { namespace Shell { namespace App { /** * @class _AppWidgetManagerStub * @brief Handles IPC requests and calls real methods. - * @since 2.1 */ class _AppWidgetManagerStub : public Tizen::Base::Object @@ -57,8 +56,8 @@ protected: // handlers bool OnRequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument, result* pRes); bool OnRequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument, result* pRes); - bool OnAcquireRemoteBuffer(const Tizen::Base::String& instanceId, int width, int height, int* pShmId); - bool OnAcquireRemoteBufferForPD(const Tizen::Base::String& instanceId, int width, int height, int* pShmId); + bool OnAcquireRemoteBuffer(const Tizen::Base::String& instanceId, int width, int height, int* pBufferId); + bool OnAcquireRemoteBufferForPD(const Tizen::Base::String& instanceId, int width, int height, int* pBufferId); bool OnSyncRemoteBuffer(const Tizen::Base::String& instanceId, int width, int height, result* pRes); bool OnSyncRemoteBufferForPD(const Tizen::Base::String& instanceId, result* pRes); bool OnReleaseRemoteBuffer(const Tizen::Base::String& instanceId, result* pRes); @@ -68,8 +67,8 @@ protected: bool OnSendAccessStatus(const Tizen::Base::String& instanceId, int accessStatus); // interface to service - virtual result RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) = 0; - virtual result RequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument) = 0; + virtual result RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const = 0; + virtual result RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument) = 0; virtual result AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId) = 0; virtual result AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId) = 0; virtual result SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height) = 0; diff --git a/inc/FShell_AppWidgetPopupContext.h b/inc/FShell_AppWidgetPopupContext.h index 563a0de..a013cec 100644 --- a/inc/FShell_AppWidgetPopupContext.h +++ b/inc/FShell_AppWidgetPopupContext.h @@ -34,8 +34,12 @@ class HashMap; namespace Tizen { namespace Shell { namespace App { -class _AppWidgetContext; +class _AppWidgetPopupContext; +/** + * @class _AppWidgetContext + * @brief Context of a AppWidgetPopupProvider and it's AppWidgetPopup + */ class _AppWidgetPopupContext :public Tizen::Base::Object , public _IAppWidgetRemoteBufferEventListener @@ -56,7 +60,7 @@ public: result SendPopupDestroyRequest(void); private: - int GetClientId(void) const; +// int GetClientId(void) const; void OnPopupDestoyed(void); virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y); diff --git a/inc/FShell_AppWidgetRemoteBuffer.h b/inc/FShell_AppWidgetRemoteBuffer.h index d586caf..1b32ba0 100644 --- a/inc/FShell_AppWidgetRemoteBuffer.h +++ b/inc/FShell_AppWidgetRemoteBuffer.h @@ -30,6 +30,7 @@ namespace Tizen { namespace Shell { namespace App { + class _IAppWidgetRemoteBufferEventListener : virtual public Tizen::Base::Runtime::IEventListener { @@ -40,6 +41,10 @@ public: virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y) = 0; }; +/** + * @class _AppWidgetContext + * @brief This class wraps provider_buffer_xxx of libprovider. + */ class _AppWidgetRemoteBuffer :public Tizen::Base::Object { diff --git a/inc/OspAppWidgetService.h b/inc/OspAppWidgetService.h index 9a666e2..db37850 100644 --- a/inc/OspAppWidgetService.h +++ b/inc/OspAppWidgetService.h @@ -46,9 +46,10 @@ public: public: OspAppWidgetService(void); + ~OspAppWidgetService(void); -public: +private: // Called when the ServiceApp is initializing. bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry); @@ -68,8 +69,9 @@ public: // Called when the battery level changes. void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel); -private: virtual void OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData); + + virtual void OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs); }; // class OspAppWidgetService #endif // _OSP_APPWIDGET_SERVICE_H_ diff --git a/src/FShell_AppWidgetContext.cpp b/src/FShell_AppWidgetContext.cpp index 06294bb..021b64f 100644 --- a/src/FShell_AppWidgetContext.cpp +++ b/src/FShell_AppWidgetContext.cpp @@ -22,13 +22,17 @@ #include #include +#include +//#include #include #include #include #include #include #include +#include #include +#include #include #include "FShell_AppWidgetManagerImpl.h" @@ -37,6 +41,7 @@ #include "FShell_AppWidgetContext.h" #include "FShell_AppWidgetContextHelper.h" #include "FShell_AppWidgetRemoteBuffer.h" +#include "FShell_TemplateUtil.h" namespace Tizen { namespace Shell { namespace App { @@ -68,20 +73,74 @@ const wchar_t APPWIDGET_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidget/tou const int UPDATE_PERIOD_MSEC_MIN = 1800000; // 30min +static const wchar_t INVALID_INSTANCE[] = L"file://invalid instance id"; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // _AppContext class ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -_AppContext::_AppContext(void) - :__isWaitingResult(false) +_AppContext::_AppContext(const AppId& appId) + :__appId(appId) + ,__isWaitingResult(false) ,__ipcClientId(0) ,__connectionState(CONNECTION_STATE_NONE) + ,__pPendingEventList(null) { + __pPendingEventList = new (nothrow) ArrayListT(); + SysTryReturnVoidResult(NID_SHELL, __pPendingEventList, E_OUT_OF_MEMORY, ""); + + result r = __pPendingEventList->Construct(); + SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct."); + + static __HashMapDefaultProviderT strHashCodeProvider; + static ComparerT strComparer; + r = __appWidgetContextList.Construct(0, 0, strHashCodeProvider, strComparer); + SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct."); } _AppContext::~_AppContext(void) { + if (__pPendingEventList) + { + for (int i = 0; i < __pPendingEventList->GetCount(); i++) + { + PendingEvent* pEvent = null; + __pPendingEventList->GetAt(i, pEvent); + delete pEvent; + } + __pPendingEventList->RemoveAll(); + delete __pPendingEventList; + } +} + +_AppWidgetContext* +_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) +{ + _AppWidgetContext* pAppWidgetContext = new (std::nothrow)_AppWidgetContext(this, userInfo, providerId, instanceId, width, height, period, priority); + SysTryReturn(NID_SHELL, pAppWidgetContext, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + + __appWidgetContextList.Add(pAppWidgetContext->GetInstanceId(), pAppWidgetContext); + pAppWidgetContext->OnAdded(); + + SysSecureLog(NID_SHELL, "%ls, %ls, count(%d)", pAppWidgetContext->GetProviderId().GetPointer(), pAppWidgetContext->GetInstanceId().GetPointer(), __appWidgetContextList.GetCount()); + return pAppWidgetContext; +} +result +_AppContext::RemoveAppWidget(const Tizen::Base::String& instanceId, bool isTriggeredByViewer) +{ + _AppWidgetContext* pAppWidgetContext = FindAppWidget(instanceId); + SysTryReturnResult(NID_SHELL, pAppWidgetContext, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]"); + + __appWidgetContextList.Remove(instanceId); + + result r = pAppWidgetContext->OnRemoved(isTriggeredByViewer); + SysTryLog(NID_SHELL, !IsFailed(r), "Failed to execute OnRemoved."); + + delete pAppWidgetContext; + + SysLog(NID_SHELL, "AppWidget(%ls, %ls) is removed. remain count(%d)", pAppWidgetContext->GetProviderId().GetPointer(), instanceId.GetPointer(), __appWidgetContextList.GetCount()); + return E_SUCCESS; } _ConnectionState @@ -96,6 +155,12 @@ _AppContext::SetConnectionState(_ConnectionState state) __connectionState = state; } +Tizen::App::AppId +_AppContext::GetAppId(void) const +{ + return __appId; +} + int _AppContext::GetClientId(void) const { @@ -103,9 +168,30 @@ _AppContext::GetClientId(void) const } void -_AppContext::SetClientId(int clientId) +_AppContext::OnIpcConnected(int clientId) { __ipcClientId = clientId; + SetConnectionState(CONNECTION_STATE_CONNECTED); +} + +void +_AppContext::OnIpcDisconnected(void) +{ + __ipcClientId = -1; + SetConnectionState(CONNECTION_STATE_DISCONNECTED); + + unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); + SysTryReturnVoidResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, ""); + + _AppWidgetContext* pAppWidgetContext = null; + while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + { + pAppWidgetContextEnum->GetValue(pAppWidgetContext); + if (pAppWidgetContext) + { + pAppWidgetContext->OnDisconnected(); + } + } } void @@ -120,6 +206,170 @@ _AppContext::GetWaitingStatus(void) const return __isWaitingResult; } +result +_AppContext::SendRequestToApp(const AppId& providerAppId, const String& operation, HashMap* pArgs) +{ + result r = E_SUCCESS; + + if (GetConnectionState() == CONNECTION_STATE_NONE || GetConnectionState() == CONNECTION_STATE_DISCONNECTED) + { + SysLog(NID_SHELL, "The application is not running."); + result r = _AppWidgetRequestHelper::SendAppControlRequest(providerAppId, operation, pArgs); + SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Failed to SendRequestToApp", GetErrorMessage(r)); + + SetWaitingStatus(true); + SetConnectionState(CONNECTION_STATE_CONNECTING); + } + else + { + if (GetConnectionState() == CONNECTION_STATE_CONNECTING || GetWaitingStatus() == true) + { + SysLog(NID_SHELL, "The application is running but IPC is not connected yet."); + __pPendingEventList->Add(new (nothrow) PendingEvent(operation, pArgs)); + } + else + { + SysLog(NID_SHELL, "The application is running and IPC is connected."); + r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), operation, pArgs); + + pArgs->RemoveAll(true); + delete pArgs; + SetWaitingStatus(true); + } + } + + return E_SUCCESS; +} + +result +_AppContext::SendPendingEvent(void) +{ + SetWaitingStatus(false); + TryReturn(__pPendingEventList->GetCount() > 0, E_DATA_NOT_FOUND, "This context has no pending event. Please find next pending event context."); + + PendingEvent* pEvent = null; + __pPendingEventList->GetAt(0, pEvent); + SysTryReturnResult(NID_SHELL, pEvent != null, E_SYSTEM, "__pPendingEventList has (%d) items, but failed to GetAt(0)", __pPendingEventList->GetCount()); + + __pPendingEventList->RemoveAt(0); + SysLog(NID_SHELL, "(%d) Remains in __pPendingEventList.", __pPendingEventList->GetCount()); + + result r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), pEvent->operation, pEvent->pArg); + delete pEvent; + SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "SendIpcRequest failed."); + + return E_SUCCESS; +} + +_AppWidgetContext* +_AppContext::FindAppWidget(const String& instanceId) const +{ + _AppWidgetContext* pAppWidgetContext = null; + + if (instanceId == INVALID_INSTANCE) + { + pAppWidgetContext = FindInvalidAppWidget(); + } + else + { + result r = __appWidgetContextList.GetValue(instanceId, pAppWidgetContext); + SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "instanceId(%ls) is not found", instanceId.GetPointer() ); + } + return pAppWidgetContext; +} + +_AppWidgetContext* +_AppContext::FindInvalidAppWidget(void) const +{ + SysTryReturn(NID_SHELL, GetConnectionState() == CONNECTION_STATE_NONE, null, E_INVALID_STATE, "[E_INVALID_STATE] connectionState(%d)", GetConnectionState()); + + _AppWidgetContext* pAppWidgetContext = null; + unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); + SysTryReturn(NID_SHELL, pAppWidgetContextEnum, null, E_SYSTEM, ""); + + while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + { + pAppWidgetContextEnum->GetValue(pAppWidgetContext); + if (pAppWidgetContext) + { + //TODO: check whether this app context has only one instance of _AppWidgetContext + return pAppWidgetContext; + } + } + return null; +} + +int +_AppContext::GetProviderCount(const String& appId) const +{ + return __appWidgetContextList.GetCount(); +} + +result +_AppContext::RequestUpdate(const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const +{ + bool found = false; + bool requestToAll = providerName.IsEmpty(); + + unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke __appWidgetContextList.GetMapEnumeratorN()"); + + while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + { + _AppWidgetContext* pAppWidgetContext = null; + pAppWidgetContextEnum->GetValue(pAppWidgetContext); + + if (pAppWidgetContext->GetProviderName() == providerName || requestToAll == true) + { + pAppWidgetContext->RequestUpdate(argument); + found = true; + } + } + + SysLog(NID_SHELL, "Exit."); + return (found) ? E_SUCCESS : E_OBJ_NOT_FOUND; +} + +result +_AppContext::OnAppWidgetBackgroundAll(void) const +{ + unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke GetMapEnumeratorN()"); + + while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + { + _AppWidgetContext* pAppWidgetContext = null; + pAppWidgetContextEnum->GetValue(pAppWidgetContext); + if (pAppWidgetContext) + { + pAppWidgetContext->OnBackground(); + } + } + + return E_SUCCESS; +} + +result +_AppContext::OnAppWidgetForegroundAll(void) const +{ + unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, "Failed to invoke GetMapEnumeratorN()"); + + while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + { + _AppWidgetContext* pAppWidgetContext = null; + pAppWidgetContextEnum->GetValue(pAppWidgetContext); + if (pAppWidgetContext) + { + pAppWidgetContext->OnForeground(); + } + } + + return E_SUCCESS; +} + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // _AppWidgetContext class ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -131,7 +381,7 @@ _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& use ,__height(height) ,__priority(priority) ,__ipcClientId(-1) - ,__updateMillis(period) + ,__updateMillis( (period > UPDATE_PERIOD_MSEC_MIN) ? period : UPDATE_PERIOD_MSEC_MIN ) ,__lastUpdatedTime(0) ,__userInfo(userInfo) ,__providerId(providerId) @@ -140,17 +390,13 @@ _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& use ,__pAppWidgetPopup(null) ,__pAppWidgetRemoteBuffer(null) ,__pPendingTouchEventList(null) - ,__pPendingEventList(null) { - _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName); - SysSecureLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority); + _AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);//TODO: extract this line to outside + 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); // for updating period if (__updateMillis > 0) { - __updateMillis = (__updateMillis > UPDATE_PERIOD_MSEC_MIN) ? __updateMillis : UPDATE_PERIOD_MSEC_MIN; - SysLog(NID_SHELL, "period(%d)", __updateMillis); - SystemTime::GetTicks(this->__lastUpdatedTime); result r = __updateTimer.Construct(*this); @@ -164,10 +410,6 @@ _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& use SysTryReturnVoidResult(NID_SHELL, __pPendingTouchEventList, E_OUT_OF_MEMORY, ""); __pPendingTouchEventList->Construct(); - __pPendingEventList = new (nothrow) ArrayListT(); - SysTryReturnVoidResult(NID_SHELL, __pPendingEventList, E_OUT_OF_MEMORY, ""); - __pPendingEventList->Construct(); - __pAppWidgetRemoteBuffer = new (nothrow) _AppWidgetRemoteBuffer(providerId, instanceId, TYPE_LB, this); SysTryReturnVoidResult(NID_SHELL, __pAppWidgetRemoteBuffer, E_OUT_OF_MEMORY, ""); } @@ -196,18 +438,6 @@ _AppWidgetContext::~_AppWidgetContext(void) delete __pPendingTouchEventList; } - if (__pPendingEventList) - { - for (int i = 0; i < __pPendingEventList->GetCount(); i++) - { - PendingEvent* pEvent = null; - __pPendingEventList->GetAt(i, pEvent); - delete pEvent; - } - __pPendingEventList->RemoveAll(); - delete __pPendingEventList; - } - if (__pAppWidgetRemoteBuffer) { delete __pAppWidgetRemoteBuffer; @@ -233,21 +463,29 @@ _AppWidgetContext::OnAdded(void) } result -_AppWidgetContext::OnRemoved(void) +_AppWidgetContext::OnRemoved(bool isTriggeredByViewer) { - return SendRemoveRequest(); + if (isTriggeredByViewer) + { + return SendRemoveRequest(); + } + else + { + std::unique_ptr providerId(_StringConverter::CopyToCharArrayN(GetProviderId())); + std::unique_ptr id(_StringConverter::CopyToCharArrayN(GetInstanceId())); + + int ret = provider_send_deleted(providerId.get(), id.get()); + SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_send_deleted."); + } + return E_SUCCESS; } void _AppWidgetContext::OnUpdate(const String& argument) { SysLog(NID_SHELL, "argument(%ls)", argument.GetPointer()); - ClearLastResult(); - AppWidgetManagerService* pMgrService = AppWidgetManagerService::GetInstance(); - SysTryReturnVoidResult(NID_SHELL, pMgrService, E_SYSTEM, "[E_SYSTEM] Failed to get an instance of AppWidgetManagerService."); - // Queueing the pointer of background context. if (!this->IsForeground()) { @@ -287,13 +525,18 @@ _AppWidgetContext::OnResize(int width, int height) result _AppWidgetContext::RequestUpdate(const String& argument) { - AppWidgetManagerService* pMgrService = AppWidgetManagerService::GetInstance(); - SysTryReturnResult(NID_SHELL, pMgrService, E_SYSTEM, "Failed to get an instance of AppWidgetManagerService."); + ArrayList* pArray = new (std::nothrow) ArrayList(); + SysTryReturnResult(NID_SHELL, pArray, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + + pArray->Construct(); + pArray->Add(this); + pArray->Add(new String(argument)); - result r = pMgrService->RequestUpdate(this, argument); - SysTryReturnResult(NID_SHELL, !IsFailed(r), r, "Failed to request update."); + result r = Tizen::App::App::GetInstance()->SendUserEvent(LOCAL_EVENT_REQUEST_UPDATE, pArray); + SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r)); + SysLog(NID_SHELL, "UserEvent(%d) is sent for '%ls.%ls'.", LOCAL_EVENT_REQUEST_UPDATE, GetAppId().GetPointer(), GetProviderName().GetPointer() ); - return r; + return E_SUCCESS; } void @@ -309,38 +552,49 @@ _AppWidgetContext::OnForeground(void) if (__hasPendingRequest == true) { - RequestUpdate(__pendingArgument); + SysLog(NID_SHELL, "There is pending update request."); +// RequestUpdate(__pendingArgument); + OnUpdate(__pendingArgument); } else { - if (this->GetPeriod() > 0) + if (IsUpdatePeriodExpired() == true) { - long long currentTicks = 0; - SystemTime::GetTicks(currentTicks); - - SysLog(NID_SHELL, "current[%lld] - updatedTime[%lld] = [%lld], period[%d]", - currentTicks, this->GetLastUpdatedTime(), currentTicks - this->GetLastUpdatedTime(), this->GetPeriod()); - - bool isPeriodExpired = (currentTicks - this->GetLastUpdatedTime()) >= (this->GetPeriod()); - if (isPeriodExpired) - { - SysLog(NID_SHELL, "The period is expired."); - RequestUpdate(L""); - } + SysLog(NID_SHELL, "The period is expired."); +// RequestUpdate(L""); + OnUpdate(L""); } } } +bool +_AppWidgetContext::IsUpdatePeriodExpired(void) const +{ + if (this->GetPeriod() <= 0) + { + return false; + } + + long long currentTicks = 0; + SystemTime::GetTicks(currentTicks); + + SysLog(NID_SHELL, "current[%lld] - last updated time[%lld] = [%lld], period[%d]", + currentTicks, this->GetLastUpdatedTime(), currentTicks - this->GetLastUpdatedTime(), this->GetPeriod()); + + bool isPeriodExpired = (currentTicks - this->GetLastUpdatedTime()) >= (this->GetPeriod()); + return isPeriodExpired; +} + void _AppWidgetContext::OnBackground(void) { - SysLog(NID_SHELL, "OnBackground"); - if (!IsForeground()) { SysLog(NID_SHELL, "%ls is already background.", (this->GetAppId()).GetPointer()); return; } + + SysLog(NID_SHELL, "OnBackground"); SetForeground(false); } @@ -367,57 +621,37 @@ _AppWidgetContext::OnPopupDestoyed(void) } result -_AppWidgetContext::SendAddRequest(int width, int height) +_AppWidgetContext::SendAddRequest(int width, int height) const { std::unique_ptr pArgs (CreateRequestArgsN()); - return SendRequestToApp(GetAppId(), APPWIDGET_ON_ADD, pArgs.release()); + return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_ADD, pArgs.release()); } result -_AppWidgetContext::SendUpdateRequest(int width, int height, const String& argument) +_AppWidgetContext::SendUpdateRequest(int width, int height, const String& argument) const { std::unique_ptr pArgs (CreateRequestArgsN()); pArgs->Add(new (nothrow) String(ARG_KEY_ARGUMENT), new (nothrow) String(argument)); - return SendRequestToApp(GetAppId(), APPWIDGET_ON_UPDATE, pArgs.release()); + return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_UPDATE, pArgs.release()); } result -_AppWidgetContext::SendResizeRequest(int width, int height) +_AppWidgetContext::SendResizeRequest(int width, int height) const { std::unique_ptr pArgs (CreateRequestArgsN() ); - return SendRequestToApp(GetAppId(), APPWIDGET_ON_RESIZE, pArgs.release()); + return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_RESIZE, pArgs.release()); } result -_AppWidgetContext::SendRemoveRequest(void) +_AppWidgetContext::SendRemoveRequest(void) const { std::unique_ptr pArgs (CreateRequestArgsN()); - return SendRequestToApp(GetAppId(), APPWIDGET_ON_REMOVE, pArgs.release()); -} - -result -_AppWidgetContext::SendPendingEvent(void) -{ - GetAppContext()->SetWaitingStatus(false); - TryReturn(__pPendingEventList->GetCount() > 0, E_DATA_NOT_FOUND, "This context has no pending event. Please find next pending event context."); - - PendingEvent* pEvent = null; - __pPendingEventList->GetAt(0, pEvent); - SysTryReturnResult(NID_SHELL, pEvent != null, E_SYSTEM, "__pPendingEventList has (%d) items, but failed to GetAt(0)", __pPendingEventList->GetCount()); - - __pPendingEventList->RemoveAt(0); - SysLog(NID_SHELL, "(%d) Remains in __pPendingEventList.", __pPendingEventList->GetCount()); - - result r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), pEvent->operation, pEvent->pArg); - delete pEvent; - SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "SendIpcRequest failed."); - - return E_SUCCESS; + return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_REMOVE, pArgs.release()); } void @@ -463,47 +697,6 @@ _AppWidgetContext::OnTouchEventReceived(buffer_event event, double timestamp, do } result -_AppWidgetContext::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs) -{ - result r = E_SUCCESS; - - if ( __pAppContext->GetConnectionState() == CONNECTION_STATE_NONE || __pAppContext->GetConnectionState() == CONNECTION_STATE_DISCONNECTED) - { - SysLog(NID_SHELL, "The application is not running."); - result r = _AppWidgetRequestHelper::SendAppControlRequest(appId, operation, pArgs); - SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Failed to SendRequestToApp", GetErrorMessage(r)); - - __pAppContext->SetWaitingStatus(true); - __pAppContext->SetConnectionState(CONNECTION_STATE_CONNECTING); - } - else - { - if ( __pAppContext->GetConnectionState() == CONNECTION_STATE_CONNECTING || __pAppContext->GetWaitingStatus() == true) - { - SysLog(NID_SHELL, "The application is running but IPC is not connected yet."); - __pPendingEventList->Add(new (nothrow) PendingEvent(operation, pArgs)); - } - else - { - SysLog(NID_SHELL, "The application is running and IPC is connected."); - r = _AppWidgetRequestHelper::SendIpcRequest(GetClientId(), operation, pArgs); - - pArgs->RemoveAll(true); - delete pArgs; - __pAppContext->SetWaitingStatus(true); - } - } - - return E_SUCCESS; -} - -result -_AppWidgetContext::SendPopupRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs) const -{ - return _AppWidgetRequestHelper::SendAppControlRequest(appId, operation, pArgs);; -} - -result _AppWidgetContext::SyncRemoteBuffer(int width, int height) { std::unique_ptr providerId(_StringConverter::CopyToCharArrayN(GetProviderId())); diff --git a/src/FShell_AppWidgetManagerService.cpp b/src/FShell_AppWidgetManagerService.cpp index d196d35..7127d35 100644 --- a/src/FShell_AppWidgetManagerService.cpp +++ b/src/FShell_AppWidgetManagerService.cpp @@ -22,6 +22,8 @@ #include #include #include + +#include #include #include #include @@ -31,7 +33,7 @@ #include #include #include -#include + #include "FShell_AppWidgetContext.h" #include "FShell_AppWidgetPopupContext.h" #include "FShell_AppWidgetManagerStub.h" @@ -51,8 +53,6 @@ using namespace Tizen::Shell::App; namespace { -static const RequestId LOCAL_EVENT_REQUEST_UPDATE = 0; -static const wchar_t INVALID_INSTANCE[] = L"file://invalid instance id"; static const char APPNAME_OSP_APPWIDGET_SERVICE[] = "osp-appwidget-service"; static const int TIMER_DURATION_PING = 120000; //extern const int UPDATE_PERIOD_MSEC_MIN; @@ -77,7 +77,7 @@ AppWidgetManagerService::~AppWidgetManagerService(void) AppWidgetManagerService* AppWidgetManagerService::GetInstance(void) { - if( __pTheInstance == null) + if (__pTheInstance == null) { __pTheInstance = CreateInstance(APPNAME_OSP_APPWIDGET_SERVICE); } @@ -87,7 +87,7 @@ AppWidgetManagerService::GetInstance(void) AppWidgetManagerService* AppWidgetManagerService::CreateInstance(const char* pCoreDaemonId) { - if( __pTheInstance == null) + if (__pTheInstance == null) { __pTheInstance = new AppWidgetManagerService(); SysTryReturn(NID_SHELL, __pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); @@ -104,28 +104,19 @@ AppWidgetManagerService::Construct(const char* pCoreDaemonId) { _AppWidgetManagerStub::StartIpcServer(); - result r = __handlerThread.Construct(THREAD_TYPE_EVENT_DRIVEN); - SysTryReturnResult(NID_SHELL, IsFailed(r) == false, r, "Event thread creation failure."); - - r = __handlerThread.Start(); - SysTryReturnResult(NID_SHELL, IsFailed(r) == false, r, "Event thread Start failure."); - SettingInfo::AddSettingEventListener(*this); static __HashMapDefaultProviderT strHashCodeProvider; static ComparerT strComparer; - r = __appWidgetContextList.Construct(0, 0, strHashCodeProvider, strComparer); - SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct."); - - r = __appContextList.Construct(0, 0, strHashCodeProvider, strComparer); + result r = __appContextList.Construct(0, 0, strHashCodeProvider, strComparer); SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute Construct."); return InitializeCoreDaemonEventReceiver(pCoreDaemonId); } int -AppWidgetManagerService::AppWidgetConnected(struct event_arg *arg, void* data) +AppWidgetManagerService::OnAppWidgetServiceConnected(struct event_arg *arg, void* data) { int ret; ret = provider_send_hello(); @@ -143,7 +134,7 @@ AppWidgetManagerService::AppWidgetConnected(struct event_arg *arg, void* data) } int -AppWidgetManagerService::AppWidgetDisconnected(struct event_arg *arg, void* data) +AppWidgetManagerService::OnAppWidgetServiceCDisconnected(struct event_arg *arg, void* data) { SysLog(NID_SHELL, "Disconnected with master daemon"); return 0; @@ -167,39 +158,28 @@ AppWidgetManagerService::OnTimerExpired(Timer& timer) provider_send_ping(); } -_AppWidgetContext* -AppWidgetManagerService::Find(const String& instanceId) const +AppId +AppWidgetManagerService::ExtractAppId(const String& providerId) { - _AppWidgetContext* pAppWidgetContext = null; - __appWidgetContextList.GetValue(instanceId, pAppWidgetContext); + int index = 0; + result r = providerId.IndexOf(".", 12, index);//"1234567890._" + SysTryReturn(NID_SHELL, !IsFailed(r), L"", E_INVALID_ARG, "[E_INVALID_ARG] Failed to get the index from providerId(%ls).", providerId.GetPointer() ); - return pAppWidgetContext; + String appId; + providerId.SubString(0, index, appId); + return appId; } -int -AppWidgetManagerService::GetProviderCount(const String& appId) const +_AppWidgetContext* +AppWidgetManagerService::FindAppWidget(const AppId& appId, const String& instanceId) const { - int providerCount = 0; - - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); - SysTryReturn(NID_SHELL, pAppWidgetContextEnum, providerCount, E_SYSTEM, "[E_SYSTEM]"); - - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); - - if (pContext->GetAppId() == appId) - { - providerCount++; - } - } + _AppContext* pAppContext = null; + result r = __appContextList.GetValue(appId, pAppContext); + SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() ); - SysLog(NID_SHELL, "The provider count is %d for %ls", providerCount, appId.GetPointer()); - return providerCount; + return pAppContext->FindAppWidget(instanceId); } - void AppWidgetManagerService::OnIpcClientConnected(const _IpcServer& server, int clientId) { @@ -210,8 +190,7 @@ AppWidgetManagerService::OnIpcClientConnected(const _IpcServer& server, int clie __appContextList.GetValue(appId, pAppContext); if (pAppContext) { - pAppContext->SetClientId(clientId); - pAppContext->SetConnectionState(CONNECTION_STATE_CONNECTED); + pAppContext->OnIpcConnected(clientId); } } @@ -225,22 +204,7 @@ AppWidgetManagerService::OnIpcClientDisconnected(const _IpcServer& server, int c __appContextList.GetValue(appId, pAppContext); if (pAppContext) { - pAppContext->SetClientId(-1); - pAppContext->SetConnectionState(CONNECTION_STATE_DISCONNECTED); - } - - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); - SysTryReturnVoidResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, ""); - - _AppWidgetContext* pContext = null; - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - - pAppWidgetContextEnum->GetValue(pContext); - if (pContext->GetAppId() == appId) - { - pContext->OnDisconnected(); - } + pAppContext->OnIpcDisconnected(); } } @@ -258,7 +222,7 @@ AppWidgetManagerService::OnSettingChanged(Tizen::Base::String& key) || key == KEY_SETTING_COUNTRY ) { SysLog(NID_SHELL, "'%ls' is changed.", key.GetPointer() ); - RequestUpdate("", "", ""); + RequestUpdateAllSuspened(); } } @@ -274,7 +238,8 @@ AppWidgetManagerService::AddAppWidget(const Tizen::Base::String& userInfo, const __appContextList.ContainsKey(appId, containsKey); if( containsKey == false) { - pAppContext = new(std::nothrow) _AppContext; + pAppContext = new(std::nothrow) _AppContext(appId); + SysTryReturn(NID_SHELL, pAppContext, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); __appContextList.Add(appId, pAppContext); } else @@ -282,30 +247,7 @@ AppWidgetManagerService::AddAppWidget(const Tizen::Base::String& userInfo, const __appContextList.GetValue(appId, pAppContext); } - _AppWidgetContext* pAppWidgetContext = new (std::nothrow)_AppWidgetContext(pAppContext, userInfo, providerId, instanceId, width, height, period, priority); - SysTryReturn(NID_SHELL, pAppWidgetContext, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); - - __appWidgetContextList.Add(pAppWidgetContext->GetInstanceId(), pAppWidgetContext); - pAppWidgetContext->OnAdded(); - - SysSecureLog(NID_SHELL, "%ls, %ls, count(%d)", pAppWidgetContext->GetProviderId().GetPointer(), pAppWidgetContext->GetInstanceId().GetPointer(), __appWidgetContextList.GetCount()); - return pAppWidgetContext; -} - -result -AppWidgetManagerService::RemoveAppWidget(const char* pProviderId, const char* pId) -{ - SysTryReturn(NID_SHELL, ( pProviderId != null && pId != null), null, E_INVALID_ARG, "[E_INVALID_ARG]"); - - _AppWidgetContext* pAppWidgetContext = Find(pId); - SysTryReturn(NID_SHELL, pAppWidgetContext, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]"); - - result r = __appWidgetContextList.Remove(pAppWidgetContext->GetInstanceId()); - - delete pAppWidgetContext; - - SysLog(NID_SHELL, "AppWidget(%s, %s) is removed. remain count(%d)", pProviderId, pId, __appWidgetContextList.GetCount()); - return r; + return pAppContext->AddAppWidget(userInfo, providerId, instanceId, width, height, period, priority); } /////////////////////////////////////////////////////// @@ -321,7 +263,7 @@ AppWidgetManagerService::OnAppWidgetCreate(struct event_arg *arg, int *width, in 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); AppWidgetManagerService* pAppWidgetService = AppWidgetManagerService::GetInstance(); - SysTryReturn (NID_SHELL, pAppWidgetService->Find(arg->id) == null, -EBUSY, E_SUCCESS,"already exist"); +// SysTryReturn (NID_SHELL, pAppWidgetService->FindAppWidget(ExtractAppId(arg->pkgname), arg->id) == null, -EBUSY, E_SUCCESS,"already exist"); const double default_priority = 1.0f; _AppWidgetContext* pAppWidgetContext = pAppWidgetService->AddAppWidget(arg->info.lb_create.content, arg->pkgname, arg->id, arg->info.lb_create.width, arg->info.lb_create.height, arg->info.lb_create.period * 1000, default_priority); @@ -339,12 +281,16 @@ AppWidgetManagerService::OnAppWidgetUpdate(struct event_arg *arg, void* data) bool isInstanceIdSpecified = (arg->id == null || strlen(arg->id) < 1) ? false : true; if (isInstanceIdSpecified == false) { - AppWidgetManagerService::GetInstance()->UpdateAppWidgetsByProviderId(arg->pkgname); + AppId appId; + String providerName; + _AppWidgetManagerImpl::ExtractAppIdAndProviderName(arg->pkgname, appId, providerName); + + AppWidgetManagerService::GetInstance()->RequestUpdate(appId, providerName, L""); } else { - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(arg->id); - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(arg->pkgname), arg->id); + SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); pAppWidgetContext->OnUpdate(L""); } @@ -353,43 +299,16 @@ AppWidgetManagerService::OnAppWidgetUpdate(struct event_arg *arg, void* data) } int -AppWidgetManagerService::UpdateAppWidgetsByProviderId(const String& providerId) -{ - SysLog(NID_SHELL, ""); - - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum(__appWidgetContextList.GetMapEnumeratorN()); - SysTryReturn(NID_SHELL, pAppWidgetContextEnum, 0, E_SYSTEM, "[E_SYSTEM]"); - - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); - - if (pContext->GetProviderId() == providerId) - { - pContext->OnUpdate(L""); - } - } - - return 0; -} - -int AppWidgetManagerService::OnAppWidgetDestroy(struct event_arg *arg, void* data) { SysTryReturn (NID_SHELL, arg->type == event_arg::EVENT_DELETE, -EPERM, E_SUCCESS, "invalid argument from master"); SysLog(NID_SHELL, "Enter"); - AppWidgetManagerService* pAppWidgetManagerService = AppWidgetManagerService::GetInstance(); - - _AppWidgetContext* pAppWidgetContext = pAppWidgetManagerService->Find(arg->id); - SysSecureTryReturn(NID_SHELL, pAppWidgetContext, 0, E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); - - result r = pAppWidgetContext->OnRemoved(); - SysTryReturn(NID_SHELL, !IsFailed(r), 0, E_SYSTEM, "[E_SYSTEM] Failed to execute OnRemoved."); + _AppContext* pAppContext = null; + result r = AppWidgetManagerService::GetInstance()->__appContextList.GetValue(ExtractAppId(arg->pkgname), pAppContext); + SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]"); - r = pAppWidgetManagerService->RemoveAppWidget(arg->pkgname, arg->id); - SysTryReturn(NID_SHELL, !IsFailed(r), 0, E_SYSTEM, "[E_SYSTEM] Failed to execute RemoveAppWidget."); + pAppContext->RemoveAppWidget(arg->id); SysLog(NID_SHELL, "Exit"); return 0; @@ -401,7 +320,7 @@ AppWidgetManagerService::OnAppWidgetPopupCreate(struct event_arg *arg, void* dat SysTryReturn (NID_SHELL, arg->type == event_arg::EVENT_PD_CREATE, -EPERM, E_SUCCESS, "invalid argument from master"); 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); - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(arg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(arg->pkgname), arg->id); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); pAppWidgetContext->OnPopupCreated(arg->info.pd_create.x, arg->info.pd_create.y, arg->info.pd_create.w, arg->info.pd_create.h); @@ -413,7 +332,7 @@ AppWidgetManagerService::OnAppWidgetPopupCreate(struct event_arg *arg, void* dat AppWidgetManagerService::OnAppWidgetPopupDestroy(struct event_arg *arg, void* data) { SysTryReturn (NID_SHELL, arg->type == event_arg::EVENT_PD_DESTROY, -EPERM, E_SUCCESS, "invalid argument from master"); - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(arg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(arg->pkgname), arg->id); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id); @@ -427,7 +346,7 @@ AppWidgetManagerService::OnAppWidgetBackground(struct event_arg *arg, void* data { SysTryReturn(NID_SHELL, arg, 0, E_SUCCESS, "arg is null!"); - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(arg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(arg->pkgname), arg->id); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , 0, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", arg->pkgname, arg->id); @@ -439,15 +358,18 @@ AppWidgetManagerService::OnAppWidgetBackground(struct event_arg *arg, void* data int AppWidgetManagerService::OnAppWidgetBackgroundAll(struct event_arg *arg, void* data) { - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum((AppWidgetManagerService::GetInstance()->__appWidgetContextList).GetMapEnumeratorN()); - SysTryReturn(NID_SHELL, pAppWidgetContextEnum, -1, E_SYSTEM, "[E_SYSTEM]"); + unique_ptr< IMapEnumeratorT > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()"); - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + while (pAppContextEnum->MoveNext() == E_SUCCESS) { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); + _AppContext* pAppContext = null; + pAppContextEnum->GetValue(pAppContext); - pContext->OnBackground(); + if (pAppContext) + { + pAppContext->OnAppWidgetBackgroundAll(); + } } return 0; @@ -457,27 +379,31 @@ int AppWidgetManagerService::OnAppWidgetForeground(struct event_arg *pArg, void* pData) { SysTryReturn(NID_SHELL, pArg || pArg->id || pArg->pkgname, 0, E_SUCCESS, "pArg is null!"); + SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", pArg->pkgname, pArg->id); - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(pArg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(pArg->pkgname), pArg->id); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", pArg->pkgname, pArg->id); - SysSecureLog(NID_SHELL, "providerId(%s), id(%s)", pArg->pkgname, pArg->id); pAppWidgetContext->OnForeground(); + return 0; } int AppWidgetManagerService::OnAppWidgetForegroundAll(struct event_arg *pArg, void* pData) { - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum((AppWidgetManagerService::GetInstance()->__appWidgetContextList).GetMapEnumeratorN()); - SysTryReturn(NID_SHELL, pAppWidgetContextEnum, -1, E_SYSTEM, "[E_SYSTEM]"); + unique_ptr< IMapEnumeratorT > pAppContextEnum(AppWidgetManagerService::GetInstance()->__appContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()"); - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) + while (pAppContextEnum->MoveNext() == E_SUCCESS) { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); + _AppContext* pAppContext = null; + pAppContextEnum->GetValue(pAppContext); - pContext->OnForeground(); + if (pAppContext) + { + pAppContext->OnAppWidgetForegroundAll(); + } } return 0; @@ -501,7 +427,7 @@ AppWidgetManagerService::OnAppWidgetResize(struct event_arg *arg, void* data) 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); - _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->Find(arg->id); + _AppWidgetContext* pAppWidgetContext = AppWidgetManagerService::GetInstance()->FindAppWidget(ExtractAppId(arg->pkgname), arg->id); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for providerId(%s), instanceId(%s)", arg->pkgname, arg->id); pAppWidgetContext->OnResize(arg->info.resize.w, arg->info.resize.h); @@ -523,6 +449,7 @@ AppWidgetManagerService::OnAppWidgetRecreate(struct event_arg *arg, void* data) SysTryReturn(NID_SHELL, arg != null, EINVAL, E_INVALID_ARG, "[E_INVALID_ARG]"); SysTryReturn(NID_SHELL, arg->pkgname != null, EINVAL, E_INVALID_ARG, "[E_INVALID_ARG]"); SysTryReturn(NID_SHELL, arg->id != null, EINVAL, E_INVALID_ARG, "[E_INVALID_ARG]"); + SysTryReturn(NID_SHELL, arg->type == event_arg::EVENT_RENEW, -EPERM, E_SUCCESS, "invalid argument from master"); 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); @@ -544,8 +471,8 @@ AppWidgetManagerService::InitializeCoreDaemonEventReceiver(const char *pCoreDaem struct event_handler cbs; memset(&cbs, 0, sizeof(event_handler)); - cbs.connected = AppWidgetConnected, - cbs.disconnected = AppWidgetDisconnected, + cbs.connected = OnAppWidgetServiceConnected, + cbs.disconnected = OnAppWidgetServiceCDisconnected, cbs.pause = OnAppWidgetBackgroundAll, cbs.resume = OnAppWidgetForegroundAll, cbs.lb_pause = OnAppWidgetBackground, @@ -581,67 +508,53 @@ AppWidgetManagerService::DeinitializeCoreDaemonEventReceiver(void) result -AppWidgetManagerService::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) +AppWidgetManagerService::RequestUpdate(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, const Tizen::Base::String& argument) const { - bool found = false; - bool updateAllSuspended = appId.IsEmpty(); - - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum((AppWidgetManagerService::GetInstance()->__appWidgetContextList).GetMapEnumeratorN()); - SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, ""); - - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); - - if ( (updateAllSuspended == true && AppManager::GetInstance()->IsRunning(appId) == false ) - || ( pContext->GetAppId() == appId && pContext->GetProviderName() == providerName ) ) - { - RequestUpdate(pContext, argument); - found = true; - } - } + _AppContext* pAppContext = null; + result r = __appContextList.GetValue(appId, pAppContext); + SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() ); - SysLog(NID_SHELL, "Exit."); - return (found) ? E_SUCCESS : E_OBJ_NOT_FOUND; + return pAppContext->RequestUpdate(providerName, argument); } -// for resuming result -AppWidgetManagerService::RequestUpdate(_AppWidgetContext* pAppWidgetContext, const String& argument) +AppWidgetManagerService::RequestUpdateAllSuspened(void) const { - SysTryReturnResult( NID_SHELL, pAppWidgetContext, E_INVALID_STATE, "pAppWidgetContext is null."); + unique_ptr< IMapEnumeratorT > pAppContextEnum(__appContextList.GetMapEnumeratorN()); + SysTryReturnResult(NID_SHELL, pAppContextEnum, E_SYSTEM, "Failed to invoke __appContextList.GetMapEnumeratorN()"); - ArrayList* pArray = new (std::nothrow) ArrayList(); - SysTryReturnResult(NID_SHELL, pArray, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + while (pAppContextEnum->MoveNext() == E_SUCCESS) + { + _AppContext* pAppContext = null; + pAppContextEnum->GetValue(pAppContext); - pArray->Construct(); - pArray->Add(pAppWidgetContext); - pArray->Add(new String(argument)); + if ( pAppContext && AppManager::GetInstance()->IsRunning(pAppContext->GetAppId()) == false ) + { + pAppContext->RequestUpdate(L"", L""); + } - result r = __handlerThread.SendUserEvent(LOCAL_EVENT_REQUEST_UPDATE, pArray); - SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r)); - SysLog(NID_SHELL, "UserEvent(%d) is sent for '%ls.%ls'.", LOCAL_EVENT_REQUEST_UPDATE, pAppWidgetContext->GetAppId().GetPointer(), pAppWidgetContext->GetProviderName().GetPointer() ); + } + SysLog(NID_SHELL, "Exit."); return E_SUCCESS; } result -AppWidgetManagerService::RequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument) +AppWidgetManagerService::RequestUpdateInstance(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, const Tizen::Base::String& argument) { SysSecureLog(NID_SHELL, "%ls, %ls", instanceId.GetPointer(), argument.GetPointer() ); - _AppWidgetContext* pAppWidgetContext = Find(instanceId); + _AppWidgetContext* pAppWidgetContext = FindAppWidget(appId, instanceId); SysTryReturnResult(NID_SHELL, pAppWidgetContext, E_OBJ_NOT_FOUND, "Failed to find the object(%ls).", instanceId.GetPointer()); - RequestUpdate(pAppWidgetContext, argument); + pAppWidgetContext->RequestUpdate(argument); return E_SUCCESS; } result AppWidgetManagerService::AcquireRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId) { - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); + _AppWidgetContext* pAppWidgetContext = this->FindAppWidget(appId, instanceId); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); bufferId = pAppWidgetContext->AcquireRemoteBuffer(width, height); @@ -653,7 +566,7 @@ AppWidgetManagerService::AcquireRemoteBuffer(const Tizen::App::AppId& appId, con result AppWidgetManagerService::AcquireRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& bufferId) { - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); + _AppWidgetContext* pAppWidgetContext = this->FindAppWidget(appId, instanceId); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); _AppWidgetPopupContext* pPopupContext = pAppWidgetContext->GetAppWidgetPopup(); @@ -668,7 +581,7 @@ AppWidgetManagerService::AcquireRemoteBufferForPD(const Tizen::App::AppId& appId result AppWidgetManagerService::SyncRemoteBuffer(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height) { - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); + _AppWidgetContext* pAppWidgetContext = this->FindAppWidget(appId, instanceId); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); return pAppWidgetContext->SyncRemoteBuffer(width, height); @@ -677,7 +590,7 @@ AppWidgetManagerService::SyncRemoteBuffer(const Tizen::App::AppId& appId, const result AppWidgetManagerService::SyncRemoteBufferForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId) { - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); + _AppWidgetContext* pAppWidgetContext = this->FindAppWidget(appId, instanceId); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext->GetAppWidgetPopup(), E_SYSTEM, "[E_SYSTEM] GetAppWidgetPopup() returns null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); @@ -701,26 +614,18 @@ AppWidgetManagerService::RequestProviderCount(const Tizen::App::AppId& appId, co { SysLog(NID_SHELL, "ENTER"); - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext, E_SYSTEM, "pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); - - providerCount = GetProviderCount(pAppWidgetContext->GetAppId()); - - std::unique_ptr providerId(_StringConverter::CopyToCharArrayN(pAppWidgetContext->GetProviderId())); - std::unique_ptr id(_StringConverter::CopyToCharArrayN(pAppWidgetContext->GetInstanceId())); - - int ret = provider_send_deleted(providerId.get(), id.get()); - SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_send_deleted."); + _AppContext* pAppContext = null; + result r = __appContextList.GetValue(appId, pAppContext); + SysTryReturn(NID_SHELL, pAppContext, null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND]"); - //result r = pAppWidgetContext->OnRemoved(); - //SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute OnRemoved."); + providerCount = pAppContext->GetProviderCount(appId); - result r = RemoveAppWidget(providerId.get(), id.get()); + r = pAppContext->RemoveAppWidget(instanceId, false); SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute RemoveAppWidget."); providerCount--; - RequestPendingEvent(); + pAppContext->SendPendingEvent(); return E_SUCCESS; } @@ -728,45 +633,13 @@ AppWidgetManagerService::RequestProviderCount(const Tizen::App::AppId& appId, co result AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, bool isSucceeded) { - _AppWidgetContext* pAppWidgetContext = null; + _AppContext* pAppContext = null; + result r = __appContextList.GetValue(appId, pAppContext); + SysTryReturn(NID_SHELL, !IsFailed(r), null, E_OBJ_NOT_FOUND, "appId(%ls) is not found", appId.GetPointer() ); if (!isSucceeded) { - SysLog(NID_SHELL, "SendResult is called[false]."); - - if (instanceId == INVALID_INSTANCE) - { - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum((AppWidgetManagerService::GetInstance()->__appWidgetContextList).GetMapEnumeratorN()); - SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, ""); - - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - pAppWidgetContextEnum->GetValue(pAppWidgetContext); - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext, E_SYSTEM, "pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); - - if (pAppWidgetContext->GetAppContext()->GetConnectionState() == CONNECTION_STATE_NONE) - { - break; - } - } - } - else - { - pAppWidgetContext = this->Find(instanceId); - } - - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext, E_SYSTEM, "pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); - - std::unique_ptr providerId(_StringConverter::CopyToCharArrayN(pAppWidgetContext->GetProviderId())); - std::unique_ptr id(_StringConverter::CopyToCharArrayN(pAppWidgetContext->GetInstanceId())); - - int ret = provider_send_deleted(providerId.get(), id.get()); - SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_send_deleted."); - - //result r = pAppWidgetContext->OnRemoved(); - //SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute OnRemoved."); - - result r = RemoveAppWidget(providerId.get(), id.get()); + r = pAppContext->RemoveAppWidget(instanceId, false); SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to execute RemoveAppWidget."); } else // for pending event excluding touch event. @@ -774,7 +647,7 @@ AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen: SysLog(NID_SHELL, "SendResult is called[true]."); } - RequestPendingEvent(); + pAppContext->SendPendingEvent(); return E_SUCCESS; } @@ -782,43 +655,14 @@ AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen: result AppWidgetManagerService::SendAccessStatus(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int accessStatus) { - _AppWidgetContext* pAppWidgetContext = this->Find(instanceId); + _AppWidgetContext* pAppWidgetContext = this->FindAppWidget(appId, instanceId); SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); return pAppWidgetContext->SendAccessStatus(accessStatus); } -result -AppWidgetManagerService::RequestPendingEvent(void) -{ - unique_ptr< IMapEnumeratorT > pAppWidgetContextEnum((AppWidgetManagerService::GetInstance()->__appWidgetContextList).GetMapEnumeratorN()); - SysTryReturnResult(NID_SHELL, pAppWidgetContextEnum, E_SYSTEM, ""); - - result r = E_SUCCESS; - - while (pAppWidgetContextEnum->MoveNext() == E_SUCCESS) - { - _AppWidgetContext* pContext = null; - pAppWidgetContextEnum->GetValue(pContext); - - r = pContext->SendPendingEvent(); - if (r == E_SUCCESS) - { - SysLog(NID_SHELL, "Found pending event."); - break; - } - } - - return E_SUCCESS; -} - -AppWidgetManagerService::_TaskHandlerThread::~_TaskHandlerThread(void) -{ - -} - void -AppWidgetManagerService::_TaskHandlerThread::OnUserEventReceivedN(RequestId reqId, IList* pArgs) +AppWidgetManagerService::OnUserEventReceivedN(RequestId reqId, IList* pArgs) { SysTryReturnVoidResult(NID_SHELL, pArgs != null, E_INVALID_STATE, "pArgs is null!."); diff --git a/src/FShell_AppWidgetManagerStub.cpp b/src/FShell_AppWidgetManagerStub.cpp index 571f700..28e7d02 100644 --- a/src/FShell_AppWidgetManagerStub.cpp +++ b/src/FShell_AppWidgetManagerStub.cpp @@ -88,26 +88,26 @@ bool _AppWidgetManagerStub::OnRequestUpdateInstance(const Tizen::Base::String& instanceId, const Tizen::Base::String& argument, result* pRes) { SysLog(NID_SHELL, ""); - *pRes = RequestUpdateInstance(instanceId, argument); + *pRes = RequestUpdateInstance(__pIpcServer->GetClientApplicationId(), instanceId, argument); return true; } bool -_AppWidgetManagerStub::OnAcquireRemoteBuffer(const String& instanceId, int w, int h, int* pShmId) +_AppWidgetManagerStub::OnAcquireRemoteBuffer(const String& instanceId, int w, int h, int* pBufferId) { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - AcquireRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId); + AcquireRemoteBuffer(__pIpcServer->GetClientApplicationId(), instanceId, w, h, *pBufferId); return true; } bool -_AppWidgetManagerStub::OnAcquireRemoteBufferForPD(const String& instanceId, int w, int h, int* pShmId) +_AppWidgetManagerStub::OnAcquireRemoteBufferForPD(const String& instanceId, int w, int h, int* pBufferId) { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - AcquireRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId, w, h, *pShmId); + AcquireRemoteBufferForPD(__pIpcServer->GetClientApplicationId(), instanceId, w, h, *pBufferId); return true; } @@ -117,7 +117,7 @@ _AppWidgetManagerStub::OnSyncRemoteBuffer(const String& instanceId, int w, int h { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - *pRes = SyncRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId, w, h); + *pRes = SyncRemoteBuffer(__pIpcServer->GetClientApplicationId(), instanceId, w, h); return true; } @@ -127,7 +127,7 @@ _AppWidgetManagerStub::OnSyncRemoteBufferForPD(const String& instanceId, result* { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - *pRes = SyncRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId); + *pRes = SyncRemoteBufferForPD(__pIpcServer->GetClientApplicationId(), instanceId); return true; } @@ -137,7 +137,7 @@ _AppWidgetManagerStub::OnReleaseRemoteBuffer(const String& instanceId, result* p { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - *pRes = ReleaseRemoteBuffer(__pIpcServer->GetClientPackageId(), instanceId); + *pRes = ReleaseRemoteBuffer(__pIpcServer->GetClientApplicationId(), instanceId); return true; } @@ -147,7 +147,7 @@ _AppWidgetManagerStub::OnReleaseRemoteBufferForPD(const String& instanceId, resu { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - *pRes = ReleaseRemoteBufferForPD(__pIpcServer->GetClientPackageId(), instanceId); + *pRes = ReleaseRemoteBufferForPD(__pIpcServer->GetClientApplicationId(), instanceId); return true; } @@ -157,7 +157,7 @@ _AppWidgetManagerStub::OnRequestProviderCount(const String& instanceId, int* pPr { SysSecureLog(NID_SHELL, "(instanceId:%ls)", instanceId.GetPointer()); - RequestProviderCount(__pIpcServer->GetClientPackageId(), instanceId, *pProviderCount); + RequestProviderCount(__pIpcServer->GetClientApplicationId(), instanceId, *pProviderCount); return true; } @@ -167,7 +167,7 @@ _AppWidgetManagerStub::OnSendResult(const String& instanceId, bool isSucceeded) { SysSecureLog(NID_SHELL, "(instanceId:%ls, data:%d)", instanceId.GetPointer(), isSucceeded); - SendResult(__pIpcServer->GetClientPackageId(), instanceId, isSucceeded); + SendResult(__pIpcServer->GetClientApplicationId(), instanceId, isSucceeded); return true; } @@ -177,7 +177,7 @@ _AppWidgetManagerStub::OnSendAccessStatus(const String& instanceId, int accessSt { SysSecureLog(NID_SHELL, "(instanceId:%ls, data:%d)", instanceId.GetPointer(), accessStatus); - SendAccessStatus(__pIpcServer->GetClientPackageId(), instanceId, accessStatus); + SendAccessStatus(__pIpcServer->GetClientApplicationId(), instanceId, accessStatus); return true; } diff --git a/src/FShell_AppWidgetPopupContext.cpp b/src/FShell_AppWidgetPopupContext.cpp index fffea88..a1190e7 100644 --- a/src/FShell_AppWidgetPopupContext.cpp +++ b/src/FShell_AppWidgetPopupContext.cpp @@ -87,7 +87,7 @@ _AppWidgetPopupContext::SendPopupCreateRequest(double x, double y, int width, in pArgs->Add(new String(ARG_KEY_POPUP_WIDTH), new String(Integer::ToString(width))); pArgs->Add(new String(ARG_KEY_POPUP_HEIGHT), new String(Integer::ToString(height))); - return __pParent->SendPopupRequestToApp(__pParent->GetAppId(), APPWIDGET_POPUP_ON_CREATE, pArgs.get()); + return _AppWidgetRequestHelper::SendAppControlRequest(__pParent->GetAppId(), APPWIDGET_POPUP_ON_CREATE, pArgs.get()); } result @@ -95,7 +95,7 @@ _AppWidgetPopupContext::SendPopupDestroyRequest(void) { std::unique_ptr pArgs (__pParent->CreateRequestArgsN() ); - return __pParent->SendPopupRequestToApp(__pParent->GetAppId(), APPWIDGET_POPUP_ON_DESTROY, pArgs.get()); + return _AppWidgetRequestHelper::SendAppControlRequest(__pParent->GetAppId(), APPWIDGET_POPUP_ON_DESTROY, pArgs.get()); } void @@ -118,11 +118,11 @@ _AppWidgetPopupContext::SyncRemoteBuffer(void) return E_SUCCESS; } -int +/*int _AppWidgetPopupContext::GetClientId(void) const { return __pParent->GetAppContext()->GetClientId(); -} +}*/ int _AppWidgetPopupContext::AcquireRemoteBuffer(int w, int h) const diff --git a/src/OspAppWidgetService.cpp b/src/OspAppWidgetService.cpp index 1cafb22..d14cc14 100644 --- a/src/OspAppWidgetService.cpp +++ b/src/OspAppWidgetService.cpp @@ -114,3 +114,9 @@ OspAppWidgetService::OnAppControlRequestReceived(RequestId reqId, const Tizen::B isServiceCreated = true; } } + +void +OspAppWidgetService::OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs) +{ + AppWidgetManagerService::GetInstance()->OnUserEventReceivedN(reqId, pArgs); +} -- 2.7.4