Add calendar condition
authorHosang Kim <hosang.kim@samsung.com>
Tue, 19 Mar 2013 04:58:43 +0000 (13:58 +0900)
committerHosang Kim <hosang.kim@samsung.com>
Fri, 22 Mar 2013 07:57:26 +0000 (16:57 +0900)
Change-Id: Iabafdd6ec1ea21b93cfa2f9dd9a870991fc42bc8
Signed-off-by: Hosang Kim <hosang.kim@samsung.com>
packaging/osp-app-service.spec
plugins/CMakeLists.txt
plugins/calendar-condition-handler/CMakeLists.txt [new file with mode: 0755]
plugins/calendar-condition-handler/CalendarConditionHandler.cpp [new file with mode: 0644]
plugins/calendar-condition-handler/CalendarConditionHandler.h [new file with mode: 0644]
res/app-launch-condition-handlers.ini
src/FApp_ConditionHandler.cpp

index 3c199f7..a4d5bcb 100755 (executable)
@@ -34,6 +34,7 @@ BuildRequires:        pkgconfig(elementary)
 BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(edbus)
 BuildRequires: pkgconfig(calendar-service2)
+BuildRequires: pkgconfig(bundle)
 BuildRequires:  osp-appfw-internal-devel
 
 BuildRequires:  pkgconfig(icu-i18n)
index ef4a927..e54b71e 100755 (executable)
@@ -7,3 +7,4 @@ ADD_SUBDIRECTORY(alarm-condition-handler)
 ADD_SUBDIRECTORY(nfc-condition-handler)
 ADD_SUBDIRECTORY(accessory-condition-handler)
 ADD_SUBDIRECTORY(message-condition-handler)
+ADD_SUBDIRECTORY(calendar-condition-handler)
diff --git a/plugins/calendar-condition-handler/CMakeLists.txt b/plugins/calendar-condition-handler/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..03d82fa
--- /dev/null
@@ -0,0 +1,32 @@
+SET (this_target osp-cond-calendar)
+
+INCLUDE_DIRECTORIES (
+       /usr/include/osp
+       /usr/include/osp/app
+       /usr/include/osp/base
+       /usr/lib/glib-2.0/include
+       /usr/include/calendar-service2
+       )
+
+SET (${this_target}_SOURCE_FILES
+       CalendarConditionHandler.cpp
+       )
+
+## SET EXTRA COMPILER FLAGS
+SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIC -Wall" )
+
+## SET C COMPILER FLAGS
+SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## SET CPP COMPILER FLAGS
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
+
+## Create Library
+ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES})
+
+ADD_DEPENDENCIES(${this_target} osp-appfw)
+
+SET_TARGET_PROPERTIES(${this_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_INSTALL_DIR}/lib")
+TARGET_LINK_LIBRARIES(${this_target} -L/usr/lib/osp -losp-appfw -lbundle -Wl,--no-undefined -Wl,--as-needed)
+TARGET_LINK_LIBRARIES(${this_target} "-lcalendar-service2" )
\ No newline at end of file
diff --git a/plugins/calendar-condition-handler/CalendarConditionHandler.cpp b/plugins/calendar-condition-handler/CalendarConditionHandler.cpp
new file mode 100644 (file)
index 0000000..a0c2664
--- /dev/null
@@ -0,0 +1,282 @@
+//
+// Open Service Platform
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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       CalendarConditionHandler.cpp
+ * @brief      This is the declaration file of the _CalendarConditionHandler class.
+ *
+ */
+
+#include <new>
+#include <unique_ptr.h>
+#include <FBaseInteger.h>
+#include <FBaseLongLong.h>
+#include <FBaseDateTime.h>
+#include <FBaseString.h>
+#include <FBaseColHashMap.h>
+#include <FBaseColAllElementsDeleter.h>
+
+#include "CalendarConditionHandler.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+static const char* REMINDER_CB_KEY_ID = "id";
+static const char* REMINDER_CB_KEY_TYPE = "type";
+static const char* REMINDER_CB_KEY_TIME = "time";
+static const char* REMINDER_CB_KEY_TICK = "tick";
+static const char* REMINDER_CB_KEY_UNIT = "unit";
+
+static const char* REMINDER_CB_VALUE_TYPE_EVENT = "1";
+static const char* REMINDER_CB_VALUE_TYPE_TODO = "2";
+
+static const wchar_t* REMINDER_ARG_KEY_RECORD_ID = L"recordid";
+static const wchar_t* REMINDER_ARG_KEY_TYPE = L"recordtype";
+static const wchar_t* REMINDER_ARG_KEY_TIME = L"time";
+static const wchar_t* REMINDER_ARG_KEY_OFFSET = L"offset";
+static const wchar_t* REMINDER_ARG_KEY_UNIT = L"unit";
+
+static const wchar_t* REMINDER_ARG_VALUE_TYPE_EVENT = L"event";
+static const wchar_t* REMINDER_ARG_VALUE_TYPE_TODO = L"todo";
+
+static const wchar_t* REMINDER_ARG_VALUE_UNIT_MINUTE = L"minute";
+static const wchar_t* REMINDER_ARG_VALUE_UNIT_HOUR = L"hour";
+static const wchar_t* REMINDER_ARG_VALUE_UNIT_DAY = L"day";
+static const wchar_t* REMINDER_ARG_VALUE_UNIT_WEEK = L"week";
+static const wchar_t* REMINDER_ARG_VALUE_UNIT_NONE = L"none";
+
+static const int MSEC_UNIT = 1000;
+static const long long EPOCH_YEAR_INTERVAL_SECONDS = 62135596800;
+
+_CalendarConditionHandler* pCalendarConditionHandler = null;
+int RefCalendarConditionHandler = 0;
+
+_CalendarConditionHandler*
+_CalendarConditionHandler::GetInstance()
+{
+       if(pCalendarConditionHandler == null)
+       {
+               pCalendarConditionHandler = new (std::nothrow) _CalendarConditionHandler;
+       }
+       RefCalendarConditionHandler ++;
+       return pCalendarConditionHandler;
+}
+
+void
+_CalendarConditionHandler::ReleaseInstance()
+{
+       if(RefCalendarConditionHandler == 0)
+       {
+               return;
+       }
+
+       RefCalendarConditionHandler --;
+       if(RefCalendarConditionHandler == 0)
+       {
+               delete pCalendarConditionHandler;
+               pCalendarConditionHandler = null;
+       }
+}
+
+_CalendarConditionHandler::_CalendarConditionHandler()
+{
+}
+
+_CalendarConditionHandler::~_CalendarConditionHandler()
+{
+}
+
+result
+_CalendarConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
+{
+       SysLog(NID_APP, "Register(calendar reminder) started. condition : %S", appLaunchCondition.GetConditionString().GetPointer());
+
+       int errorCode = 0;
+
+       // set user data
+       appLaunchCondition.SetUserData(this);
+
+       errorCode = calendar_connect();
+       SysTryReturnResult(NID_APP, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
+
+       std::unique_ptr<String> pAppId(new (std::nothrow) String(appLaunchCondition.GetAppId()));
+       SysTryCatch(NID_APP, pAppId != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+       errorCode = calendar_reminder_add_cb(ReminderCallback, &appLaunchCondition);
+       SysTryCatch(NID_APP, errorCode == CALENDAR_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
+
+       return E_SUCCESS;
+
+CATCH:
+
+       errorCode = calendar_disconnect();
+
+       return E_SYSTEM;
+}
+
+
+result
+_CalendarConditionHandler::Unregister( _AppLaunchCondition& appLaunchCondition)
+{
+       SysLog(NID_APP, "Unregister(calendar reminder) started");
+
+       int errorCode = 0;
+
+       errorCode = calendar_reminder_remove_cb(ReminderCallback, null);
+       SysTryReturnResult(NID_APP, errorCode == CALENDAR_ERROR_NONE, E_SYSTEM, "A system error has been occurred.");
+
+       SysLog(NID_APP, "Callback is successfully removed. (%S)", appLaunchCondition.GetAppId().GetPointer());
+
+       errorCode = calendar_disconnect();
+
+       return E_SUCCESS;
+}
+
+void
+_CalendarConditionHandler::ReminderCallback(bundle* pBundle, void* pUserData)
+{
+       _AppLaunchCondition* pAppLaunchCondition = static_cast<_AppLaunchCondition*>(pUserData);
+       SysTryReturnVoidResult(NID_APP, pAppLaunchCondition != null, E_INVALID_STATE, "[E_INVALID_STATE] pUserData should NOT be null.");
+
+       _CalendarConditionHandler* pHandler = dynamic_cast<_CalendarConditionHandler*>(pAppLaunchCondition->GetUserData());
+       SysTryReturnVoidResult(NID_APP, pHandler != null, E_INVALID_STATE, "user data is null");
+
+       SysTryReturnVoidResult(NID_APP, pBundle != null, E_INVALID_STATE, "[E_INVALID_STATE] pBundle should NOT be null.");
+
+       std::unique_ptr<HashMap, AllElementsDeleter> pResultMap(new (std::nothrow) HashMap());
+       SysTryReturnVoidResult(NID_APP, pResultMap != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
+
+       result r = pResultMap->Construct();
+       SysTryReturnVoidResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
+
+       // get values
+       const char* pStrRecordId = bundle_get_val(pBundle, REMINDER_CB_KEY_ID);
+       SysTryReturnVoidResult(NID_APP, pStrRecordId != null, E_INVALID_STATE, "[E_INVALID_STATE] id should NOT be null.");
+
+       const char* pStrType = bundle_get_val(pBundle, REMINDER_CB_KEY_TYPE);
+       SysTryReturnVoidResult(NID_APP, pStrType != null, E_INVALID_STATE, "[E_INVALID_STATE] type should NOT be null.");
+
+       const char* pStrTime = bundle_get_val(pBundle, REMINDER_CB_KEY_TIME);
+       SysTryReturnVoidResult(NID_APP, pStrTime != null, E_INVALID_STATE, "[E_INVALID_STATE] time should NOT be null.");
+
+       const char* pStrTick = bundle_get_val(pBundle, REMINDER_CB_KEY_TICK);
+       SysTryReturnVoidResult(NID_APP, pStrTick != null, E_INVALID_STATE, "[E_INVALID_STATE] tick should NOT be null.");
+
+       const char* pStrUnit = bundle_get_val(pBundle, REMINDER_CB_KEY_UNIT);
+       SysTryReturnVoidResult(NID_APP, pStrUnit != null, E_INVALID_STATE, "[E_INVALID_STATE] unit should NOT be null.");
+
+       SysLog(NID_APP, "Reminder callback is called. id : %s, type : %s, time : %s, tick : %s, unit : %s", pStrRecordId, pStrType, pStrTime, pStrTick, pStrUnit);
+
+       // convert
+       std::unique_ptr<String> pRecordType;
+       if (strcmp(pStrType, REMINDER_CB_VALUE_TYPE_EVENT) == 0)
+       {
+               pRecordType.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_TYPE_EVENT));
+       }
+       else if (strcmp(pStrType, REMINDER_CB_VALUE_TYPE_TODO) == 0)
+       {
+               pRecordType.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_TYPE_TODO));
+       }
+
+       int unit = 0;
+       r = Integer::Parse(pStrUnit, unit);
+       int offset = 0;
+       r = Integer::Parse(pStrTick, offset);
+
+       std::unique_ptr<String> pReminderUnit;
+       switch (unit)
+       {
+       case CALENDAR_ALARM_NONE:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_NONE));
+               offset = 0;
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_NONE));
+               offset = 0;
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_MINUTE:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_MINUTE));
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_HOUR:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_HOUR));
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_DAY:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_DAY));
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_WEEK:
+               pReminderUnit.reset(new (std::nothrow) String(REMINDER_ARG_VALUE_UNIT_WEEK));
+               break;
+       default:
+               SysLogException(NID_APP, E_INVALID_STATE, "[E_INVALID_STATE] unit should NOT be null.");
+               return;
+       }
+
+       std::unique_ptr<String> pReminderOffset(new (std::nothrow) String());
+       pReminderOffset->Append(offset);
+
+       long long time = 0;
+       r = LongLong::Parse(pStrTime, time);
+       std::unique_ptr<String> pTime(new (std::nothrow) String(ConvertEpochTimeToDateTime(time).ToString()));
+
+       r = pResultMap->Add(new String(REMINDER_ARG_KEY_RECORD_ID), new String(pStrRecordId));
+       SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add id to the hash map.", GetErrorMessage(r));
+
+       r = pResultMap->Add(new String(REMINDER_ARG_KEY_TYPE), pRecordType.release());
+       SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add type to the hash map.", GetErrorMessage(r));
+
+       r = pResultMap->Add(new String(REMINDER_ARG_KEY_OFFSET), pReminderOffset.release());
+       SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add offset to the hash map.", GetErrorMessage(r));
+
+       r = pResultMap->Add(new String(REMINDER_ARG_KEY_UNIT), pReminderUnit.release());
+       SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add unit to the hash map.", GetErrorMessage(r));
+
+       r = pResultMap->Add(new String(REMINDER_ARG_KEY_TIME), pTime.release());
+       SysTryReturnVoidResult(NID_APP, r == E_SUCCESS, r, "[%s] Failed to add time to the hash map.", GetErrorMessage(r));
+
+       r = pHandler->Fire(*pAppLaunchCondition, pResultMap.release());
+       SysTryReturnVoidResult(NID_APP, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
+}
+
+DateTime
+_CalendarConditionHandler::ConvertEpochTimeToDateTime(long long int dateTime)
+{
+       DateTime tmpDateTime;
+       tmpDateTime.SetValue(TimeSpan((dateTime + EPOCH_YEAR_INTERVAL_SECONDS) * MSEC_UNIT));
+       return tmpDateTime;
+}
+
+//////////////////////////////////////////////////////////////
+//     All plugins must provide both a creation and a destruction function
+/////////////////////////////////////////////////////////////
+extern "C"
+{
+_OSP_EXPORT_ _AppLaunchConditionHandlerBase*
+CreatePlugin(void)
+{
+       return _CalendarConditionHandler::GetInstance();
+}
+
+_OSP_EXPORT_ void
+DestroyPlugin(_AppLaunchConditionHandlerBase* p)
+{
+        _CalendarConditionHandler::ReleaseInstance();
+}
+
+}//extern "C"
diff --git a/plugins/calendar-condition-handler/CalendarConditionHandler.h b/plugins/calendar-condition-handler/CalendarConditionHandler.h
new file mode 100644 (file)
index 0000000..e9b76d0
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// Open Service Platform
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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       CalendarConditionHandler.h
+ * @brief      This is the implementation file of the _CalendarConditionHandler class.
+ *
+ */
+#include <bundle.h>
+#include <calendar2.h>
+#include "FApp_AppLaunchConditionHandlerBase.h"
+
+namespace Tizen { namespace Base
+{
+class DateTime;
+}}
+
+/**
+ * @class      _CalendarConditionHandler
+ * @brief      This class implements conditional app launch for calendar condition.
+ * @final      This class is not intended for extension.
+ */
+class _CalendarConditionHandler:
+       public Tizen::App::_AppLaunchConditionHandlerBase
+{
+
+public:
+       static _CalendarConditionHandler* GetInstance(void);
+       static void ReleaseInstance(void);
+
+       virtual result Register( Tizen::App::_AppLaunchCondition& appLaunchCondition);
+       virtual result Unregister( Tizen::App::_AppLaunchCondition& appLaunchCondition);
+
+       static void ReminderCallback(bundle* pBundle, void* pUserData);
+
+private:
+       _CalendarConditionHandler(void);
+       virtual ~_CalendarConditionHandler(void);
+
+       static Tizen::Base::DateTime ConvertEpochTimeToDateTime(long long int dateTime);
+};
index 002deff..463d2f3 100644 (file)
@@ -13,3 +13,7 @@ Filename=libosp-cond-accessory.so
 #libosp-cond-message.so
 Key=SmsPort,WapPush
 Filename=libosp-cond-message.so
+
+#libosp-cond-calendar.so
+Key=CalendarItem
+Filename=libosp-cond-calendar.so
index a8f6033..e982cbe 100644 (file)
@@ -302,16 +302,34 @@ _ConditionHandler::OnAppLaunchConditionMet(const _AppLaunchCondition& operation,
 
        if (pExtraData != null)
        {
+               SysLog(NID_APP, "pExtraData is not null");
+
                _AppArg* pArg = new (std::nothrow) _AppArg();
                
                result r = pArg->ConstructForAppLaunchCondition(operation.GetConditionString(), operation.__pArguments, pExtraData);
                SysTryLog(NID_APP, !IsFailed(r), "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), operation.GetConditionString().GetPointer());
 
+
+
+               HashMap* temp = pArg->GetArgMapN();
+               if (temp != null)
+               {
+                       SysLog(NID_APP, "not null");
+               }
+               else
+               {
+                       SysLog(NID_APP, "null");
+               }
+
+
+
            r = _AppControlManager::GetInstance()->LaunchApp(operation.GetAppId(), pArg);
                SysTryLog(NID_APP, !IsFailed(r), "[%ls] LaunchApplication failed, appId(%ls).", GetErrorMessage(r), operation.GetAppId().GetPointer());
        }
        else
        {
+               SysLog(NID_APP, "pExtraData is null");
+
            result r  = _AppControlManager::GetInstance()->LaunchAppWithCondition(operation.GetAppId(), operation.GetConditionString(), operation.__pArguments );
            SysTryLog(NID_APP, !IsFailed(r), "[%ls] LaunchApplication failed.", GetErrorMessage(r));
        }