Add an API to check the supported boxsize.
[platform/framework/web/web-provider.git] / src / API / web_provider_plugin_info.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 2f776a0..1f9b71b
@@ -52,10 +52,12 @@ static const std::string jsonMemberType("type");
 static const std::string jsonMemberPath("path");
 static const std::string jsonMemberBoxId("service_boxid");
 static const std::string jsonMemberBoxScrollable("box_scrollable");
+static const std::string jsonMemberBoxSize("supported_size");
 
 static const std::string jsonValueBoolTrue("true");
 static const std::string jsonValueBoolFalse("false");
 static const std::string jsonFileExtension(".json");
+static const std::string mendatoryBoxSize("1x1");
 
 web_provider_plugin_info** web_provider_plugin_get_installed_list(int* count)
 {
@@ -201,7 +203,11 @@ static web_provider_plugin_info* get_parsed_json_data(std::string& configPath)
         static_cast<const char*>(
             json_object_get_string_member(object, jsonMemberPath.c_str()));
 
-    if (!type || !path) {
+    JsonArray* size =
+        json_object_get_array_member(object, jsonMemberBoxSize.c_str());
+    int sizeCount = static_cast<int>(json_array_get_length(size));
+
+    if (!type || !path || !sizeCount) {
         LogD("mandatory members don't exist");
         g_error_free(error);
         g_object_unref(parser);
@@ -215,6 +221,13 @@ static web_provider_plugin_info* get_parsed_json_data(std::string& configPath)
 
     info->type = strdup(type);
     info->path = strdup(path);
+    info->box_size = static_cast<char**>(malloc(sizeof(char*) * sizeCount));
+
+    for (int i = 0; i < sizeCount; i++) {
+        info->box_size[i] =
+            strdup(static_cast<const char*>(json_array_get_string_element(size, i)));
+    }
+    info->box_size_count = sizeCount;
 
     gboolean hasBoxId = json_object_has_member(object, jsonMemberBoxId.c_str());
     if (hasBoxId == TRUE) {
@@ -250,7 +263,7 @@ static web_provider_plugin_info* get_parsed_json_data(std::string& configPath)
     g_error_free(error);
     g_object_unref(parser);
 
-    return info; 
+    return info;
 }
 
 bool web_provider_plugin_release_info(web_provider_plugin_info* info)
@@ -265,7 +278,60 @@ bool web_provider_plugin_release_info(web_provider_plugin_info* info)
     delete info->type;
     delete info->path;
     delete info->service_boxid;
+    for(int i = 0; i < info->box_size_count; i++) {
+        delete[] info->box_size[i];
+    }
     delete info;
 
     return true;
 }
+
+int web_provider_plugin_check_supported_size(
+    const char* plugin_type, char** size, int sizeCount)
+{
+    bool mendatoryChk = false;
+
+    // read plugin directory and store plugin config path
+    std::string configPath;
+    configPath = installedPluginDirPath;
+    configPath += plugin_type;
+    configPath += jsonFileExtension;
+
+    // get the json datas
+    web_provider_plugin_info* jsonData = get_parsed_json_data(configPath);
+    if (!jsonData) {
+        LogD("failed to get the json file");
+        return false;
+    }
+
+    // compare the parsed config data with the parsed json data
+    for (int configCnt = 0; configCnt < sizeCount; configCnt++) {
+        bool supportedSizeChk = false;
+
+        for (int jsonCnt = 0; jsonCnt < jsonData->box_size_count; jsonCnt++) {
+
+            // check mendatory size
+            if (!strcmp(mendatoryBoxSize.c_str(), size[configCnt])) {
+                mendatoryChk = true;
+            }
+
+            // check supported size
+            if (!strcmp(jsonData->box_size[jsonCnt], size[configCnt])) {
+                supportedSizeChk = true;
+                break;
+            }
+        }
+
+        if (!supportedSizeChk) {
+            LogD("Not supported size: %s", size[configCnt]);
+            return false;
+        }
+    }
+
+    if (!mendatoryChk) {
+        LogD("Mandatory members don't exist ");
+        return false;
+    }
+
+    return true;
+}