From: kyeongwoo.lee Date: Tue, 9 Jul 2013 08:28:31 +0000 (+0900) Subject: 1) _AppWidgetContextBase is removed and _AppWidgetContext includes the drop view. X-Git-Tag: submit/tizen/20130912.075546~18^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29246f80dec98f105e0ee2577de9de482daabdd7;p=platform%2Fframework%2Fnative%2Fappwidget-service.git 1) _AppWidgetContextBase is removed and _AppWidgetContext includes the drop view. 2) add _AppWidgetRemoteBuffer class 3) remove dependency between _AppWidgetManagerService and _AppWidgetRemoteBuffer 4) add listener for touch event Change-Id: Id688494d5dbb5a591b48c0af3e9187ea5f916483 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c52ed1..538baa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ SET (${this_target}_SOURCE_FILES src/OspAppWidgetService.cpp src/OspAppWidgetServiceEntry.cpp src/FShell_AppWidgetContext.cpp - src/FShell_AppWidgetContextBase.cpp + src/FShell_AppWidgetRemoteBuffer.cpp src/FShell_AppWidgetManagerService.cpp src/FShell_AppWidgetManagerStub.cpp src/FShell_AppWidgetPopupContext.cpp diff --git a/inc/FShell_AppWidgetContext.h b/inc/FShell_AppWidgetContext.h index 367d9a9..aa42d5c 100644 --- a/inc/FShell_AppWidgetContext.h +++ b/inc/FShell_AppWidgetContext.h @@ -25,9 +25,10 @@ #define _FSHELL_INTERNAL_APPWIDGET_CONTEXT_H_ #include +#include #include #include -#include "FShell_AppWidgetContextBase.h" +#include "FShell_AppWidgetRemoteBuffer.h" namespace Tizen { namespace Base { namespace Collection { @@ -37,10 +38,22 @@ class HashMap; namespace Tizen { namespace Shell { namespace App { -class _AppWidgetPopupContext; +extern const wchar_t ARG_KEY_INSTANCE_ID[]; +extern const wchar_t ARG_KEY_PROVIDER_NAME[]; +extern const wchar_t ARG_KEY_USER_INFO[]; +extern const wchar_t ARG_KEY_X[]; +extern const wchar_t ARG_KEY_Y[]; +extern const wchar_t ARG_KEY_WIDTH[]; +extern const wchar_t ARG_KEY_HEIGHT[]; +extern const wchar_t ARG_KEY_POPUP_WIDTH[]; +extern const wchar_t ARG_KEY_POPUP_HEIGHT[]; +extern const wchar_t ARG_KEY_ARGUMENT[]; +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; //////////////////////////////////////////////// // _AppContext @@ -79,44 +92,67 @@ private: // _AppWidgetContext //////////////////////////////////////////////// class _AppWidgetContext - : public _AppWidgetContextBase - , public Tizen::Base::Runtime::ITimerEventListener + : public Tizen::Base::Runtime::ITimerEventListener + , public _IAppWidgetRemoteBufferEventListener + , public Tizen::Base::Object { public: _AppWidgetContext(_AppContext* pAppContext, const Tizen::Base::String& name, const Tizen::Base::String& appId, const Tizen::Base::String& instanceId, int width, int height, int period, int priority); virtual ~_AppWidgetContext(void); + // handle dynamic box void OnAdded(void); void OnUpdate(const Tizen::Base::String& argument); void OnResize(int width, int height); result OnRemoved(void); + result SendPendingEvent(void); + int GetPeriod(void) const; + long long GetLastUpdatedTime(void) const; + bool IsForeground(void) const; + void SetForeground(bool forground); + int GetSharedMemId(int w, int h) const; + void OnDisconnected(void); + virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y); + // dynamic box state bool IsPaused(void) const; void OnForeground(void); void OnBackground(void); - virtual void OnPopupCreated(double x, double y, int width, int height); - virtual void OnPopupDestoyed(void); + // handle drop view + 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); - virtual result SendTouchEvent(buffer_event event, double timestamp, double x, double y); - result RequestUpdateRemote(int width, int height); - result SendPendingEvent(void); - result SendAccessStatus(int accessStatus); - - int GetPeriod(void) const; - long long GetLastUpdatedTime(void) const; - + // for common _AppContext* GetAppContext(void) const; + result SendAccessStatus(int accessStatus); + result RequestUpdateRemote(int width, int height); + Tizen::Base::String GetAppId(void) const; + Tizen::Base::String GetProviderName(void) const; + + Tizen::Base::String GetUserInfo(void) const; + void SetUserInfo(const Tizen::Base::String& userInfo); + Tizen::Base::String GetProviderId(void) const; + void SetProviderId(const Tizen::Base::String& providerId); + Tizen::Base::String GetInstanceId(void) const; + void SetInstanceId(const Tizen::Base::String& instanceId); + int GetWidth(void) const; + void SetWidth(int width); + int GetHeight(void) const; + void SetHeight(int height); + int GetPriority(void) const; + 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 SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs); 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 Tizen::Base::Collection::HashMap* CreateRequestArgsN(void); int GetClientId(void) const; @@ -143,14 +179,28 @@ private: }; private: - _AppWidgetPopupContext* __pAppWidgetPopup; - Tizen::Base::Runtime::Timer __updateTimer; + mutable bool __isTouchAvailable; + bool __hasPendingRequest; + bool __isForeground; + int __width; + int __height; + int __priority; + int __ipcClientId; int __updateMillis; long long __lastUpdatedTime; - Tizen::Base::Collection::ArrayListT* __pPendingTouchEventList; + + Tizen::Base::String __userInfo; + Tizen::Base::String __providerId; + Tizen::Base::String __instanceId; + Tizen::Base::String __appId; + Tizen::Base::String __providerName; Tizen::Base::String __pendingArgument; - bool __hasPendingRequest; + Tizen::Base::Runtime::Timer __updateTimer; + _AppContext* __pAppContext; + _AppWidgetPopupContext* __pAppWidgetPopup; + _AppWidgetRemoteBuffer* __pAppWidgetRemoteBuffer; + Tizen::Base::Collection::ArrayListT* __pPendingTouchEventList; Tizen::Base::Collection::ArrayListT* __pPendingEventList; }; // class _AppWidgetContext diff --git a/inc/FShell_AppWidgetContextBase.h b/inc/FShell_AppWidgetContextBase.h deleted file mode 100644 index d192c51..0000000 --- a/inc/FShell_AppWidgetContextBase.h +++ /dev/null @@ -1,111 +0,0 @@ -// -// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.1 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/** - * @file FShell_AppWidgetContextBase.h - * @brief This is the header file for the _AppWidgetContextBase class. - * - * This header file contains the declarations of the _AppWidgetContextBase class. - */ - -#ifndef _FSHELL_INTERNAL_APPWIDGET_CONTEXT_BASE_H_ -#define _FSHELL_INTERNAL_APPWIDGET_CONTEXT_BASE_H_ - -#include -#include - -#define APPWIDGET_PROVIDER_ID_ENABLE true - -namespace Tizen { namespace Base { namespace Collection -{ -class HashMap; -}}} - -namespace Tizen { namespace Shell { namespace App -{ - -class _AppWidgetContextBase - : public Tizen::Base::Object -{ -public: - _AppWidgetContextBase(target_type type, const Tizen::Base::String& userInfo, const Tizen::Base::String& providerId, const Tizen::Base::String& instanceId, int width, int height, int priority); - virtual ~_AppWidgetContextBase(void); - virtual void OnPopupCreated(double x, double y, int width, int height) = 0; - virtual void OnPopupDestoyed(void) = 0; - virtual result SendTouchEvent(buffer_event event, double timestamp, double x, double y) = 0; - - // for buffered appWidget - int GetSharedMemId(int w, int h); - result ReleaseSharedMem(void); - - Tizen::Base::String GetInstanceId(void) const; - int GetWidth(void) const; - int GetHeight(void) const; - Tizen::Base::String GetProviderId(void) const; - Tizen::Base::String GetAppId(void) const; - int GetPriority(void) const; - Tizen::Base::String GetProviderName(void) const; - - void OnDisconnected(void); - bool IsRemoteBufferCreated(void) const; - -protected: - bool IsSharedMemCreated(void) const; - virtual Tizen::Base::Collection::HashMap* CreateRequestArgsN(void) = 0; - result SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs); - result SendRequestToApp(const int clientId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs); - void SetForeground(bool forground); - bool IsForeground(void) const; - Tizen::Base::String GetUserInfo(void) const; - void SetWidth(int width); - void SetHeight(int height); - -protected: - bool __isRemoteBufferCreated; - -private: - target_type __type; - Tizen::Base::String __userInfo; - Tizen::Base::String __providerId; - Tizen::Base::String __instanceId; - int __width; - int __height; - int __priority; - bool __isForeground; - int __ipcClientId; - Tizen::Base::String __appId; - Tizen::Base::String __providerName; - struct livebox_buffer *__buffer_info; - void *__buffer; - -}; // class _AppWidgetContextBase - -extern const Tizen::Base::String ARG_KEY_INSTANCE_ID; -extern const Tizen::Base::String ARG_KEY_PROVIDER_NAME; -extern const Tizen::Base::String ARG_KEY_USER_INFO; -extern const Tizen::Base::String ARG_KEY_X; -extern const Tizen::Base::String ARG_KEY_Y; -extern const Tizen::Base::String ARG_KEY_WIDTH; -extern const Tizen::Base::String ARG_KEY_HEIGHT; -extern const Tizen::Base::String ARG_KEY_POPUP_WIDTH; -extern const Tizen::Base::String ARG_KEY_POPUP_HEIGHT; -extern const Tizen::Base::String ARG_KEY_ARGUMENT; -extern const Tizen::Base::String ARG_KEY_EVENT_TYPE; -extern const Tizen::Base::String ARG_KEY_TIME_STAMP; - -}}} // Tizen::Shell::App - -#endif // _FSHELL_INTERNAL_APPWIDGET_CONTEXT_BASE_H_ diff --git a/inc/FShell_AppWidgetPopupContext.h b/inc/FShell_AppWidgetPopupContext.h index 656e479..73bd333 100644 --- a/inc/FShell_AppWidgetPopupContext.h +++ b/inc/FShell_AppWidgetPopupContext.h @@ -24,7 +24,12 @@ #ifndef _FSHELL_INTERNAL_APPWIDGET_POPUP_CONTEXT_H_ #define _FSHELL_INTERNAL_APPWIDGET_POPUP_CONTEXT_H_ -#include "FShell_AppWidgetContextBase.h" +#include "FShell_AppWidgetRemoteBuffer.h" + +namespace Tizen { namespace Base { namespace Collection +{ +class HashMap; +}}} namespace Tizen { namespace Shell { namespace App { @@ -32,10 +37,11 @@ namespace Tizen { namespace Shell { namespace App class _AppWidgetContext; class _AppWidgetPopupContext - :public Tizen::Shell::App::_AppWidgetContextBase + :public Tizen::Base::Object + , public _IAppWidgetRemoteBufferEventListener { public: - _AppWidgetPopupContext(const Tizen::Base::String& userInfo, const Tizen::Base::String& appId, const Tizen::Base::String& instanceId, int width, int height, int priority, _AppWidgetContext* pParent); + _AppWidgetPopupContext(_AppWidgetContext* pParent); virtual ~_AppWidgetPopupContext(void); // event handler @@ -45,15 +51,18 @@ public: // request to app result SendPopupCreateRequest(double x, double y, int width, int height); result SendPopupDestroyRequest(void); - virtual result SendTouchEvent(buffer_event event, double timestamp, double x, double y); result RequestUpdateRemote(void); + int GetSharedMemId(int w, int h) const; + + virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y); private: - virtual Tizen::Base::Collection::HashMap* CreateRequestArgsN(void); + Tizen::Base::Collection::HashMap* CreateRequestArgsN(void); int GetClientId(void) const; private: _AppWidgetContext* __pParent; + _AppWidgetRemoteBuffer* __pAppWidgetRemoteBuffer; }; // class _AppWidgetPopupContext diff --git a/inc/FShell_AppWidgetRemoteBuffer.h b/inc/FShell_AppWidgetRemoteBuffer.h new file mode 100644 index 0000000..ab5cb80 --- /dev/null +++ b/inc/FShell_AppWidgetRemoteBuffer.h @@ -0,0 +1,67 @@ +// +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.1 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FShell_AppWidgetRemoteBuffer.h + * @brief This is the header file for the _AppWidgetRemoteBuffer class. + * + * This header file contains the declarations of the _AppWidgetRemoteBuffer class. + */ + +#ifndef _FSHELL_APPWIDGET_REMOTE_BUFFER_H_ +#define _FSHELL_APPWIDGET_REMOTE_BUFFER_H_ + +#include +#include + +namespace Tizen { namespace Shell { namespace App +{ + +class _IAppWidgetRemoteBufferEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + _IAppWidgetRemoteBufferEventListener(void){} + ~_IAppWidgetRemoteBufferEventListener(void){} + + virtual void OnTouchEventReceived(buffer_event event, double timestamp, double x, double y) = 0; +}; + +class _AppWidgetRemoteBuffer + :public Tizen::Base::Object +{ +public: + _AppWidgetRemoteBuffer(const Tizen::Base::String& providerId, const Tizen::Base::String& instanceId, target_type type, _IAppWidgetRemoteBufferEventListener* pListener); + ~_AppWidgetRemoteBuffer(void); + + int GetSharedMemId(int w, int h); + +private: + result ReleaseSharedMem(void); + +private: + target_type __type; + Tizen::Base::String __providerId; + Tizen::Base::String __instanceId; + void* __buffer; + struct livebox_buffer* __buffer_info; + _IAppWidgetRemoteBufferEventListener* __pListener; + +}; // class _AppWidgetRemoteBuffer + +}}} // Tizen::Shell::App + +#endif // _FSHELL_APPWIDGET_REMOTE_BUFFER_H_ diff --git a/src/FShell_AppWidgetContext.cpp b/src/FShell_AppWidgetContext.cpp index bb91d1f..6fc0274 100644 --- a/src/FShell_AppWidgetContext.cpp +++ b/src/FShell_AppWidgetContext.cpp @@ -31,10 +31,12 @@ #include #include +#include "FShell_AppWidgetManagerImpl.h" #include "FShell_AppWidgetManagerService.h" #include "FShell_AppWidgetPopupContext.h" #include "FShell_AppWidgetContext.h" #include "FShell_AppWidgetContextHelper.h" +#include "FShell_AppWidgetRemoteBuffer.h" namespace Tizen { namespace Shell { namespace App { @@ -45,24 +47,49 @@ using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::System; -const String APPWIDGET_ON_ADD = L"http://tizen.org/appcontrol/appwidget/add"; -const String APPWIDGET_ON_REMOVE = L"http://tizen.org/appcontrol/appwidget/remove"; -const String APPWIDGET_ON_UPDATE = L"http://tizen.org/appcontrol/appwidget/update"; -const String APPWIDGET_ON_RESIZE = L"http://tizen.org/appcontrol/appwidget/resize"; -const String APPWIDGET_ON_TOUCH = L"http://tizen.org/appcontrol/appwidget/touch"; +const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId"; +const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName"; +const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo"; +const wchar_t ARG_KEY_X[] = L"_X"; +const wchar_t ARG_KEY_Y[] = L"_Y"; +const wchar_t ARG_KEY_WIDTH[] = L"_Width"; +const wchar_t ARG_KEY_HEIGHT[] = L"_Height"; +const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth"; +const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight"; +const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument"; +const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType"; +const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp"; + +const wchar_t APPWIDGET_ON_ADD[] = L"http://tizen.org/appcontrol/appwidget/add"; +const wchar_t APPWIDGET_ON_REMOVE[] = L"http://tizen.org/appcontrol/appwidget/remove"; +const wchar_t APPWIDGET_ON_UPDATE[] = L"http://tizen.org/appcontrol/appwidget/update"; +const wchar_t APPWIDGET_ON_RESIZE[] = L"http://tizen.org/appcontrol/appwidget/resize"; +const wchar_t APPWIDGET_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidget/touch"; const int UPDATE_PERIOD_MSEC_MIN = 1800000; // 30min _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& info, const String& providerId, const String& instanceId, int width, int height, int period, int priority) - :_AppWidgetContextBase(TYPE_LB, info, providerId, instanceId, width, height, priority) - ,__pAppWidgetPopup(null) + :__isTouchAvailable(false) + ,__hasPendingRequest(false) + ,__isForeground(true) + ,__width(width) + ,__height(height) + ,__priority(priority) + ,__ipcClientId(-1) ,__updateMillis(period) ,__lastUpdatedTime(0) - ,__pPendingTouchEventList(null) - ,__hasPendingRequest(false) + ,__userInfo(info) + ,__providerId(providerId) + ,__instanceId(instanceId) ,__pAppContext(pAppContext) + ,__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); + // for updating period if (__updateMillis > 0) { @@ -76,10 +103,15 @@ _AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& inf } __pPendingTouchEventList = new (nothrow) ArrayListT(); + 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, ""); } _AppWidgetContext::~_AppWidgetContext(void) @@ -118,6 +150,11 @@ _AppWidgetContext::~_AppWidgetContext(void) __pPendingEventList->RemoveAll(); delete __pPendingEventList; } + + if (__pAppWidgetRemoteBuffer) + { + delete __pAppWidgetRemoteBuffer; + } } _AppContext* @@ -261,7 +298,9 @@ _AppWidgetContext::IsPaused(void) const void _AppWidgetContext::OnPopupCreated(double x, double y, int width, int height) { - __pAppWidgetPopup = new (nothrow) _AppWidgetPopupContext(GetUserInfo(), GetProviderId(), GetInstanceId(), GetWidth(), GetHeight(), GetPriority(), this); + __pAppWidgetPopup = new (nothrow) _AppWidgetPopupContext(this); + SysTryReturnVoidResult(NID_SHELL, __pAppWidgetPopup, E_OUT_OF_MEMORY, ""); + __pAppWidgetPopup->OnPopupCreated(x, y, width, height); } @@ -354,18 +393,17 @@ _AppWidgetContext::SendPendingTouchEvent(void) __pPendingTouchEventList->RemoveAll(); } -result -_AppWidgetContext::SendTouchEvent(buffer_event eventType, double timeStamp, double x, double y) +void +_AppWidgetContext::OnTouchEventReceived(buffer_event event, double timestamp, double x, double y) { - if (__pAppContext->GetConnectionState() == _AppContext::CONNECTED && IsRemoteBufferCreated()) + if (__pAppContext->GetConnectionState() == _AppContext::CONNECTED && __isTouchAvailable) { - SysAssert(IsSharedMemCreated() == true); - SysLog(NID_SHELL, "%d, %f, %f", eventType, x, y); - AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), eventType, timeStamp, x, y); + SysLog(NID_SHELL, "%d, %f, %f", event, x, y); + AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), event, timestamp, x, y); } else { - __pPendingTouchEventList->Add(new (nothrow) PendingTouchEvent(eventType, timeStamp, x, y)); + __pPendingTouchEventList->Add(new (nothrow) PendingTouchEvent(event, timestamp, x, y)); if( AppManager::GetInstance()->IsRunning(this->GetAppId() ) == false) { @@ -373,15 +411,14 @@ _AppWidgetContext::SendTouchEvent(buffer_event eventType, double timeStamp, doub std::unique_ptr pArgs (CreateRequestArgsN() ); // TODO: consider to remove these unused args. - pArgs->Add(new (nothrow) String(ARG_KEY_EVENT_TYPE), new (nothrow) String(Integer::ToString(eventType))); - pArgs->Add(new (nothrow) String(ARG_KEY_TIME_STAMP), new (nothrow) String(Double::ToString(timeStamp))); + pArgs->Add(new (nothrow) String(ARG_KEY_EVENT_TYPE), new (nothrow) String(Integer::ToString(event))); + pArgs->Add(new (nothrow) String(ARG_KEY_TIME_STAMP), new (nothrow) String(Double::ToString(timestamp))); pArgs->Add(new (nothrow) String(ARG_KEY_X), new (nothrow) String(Double::ToString(x))); pArgs->Add(new (nothrow) String(ARG_KEY_Y), new (nothrow) String(Double::ToString(y))); - return SendRequestToApp(GetAppId(), APPWIDGET_ON_TOUCH, pArgs.get()); + SendRequestToApp(GetAppId(), APPWIDGET_ON_TOUCH, pArgs.get()); } } - return E_SUCCESS; } result @@ -392,7 +429,7 @@ _AppWidgetContext::SendRequestToApp(const AppId& appId, const String& operation, if ( __pAppContext->GetConnectionState() == _AppContext::NONE || __pAppContext->GetConnectionState() == _AppContext::DISCONNECTED) { SysLog(NID_SHELL, "The application is not running."); - result r = _AppWidgetContextBase::SendRequestToApp(appId, operation, pArgs); + result r = _AppWidgetRequestHelper::SendAppControlRequest(appId, operation, pArgs); SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "[%s] Failed to SendRequestToApp", GetErrorMessage(r)); __pAppContext->__isWaitingResult = true; @@ -419,6 +456,12 @@ _AppWidgetContext::SendRequestToApp(const AppId& appId, const String& operation, return E_SUCCESS; } +result +_AppWidgetContext::SendPopupRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs) +{ + return _AppWidgetRequestHelper::SendAppControlRequest(appId, operation, pArgs);; +} + result _AppWidgetContext::RequestUpdateRemote(int width, int height) { @@ -481,6 +524,96 @@ _AppWidgetContext::GetClientId(void) const return GetAppContext()->GetClientId(); } +int +_AppWidgetContext::GetWidth(void) const +{ + return __width; +} + +void +_AppWidgetContext::SetWidth(int width) +{ + __width = width; +} + +int +_AppWidgetContext::GetHeight(void) const +{ + return __height; +} + +void +_AppWidgetContext::SetHeight(int height) +{ + __height = height; +} + +String +_AppWidgetContext::GetProviderId(void) const +{ + return __providerId; +} + +void +_AppWidgetContext::SetProviderId(const String& providerId) +{ + __providerId = providerId; +} + +String +_AppWidgetContext::GetAppId(void) const +{ + return __appId; +} + +int +_AppWidgetContext::GetPriority(void) const +{ + return __priority; +} + +void +_AppWidgetContext::SetPriority(int priority) +{ + __priority = priority; +} + +String +_AppWidgetContext::GetProviderName(void) const +{ + return __providerName; +} + +void +_AppWidgetContext::SetForeground(bool foreground) +{ + __isForeground = foreground; +} + +bool +_AppWidgetContext::IsForeground(void) const +{ + return __isForeground; +} + +String +_AppWidgetContext::GetUserInfo(void) const +{ + return __userInfo; +} + +void +_AppWidgetContext::SetUserInfo(const String& userInfo) +{ + __userInfo = userInfo; +} + +String +_AppWidgetContext::GetInstanceId(void) const +{ + return __instanceId; +} + void _AppWidgetContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer) { @@ -491,4 +624,21 @@ _AppWidgetContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer) } } +void +_AppWidgetContext::OnDisconnected(void) +{ + __isTouchAvailable = false; +} + +int +_AppWidgetContext::GetSharedMemId(int w, int h) const +{ + int id = __pAppWidgetRemoteBuffer->GetSharedMemId(w, h); + if (id != -1) + { + __isTouchAvailable = true; + } + return id; +} + }}} // Tizen::Shell::App diff --git a/src/FShell_AppWidgetContextBase.cpp b/src/FShell_AppWidgetContextBase.cpp deleted file mode 100644 index 4c77a35..0000000 --- a/src/FShell_AppWidgetContextBase.cpp +++ /dev/null @@ -1,313 +0,0 @@ -// -// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.1 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/** - * @file FShell_AppWidgetContextBase.cpp - * @brief This is the implementation for the _AppWidgetContextBase class. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "FShell_AppWidgetManagerImpl.h" -#include "FShell_AppWidgetContextBase.h" -#include "FShell_AppWidgetManagerService.h" -#include "FShell_AppWidgetContextHelper.h" - -// provider/src/fb.c -struct fb_info { - char *id; - int w; - int h; - int bufsz; - void *buffer; - - int handle; -}; - -// provider/inc/provider_buffer_internal.h -struct livebox_buffer { - enum { - BUFFER_CREATED = 0x00beef00, - BUFFER_DESTROYED = 0x00dead00, - } state; - - enum target_type type; - - union { - int fd; /* File handle(descriptor) */ - int id; /* SHM handle(id) */ - } handle; - - char *pkgname; - char *id; - int width; - int height; - int pixel_size; - - struct fb_info *fb; - - int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data); - void *data; -}; - -static int AppWidgetHandleBufferEventCallback(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data); - -namespace Tizen { namespace Shell { namespace App -{ - -using namespace Tizen::App; -using namespace Tizen::Base; -using namespace Tizen::Base::Collection; - -extern const String ARG_KEY_INSTANCE_ID = L"_InstanceId"; -extern const String ARG_KEY_PROVIDER_NAME = L"_ProviderName"; -extern const String ARG_KEY_USER_INFO = L"_UserInfo"; -extern const String ARG_KEY_X = L"_X"; -extern const String ARG_KEY_Y = L"_Y"; -extern const String ARG_KEY_WIDTH = L"_Width"; -extern const String ARG_KEY_HEIGHT = L"_Height"; -extern const String ARG_KEY_POPUP_WIDTH = L"_PopupWidth"; -extern const String ARG_KEY_POPUP_HEIGHT = L"_PopupHeight"; -extern const String ARG_KEY_ARGUMENT = L"_Argument"; -extern const String ARG_KEY_EVENT_TYPE = L"_EventType"; -extern const String ARG_KEY_TIME_STAMP = L"_TimeStamp"; - -_AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority) - :__type(type) - ,__userInfo(userInfo) - ,__providerId(providerId) - ,__instanceId(instanceId) - ,__width(width) - ,__height(height) - ,__priority(priority) - ,__isForeground(true) - ,__buffer_info(null) - ,__buffer(null) - ,__isRemoteBufferCreated(false) -{ - _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); -} - -_AppWidgetContextBase::~_AppWidgetContextBase(void) -{ - SysSecureLog(NID_SHELL, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority); - ReleaseSharedMem(); -} - -bool -_AppWidgetContextBase::IsSharedMemCreated(void) const -{ - return ( __buffer_info && __buffer); -} - -int -_AppWidgetContextBase::GetSharedMemId(int w, int h) -{ - SysLog(NID_SHELL, "Enter"); - - bool isResized = (__buffer_info != null) && (__buffer_info->width != w || __buffer_info->height != h); - if ( isResized ) - { - ReleaseSharedMem(); - } - - if( __buffer_info == null) - { - std::unique_ptr packageName(_StringConverter::CopyToCharArrayN(__providerId)); - std::unique_ptr id(_StringConverter::CopyToCharArrayN(__instanceId)); - - __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, this); - SysTryReturnResult(NID_SHELL, __buffer_info , -1, "[E_SYSTEM] failed to provider_buffer_acquire"); - SysLog(NID_SHELL, "provider_buffer_acquire successed"); - - __buffer = provider_buffer_ref(__buffer_info); - SysTryReturnResult(NID_SHELL, __buffer , -1, "[E_SYSTEM] failed to provider_buffer_ref"); - SysLog(NID_SHELL, "provider_buffer_ref successed"); - } - - int bufferId = __buffer_info->fb->handle; - __isRemoteBufferCreated = true; - - SysLog(NID_SHELL, "(%d) Exit", bufferId); - return bufferId; -} - - -void -_AppWidgetContextBase::OnDisconnected(void) -{ - __isRemoteBufferCreated = false; -} - -bool -_AppWidgetContextBase::IsRemoteBufferCreated(void) const -{ - return __isRemoteBufferCreated; -} - -result -_AppWidgetContextBase::ReleaseSharedMem(void) -{ - SysLog(NID_SHELL, "Enter"); - - int ret; - - if( __buffer) - { - ret = provider_buffer_unref(__buffer); - __buffer = null; - SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_unref"); - SysLog(NID_SHELL, "provider_buffer_unref successed"); - } - - if( __buffer_info) - { - ret = provider_buffer_release(__buffer_info); - __buffer_info = null; - SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_buffer_release"); - SysLog(NID_SHELL, "provider_buffer_release successed"); - } - - SysLog(NID_SHELL, "Exit."); - - return E_SUCCESS; -} - -result -_AppWidgetContextBase::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs) -{ - result r = _AppWidgetRequestHelper::SendAppControlRequest(appId, operation, pArgs); - SysTryReturnResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "Failed to SendRequestToApp"); - - return r; -} - -String -_AppWidgetContextBase::GetAppId(void) const -{ - return __appId; -} - -String -_AppWidgetContextBase::GetProviderName(void) const -{ - return __providerName; -} - -String -_AppWidgetContextBase::GetUserInfo(void) const -{ - return __userInfo; -} - -void -_AppWidgetContextBase::SetForeground(bool foreground) -{ - __isForeground = foreground; -} - -bool -_AppWidgetContextBase::IsForeground(void) const -{ - return __isForeground; -} - -int -_AppWidgetContextBase::GetWidth(void) const -{ - return __width; -} - -int -_AppWidgetContextBase::GetHeight(void) const -{ - return __height; -} - -String -_AppWidgetContextBase::GetInstanceId(void) const -{ - return __instanceId; -} - -String -_AppWidgetContextBase::GetProviderId(void) const -{ - return __providerId; -} - -int -_AppWidgetContextBase::GetPriority(void) const -{ - return __priority; -} - -void -_AppWidgetContextBase::SetWidth(int width) -{ - __width = width; -} - -void -_AppWidgetContextBase::SetHeight(int height) -{ - __height = height; -} - -}}} // Tizen::Shell::App - -//////////////////////////////////////////// -// callback -//////////////////////////////////////////// -static int AppWidgetHandleBufferEventCallback( struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data) -{ - SysLog(NID_SHELL, "timestamp(%f), x(%f), y(%f)", timestamp, x, y); - - Tizen::Shell::App::_AppWidgetContextBase *pAppWidgetBase = static_cast(data); - SysTryReturn(NID_SHELL, pAppWidgetBase != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetBase is null"); - - if (event == BUFFER_EVENT_ENTER) - { - SysLog(NID_SHELL, "BUFFER_EVENT_ENTER"); - } - else if (event == BUFFER_EVENT_LEAVE) - { - SysLog(NID_SHELL, "BUFFER_EVENT_LEAVE"); - } - else if (event == BUFFER_EVENT_DOWN) - { - SysLog(NID_SHELL, "BUFFER_EVENT_DOWN"); - } - else if (event == BUFFER_EVENT_MOVE) - { - SysLog(NID_SHELL, "BUFFER_EVENT_MOVE"); - } - else if(event == BUFFER_EVENT_UP) - { - SysLog(NID_SHELL, "BUFFER_EVENT_UP"); - } - - pAppWidgetBase->SendTouchEvent(event, timestamp, x, y); - - return 0; -} diff --git a/src/FShell_AppWidgetContextHelper.cpp b/src/FShell_AppWidgetContextHelper.cpp index 0300d53..b9ce833 100644 --- a/src/FShell_AppWidgetContextHelper.cpp +++ b/src/FShell_AppWidgetContextHelper.cpp @@ -40,8 +40,8 @@ using namespace Tizen::Base::Collection; result _AppWidgetRequestHelper::SendAppControlRequest(const AppId& appId, const String& operation, HashMap* pArgs) { - const String* pInstanceId = dynamic_cast(pArgs->GetValue(ARG_KEY_INSTANCE_ID)); - SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "Failed to GetValue(%ls)", ARG_KEY_INSTANCE_ID.GetPointer() ); + const String* pInstanceId = dynamic_cast(pArgs->GetValue(String(ARG_KEY_INSTANCE_ID))); + SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "Failed to get the instance id."); SysSecureLog(NID_SHELL, "[ac] pInstanceId(%ls), operation(%ls), appId(%ls), arg count(%d)", pInstanceId->GetPointer(), operation.GetPointer(), appId.GetPointer(), pArgs->GetCount()); @@ -82,8 +82,8 @@ _AppWidgetRequestHelper::SendAppControlRequest(const AppId& appId, const String& result _AppWidgetRequestHelper::SendIpcRequest(const int clientId, const String& operation, HashMap* pArgs) { - const String* pInstanceId = dynamic_cast(pArgs->GetValue(ARG_KEY_INSTANCE_ID)); - SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "Failed to GetValue(%ls)", ARG_KEY_INSTANCE_ID.GetPointer() ); + const String* pInstanceId = dynamic_cast(pArgs->GetValue(String(ARG_KEY_INSTANCE_ID))); + SysTryReturnResult(NID_SHELL, pInstanceId, E_FAILURE, "Failed to get the instance id."); SysSecureLog(NID_SHELL, "[ipc] pInstanceId(%ls), operation(%ls), clientId(%d)", pInstanceId->GetPointer(), operation.GetPointer(), clientId); diff --git a/src/FShell_AppWidgetManagerService.cpp b/src/FShell_AppWidgetManagerService.cpp index 93b9f19..ca98ad6 100644 --- a/src/FShell_AppWidgetManagerService.cpp +++ b/src/FShell_AppWidgetManagerService.cpp @@ -688,13 +688,13 @@ result AppWidgetManagerService::RequestSharedMemoryIdForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId, int width, int height, int& shmId) { _AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId); - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); + SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , E_SYSTEM, "pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); - _AppWidgetPopupContext* pPd = pAppWidgetContext->GetAppWidgetPopup(); - SysSecureTryReturnResult(NID_SHELL, pPd , E_SYSTEM, "[E_SYSTEM] pPd is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); + _AppWidgetPopupContext* pPopupContext = pAppWidgetContext->GetAppWidgetPopup(); + SysSecureTryReturnResult(NID_SHELL, pPopupContext , E_SYSTEM, "[E_SYSTEM] pPd is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); - shmId = pPd->GetSharedMemId(width, height); - SysSecureTryReturnResult(NID_SHELL, pAppWidgetContext , shmId != -1, "[E_SYSTEM] failed to GetSharedMemId for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); + shmId = pPopupContext->GetSharedMemId(width, height); + SysSecureTryReturnResult(NID_SHELL, shmId != -1, E_SYSTEM, "Failed to GetSharedMemId for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer()); return E_SUCCESS; } diff --git a/src/FShell_AppWidgetPopupContext.cpp b/src/FShell_AppWidgetPopupContext.cpp index 39e2bdc..e99d027 100644 --- a/src/FShell_AppWidgetPopupContext.cpp +++ b/src/FShell_AppWidgetPopupContext.cpp @@ -32,10 +32,13 @@ #include "FShell_AppWidgetManagerService.h" #include "FShell_AppWidgetContext.h" #include "FShell_AppWidgetPopupContext.h" +#include "FShell_AppWidgetContextHelper.h" +#include "FShell_AppWidgetRemoteBuffer.h" namespace Tizen { namespace Shell { namespace App { +using namespace std; using namespace Tizen::Base; using namespace Tizen::Base::Collection; @@ -43,16 +46,23 @@ const wchar_t APPWIDGET_POPUP_ON_CREATE[] = L"http://tizen.org/appcontrol/appwid const wchar_t APPWIDGET_POPUP_ON_DESTROY[] = L"http://tizen.org/appcontrol/appwidgetpopup/destroy"; const wchar_t APPWIDGET_POPUP_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidgetpopup/touch"; -_AppWidgetPopupContext::_AppWidgetPopupContext(const String& info, const String& appId, const String& instanceId, int width, int height, int priority, _AppWidgetContext* pParent) -:_AppWidgetContextBase(TYPE_PD, info, appId, instanceId, width, height, priority) +_AppWidgetPopupContext::_AppWidgetPopupContext(_AppWidgetContext* pParent) + : __pParent(pParent) { - __pParent = pParent; - SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d)", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight()); + __pAppWidgetRemoteBuffer = new (nothrow) _AppWidgetRemoteBuffer(__pParent->GetProviderId(), __pParent->GetInstanceId(), TYPE_PD, this); + SysTryReturnVoidResult(NID_SHELL, __pAppWidgetRemoteBuffer, E_OUT_OF_MEMORY, ""); + + SysLog(NID_SHELL, "The drop view for %ls is constructed.", (__pParent->GetInstanceId()).GetPointer()); } _AppWidgetPopupContext::~_AppWidgetPopupContext(void) { - SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d))", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight()); + SysLog(NID_SHELL, "The drop view for %ls destructed.", (__pParent->GetInstanceId()).GetPointer()); + + if (__pAppWidgetRemoteBuffer) + { + delete __pAppWidgetRemoteBuffer; + } } void @@ -79,7 +89,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 SendRequestToApp(GetAppId(), APPWIDGET_POPUP_ON_CREATE, pArgs.get()); + return __pParent->SendPopupRequestToApp(__pParent->GetAppId(), APPWIDGET_POPUP_ON_CREATE, pArgs.get()); } result @@ -87,22 +97,21 @@ _AppWidgetPopupContext::SendPopupDestroyRequest(void) { std::unique_ptr pArgs (CreateRequestArgsN() ); - return SendRequestToApp(GetAppId(), APPWIDGET_POPUP_ON_DESTROY, pArgs.get()); + return __pParent->SendPopupRequestToApp(__pParent->GetAppId(), APPWIDGET_POPUP_ON_DESTROY, pArgs.get()); } -result -_AppWidgetPopupContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y) +void +_AppWidgetPopupContext::OnTouchEventReceived(buffer_event event, double timestamp, double x, double y) { SysLog(NID_SHELL, ""); - AppWidgetManagerService::GetInstance()->SendTouchEventForPD(GetClientId(), GetInstanceId(), event, timestamp, x, y); - return E_SUCCESS; + AppWidgetManagerService::GetInstance()->SendTouchEventForPD(__pParent->GetAppContext()->GetClientId(), __pParent->GetInstanceId(), event, timestamp, x, y); } result _AppWidgetPopupContext::RequestUpdateRemote(void) { - std::unique_ptr packageName(_StringConverter::CopyToCharArrayN(GetProviderId())); - std::unique_ptr id(_StringConverter::CopyToCharArrayN(GetInstanceId())); + std::unique_ptr packageName(_StringConverter::CopyToCharArrayN(__pParent->GetProviderId())); + std::unique_ptr id(_StringConverter::CopyToCharArrayN(__pParent->GetInstanceId())); int ret = provider_send_desc_updated(packageName.get(), id.get(), null); SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated"); @@ -114,11 +123,11 @@ _AppWidgetPopupContext::RequestUpdateRemote(void) Tizen::Base::Collection::HashMap* _AppWidgetPopupContext::CreateRequestArgsN(void) { - HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter); + HashMap* pArgs = new (nothrow) HashMap(SingleObjectDeleter); pArgs->Construct(); - pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(GetInstanceId())); - pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(GetProviderName())); - pArgs->Add(new String(ARG_KEY_USER_INFO), new String(GetUserInfo())); + pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__pParent->GetInstanceId())); + pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__pParent->GetProviderName())); + pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__pParent->GetUserInfo())); pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__pParent->GetWidth()))); pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__pParent->GetHeight()))); @@ -131,4 +140,10 @@ _AppWidgetPopupContext::GetClientId(void) const return __pParent->GetAppContext()->GetClientId(); } +int +_AppWidgetPopupContext::GetSharedMemId(int w, int h) const +{ + return __pAppWidgetRemoteBuffer->GetSharedMemId(w, h); +} + }}} // Tizen::Shell::App diff --git a/src/FShell_AppWidgetRemoteBuffer.cpp b/src/FShell_AppWidgetRemoteBuffer.cpp new file mode 100644 index 0000000..677e028 --- /dev/null +++ b/src/FShell_AppWidgetRemoteBuffer.cpp @@ -0,0 +1,182 @@ +// +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Flora License, Version 1.1 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://floralicense.org/license/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FShell_AppWidgetRemoteBuffer.cpp + * @brief This is the implementation for the _AppWidgetRemoteBuffer class. + */ + +#include +#include +#include +#include +#include "FShell_AppWidgetRemoteBuffer.h" + +// provider/src/fb.c +struct fb_info { + char *id; + int w; + int h; + int bufsz; + void *buffer; + + int handle; +}; + +// provider/inc/provider_buffer_internal.h +struct livebox_buffer { + enum { + BUFFER_CREATED = 0x00beef00, + BUFFER_DESTROYED = 0x00dead00, + } state; + + enum target_type type; + + union { + int fd; /* File handle(descriptor) */ + int id; /* SHM handle(id) */ + } handle; + + char *pkgname; + char *id; + int width; + int height; + int pixel_size; + + struct fb_info *fb; + + int (*handler)(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void *data); + void *data; +}; + +static int AppWidgetHandleBufferEventCallback(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data); + +namespace Tizen { namespace Shell { namespace App +{ + +using namespace std; +using namespace Tizen::Base; + +_AppWidgetRemoteBuffer::_AppWidgetRemoteBuffer(const String& providerId, const String& instanceId, target_type type, _IAppWidgetRemoteBufferEventListener* pListener) + :__type(type) + ,__providerId(providerId) + ,__instanceId(instanceId) + ,__buffer(null) + ,__buffer_info(null) + ,__pListener(pListener) +{ + SysLog(NID_SHELL, "_AppWidgetRemoteBuffer is constructed."); +} + +_AppWidgetRemoteBuffer::~_AppWidgetRemoteBuffer(void) +{ + ReleaseSharedMem(); + SysLog(NID_SHELL, "_AppWidgetRemoteBuffer is destructed."); +} + +int +_AppWidgetRemoteBuffer::GetSharedMemId(int w, int h) +{ + SysLog(NID_SHELL, "Enter"); + + bool isResized = (__buffer_info != null) && (__buffer_info->width != w || __buffer_info->height != h); + if ( isResized ) + { + ReleaseSharedMem(); + } + + if( __buffer_info == null) + { + std::unique_ptr packageName(_StringConverter::CopyToCharArrayN(__providerId)); + std::unique_ptr id(_StringConverter::CopyToCharArrayN(__instanceId)); + + __buffer_info = provider_buffer_acquire(__type, packageName.get(), id.get(), w, h, sizeof(int), AppWidgetHandleBufferEventCallback, __pListener); + SysTryReturn(NID_SHELL, __buffer_info, -1, E_SYSTEM, "[E_SYSTEM] Failed to execute provider_buffer_acquire"); + SysLog(NID_SHELL, "provider_buffer_acquire successed"); + + __buffer = provider_buffer_ref(__buffer_info); + SysTryReturn(NID_SHELL, __buffer, -1, E_SYSTEM, "[E_SYSTEM] Failed to execute provider_buffer_ref"); + SysLog(NID_SHELL, "provider_buffer_ref successed"); + } + + int bufferId = __buffer_info->fb->handle; + + SysLog(NID_SHELL, "(%d) Exit", bufferId); + return bufferId; +} + +result +_AppWidgetRemoteBuffer::ReleaseSharedMem(void) +{ + SysLog(NID_SHELL, "Enter"); + + int ret; + + if( __buffer) + { + ret = provider_buffer_unref(__buffer); + __buffer = null; + SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_buffer_unref"); + SysLog(NID_SHELL, "provider_buffer_unref successed"); + } + + if( __buffer_info) + { + ret = provider_buffer_release(__buffer_info); + __buffer_info = null; + SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_buffer_release"); + SysLog(NID_SHELL, "provider_buffer_release successed"); + } + + SysLog(NID_SHELL, "Exit."); + + return E_SUCCESS; +} + +}}} // Tizen::Shell::App + +static int AppWidgetHandleBufferEventCallback(struct livebox_buffer *info, enum buffer_event event, double timestamp, double x, double y, void* data) +{ + SysLog(NID_SHELL, "timestamp(%f), x(%f), y(%f)", timestamp, x, y); + + Tizen::Shell::App::_IAppWidgetRemoteBufferEventListener* pListener = static_cast(data); + SysTryReturn(NID_SHELL, pListener != null, 0, E_SYSTEM, "[E_SYSTEM] retrieved pAppWidgetContext is null"); + + if (event == BUFFER_EVENT_ENTER) + { + SysLog(NID_SHELL, "BUFFER_EVENT_ENTER"); + } + else if (event == BUFFER_EVENT_LEAVE) + { + SysLog(NID_SHELL, "BUFFER_EVENT_LEAVE"); + } + else if (event == BUFFER_EVENT_DOWN) + { + SysLog(NID_SHELL, "BUFFER_EVENT_DOWN"); + } + else if (event == BUFFER_EVENT_MOVE) + { + SysLog(NID_SHELL, "BUFFER_EVENT_MOVE"); + } + else if(event == BUFFER_EVENT_UP) + { + SysLog(NID_SHELL, "BUFFER_EVENT_UP"); + } + + pListener->OnTouchEventReceived(event, timestamp, x, y); + + return 0; +}