AppControl 2.0/2.1 argument handling
[framework/osp/app-controls.git] / src / camera-app-control / CameraAppControlDllEntry.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file         CameraAppControlDllEntry.cpp
20  * @brief       This is the implementation for the CameraAppControlDllEntry.cpp class.
21  */
22
23 #include <bundle.h>
24 #include <appsvc/appsvc.h>
25
26 #include <FBaseSysLog.h>
27 #include <FAppAppControl.h>
28 #include <FBaseColHashMap.h>
29
30 #include <FApp_AppControlManager.h>
31 #include <FApp_AppMessageImpl.h>
32 #include <FApp_Aul.h>
33 #include <FApp_AppArg.h>
34 #include <FApp_AppMessageImpl.h>
35
36
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
47 result _OSP_EXPORT_ TerminateAppControl(int req);
48 void OnAppControlResult(void*, int, service_result_e, void*);
49
50 static int __req = -1;
51 static int __processId = -1;
52
53
54 result
55 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
56 {
57         result r = E_SYSTEM;
58         SysLog(NID_APP, "StartAppControl: Entry to Camera AppControl");
59
60         if (aId == "osp.appcontrol.CAMERA"
61                         || aId == "osp.appcontrol.provider.camera"
62                         || aId == "tizen.camera")
63         {
64                 SysLog(NID_APP, "oId : %ls", oId.GetPointer());
65
66                 _AppMessageImpl msg;
67
68                 const String* pActualMime = pMime;
69                 String tmp;
70
71                 if (pMap)
72                 {
73                         msg.AddData(pMap);
74
75                         if (pMime == null)
76                         {
77                                 const String& str = msg.GetValue(L"type");
78                                 if (str == L"camcorder")
79                                 {
80                                         tmp = L"video/3gp";
81                                 }
82                                 else
83                                 {
84                                         tmp = L"image/jpg";
85                                 }
86
87                                 msg.RemoveData(L"type");
88                                 pActualMime = &tmp;
89                         }
90                 }
91
92                 const String& package = _AppControlManager::GetAliasAppId(aId);
93                 SysLog(NID_APP, "Actual packageId is %ls.", package.GetPointer());
94
95                 __req = req;
96                 __processId = _AppControlManager::GetInstance()->Launch(msg, package, String(APPSVC_OPERATION_CREATE_CONTENT), pUri, pActualMime, OnAppControlResult, 0);
97
98                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Camera AppControl is failed.");
99
100                 r = E_SUCCESS;
101                 SysLog(NID_APP, "StartAppControl: Launching Camera AppControl succeeded");
102         }
103
104         return r;
105 }
106
107 result
108 TerminateAppControl(int req)
109 {
110         if (__processId >= 0)
111         {
112                 _Aul::TerminateApplicationByPid(__processId);           
113         }
114         return E_SUCCESS;
115 }
116
117 void
118 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
119 {
120         SysLog(NID_APP, "Camera AppControl result");
121
122         result r = E_SYSTEM;
123         int type = BUNDLE_TYPE_NONE;
124         bundle* pBundle = static_cast<bundle*>(b);
125
126         HashMap* pResult = new (std::nothrow) HashMap();
127         SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
128
129         r = pResult->Construct();
130
131         _AppArg::SetArgMap(pBundle, pResult);
132
133         type = bundle_get_type(pBundle, SERVICE_DATA_SELECTED);
134         switch (type)
135         {
136         case BUNDLE_TYPE_STR:
137                 {
138                         const char* pFile = appsvc_get_data(pBundle, SERVICE_DATA_SELECTED);
139                         if (pFile)
140                         {
141                                 pResult->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(pFile));
142                         }
143                 }
144                 break;
145         case BUNDLE_TYPE_STR_ARRAY:
146                 {
147                         ArrayList* pArray = _AppMessageImpl::GetValueArrayN(pBundle, SERVICE_DATA_SELECTED);
148                         pResult->Add(new (std::nothrow) String(L"path"), pArray);
149                 }
150                 break;
151         case BUNDLE_TYPE_NONE:
152         default:
153                 break;
154         }
155
156         _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
157
158 CATCH:
159         __req = -1;
160 }
161
162
163 #ifdef __cplusplus
164 }
165 #endif