Revert "[Tizen] Add log if destroyed visual get some signal"
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / navigation-mesh-factory.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // CLASS HEADER
18 #include <dali-scene3d/public-api/loader/navigation-mesh-factory.h>
19
20 // EXTERNAL INCLUDES
21 #include <dali/integration-api/debug.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-scene3d/internal/algorithm/navigation-mesh-impl.h>
25 #include <dali/devel-api/adaptor-framework/file-stream.h>
26
27 namespace Dali::Scene3D::Loader
28 {
29 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromFile(std::string filename)
30 {
31   std::vector<uint8_t> buffer;
32
33   Dali::FileStream fileStream(filename, Dali::FileStream::READ | Dali::FileStream::BINARY);
34   auto             fin = fileStream.GetFile();
35
36   if(DALI_UNLIKELY(!fin))
37   {
38     const int bufferLength = 128;
39     char      buffer[bufferLength];
40
41     // Return type of stderror_r is different between system type. We should not use return value.
42     [[maybe_unused]] auto ret = strerror_r(errno, buffer, bufferLength - 1);
43
44     DALI_LOG_ERROR("NavigationMesh: Can't open %s for reading: %s", filename.c_str(), buffer);
45     return nullptr;
46   }
47
48   if(DALI_UNLIKELY(fseek(fin, 0, SEEK_END)))
49   {
50     DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
51     return nullptr;
52   }
53
54   auto size = ftell(fin);
55   if(DALI_UNLIKELY(size < 0))
56   {
57     DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
58     return nullptr;
59   }
60
61   auto fileSize = size_t(size);
62   if(DALI_UNLIKELY(fseek(fin, 0, SEEK_SET)))
63   {
64     DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
65     return nullptr;
66   }
67
68   buffer.resize(size);
69   auto count = fread(buffer.data(), 1, fileSize, fin);
70   if(DALI_UNLIKELY(count != fileSize))
71   {
72     DALI_LOG_ERROR("NavigationMesh: Error reading file: %s\n", filename.c_str());
73     return nullptr;
74   }
75   return CreateFromBuffer(buffer);
76 }
77
78 std::unique_ptr<Algorithm::NavigationMesh> NavigationMeshFactory::CreateFromBuffer(const std::vector<uint8_t>& buffer)
79 {
80   auto impl = new Scene3D::Internal::Algorithm::NavigationMesh(buffer);
81   return std::unique_ptr<Algorithm::NavigationMesh>(new Algorithm::NavigationMesh(impl));
82 }
83
84 } // namespace Dali::Scene3D::Loader