All file read operations should be done through FileLoader. 28/209228/3
authorAnton Obzhirov <a.obzhirov@samsung.com>
Tue, 2 Jul 2019 16:07:37 +0000 (17:07 +0100)
committerAnton Obzhirov <a.obzhirov@samsung.com>
Fri, 5 Jul 2019 10:59:46 +0000 (10:59 +0000)
Change-Id: I3c5cd1a538efb1863aaf6e6f6b349e8619452169

automated-tests/src/dali-toolkit-styling/CMakeLists.txt
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp [deleted file]
dali-toolkit/internal/builder/builder-filesystem.h
dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp
dali-toolkit/internal/visuals/mesh/mesh-visual.cpp

index 58225f0..68bbd23 100644 (file)
@@ -21,7 +21,6 @@ LIST(APPEND TC_SOURCES
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-event-thread-callback.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-environment-variable.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-feedback-player.cpp
-   ../dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-lifecycle-controller.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-native-image-source.cpp
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-file-loader.cpp
deleted file mode 100644 (file)
index d1611c7..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string>
-#include <dali-toolkit/public-api/dali-toolkit-common.h>
-#include <dali/public-api/object/base-handle.h>
-#include <dali/devel-api/adaptor-framework/file-loader.h>
-
-namespace Dali
-{
-
-namespace FileLoader
-{
-
-int ReadFile(
-  const std::string& filename,
-  Dali::Vector<char> & memblock,
-  FileLoader::FileType fileType)
-{
-  return 0;
-}
-
-int ReadFile(
-  const std::string& filename,
-  std::streampos& fileSize,
-  Dali::Vector<char> & memblock,
-  FileLoader::FileType fileType)
-{
-  return 0;
-}
-
-std::streampos GetFileSize(const std::string& filename)
-{
-  return 0;
-}
-
-}
-}
index 75e9d28..947f8ce 100755 (executable)
@@ -27,6 +27,8 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#include <dali/devel-api/adaptor-framework/file-loader.h>
+
 inline std::string ExpandPath(const std::string &name)
 {
   wordexp_t p;
@@ -54,8 +56,14 @@ inline std::string ExePath(void)
 
 inline std::string GetFileContents(const std::string &fn)
 {
-  std::ifstream t(fn.c_str());
-  return std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> fileBuffer;
+  if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, Dali::FileLoader::FileType::BINARY ) )
+  {
+      return std::string();
+  }
+
+  return std::string( &fileBuffer[0], bufferSize );
 }
 
 #endif // DALI_TOOLKIT_INTERNAL_BUILDER_FILESYSTEM_H
index 4115fb7..e1d9d34 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 #include <dali-toolkit/internal/controls/scene3d-view/gltf-shader.h>
 
 // EXTERNAL INCLUDES
-#include <fstream>
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/devel-api/adaptor-framework/file-loader.h>
@@ -237,12 +236,15 @@ void FitBuffer( Dali::Vector<Vector4>& bufferDestination, Dali::Vector<T>& buffe
 template <typename T>
 bool ReadBinFile( Vector<T> &dataBuffer, std::string url, int32_t offset, int32_t count )
 {
-  dataBuffer.Resize( count );
-  FILE* fp = fopen( url.c_str(), "rb" );
-  if( fp == NULL )
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> fileBuffer;
+  if( !Dali::FileLoader::ReadFile( url, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
   {
     return false;
   }
+
+  FILE* fp = fmemopen( &fileBuffer[0], bufferSize, "rb" );
+  dataBuffer.Resize( count );
   ssize_t result = -1;
   if( !fseek( fp, offset, SEEK_SET ) )
   {
@@ -1228,11 +1230,16 @@ bool Loader::LoadScene( const std::string& filePath, Internal::Scene3dView& scen
 
 bool Loader::ParseGltf( const std::string& filePath )
 {
-  std::ifstream fileStream( filePath.c_str() );
-  std::string fileBuffer( ( std::istreambuf_iterator<char>( fileStream ) ),
-    ( std::istreambuf_iterator<char>() ) );
-  mParser = Dali::Toolkit::JsonParser::New();
+  std::streampos bufferSize = 0;
+  Dali::Vector<char> buffer;
+  std::string fileBuffer;
+  if( !Dali::FileLoader::ReadFile( filePath, bufferSize, buffer, FileLoader::FileType::BINARY ) )
+  {
+    return false;
+  }
 
+  fileBuffer.assign( &buffer[0], bufferSize );
+  mParser = Dali::Toolkit::JsonParser::New();
   return mParser.Parse( fileBuffer );
 }
 
index 0d81192..19357f5 100644 (file)
@@ -25,7 +25,6 @@
 #include <dali/devel-api/adaptor-framework/file-loader.h>
 #include <dali/devel-api/scripting/enum-helper.h>
 #include <dali/devel-api/scripting/scripting.h>
-#include <fstream>
 
 //INTERNAL INCLUDES
 #include <dali-toolkit/public-api/visuals/visual-properties.h>