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 #ifndef _WRTPLUGINS_COMMONS_SRC_COMMONS_STATICDECLARATIOS_H_
18 #define _WRTPLUGINS_COMMONS_SRC_COMMONS_STATICDECLARATIOS_H_
23 #include <dpl/noncopyable.h>
24 #include <dpl/assert.h>
25 #include <dpl/foreach.h>
26 #include <Commons/TypesDeclaration.h>
29 namespace WrtDeviceApis {
30 namespace CommonsJavaScript {
32 template<typename ParamType,
33 typename DeviceCapType,
34 typename FunctionType>
35 class StaticDeclarations : public DPL::Noncopyable
37 struct FunctionTriplet {
39 std::vector<DeviceCapType> devCaps;
40 std::vector<const char*> features;
45 typedef typename std::map<ParamType, const char*> ParamsMap;
47 typedef std::map<DeviceCapType,
48 std::pair<const char*,
49 std::vector<ParamType> > > DeviceCapsMaps;
51 typedef std::map<FunctionType, FunctionTriplet > FunctionsMap;
53 typedef std::map<FunctionType, WrtDeviceApis::Commons::AceFunction>
56 typedef std::map<std::string, std::vector<DeviceCapType> > FeaturesMap;
58 static const std::string getParamName(const ParamType& paramId)
60 auto it = m_params.find(paramId);
62 Assert(it != m_params.end() && "No such paramId");
68 * Returns set of device capabilities WITHOUT params
69 * for given device capability id
71 static WrtDeviceApis::Commons::AceDeviceCapability
72 getDeviceCapabilityWithoutParams(const DeviceCapType& devCapsId)
74 WrtDeviceApis::Commons::AceDeviceCapability deviceCap;
75 auto it = m_deviceCaps.find(devCapsId);
77 Assert(it != m_deviceCaps.end() && "No such device cap");
79 deviceCap.devCapName = it->second.first;
85 * Returns set of device capabilities with set params
86 * for given device capability id
88 static WrtDeviceApis::Commons::AceDeviceCapability
89 getDeviceCapability(const DeviceCapType& devCapsId)
91 auto it = m_deviceCaps.find(devCapsId);
93 Assert(it != m_deviceCaps.end() && "No such dev-cap found");
95 WrtDeviceApis::Commons::AceDeviceCapability deviceCap;
96 deviceCap.devCapName = it->second.first;
98 FOREACH(paramIt, it->second.second)
100 WrtDeviceApis::Commons::AceDeviceCapParam param(
101 getParamName(*paramIt),
104 deviceCap.devCapParams.push_back(param);
110 static void addDeviceCapabilty(
111 const DeviceCapType& devCapsId,
112 WrtDeviceApis::Commons::AceFunction& aceFunction)
114 aceFunction.deviceCapabilities.push_back(
115 getDeviceCapability(devCapsId));
119 * Returns names of device-capabilities base on capability id
121 static std::string getDevCapNameById(DeviceCapType devCapId)
123 auto it = m_deviceCaps.find(devCapId);
124 Assert(it != m_deviceCaps.end() && "No such devcapid found!");
125 return it->second.first;
129 * Sets parameter value for given paramId
131 static bool setParamValue(WrtDeviceApis::Commons::AceFunction& function,
133 DeviceCapType devCapId,
134 const std::string& value)
136 //get name of the deviceCaps
137 std::string devCapName = getDevCapNameById(devCapId) ;
138 std::string paramName = getParamName(paramId);
140 //search throw all the device capabilities
141 FOREACH(devCapIt, function.deviceCapabilities) {
142 if(devCapIt->devCapName == devCapName) {
143 //device capability has been found
145 FOREACH(devParamIt, devCapIt->devCapParams) {
146 if(devParamIt->name == paramName) {
147 devParamIt->value = value;
156 * Return struct Commons::AceFunction with set function name
158 * To set device capabilities you may use setDeviceCap function
159 * To set param value function you may use setParamValue Function
161 static WrtDeviceApis::Commons::AceFunction getEmptyFunction(
162 const FunctionType& functionId)
164 WrtDeviceApis::Commons::AceFunction function;
165 auto it = m_functions.find(functionId);
166 Assert(it != m_functions.end() && "No such a function");
167 function.name = it->second.first;
173 * The most useful Function
174 * Return Commons::AceFunction with filled all required fields:
175 * name, device caps and proper param namespace
177 * To set param value function you may use setParamValue function
179 static WrtDeviceApis::Commons::AceFunction getSecurityFunction(
180 const FunctionType& functionId)
182 WrtDeviceApis::Commons::AceFunction function;
183 auto it = m_functions.find(functionId);
184 Assert(it != m_functions.end() && "No such function found!");
186 function.name = it->second.name;
188 FOREACH (featIt, it->second.features)
189 function.features.push_back(std::string(*featIt));
191 FOREACH(devCapIt, it->second.devCaps) {
192 function.deviceCapabilities.push_back(
193 getDeviceCapability(*devCapIt));
199 * To create static map
201 static void createStaticAceFunctions()
203 FOREACH(functionIt, m_functions)
205 m_aceFunctions[functionIt->first] =
206 getSecurityFunction(functionIt->first);
211 static ParamsMap m_params;
212 static DeviceCapsMaps m_deviceCaps;
213 static FunctionsMap m_functions;
214 static AceFunctionsMap m_aceFunctions;
216 static FeaturesMap m_features;