2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
24 #include <dpl/log/log.h>
25 #include <dpl/scoped_array.h>
26 #include <dpl/scoped_resource.h>
27 #include <dpl/assert.h>
28 #include <wrt_plugin_export.h>
29 #include <Commons/Exception.h>
30 #include "WrtWrapper.h"
31 #include "WrtCameraManager.h"
32 #include <ace-client/ace_client.h>
34 namespace WrtDeviceApis {
37 struct DeviceCapParamPolicy
39 typedef AceClient::AceParamList* Type;
40 static Type NullValue()
44 static void Destroy(Type ptr)
54 * Helper class - modified ScopedArray for ace_param_list_t
56 class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
59 explicit ScopedDeviceCapArray(AceClient::AceParamList *ptr =
60 DeviceCapParamPolicy::NullValue()) :
61 DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
65 AceClient::AceParamList & operator [](std::ptrdiff_t k) const
67 Assert(this->m_value != DeviceCapParamPolicy::NullValue() &&
68 "Dereference of scoped NULL array!");
69 Assert(k >= 0 && "Negative array index");
71 return this->m_value[k];
75 WrtWrapper::WrtWrapper(int widgetId,
76 const engine_interface_t* interface) :
82 LogError("Pointer to interface is NULL");
85 m_cameraManager = IWrtCameraManagerPtr(
86 new WrtCameraManager(widgetId, interface));
89 WrtWrapper::~WrtWrapper()
94 int WrtWrapper::getWidgetId() const
100 bool WrtWrapper::checkAccess(const AceFunction& aceFunction) const
102 size_t deviceCount = aceFunction.deviceCapabilities.size();
104 DPL::ScopedArray <const char *> deviceScopedArray;
105 ScopedDeviceCapArray paramsScopedArray;
108 deviceScopedArray.Reset(new const char*[deviceCount]);
109 paramsScopedArray.Reset(new AceClient::AceParamList[deviceCount]);
111 for (size_t i = 0; i < deviceCount; ++i) {
112 deviceScopedArray[i] =
113 aceFunction.deviceCapabilities.at(i).devCapName.c_str();
114 paramsScopedArray[i].count =
115 aceFunction.deviceCapabilities.at(i).devCapParams.size();
117 paramsScopedArray[i].param =
118 new AceClient::AceParam[paramsScopedArray[i].count];
120 for (size_t j = 0; j < paramsScopedArray[i].count; ++j) {
121 paramsScopedArray[i].param[j].name =
122 aceFunction.deviceCapabilities.at(i).
123 devCapParams[j].name.c_str();
124 paramsScopedArray[i].param[j].value =
125 aceFunction.deviceCapabilities.at(i).
126 devCapParams[j].value.c_str();
131 size_t featuresCount = aceFunction.features.size();
133 DPL::ScopedArray <const char*> featureScopedArray;
135 featureScopedArray.Reset(new const char*[featuresCount]);
137 for (size_t i = 0; i < featuresCount; ++i) {
138 featureScopedArray[i] =
139 aceFunction.features.at(i).name.c_str();
143 AceClient::AceRequest aceRequest;
144 aceRequest.sessionId = ""; // TODO for now empty session
145 aceRequest.widgetHandle = getWidgetId();
146 aceRequest.apiFeatures.count = featuresCount;
147 aceRequest.apiFeatures.apiFeature = featureScopedArray.Get();
148 aceRequest.functionName = aceFunction.name.c_str();
149 aceRequest.deviceCapabilities.devcapsCount = deviceCount;
150 aceRequest.deviceCapabilities.devCapNames = deviceScopedArray.Get();
151 aceRequest.deviceCapabilities.paramsCount = deviceCount;
152 aceRequest.deviceCapabilities.params = paramsScopedArray.Get();
154 return AceClient::AceThinClientSingleton::
155 Instance().checkFunctionCall(aceRequest);
158 IWrtCameraManagerPtr WrtWrapper::getCameraManagerInterface() const
160 return m_cameraManager;
164 } // WrtDeviceApisCommon