#include <FAppTypes.h>
#include <FBaseRtTimer.h>
#include <FBaseObject.h>
-#include <FBaseColArrayList.h>
+#include <FBaseColArrayListT.h>
#include "FShell_AppWidgetContextBase.h"
void OnRemoved();
void OnForeground();
void OnBackground();
+
virtual void OnPopupCreated(double x, double y, int width, int height);
virtual void OnPopupDestoyed(void);
result SendRemoveRequest();
result SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs);
+ void SendPendingTouchEvent(void);
virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+ struct PendingTouchEvent
+ {
+ public:
+ PendingTouchEvent(int eventType, double timeStamp, double x, double y)
+ : eventType(eventType), timeStamp(timeStamp), x(x), y(y) { }
+
+ int eventType;
+ double timeStamp;
+ double x;
+ double y;
+ };
+
private:
_AppWidgetPopupContext* __pAppWidgetPopup;
Tizen::Base::Runtime::Timer __lifeDurationTimer;
Tizen::Base::Runtime::Timer __UpdateTimer;
- int __UpdateMillis;
-
+ int __updateMillis;
+ Tizen::Base::Collection::ArrayListT<PendingTouchEvent*>* __pPendingTouchEventList;
};
class _AppWidgetContextBase:
public Tizen::Base::Object
{
+protected:
+ enum _AppWidgetProviderState
+ {
+ INVALID = 0,
+ RUNNING,
+ SUSPENDED,
+ };
+
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();
virtual result SendTouchEvent(buffer_event event, double timestamp, double x, double y) = 0;
- void SetClientId(int clientId);
- bool HasValidClientId() const;
+ void SetIpcClientId(int clientId);
+ bool HasValidClientId(void) const;
// for buffered appWidget
int GetSharedMemId(int w, int h);
- result ReleaseSharedMem();
+ result ReleaseSharedMem(void);
+ void Suspend(void);
protected:
+ bool IsRunning(void) const;
+ bool IsSharedMemCreated(void) const;
+
Tizen::Base::Collection::HashMap* CreateRequestArgs(void);
result SendRequestToApp(const Tizen::App::AppId& appId, const Tizen::Base::String& operation, Tizen::Base::Collection::HashMap* pArgs);
private:
struct livebox_buffer *__buffer_info;
void *__buffer;
+ _AppWidgetProviderState __providerState;
};
class _AppWidgetRequestHelper
virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId);
// helpers
- result SetClientIds(const Tizen::App::AppId& appId, int clientId);
+ result SetIpcClientIds(const Tizen::App::AppId& appId, int clientId);
int UpdateAllAppWidgetsByAppId(const Tizen::Base::String& appId);
void StartPingTimer();
const char APPWIDGET_ON_RESIZE[] = "http://tizen.org/appcontrol/appwidget/resize";
const char APPWIDGET_ON_TOUCH[] = "http://tizen.org/appcontrol/appwidget/touch";
-const String ARG_KEY_WIDTH = L"_Width";
-const String ARG_KEY_HEIGHT = L"_Height";
const String ARG_KEY_ARGUMENT = L"_Argument";
const String ARG_KEY_EVENT_TYPE = L"_EventType";
const String ARG_KEY_TIME_STAMP = L"_TimeStamp";
const String ARG_KEY_X = L"_X";
const String ARG_KEY_Y = L"_Y";
-const int LIVE_DURATION_MSEC= 30000;//30sec
+const int DEFAULT_LIFE_DURATION_MSEC = 30000;//30sec
+const int UPDATE_PERIOD_MSEC_MIN = 1800000;//30min
_AppWidgetContext::_AppWidgetContext(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), __UpdateMillis(period)
+ :_AppWidgetContextBase(TYPE_LB, info, providerId, instanceId, width, height, priority)
+ ,__pAppWidgetPopup(null)
+ ,__updateMillis(period)
+ ,__pPendingTouchEventList(null)
{
- SysLog(NID_APP, "period(%d)", period);
-
__lifeDurationTimer.Construct(*this);//, true);
- __lifeDurationTimer.Start(LIVE_DURATION_MSEC);
+ __lifeDurationTimer.Start(DEFAULT_LIFE_DURATION_MSEC );
- SysLog(NID_APP, "period(%d)", __UpdateMillis);
- if( __UpdateMillis > 0)
+ __updateMillis = (__updateMillis > UPDATE_PERIOD_MSEC_MIN) ? __updateMillis : UPDATE_PERIOD_MSEC_MIN;
+ SysLog(NID_APP, "period(%d)", __updateMillis);
+ if( __updateMillis > 0)
{
__UpdateTimer.Construct(*this);//, false);
- __UpdateTimer.StartAsRepeatable(__UpdateMillis);
+ __UpdateTimer.StartAsRepeatable(__updateMillis);
}
+
+ __pPendingTouchEventList = new ArrayListT<PendingTouchEvent*>();
+ __pPendingTouchEventList->Construct();
}
_AppWidgetContext::~_AppWidgetContext()
__pAppWidgetPopup->OnPopupDestoyed();
delete __pAppWidgetPopup;
}
+
+
+ if( __pPendingTouchEventList )
+ {
+ for( int i = 0; i < __pPendingTouchEventList->GetCount(); i++)
+ {
+ PendingTouchEvent* pTouchEvent = null;
+ __pPendingTouchEventList->GetAt(i, pTouchEvent);
+ delete pTouchEvent;
+ }
+ __pPendingTouchEventList->RemoveAll();
+ delete __pPendingTouchEventList;
+ }
}
_AppWidgetPopupContext*
__isForeground = true;
__UpdateTimer.Cancel();
- __UpdateTimer.StartAsRepeatable(__UpdateMillis);
+ __UpdateTimer.StartAsRepeatable(__updateMillis);
}
void
_AppWidgetContext::OnPopupCreated(double x, double y, int width, int height)
{
__pAppWidgetPopup = new (std::nothrow) _AppWidgetPopupContext(__userInfo, __providerId, __instanceId, width, height, __priority);
- __pAppWidgetPopup->SetClientId(__ipcClientId);
+ __pAppWidgetPopup->SetIpcClientId(__ipcClientId);
__pAppWidgetPopup->OnPopupCreated(x, y, width, height);
__lifeDurationTimer.Cancel();
void
_AppWidgetContext::OnPopupDestoyed(void)
{
+ SysLog(NID_APP, "");
if (__pAppWidgetPopup)
{
__pAppWidgetPopup->OnPopupDestoyed();
result
_AppWidgetContext::SendAddRequest(int width, int height)
{
-/* std::unique_ptr<ArrayList, AllElementsDeleter> pArgs (new (std::nothrow) ArrayList);
- pArgs->Construct();
- pArgs->Add(*new String(__instanceId));
- pArgs->Add(*new String(__providerId));
- pArgs->Add(*new String(__info));
- pArgs->Add(*new String(Integer::ToString(width)));
- pArgs->Add(*new String(Integer::ToString(height)));*/
-
std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
- pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
- pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
-
return SendRequestToApp( __appId, APPWIDGET_ON_ADD, pArgs.get());
}
{
std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
- pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
- pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
pArgs->Add(new String(ARG_KEY_ARGUMENT), new String(argument));
return SendRequestToApp( __appId, APPWIDGET_ON_UPDATE, pArgs.get());
{
std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
- pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(width)));
- pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(height)));
-
return SendRequestToApp( __appId, APPWIDGET_ON_RESIZE, pArgs.get());
}
return SendRequestToApp( __appId, APPWIDGET_ON_REMOVE, pArgs.get());
}
+void
+_AppWidgetContext::SendPendingTouchEvent(void)
+{
+ for(int i =0; i< __pPendingTouchEventList->GetCount(); i++)
+ {
+ PendingTouchEvent* pTouchEvent = null;
+ __pPendingTouchEventList->GetAt(i, pTouchEvent);
+ AppWidgetManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, pTouchEvent->eventType, pTouchEvent->timeStamp, pTouchEvent->x, pTouchEvent->y);
+ delete pTouchEvent;
+ }
+ __pPendingTouchEventList->RemoveAll();
+}
+
result
-_AppWidgetContext::SendTouchEvent(buffer_event event, double timestamp, double x, double y)
+_AppWidgetContext::SendTouchEvent(buffer_event eventType, double timeStamp, double x, double y)
{
- SysLog(NID_APP, "");
- if( HasValidClientId() == false )
+ if( HasValidClientId() && IsRunning() )
+ {
+ SysAssert(IsSharedMemCreated() == true);
+ SysLog(NID_APP, "send IPC message");
+ AppWidgetManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, eventType, timeStamp, x, y);
+ }
+ else
{
+ SysLog(NID_APP, "request to start AppControl");
+ __pPendingTouchEventList->Add(new PendingTouchEvent(eventType, timeStamp, x, y));
+
+ //
std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgs() );
- pArgs->Add(new String(ARG_KEY_EVENT_TYPE), new String(Integer::ToString(event)));
- pArgs->Add(new String(ARG_KEY_TIME_STAMP), new String(Double::ToString(timestamp)));
+ pArgs->Add(new String(ARG_KEY_EVENT_TYPE), new String(Integer::ToString(eventType)));
+ pArgs->Add(new String(ARG_KEY_TIME_STAMP), new String(Double::ToString(timeStamp)));
pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
return SendRequestToApp( __appId, APPWIDGET_ON_TOUCH, pArgs.get());
}
- else
- {
-// SysAssertf( Tizen::App::AppManager::GetInstance()->IsRunning(__appId) == false, "application isn't running");
- AppWidgetManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, event, timestamp, x, y);
- }
return E_SUCCESS;
}
int ret = provider_send_updated(packageName.get(), id.get(), width, height, __priority, content_info.get(), null);
SysTryReturnResult(NID_APP, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
+ SendPendingTouchEvent();
SysLog(NID_APP, "Done");
return E_SUCCESS;
}
_AppWidgetContext::RestartLifeDurationTimer()
{
__lifeDurationTimer.Cancel();
- __lifeDurationTimer.Start(LIVE_DURATION_MSEC);
- SysLog(NID_APP, "lifeDuration timer restarted (%d)msec", LIVE_DURATION_MSEC);
+ __lifeDurationTimer.Start(DEFAULT_LIFE_DURATION_MSEC);
+ SysLog(NID_APP, "lifeDuration timer restarted (%d)msec", DEFAULT_LIFE_DURATION_MSEC);
}
void
_AppWidgetContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
{
- SysLog(NID_APP, "");
-
if( &timer == &__lifeDurationTimer)
{
SysLog(NID_APP, "lifeDuration timer is expired, so terminating appWidget app(%ls)..", __providerId.GetPointer() );
- ReleaseSharedMem();
+// ReleaseSharedMem();
AppManager::GetInstance()->TerminateApplication(__appId);
}
const String ARG_KEY_INSTANCE_ID = L"_InstanceId";
const String ARG_KEY_PROVIDER_NAME = L"_ProviderName";
const String ARG_KEY_USER_INFO = L"_UserInfo";
+const String ARG_KEY_WIDTH = L"_Width";
+const String ARG_KEY_HEIGHT = L"_Height";
_AppWidgetContextBase::_AppWidgetContextBase(target_type type, const String& userInfo, const String& providerId, const String& instanceId, int width, int height, int priority)
,__ipcClientId(-1)
,__buffer_info(null)
,__buffer(null)
+ ,__providerState(INVALID)
{
_AppWidgetManagerImpl::ExtractAppIdAndProviderName(providerId, __appId, __providerName);
_AppWidgetContextBase::~_AppWidgetContextBase()
{
SysLog(NID_APP, "providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
+ ReleaseSharedMem();
}
void
-_AppWidgetContextBase::SetClientId(int clientId)
+_AppWidgetContextBase::SetIpcClientId(int clientId)
{
__ipcClientId = clientId;
}
bool
-_AppWidgetContextBase::HasValidClientId() const
+_AppWidgetContextBase::HasValidClientId(void) const
{
SysLog(NID_APP, "%d", __ipcClientId);
return (__ipcClientId > -1);
}
+bool
+_AppWidgetContextBase::IsSharedMemCreated(void) const
+{
+ return ( __buffer_info && __buffer_info);
+}
+
int
_AppWidgetContextBase::GetSharedMemId(int w, int h)
{
}
int bufferId = __buffer_info->fb->handle;
+ __providerState = RUNNING;
SysLog(NID_APP, "(%d) Exit", bufferId);
return bufferId;
}
+
+void
+_AppWidgetContextBase::Suspend()
+{
+ __providerState = SUSPENDED;
+}
+
+bool
+_AppWidgetContextBase::IsRunning() const
+{
+ return (__providerState == RUNNING);
+}
+
result
_AppWidgetContextBase::ReleaseSharedMem()
{
pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
+ pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__width)));
+ pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__height)));
return pArgs;
}
}
result
-AppWidgetManagerService::SetClientIds(const Tizen::App::AppId& appId, int clientId)
+AppWidgetManagerService::SetIpcClientIds(const Tizen::App::AppId& appId, int clientId)
{
for( int i = 0; i < __appWidgetContextList.GetCount(); i++ )
{
if ( pAppWidgetContext->__appId == appId )
{
- pAppWidgetContext->SetClientId(clientId);
+ SysLog(NID_APP,"");
+ pAppWidgetContext->SetIpcClientId(clientId);
SysLog(NID_APP, "client is registered.(%d)", clientId);
- if( clientId == -1)
+
+ if( clientId == -1)//disconnected
{
- pAppWidgetContext->ReleaseSharedMem();
+// pAppWidgetContext->ReleaseSharedMem();
+ pAppWidgetContext->Suspend();
if(pAppWidgetContext->GetAppWidgetPopup())
{
pAppWidgetContext->OnPopupDestoyed();
void
AppWidgetManagerService::OnIpcClientConnected(const _IpcServer& server, int clientId)
{
- //SysLog(NID_APP, "(clientId:%d)\n", clientId);
- String fullAppId = server.GetClientApplicationId();
- SysLog(NID_APP, "(%ls)\n", fullAppId.GetPointer());
-// this->SetClientIds(fullAppId, clientId);//Todo
+ String appId = server.GetClientApplicationId();
+ SysLog(NID_APP, "(%ls)\n", appId.GetPointer());
+ this->SetIpcClientIds(appId, clientId);
}
void
AppWidgetManagerService::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
{
- String fullAppId = server.GetClientApplicationId();
- SysLog(NID_APP, "(%ls)\n", fullAppId.GetPointer());
- this->SetClientIds(fullAppId, -1);
+ String appId = server.GetClientApplicationId();
+ SysLog(NID_APP, "(%ls)\n", appId.GetPointer());
+
+ this->SetIpcClientIds(appId, -1);
}
result
_AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId);
SysTryReturnResult(NID_APP, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
- if(pAppWidgetContext->HasValidClientId() == false)
- {
- String fullAppId = __pIpcServer->GetClientApplicationId();
- this->SetClientIds(fullAppId, __pIpcServer->GetClientId());
- }
+// if(pAppWidgetContext->HasValidClientId() == false)
+// {
+// String fullAppId = __pIpcServer->GetClientApplicationId();
+// this->SetIpcClientIds(fullAppId, __pIpcServer->GetClientId());
+// }
shmId = pAppWidgetContext->GetSharedMemId(width, height);
SysTryReturnResult(NID_APP, pAppWidgetContext , shmId != -1, "[E_SYSTEM] failed to GetSharedMemId for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
if(pPd->HasValidClientId() == false)
{
String fullAppId = __pIpcServer->GetClientApplicationId();
- pPd->SetClientId(__pIpcServer->GetClientId());
+ pPd->SetIpcClientId(__pIpcServer->GetClientId());
}
shmId = pPd->GetSharedMemId(width, height);
result
AppWidgetManagerService::RequestReleaseSharedMemory(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
{
- std::unique_ptr<char[]> pkgname(_StringConverter::CopyToCharArrayN(appId));
- std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(instanceId));
-
- _AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId);
- SysTryReturnResult(NID_APP, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
-
- return pAppWidgetContext->ReleaseSharedMem();
+// std::unique_ptr<char[]> pkgname(_StringConverter::CopyToCharArrayN(appId));
+// std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(instanceId));
+//
+// _AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId);
+// SysTryReturnResult(NID_APP, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
+//
+// return pAppWidgetContext->ReleaseSharedMem();
+ return E_SUCCESS;
}
result
AppWidgetManagerService::RequestReleaseSharedMemoryForPD(const Tizen::App::AppId& appId, const Tizen::Base::String& instanceId)
{
- std::unique_ptr<char[]> pkgname(_StringConverter::CopyToCharArrayN(appId));
- std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(instanceId));
-
- _AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId);
- SysTryReturnResult(NID_APP, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
- SysTryReturnResult(NID_APP, pAppWidgetContext->GetAppWidgetPopup(), E_SYSTEM, "[E_SYSTEM] GetAppWidgetPopup() returns null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
-
+// std::unique_ptr<char[]> pkgname(_StringConverter::CopyToCharArrayN(appId));
+// std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(instanceId));
+//
+// _AppWidgetContext* pAppWidgetContext = this->Find(appId, instanceId);
+// SysTryReturnResult(NID_APP, pAppWidgetContext , E_SYSTEM, "[E_SYSTEM] pAppWidgetContext is null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
+// SysTryReturnResult(NID_APP, pAppWidgetContext->GetAppWidgetPopup(), E_SYSTEM, "[E_SYSTEM] GetAppWidgetPopup() returns null for (%ls) (%ls)", appId.GetPointer(), instanceId.GetPointer());
+//
// return pAppWidgetContext->GetAppWidgetPopup()->ReleaseSharedMem();
return E_SUCCESS;
}
_AppWidgetPopupContext::~_AppWidgetPopupContext()
{
SysLog(NID_APP, "appId(%ls), instanceId(%ls), width(%d), height(%d))", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height);
- ReleaseSharedMem();
}