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 "WrtAccess.h"
31 #include <ace-client/ace_client.h>
32 #include <dpl/singleton_impl.h>
34 IMPLEMENT_SINGLETON(WrtDeviceApis::Commons::WrtAccess)
36 namespace WrtDeviceApis {
39 struct DeviceCapParamPolicy
41 typedef AceClient::AceParamList* Type;
42 static Type NullValue()
46 static void Destroy(Type ptr)
56 * Helper class - modified ScopedArray for ace_param_list_t
58 class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
61 explicit ScopedDeviceCapArray(AceClient::AceParamList *ptr =
62 DeviceCapParamPolicy::NullValue()) :
63 DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
67 AceClient::AceParamList & operator [](std::ptrdiff_t k) const
69 Assert(this->m_value != DeviceCapParamPolicy::NullValue() &&
70 "Dereference of scoped NULL array!");
71 Assert(k >= 0 && "Negative array index");
73 return this->m_value[k];
77 WrtAccess::WrtAccess()
79 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
82 WrtAccess::~WrtAccess()
86 void WrtAccess::initialize(int widgetId)
88 LogDebug("initialize");
92 LogDebug("Invalid widget id");
96 m_widgetId = widgetId;
99 void WrtAccess::deinitialize(int widgetId)
101 LogDebug("deinitialize");
104 int WrtAccess::getWidgetId() const
109 bool WrtAccess::checkAccessControl(const AceFunction& aceFunction) const
111 size_t deviceCount = aceFunction.deviceCapabilities.size();
113 DPL::ScopedArray <const char *> deviceScopedArray;
114 ScopedDeviceCapArray paramsScopedArray;
117 deviceScopedArray.Reset(new const char*[deviceCount]);
118 paramsScopedArray.Reset(new AceClient::AceParamList[deviceCount]);
120 for (size_t i = 0; i < deviceCount; ++i) {
121 deviceScopedArray[i] =
122 aceFunction.deviceCapabilities.at(i).devCapName.c_str();
123 paramsScopedArray[i].count =
124 aceFunction.deviceCapabilities.at(i).devCapParams.size();
126 paramsScopedArray[i].param =
127 new AceClient::AceParam[paramsScopedArray[i].count];
129 for (size_t j = 0; j < paramsScopedArray[i].count; ++j) {
130 paramsScopedArray[i].param[j].name =
131 aceFunction.deviceCapabilities.at(i).
132 devCapParams[j].name.c_str();
133 paramsScopedArray[i].param[j].value =
134 aceFunction.deviceCapabilities.at(i).
135 devCapParams[j].value.c_str();
140 size_t featuresCount = aceFunction.features.size();
142 DPL::ScopedArray <const char*> featureScopedArray;
144 featureScopedArray.Reset(new const char*[featuresCount]);
146 for (size_t i = 0; i < featuresCount; ++i) {
147 featureScopedArray[i] =
148 aceFunction.features.at(i).name.c_str();
152 AceClient::AceRequest aceRequest;
153 aceRequest.sessionId = ""; // TODO for now empty session
154 aceRequest.widgetHandle = getWidgetId();
155 aceRequest.apiFeatures.count = featuresCount;
156 aceRequest.apiFeatures.apiFeature = featureScopedArray.Get();
157 aceRequest.functionName = aceFunction.name.c_str();
158 aceRequest.deviceCapabilities.devcapsCount = deviceCount;
159 aceRequest.deviceCapabilities.devCapNames = deviceScopedArray.Get();
160 aceRequest.deviceCapabilities.paramsCount = deviceCount;
161 aceRequest.deviceCapabilities.params = paramsScopedArray.Get();
163 return AceClient::AceThinClientSingleton::
164 Instance().checkFunctionCall(aceRequest);
168 } // WrtDeviceApisCommon