fix to send id for core daemon as param of provider_init()
authorjungmin76.park <jungmin76.park@samsung.com>
Mon, 10 Jun 2013 12:40:37 +0000 (21:40 +0900)
committerjungmin76.park <jungmin76.park@samsung.com>
Mon, 10 Jun 2013 13:27:05 +0000 (22:27 +0900)
Change-Id: I1bb8d2711994ee0fab17f35dcc9f9b1a72117bbb
Signed-off-by: jungmin76.park <jungmin76.park@samsung.com>
inc/FShell_AppWidgetManagerService.h
inc/OspAppWidgetService.h
src/FShell_AppWidgetContext.cpp
src/FShell_AppWidgetManagerService.cpp
src/OspAppWidgetService.cpp

index 26ee083..7c3f0a6 100644 (file)
@@ -43,13 +43,14 @@ class AppWidgetManagerService
 {
 public:
        static AppWidgetManagerService* GetInstance(void);
+       static AppWidgetManagerService* CreateInstance(const char* pServiceIdForCoreDaemon);
        result AddAppWidget(_AppWidgetContext* pAppWidget);
        result RemoveAppWidget(const char* pPackageName, const char* pId, bool free);
 
 private:
-       result Construct(void);
-       result InitializeMasterDaemonEventReceiver(const char* pServiceExecutableName);
-       result DeinitializeMasterDaemonEventReceiver(void);
+       result Construct(const char* pServiceIdForCoreDaemon);
+       result InitializeCoreDaemonEventReceiver(const char* pServiceIdForCoreDaemon);
+       result DeinitializeCoreDaemonEventReceiver(void);
 
        // master daemon callbacks
        static int AppWidgetConnected(struct event_arg *arg, void* data);
@@ -105,10 +106,10 @@ private:
        };
 
 private:
+       static AppWidgetManagerService* __pTheInstance;
        Tizen::Base::Collection::ArrayListT<_AppWidgetContext*> __appWidgetContextList;
        Tizen::Base::Runtime::Timer __pingTimer;
        _TaskHandlerThread      __handlerThread;
-
 };     // class AppWidgetManagerService
 
 }}} // Tizen::Shell::App
index 58e4a3d..9a666e2 100644 (file)
@@ -34,6 +34,7 @@
  */
 class OspAppWidgetService
        : public Tizen::App::ServiceApp
+       ,public Tizen::App::IAppControlProviderEventListener
 {
 public:
 
@@ -67,6 +68,8 @@ 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);
 };     // class OspAppWidgetService
 
 #endif // _OSP_APPWIDGET_SERVICE_H_
index 70749df..df7a73a 100644 (file)
@@ -291,18 +291,19 @@ _AppWidgetContext::SendTouchEvent(buffer_event eventType, double timeStamp, doub
        if (HasValidClientId() && IsRunning())
        {
                SysAssert(IsSharedMemCreated() == true);
-               SysLog(NID_SHELL, "send IPC message");
+               SysLog(NID_SHELL, "%d, %f, %f", eventType, x, y);
                AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), eventType, timeStamp, x, y);
        }
        else
        {
-               SysLog(NID_SHELL, "request to start AppControl");
                __pPendingTouchEventList->Add(new PendingTouchEvent(eventType, timeStamp, x, y));
 
                if( AppManager::GetInstance()->IsRunning(this->GetAppId() ) == false)
                {
+                       SysLog(NID_SHELL, "request to start AppControl");
                        std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
 
+                       // TODO: consider to remove these unused args.
                        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)));
index b1d54c5..3dd150d 100644 (file)
@@ -49,6 +49,8 @@ static const RequestId        LOCAL_EVENT_REQUEST_UPDATE = 0;
 
 extern const int UPDATE_PERIOD_MSEC_MIN;
 
+AppWidgetManagerService* AppWidgetManagerService::__pTheInstance = null;
+
 AppWidgetManagerService::AppWidgetManagerService(void)
 {
 
@@ -57,27 +59,36 @@ AppWidgetManagerService::AppWidgetManagerService(void)
 AppWidgetManagerService::~AppWidgetManagerService(void)
 {
        __pingTimer.Cancel();
-       DeinitializeMasterDaemonEventReceiver();
+       DeinitializeCoreDaemonEventReceiver();
 }
 
 AppWidgetManagerService*
 AppWidgetManagerService::GetInstance(void)
 {
-       static AppWidgetManagerService* pSelf = null;
-       if( pSelf == null)
+       if( __pTheInstance == null)
+       {
+               __pTheInstance = CreateInstance("osp-appwidget-service");
+       }
+       return __pTheInstance;
+}
+
+AppWidgetManagerService*
+AppWidgetManagerService::CreateInstance(const char* pIdForCoreDaemon)
+{
+       if( __pTheInstance == null)
        {
-               pSelf = new AppWidgetManagerService();
-               SysTryReturn(NID_SHELL, pSelf != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
+               __pTheInstance = new AppWidgetManagerService();
+               SysTryReturn(NID_SHELL, __pTheInstance != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
 
-               result r = pSelf->Construct();
+               result r = __pTheInstance->Construct(pIdForCoreDaemon);
                SysAssertf(!IsFailed(r), "Failed to construct AppWidgetManagerService");
                SysLog(NID_SHELL, "AppWidgetManagerService is created.");
        }
-       return pSelf;
+       return __pTheInstance;
 }
 
 result
-AppWidgetManagerService::Construct(void)
+AppWidgetManagerService::Construct(const char* pIdForCoreDaemon)
 {
        _AppWidgetManagerStub::StartIpcServer();
 
@@ -87,7 +98,7 @@ AppWidgetManagerService::Construct(void)
        r = __handlerThread.Start();
        SysTryReturnResult(NID_SHELL, IsFailed(r) == false, r, "Event thread Start failure.");
 
-       return InitializeMasterDaemonEventReceiver("osp-appwidget-service");
+       return InitializeCoreDaemonEventReceiver(pIdForCoreDaemon);
 }
 
 int
@@ -242,7 +253,7 @@ AppWidgetManagerService::RemoveAppWidget(const char* pPackageName, const char* p
 }
 
 ///////////////////////////////////////////////////////
-// MasterDaemonEventReceiver implementation
+// CoreDaemonEventReceiver implementation
 ///////////////////////////////////////////////////////
 int
 AppWidgetManagerService::OnAppWidgetCreate(struct event_arg *arg, int *width, int *height, double *priority, void* data)
@@ -497,10 +508,9 @@ AppWidgetManagerService::OnAppWidgetRecreate(struct event_arg *arg, void* data)
 }
 
 result
-AppWidgetManagerService::InitializeMasterDaemonEventReceiver(const char *pServiceExecutableName)
+AppWidgetManagerService::InitializeCoreDaemonEventReceiver(const char *pIdForCoreDaemon)
 {
-       SysTryReturnResult(NID_SHELL, pServiceExecutableName != null, E_INVALID_ARG, "");
-       SysLog(NID_SHELL, "Enter.");
+       SysTryReturnResult(NID_SHELL, pIdForCoreDaemon != null, E_INVALID_ARG, "pIdForCoreDaemon should not be null!");
 
        __appWidgetContextList.Construct();
 
@@ -528,15 +538,15 @@ AppWidgetManagerService::InitializeMasterDaemonEventReceiver(const char *pServic
     cbs.lb_recreate = OnAppWidgetRecreate;/* Recover from the fault of slave */
     //cbs.content_event = OnAppWidgetContentEvent,
 
-    int ret = provider_init(null, pServiceExecutableName, &cbs, this);
+    int ret = provider_init(null, pIdForCoreDaemon, &cbs, this);
     SysTryReturnResult(NID_SHELL, ret == 0, E_SYSTEM, "provider_init failed.");
 
-    SysLog(NID_SHELL, "Exit.");
+    SysLog(NID_SHELL, "provider_init is invoked with (%s)", pIdForCoreDaemon);
     return E_SUCCESS;
 }
 
 result
-AppWidgetManagerService::DeinitializeMasterDaemonEventReceiver(void)
+AppWidgetManagerService::DeinitializeCoreDaemonEventReceiver(void)
 {
        SysLog(NID_SHELL, "Enter.");
     provider_fini();
@@ -696,6 +706,7 @@ AppWidgetManagerService::SendResult(const Tizen::App::AppId& appId, const Tizen:
        return E_SUCCESS;
 }
 
+
 AppWidgetManagerService::_TaskHandlerThread::~_TaskHandlerThread(void)
 {
 
index 1cdc1f6..0820901 100644 (file)
@@ -19,6 +19,8 @@
  * @brief      This is the implementation for the OspAppWidgetService class.
  */
 
+#include <FAppAppControlProviderManager.h>
+#include <FBase_StringConverter.h>
 #include "FShell_AppWidgetManagerService.h"
 #include "OspAppWidgetService.h"
 
@@ -27,6 +29,9 @@ using namespace Tizen::Base;
 using namespace Tizen::System;
 using namespace Tizen::Shell::App;
 
+const wchar_t OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
+const wchar_t KEY_NAME[] = L"name";
+
 OspAppWidgetService::OspAppWidgetService(void)
 {
 }
@@ -45,10 +50,7 @@ OspAppWidgetService::CreateInstance(void)
 bool
 OspAppWidgetService::OnAppInitializing(AppRegistry& appRegistry)
 {
-       AppLog("Enter.");
-
-       AppWidgetManagerService* pSvc = AppWidgetManagerService::GetInstance();
-       AppAssertf( pSvc != null, "AppWidgetManagerService::GetInstance() failed.");
+       AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
 
        return true;
 }
@@ -80,3 +82,24 @@ void
 OspAppWidgetService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
 {
 }
+
+void
+OspAppWidgetService::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
+{
+       if( operationId == OPERATION_MAIN)
+       {
+               static bool isServiceCreated = false;
+
+               if( isServiceCreated == false)
+               {
+                       String key(KEY_NAME);
+                       const String* pValue = dynamic_cast<const String*>(pExtraData->GetValue(key));
+
+                       std::unique_ptr<char[]> pIdForCoreDaemon(_StringConverter::CopyToCharArrayN(*pValue));
+                       AppWidgetManagerService* pSvc = AppWidgetManagerService::CreateInstance(pIdForCoreDaemon.get());
+                       AppAssertf( pSvc != null, "AppWidgetManagerService::GetInstance() failed.");
+
+                       isServiceCreated = true;
+               }
+       }
+}