merge with master
[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 <appsvc/appsvc.h>
24
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27 #include <FBaseColHashMap.h>
28
29 #include <FApp_AppControlManager.h>
30 #include <FApp_AppMessageImpl.h>
31 #include <FApp_Aul.h>
32
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
43 result _OSP_EXPORT_ TerminateAppControl(int req);
44 void OnAppControlResult(void*, int, service_result_e, void*);
45
46 static int __req = -1;
47 static int __processId = -1;
48
49
50 result
51 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
52 {
53         result r = E_SYSTEM;
54         SysLog(NID_APP, "StartAppControl: Entry to Camera AppControl");
55
56         if (aId == "osp.appcontrol.CAMERA"
57                         || aId == L"osp.appcontrol.provider.camera"
58                         || aId == L"tizen.camera"
59                         || aId == L"http://tizen.org/appcontrol/provider/camera")
60         {
61                 SysLog(NID_APP, "oId : %ls", oId.GetPointer());
62
63                 if (pMap)
64                 {
65                         char buffer[10] = {0, };
66
67                         _AppMessageImpl msg;
68                         msg.AddData(pMap);
69
70                         const String& str = msg.GetValue(L"type");
71                         if (str == L"camcorder")
72                         {
73                                 strncpy(buffer, "video/3gp", 9);
74                         }
75                         else
76                         {
77                                 strncpy(buffer, "image/jpg", 9);
78                         }
79
80                         __req = req;
81                         __processId = _AppControlManager::GetInstance()->Launch(msg, "camera-efl", APPSVC_OPERATION_CREATE_CONTENT, buffer, NULL, OnAppControlResult, 0);
82                 }
83                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Camera AppControl is failed.");
84
85                 r = E_SUCCESS;
86                 SysLog(NID_APP, "StartAppControl: Launching Camera AppControl succeeded");
87         }
88
89         return r;
90 }
91
92 result
93 TerminateAppControl(int req)
94 {
95         if (__processId >= 0)
96         {
97                 _Aul::TerminateApplicationByPid(__processId);           
98         }
99         return E_SUCCESS;
100 }
101
102 void
103 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
104 {
105         result r = E_SYSTEM;
106         bundle* pBundle = static_cast<bundle*>(b);
107
108         HashMap* pResult = new (std::nothrow) HashMap();
109         SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
110
111         r = pResult->Construct();
112
113         switch (res)
114         {
115         case SERVICE_RESULT_SUCCEEDED:
116                 {
117                         const char* pFile = appsvc_get_data(pBundle, SERVICE_DATA_SELECTED);
118                         if (pFile)
119                         {
120                                 pResult->Add(new (std::nothrow) String(L"path"), new (std::nothrow) String(pFile));
121                         }
122                 }
123                 break;
124         case SERVICE_RESULT_FAILED:
125                 break;
126         case SERVICE_RESULT_CANCELED:
127                 break;
128         default:
129                 break;
130         }
131
132         _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
133
134 CATCH:
135         __req = -1;
136 }
137
138
139 #ifdef __cplusplus
140 }
141 #endif