2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file CalendarAppControlDllEntry.cpp
20 * @brief This is the implementation for the CalendarAppControlDllEntry.cpp class.
23 #include <appsvc/appsvc.h>
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27 #include <FBaseColHashMap.h>
29 #include <FBase_StringConverter.h>
30 #include <FIo_FileImpl.h>
31 #include <FSys_EnvironmentImpl.h>
32 #include <FApp_AppControlManager.h>
33 #include <FApp_AppMessageImpl.h>
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Io;
41 using namespace Tizen::System;
49 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
50 result _OSP_EXPORT_ TerminateAppControl(int req);
51 void OnAppControlResult(void*, int, service_result_e, void*);
53 static int __req = -1;
54 static int __processId = -1;
56 static const wchar_t __allowedAppControlPickTable[][2][64] =
58 {L"osp.appcontrol.CALENDAR", L"osp.appcontrol.operation.PICK"},
59 {L"osp.appcontrol.provider.calendar", L"osp.appcontrol.operation.pick"},
60 {L"http://tizen.org/appcontrol/provider/calendar", L"http://tizen.org/appcontrol/operation/pick"},
61 {L"tizen.calendar", L"http://tizen.org/appcontrol/operation/pick"},
64 static const wchar_t __allowedAppControlViewTable[][2][64] =
66 {L"osp.appcontrol.CALENDAR", L"osp.appcontrol.operation.VIEW"},
67 {L"osp.appcontrol.provider.calendar", L"osp.appcontrol.operation.view"},
68 {L"http://tizen.org/appcontrol/provider/calendar", L"http://tizen.org/appcontrol/operation/view"},
69 {L"tizen.calendar", L"http://tizen.org/appcontrol/operation/view"},
73 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
75 SysLog(NID_APP, "StartAppControl: Entry to Calendar AppControl");
78 bool hasOutput = false;
82 const bool isCalendarView = _AppControlManager::IsAllowedAppControl(__allowedAppControlViewTable, 4, aId, oId);
83 const bool isCalendarPick = _AppControlManager::IsAllowedAppControl(__allowedAppControlPickTable, 4, aId, oId);
87 SysLog(NID_APP, "Calendar AppControl : PICK operation.");
91 const String* pItemTypeValue = static_cast<const String*>(pMap->GetValue(String(L"itemType")));
92 if (pItemTypeValue == null || (*pItemTypeValue != L"event" && *pItemTypeValue != L"todo"))
94 SysLog(NID_APP, "itemType is invalid.");
98 const String* pSelectionModeValue = static_cast<const String*>(pMap->GetValue(String(L"selectionMode")));
99 if (pSelectionModeValue == null || (*pSelectionModeValue != L"single" && *pSelectionModeValue != L"multiple"))
101 SysLog(NID_APP, "selectionMode is invalid.");
109 __processId = _AppControlManager::GetInstance()->Launch(msg, "calendar-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResult, 0);
110 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Calendar AppControl is failed.");
111 SysLog(NID_APP, "StartAppControl: Launching Calendar AppControl succeeded.");
113 else if (isCalendarView)
115 SysLog(NID_APP, "Calendar AppControl : VIEW operation.");
117 const String* pViewTypeValue = static_cast<const String*>(pMap->GetValue(String(L"viewType")));
118 if (pViewTypeValue == null)
120 SysLog(NID_APP, "viewType is invalid.");
125 if (*pViewTypeValue == L"vcs")
127 const String* pPathValue = static_cast<const String*>(pMap->GetValue(String(L"path")));
128 if (pPathValue == null || pPathValue->GetLength() == 0)
130 SysLog(NID_APP, "path is invalid.");
135 else if (*pViewTypeValue == L"event")
137 const String* pEventIdValue = static_cast<const String*>(pMap->GetValue(String(L"eventId")));
138 if (pEventIdValue == null || pEventIdValue->GetLength() == 0)
140 SysLog(NID_APP, "eventId is invalid.");
145 else if (*pViewTypeValue == L"todo")
147 const String* pTodoIdValue = static_cast<const String*>(pMap->GetValue(String(L"todoId")));
148 if (pTodoIdValue == null || pTodoIdValue->GetLength() == 0)
150 SysLog(NID_APP, "todoId is invalid.");
157 SysLog(NID_APP, "viewType is invalid.");
165 const String& tmp = msg.GetValue(L"viewType");
168 msg.AddData(L"itemType", tmp);
171 __processId = _AppControlManager::GetInstance()->Launch(msg, "calendar-detail-efl", APPSVC_OPERATION_VIEW, NULL, NULL, NULL, 0);
172 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Calendar AppControl is failed.");
173 SysLog(NID_APP, "StartAppControl: Launching Calendar AppControl succeeded.");
182 _AppControlManager::GetInstance()->FinishAppControl(req, APP_CTRL_RESULT_FAILED, null);
190 TerminateAppControl(int req)
192 if (__processId >= 0)
194 _Aul::TerminateApplicationByPid(__processId);
200 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
203 bundle* pBundle = static_cast<bundle*>(b);
205 HashMap* pResult = null;
209 case SERVICE_RESULT_SUCCEEDED:
211 pResult = new (std::nothrow) HashMap();
212 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
214 r = pResult->Construct();
216 const char* pData = appsvc_get_data(pBundle, "itemType");
219 pResult->Add(new (std::nothrow) String(L"itemType"), new (std::nothrow) String(pData));
223 const char** pPaths = null;
224 pPaths = appsvc_get_data_array(pBundle, "path", &count);
228 String* pPathValue = new (std::nothrow) String();
229 SysTryCatch(NID_APP, pPathValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
231 for (int i = 0; i< count; i++)
235 pPathValue->Append(L";");
238 pPathValue->Append(pPaths[i]);
241 pResult->Add(new (std::nothrow) String(L"path"), pPathValue);
245 case SERVICE_RESULT_FAILED:
248 case SERVICE_RESULT_CANCELED:
249 pResult->Add(*(new (std::nothrow) String(L"Canceled")));
256 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
263 pResult->RemoveAll(true);