Fix configure-manager to parse cached file buffer. 54/251454/4
authorseungho <sbsh.baek@samsung.com>
Thu, 14 Jan 2021 03:55:06 +0000 (12:55 +0900)
committerseungho <sbsh.baek@samsung.com>
Mon, 25 Jan 2021 07:52:40 +0000 (16:52 +0900)
 - Current configure-manager force to read cached file buffer with fixed order.
 - It can load variables efficiently but have lisk of changing order.
 - The order is defined by order of getter call of the variables.
 - If a system already has cache file that has 3 variable A, B, and  C with this order.(that means getter called A, B, and C in sequence)
 - And we can merge new patch that adds new variable D to the cache but the getter of the variable called earlier than other existed ones.
 - then, a new system that launchs dali app first after the patche is merged can produce cache file that has variables with D, A, B, C order.
 - It is no problem. But the system we mentioned first that already has cache file of A, B, and C sequence will get modified cache file that has A, B, C, and D variable order.
 - This makes cached D useless and will produce unlimited cache file finally.(with wrong order will produce a new line per a launching dali app)

 - This patch fix configure-manager to parse cache file
 - And to block to compare string when the variable is already loaded we can reduce the increased cost.

Change-Id: I93387266099fd54295064d8ae59921999e332ef9
Signed-off-by: seungho <sbsh.baek@samsung.com>
dali/internal/system/common/configuration-manager.cpp

index e587db8..0276761 100644 (file)
@@ -42,34 +42,6 @@ const std::string DALI_ENV_MULTIPLE_WINDOW_SUPPORT     = "DALI_ENV_MULTIPLE_WIND
 const std::string DALI_BLEND_EQUATION_ADVANCED_SUPPORT = "DALI_BLEND_EQUATION_ADVANCED_SUPPORT";
 const std::string DALI_GLSL_VERSION                    = "DALI_GLSL_VERSION";
 
-bool RetrieveKeyFromConfigFile(std::iostream& stream, const std::string& key, std::string& value)
-{
-  bool keyFound = false;
-
-  std::string line;
-  while(std::getline(stream, line))
-  {
-    line.erase(line.find_last_not_of(" \t\r\n") + 1);
-    line.erase(0, line.find_first_not_of(" \t\r\n"));
-    if('#' == *(line.cbegin()) || line == "")
-    {
-      continue;
-    }
-
-    std::istringstream stream(line);
-    std::string        name;
-    std::getline(stream, name, ' ');
-    if(name == key)
-    {
-      std::getline(stream, value);
-      keyFound = true;
-      break;
-    }
-  }
-
-  return keyFound;
-}
-
 } // unnamed namespace
 
 ConfigurationManager::ConfigurationManager(std::string systemCachePath, GraphicsInterface* graphics, ThreadController* threadController)
@@ -97,33 +69,44 @@ void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configF
   std::iostream&   stream = configFile.GetStream();
   if(stream.rdbuf()->in_avail())
   {
-    std::string value;
-    if(!mMaxTextureSizeCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_ENV_MAX_TEXTURE_SIZE, value))
-    {
-      mMaxTextureSize       = std::atoi(value.c_str());
-      mMaxTextureSizeCached = true;
-    }
-
-    if(!mShaderLanguageVersionCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_GLSL_VERSION, value))
-    {
-      mShaderLanguageVersion       = std::atoi(value.c_str());
-      mShaderLanguageVersionCached = true;
-    }
-
-    if(!mIsMultipleWindowSupportedCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_ENV_MULTIPLE_WINDOW_SUPPORT, value))
+    std::string line;
+    while( std::getline( stream, line ) )
     {
-      mIsMultipleWindowSupported       = std::atoi(value.c_str());
-      mIsMultipleWindowSupportedCached = true;
-    }
+      line.erase( line.find_last_not_of( " \t\r\n" ) + 1 );
+      line.erase( 0, line.find_first_not_of( " \t\r\n" ) );
+      if( '#' == *( line.cbegin() ) || line == "" )
+      {
+        continue;
+      }
 
-    if(!mIsAdvancedBlendEquationSupportedCached &&
-       RetrieveKeyFromConfigFile(stream, DALI_BLEND_EQUATION_ADVANCED_SUPPORT, value))
-    {
-      mIsAdvancedBlendEquationSupported       = std::atoi(value.c_str());
-      mIsAdvancedBlendEquationSupportedCached = true;
+      std::istringstream subStream(line);
+      std::string name;
+      std::string value;
+      std::getline(subStream, name, ' ');
+      if(!mMaxTextureSizeCached && name == DALI_ENV_MAX_TEXTURE_SIZE)
+      {
+        std::getline(subStream, value);
+        mMaxTextureSize       = std::atoi(value.c_str());
+        mMaxTextureSizeCached = true;
+      }
+      else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT)
+      {
+        std::getline(subStream, value);
+        mIsAdvancedBlendEquationSupported       = std::atoi(value.c_str());
+        mIsAdvancedBlendEquationSupportedCached = true;
+      }
+      else if(!mShaderLanguageVersionCached && name == DALI_GLSL_VERSION)
+      {
+        std::getline(subStream, value);
+        mShaderLanguageVersion       = std::atoi(value.c_str());
+        mShaderLanguageVersionCached = true;
+      }
+      else if(!mIsMultipleWindowSupportedCached && name == DALI_ENV_MULTIPLE_WINDOW_SUPPORT)
+      {
+        std::getline(subStream, value);
+        mIsMultipleWindowSupported       = std::atoi(value.c_str());
+        mIsMultipleWindowSupportedCached = true;
+      }
     }
   }
 }
@@ -172,7 +155,6 @@ uint32_t ConfigurationManager::GetShadingLanguageVersion()
 
       // Query from graphics and save the cache
       mShaderLanguageVersion = mGraphics->GetShaderLanguageVersion();
-      DALI_LOG_ERROR("mShaderLanguageVersion : %d\n", mShaderLanguageVersion);
       mShaderLanguageVersionCached = true;
 
       Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT);