fix CalendarService B/S on boot issue
authorYoung Ik Cho <youngik.cho@samsung.com>
Mon, 14 Jan 2013 03:57:04 +0000 (12:57 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Mon, 14 Jan 2013 03:57:04 +0000 (12:57 +0900)
Change-Id: Ibcac4ee954c5651f5868cc0ff10935487b7e4db1
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
CMakeLists.txt
packaging/osp-app-service.spec
plugins/accessory-condition-handler/AccessoryConditionHandler.cpp
plugins/alarm-condition-handler/AlarmConditionHandler.cpp
src/AppService.cpp

index 1139944..1b761c1 100755 (executable)
@@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES (
        /usr/include/osp/security
        /usr/include/osp/shell
        /usr/include/chromium
+       /usr/include/calendar-service2
        inc
        )
 
@@ -72,6 +73,7 @@ TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-app-manager" )
 TARGET_LINK_LIBRARIES(${this_target} "-lnotification" )
 TARGET_LINK_LIBRARIES(${this_target} "-lsysman" )
 TARGET_LINK_LIBRARIES(${this_target} "-lvconf" )
+TARGET_LINK_LIBRARIES(${this_target} "-lcalendar-service2" )
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/etc/rc.d/init.d/boot-osp.sh DESTINATION ../etc/rc.d/init.d)
 INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin)
index e20bb9c..a65205f 100644 (file)
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(osp-appfw)
 BuildRequires:  pkgconfig(osp-shell)
 BuildRequires: pkgconfig(sysman)
 BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(calendar-service2)
 BuildRequires:  osp-appfw-internal-devel
 BuildRequires:  osp-shell-internal-devel
 
index 1ca7306..54d3be9 100644 (file)
@@ -181,11 +181,11 @@ AccessoryConditionHandler::TizenRequestCommand(const char* command, int length)
        char request[16] = {0,};
        char value[32] = {0, };
        char condition[512] = {0, };
-       char* response = NULL;
+       char* response = null;
        bool executed = false;
-       char* registered = NULL;
-       char* executionCondition = NULL;
-       IMapEnumerator* pMapEnum = NULL;
+       char* registered = null;
+       char* executionCondition = null;
+       IMapEnumerator* pMapEnum = null;
 
        result r = E_SUCCESS;
 
@@ -271,26 +271,15 @@ AccessoryConditionHandler::TizenRequestCommand(const char* command, int length)
                response = strcat(response, "'\r\n");
        }
 
+       SysTryCatch(NID_IO, response != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failure.");
        r = __pAccessoryMonitor->SendData(response, strlen(response)+1);
        SysTryCatch(NID_IO, r == E_SUCCESS, executed = false, E_SYSTEM, "[%s] Fail to send data");
 
 CATCH:
-       if(registered != null)
-       {
-               delete [] registered;
-       }
-       if(executionCondition != null)
-       {
-               delete [] executionCondition;
-       }
-       if(response != null)
-       {
-               delete [] response;
-       }
-       if(pMapEnum != null)
-       {
-               delete pMapEnum;
-       }
+       delete [] registered;
+       delete [] executionCondition;
+       delete [] response;
+       delete pMapEnum;
 
        return executed;
 }
index ac5897d..80b2aea 100644 (file)
@@ -22,6 +22,8 @@
  */
 
 #include <new>
+#include <unique_ptr.h>
+
 #include <appfw/app.h>
 
 #include <FBaseInteger.h>
@@ -91,7 +93,6 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 {
        //For condition parsing.
        int ret = 0;
-       char* convertedString = null;
        String buf(appLaunchCondition.GetConditionString());
 
        //For alarm reserve.
@@ -104,25 +105,21 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 
        SysLog(NID_SYS, "%ls", buf.GetPointer());
 
-       convertedString = _StringConverter::CopyToCharArrayN(buf);
+       std::unique_ptr<char[]> convertedString(_StringConverter::CopyToCharArrayN(buf));
+       SysTryReturnResult(NID_SYS, convertedString.get() != null, E_OUT_OF_MEMORY, "Memory allocation failure.");
 
        if(buf.StartsWith(L"DueTime", 0) == true)
        {
 
-               sscanf(convertedString, "DueTime='%d/%d/%d %d:%d:%d' LaunchPeriod='%d'", &(expireTime.tm_mon), &(expireTime.tm_mday), &(expireTime.tm_year), &(expireTime.tm_hour), &(expireTime.tm_min), &(expireTime.tm_sec), &period);
+               sscanf(convertedString.get(), "DueTime='%d/%d/%d %d:%d:%d' LaunchPeriod='%d'", &(expireTime.tm_mon), &(expireTime.tm_mday), &(expireTime.tm_year), &(expireTime.tm_hour), &(expireTime.tm_min), &(expireTime.tm_sec), &period);
        }
        else if(buf.StartsWith(L"DateTime", 0) == true)
        {
-               sscanf(convertedString, "DateTime='%d/%d/%d %d:%d:%d'", &(expireTime.tm_mon), &(expireTime.tm_mday), &(expireTime.tm_year), &(expireTime.tm_hour), &(expireTime.tm_min), &(expireTime.tm_sec));
+               sscanf(convertedString.get(), "DateTime='%d/%d/%d %d:%d:%d'", &(expireTime.tm_mon), &(expireTime.tm_mday), &(expireTime.tm_year), &(expireTime.tm_hour), &(expireTime.tm_min), &(expireTime.tm_sec));
        }
        else
        {
-               if(convertedString != null)
-               {
-                       SysLog(NID_SYS, "wrong alarm condition");
-                       delete [] convertedString;
-                       convertedString = null;
-               }
+               SysLog(NID_SYS, "wrong alarm condition");
                return E_SYSTEM;
        }
 
@@ -163,11 +160,6 @@ CATCH:
                service_destroy(service);
        }
 
-       if (convertedString != null)
-       {
-               delete [] convertedString;
-       }
-
        return r;
 }
 
index bae2d25..5920811 100644 (file)
@@ -19,6 +19,9 @@
 #include <signal.h>
 #include <unique_ptr.h>
 
+#include <calendar_service.h>
+#include <calendar_types2.h>
+
 #include <FIoFile.h>
 #include <FBaseSysLog.h>
 
@@ -150,7 +153,7 @@ AppService::OnAppInitialized(void)
 
        const String tmpPath = _HEARTBEAT_PATH;
        File file;
-       file.Construct(tmpPath, "w");
+       (void) file.Construct(tmpPath, "w");
 
        SysLog(NID_APP, "Exit.");
        return true;
@@ -609,6 +612,40 @@ AppService::OnPackageInstallationInProgress(const PackageId& packageId, int prog
 {
 }
 
+bool
+ConfirmCalendarService(void)
+{
+       int count = 0;
+       long interval = 100;
+       int ret = CALENDAR_ERROR_NONE;
+       int WAIT_COUNT = 20;
+
+       while (true)
+       {
+               int ret = calendar_connect();
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       calendar_disconnect();
+                       SysLog(NID_APP, "Found calendar service on %dth trial.", count);
+                       return true;
+               }
+
+               SysLog(NID_APP, "Waiting for calendar service %dth time(%d msec).", count, interval);
+
+               if (count >= WAIT_COUNT)
+               {
+                       SysLog(NID_APP, "Count overflow.");
+                       return false;
+               }
+
+               Thread::Sleep(interval);
+               count++;
+               interval += 100 * count;
+       }
+
+       return false;
+}
+
 void
 AppService::OnApplicationLaunched(const AppId& appId, Tizen::App::_AppType type)
 {
@@ -635,6 +672,8 @@ AppService::OnApplicationLaunched(const AppId& appId, Tizen::App::_AppType type)
 
                Tizen::App::Package::_PackageManagerImpl::GetInstance()->AddEventListener(this, 0);
 
+               ConfirmCalendarService();
+
                LaunchUserServices();
        }
 }