bfba4c67c1ab17aef59e513a984c005777452675
[platform/framework/native/app-controls.git] / src / image-app-control / ImageAppControlDllEntry.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         ImageAppControlDllEntry.cpp
20  * @brief       This is the implementation for the ImageAppControlDllEntry.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 <FBase_StringConverter.h>
30 #include <FApp_AppControlManager.h>
31 #include <FApp_AppMessageImpl.h>
32 #include <FApp_Aul.h>
33 #include <FApp_AppArg.h>
34
35
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
46 result _OSP_EXPORT_ TerminateAppControl(int req);
47 void OnAppControlResult(void*, int, service_result_e, void*);
48
49 static int __req = -1;
50 static int __processId = -1;
51
52 static const char __allowedAppControlImageTable[][2][96] =
53 {
54         {"osp.appcontrol.IMAGE", "osp.appcontrol.operation.VIEW"},
55         {"osp.appcontrol.provider.image", "osp.appcontrol.operation.view"},
56         {"http://tizen.org/appcontrol/provider/image", "http://tizen.org/appcontrol/operation/view"},
57         {"tizen.imageviewer", "http://tizen.org/appcontrol/operation/view"},
58 };
59
60 static const char __allowedAppControlCropTable[][2][96] =
61 {
62         {"tizen.imageviewer", "http://tizen.org/appcontrol/operation/image/crop"},
63 };
64
65 result
66 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
67 {
68         result r = E_SYSTEM;
69         SysLog(NID_APP, "StartAppControl: Entry to Image AppControl");
70
71         const bool isImage = _AppControlManager::IsAllowedAppControl(__allowedAppControlImageTable, 4, aId, oId);
72         const bool isCrop = _AppControlManager::IsAllowedAppControl(__allowedAppControlCropTable, 1, aId, oId);
73         SysTryReturnResult(NID_APP, isImage || isCrop, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
74
75         _AppMessageImpl msg;
76         msg.AddData(pMap);
77
78         String path = msg.GetValue(L"path");
79         const String* pActualUri = pUri;
80
81         if (pUri == null)
82         {
83                 if (!path.IsEmpty())
84                 {
85                         pActualUri = &path;
86                 }
87         }
88
89         const String& package = _AppControlManager::GetAliasAppId(aId);
90         SysLog(NID_APP, "Actual app is %ls.", package.GetPointer());
91
92         if (!isCrop)
93         {
94                 __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pActualUri, pMime, NULL, 0);
95         }
96         else
97         {
98                 __req = req;
99                 __processId = _AppControlManager::GetInstance()->Launch(msg, package, oId, pActualUri, pMime, OnAppControlResult, 0);
100         }
101
102         SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Image AppControl is failed.");
103         r = E_SUCCESS;
104
105         SysLog(NID_APP, "StartAppControl: Launching ImageViewer AppControl succeeded");
106
107         return r;
108 }
109
110 result
111 TerminateAppControl(int req)
112 {
113         if (__processId >= 0)
114         {
115                 _Aul::TerminateApplicationByPid(__processId);           
116         }
117         return E_SUCCESS;
118 }
119
120 void
121 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
122 {
123         SysLog(NID_APP, "@@@@@@ OnAppControlResult");
124
125         result r = E_SYSTEM;
126         bundle* pBundle = static_cast<bundle*>(b);
127
128         HashMap* pResult = new (std::nothrow) HashMap();
129         SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
130
131         r = pResult->Construct();
132
133         _AppArg::SetArgMap(pBundle, pResult);
134
135         _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
136
137 CATCH:
138         __req = -1;
139 }
140
141 #ifdef __cplusplus
142 }
143 #endif