apply dynamic singleton pattern to internal classes and add retry code to AppWidgetMa...
[platform/framework/native/shell.git] / src / FShell_AppWidgetManagerProxy.cpp
index fcfc1b7..61e90bc 100644 (file)
@@ -19,6 +19,7 @@
  * @brief      This is the implementation for the _AppWidgetManagerProxy class.
  */
 
+#include <FBaseRt.h>
 #include <FIo_IpcClient.h>
 #include <FShell_AppWidgetManagerIpcMessage.h>
 #include "FShell_AppWidgetProviderManagerImpl.h"
@@ -82,8 +83,23 @@ _AppWidgetManagerProxy::Construct(void)
        __pIpcClient = new (std::nothrow) _IpcClient();
        SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
 
-       result r = __pIpcClient->Construct(IPC_SERVER_NAME, this);
-       SysTryReturn(NID_SHELL, !IsFailed(r), r, r, "_IpcClient constructing failed [%s].", GetErrorMessage(r));
+       const int MAX_TRY_COUNT = 5;
+       const int TRY_SLEEP_TIME = 500;
+
+       int count = 0;
+       while (true)
+       {
+               result r = __pIpcClient->Construct(IPC_SERVER_NAME, this);
+               if (r == E_SUCCESS)
+               {
+                       SysLog(NID_APP, "Succeeded in connecting service(%s)", IPC_SERVER_NAME);
+                       return E_SUCCESS;
+               }
+
+               SysTryReturn(NID_APP, ++count < MAX_TRY_COUNT, E_SYSTEM, r, "[%s] Failed to connect service.(%s)", GetErrorMessage(r), IPC_SERVER_NAME);
+
+               Tizen::Base::Runtime::Thread::Sleep(TRY_SLEEP_TIME);
+       }
 
        SysLog(NID_SHELL, "Exit.");
        return E_SUCCESS;