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 <unique_ptr.h>
24 #include <appsvc/appsvc.h>
26 #include <FBaseSysLog.h>
27 #include <FAppAppControl.h>
28 #include <FBaseColHashMap.h>
30 #include <FBase_StringConverter.h>
31 #include <FIo_FileImpl.h>
32 #include <FSys_EnvironmentImpl.h>
33 #include <FApp_AppControlManager.h>
34 #include <FApp_AppMessageImpl.h>
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Io;
42 using namespace Tizen::System;
50 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
51 result _OSP_EXPORT_ TerminateAppControl(int req);
52 void OnAppControlResult(void*, int, service_result_e, void*);
54 static int __req = -1;
55 static int __processId = -1;
57 static const wchar_t __allowedAppControlPickTable[][2][64] =
59 {L"osp.appcontrol.CALENDAR", L"osp.appcontrol.operation.PICK"},
60 {L"osp.appcontrol.provider.calendar", L"osp.appcontrol.operation.pick"},
61 {L"http://tizen.org/appcontrol/provider/calendar", L"http://tizen.org/appcontrol/operation/pick"},
62 {L"tizen.calendar", L"http://tizen.org/appcontrol/operation/pick"},
65 static const wchar_t __allowedAppControlViewTable[][2][64] =
67 {L"osp.appcontrol.CALENDAR", L"osp.appcontrol.operation.VIEW"},
68 {L"osp.appcontrol.provider.calendar", L"osp.appcontrol.operation.view"},
69 {L"http://tizen.org/appcontrol/provider/calendar", L"http://tizen.org/appcontrol/operation/view"},
70 {L"tizen.calendar", L"http://tizen.org/appcontrol/operation/social/view"},
73 static const wchar_t __allowedAppControlVcsViewTable[][2][64] =
75 {L"tizen.calendar", L"http://tizen.org/appcontrol/operation/view"},
79 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
81 SysLog(NID_APP, "StartAppControl: Entry to Calendar AppControl");
84 bool hasOutput = false;
88 const bool isCalendarVcsView = _AppControlManager::IsAllowedAppControl(__allowedAppControlVcsViewTable, 1, aId, oId);
89 const bool isCalendarView = _AppControlManager::IsAllowedAppControl(__allowedAppControlViewTable, 4, aId, oId);
90 const bool isCalendarPick = _AppControlManager::IsAllowedAppControl(__allowedAppControlPickTable, 4, aId, oId);
94 SysLog(NID_APP, "Calendar AppControl : PICK operation.");
98 const String* pItemTypeValue = static_cast<const String*>(pMap->GetValue(String(L"itemType")));
99 if (pItemTypeValue == null || (*pItemTypeValue != L"event" && *pItemTypeValue != L"todo"))
101 SysLog(NID_APP, "itemType is invalid.");
105 const String* pSelectionModeValue = static_cast<const String*>(pMap->GetValue(String(L"selectionMode")));
106 if (pSelectionModeValue == null || (*pSelectionModeValue != L"single" && *pSelectionModeValue != L"multiple"))
108 SysLog(NID_APP, "selectionMode is invalid.");
119 __processId = _AppControlManager::GetInstance()->Launch(msg, "calendar-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResult, 0);
120 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Calendar AppControl is failed.");
121 SysLog(NID_APP, "StartAppControl: Launching Calendar AppControl succeeded.");
123 else if (isCalendarVcsView)
125 SysLog(NID_APP, "Calendar AppControl : VIEW operation (vcs).");
127 std::unique_ptr<char[]> pConvertedUri;
130 pConvertedUri.reset(_StringConverter::CopyToCharArrayN(*pUri));
133 std::unique_ptr<char[]> pConvertedMime;
136 pConvertedMime.reset(_StringConverter::CopyToCharArrayN(*pMime));
145 __processId = _AppControlManager::GetInstance()->Launch(msg, "calendar-detail-efl", APPSVC_OPERATION_VIEW, pConvertedMime.get(), pConvertedUri.get(), NULL, 0);
146 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Calendar AppControl is failed.");
147 SysLog(NID_APP, "StartAppControl: Launching Calendar AppControl(vcs) succeeded.");
149 else if (isCalendarView)
151 SysLog(NID_APP, "Calendar AppControl : VIEW operation.");
158 const String* pViewTypeValue = static_cast<const String*>(pMap->GetValue(String(L"viewType")));
159 if (pViewTypeValue == null)
161 SysLog(NID_APP, "viewType is invalid.");
166 if (*pViewTypeValue == L"vcs")
168 const String* pPathValue = static_cast<const String*>(pMap->GetValue(String(L"path")));
169 if (pPathValue == null || pPathValue->GetLength() == 0)
171 SysLog(NID_APP, "path is invalid.");
176 else if (*pViewTypeValue == L"event")
178 const String* pEventIdValue = static_cast<const String*>(pMap->GetValue(String(L"eventId")));
179 if (pEventIdValue == null || pEventIdValue->GetLength() == 0)
181 SysLog(NID_APP, "eventId is invalid.");
186 else if (*pViewTypeValue == L"todo")
188 const String* pTodoIdValue = static_cast<const String*>(pMap->GetValue(String(L"todoId")));
189 if (pTodoIdValue == null || pTodoIdValue->GetLength() == 0)
191 SysLog(NID_APP, "todoId is invalid.");
198 SysLog(NID_APP, "viewType is invalid.");
204 const String& tmp = msg.GetValue(L"viewType");
207 msg.AddData(L"itemType", tmp);
210 __processId = _AppControlManager::GetInstance()->Launch(msg, "calendar-detail-efl", APPSVC_OPERATION_VIEW, NULL, NULL, NULL, 0);
211 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Calendar AppControl is failed.");
212 SysLog(NID_APP, "StartAppControl: Launching Calendar AppControl succeeded.");
221 _AppControlManager::GetInstance()->FinishAppControl(req, APP_CTRL_RESULT_FAILED, null);
229 TerminateAppControl(int req)
231 if (__processId >= 0)
233 _Aul::TerminateApplicationByPid(__processId);
239 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
242 bundle* pBundle = static_cast<bundle*>(b);
244 HashMap* pResult = null;
248 case SERVICE_RESULT_SUCCEEDED:
250 pResult = new (std::nothrow) HashMap();
251 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
253 r = pResult->Construct();
255 const char* pData = appsvc_get_data(pBundle, "itemType");
258 pResult->Add(new (std::nothrow) String(L"itemType"), new (std::nothrow) String(pData));
262 const char** pPaths = null;
263 pPaths = appsvc_get_data_array(pBundle, "path", &count);
267 String* pPathValue = new (std::nothrow) String();
268 SysTryCatch(NID_APP, pPathValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
270 for (int i = 0; i< count; i++)
274 pPathValue->Append(L";");
277 pPathValue->Append(pPaths[i]);
280 pResult->Add(new (std::nothrow) String(L"path"), pPathValue);
284 case SERVICE_RESULT_FAILED:
287 case SERVICE_RESULT_CANCELED:
288 pResult->Add(*(new (std::nothrow) String(L"Canceled")));
295 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
302 pResult->RemoveAll(true);