#include <map>
#include <vector>
#include <string>
+#include <string.h>
#include <dpl/noncopyable.h>
#include <dpl/assert.h>
#include <dpl/foreach.h>
#include <Commons/TypesDeclaration.h>
-
+#include <wrt-commons/wrt_plugin_export.h>
namespace WrtDeviceApis {
namespace CommonsJavaScript {
}
}
+ static feature_mapping_t* getFeaturesToDevCapMapping()
+ {
+ feature_mapping_t* mapping = new feature_mapping_t;
+
+ mapping->featuresCount = m_features.size();
+ mapping->features = new feature_devcaps_t[mapping->featuresCount];
+
+ size_t i = 0;
+
+ FOREACH(featureIt, m_features)
+ {
+ mapping->features[i].feature_name =
+ strndup(featureIt->first.c_str(), featureIt->first.size() + 1);
+
+ mapping->features[i].devCaps.devCapsCount =
+ featureIt->second.size();
+
+ mapping->features[i].devCaps.deviceCaps =
+ new char*[mapping->features[i].devCaps.devCapsCount];
+
+ for (size_t j = 0;
+ j < mapping->features[i].devCaps.devCapsCount;
+ ++j)
+ {
+ std::string dc = getDevCapNameById(featureIt->second[j]);
+
+ mapping->features[i].devCaps.deviceCaps[j] =
+ strndup(dc.c_str(), dc.size() + 1);
+ }
+
+ ++i;
+ }
+
+ return mapping;
+ }
+
+ static const devcaps_t* devcapsGetter(pfeature_mapping_t feats,
+ const char* featureName)
+ {
+ Assert(featureName && "Trying to extract info about NULL api feature");
+
+ std::string feature(featureName);
+
+ devcaps_t* ret = NULL;
+
+ for (size_t i = 0; i < feats->featuresCount ; ++i)
+ {
+ Assert(feats->features &&
+ feats->features[i].feature_name &&
+ "NULL api feature in feature mapping");
+
+ std::string feat(feats->features[i].feature_name);
+
+ if (feature == feat)
+ {
+ ret = &(feats->features[i].devCaps);
+ break;
+ }
+ }
+
+ return ret;
+ }
+
+ static void featuresDeinitializer(feature_mapping_t* mapping)
+ {
+ if (mapping)
+ {
+ if (mapping->features)
+ {
+ for (size_t i = 0; i < mapping->featuresCount; ++i)
+ {
+ free(mapping->features[i].feature_name);
+
+ devcaps_t& dc = mapping->features[i].devCaps;
+
+ if (dc.deviceCaps)
+ {
+ for (size_t j = 0; j < dc.devCapsCount; ++j)
+ {
+ free(dc.deviceCaps[j]);
+ }
+
+ delete []dc.deviceCaps;
+ }
+ }
+ delete []mapping->features;
+ }
+ delete mapping;
+ }
+ }
+
+ static void getMappingInterface(feature_mapping_interface_t *mapping)
+ {
+ if (mapping)
+ {
+ mapping->featGetter =
+ StaticDeclarations::getFeaturesToDevCapMapping;
+ mapping->dcGetter = StaticDeclarations::devcapsGetter;
+ mapping->release = StaticDeclarations::featuresDeinitializer;
+ }
+ }
+
private:
static ParamsMap m_params;
static DeviceCapsMaps m_deviceCaps;