X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FCommonsJavaScript%2FSecurity%2FStaticDeclaration.h;h=736b14ac29dec4bc09d958d66e06c7e326edca32;hb=afa7fe810d3cee7ce1dfabebac91e97da9ea34dc;hp=53c04a9816dc8051dfcb0710301641fcf8edd6db;hpb=9c61c076f198660f9d9683fc1f091cbc95b3286b;p=platform%2Fframework%2Fweb%2Fwrt-plugins-common.git diff --git a/src/CommonsJavaScript/Security/StaticDeclaration.h b/src/CommonsJavaScript/Security/StaticDeclaration.h index 53c04a9..736b14a 100644 --- a/src/CommonsJavaScript/Security/StaticDeclaration.h +++ b/src/CommonsJavaScript/Security/StaticDeclaration.h @@ -20,11 +20,12 @@ #include #include #include +#include #include #include #include #include - +#include namespace WrtDeviceApis { namespace CommonsJavaScript { @@ -207,6 +208,108 @@ class StaticDeclarations : public DPL::Noncopyable } } + 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;