[enco] Replace OwnedFileDescriptor with cwrap::Fildes (#3207)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 10 Apr 2019 08:31:53 +0000 (17:31 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 10 Apr 2019 08:31:53 +0000 (17:31 +0900)
This commit replaces OwnedFileDescriptor in enco with cwrap::Fildes.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/frontend/tflite/src/RawModelLoader.cpp
contrib/enco/requires.cmake

index c610684..834f071 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "RawModelLoader.h"
 
+#include "cwrap/Fildes.h"
+
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/stat.h>
@@ -57,64 +59,18 @@ private:
 
 } // namespace
 
-namespace
-{
-
-class OwnedFileDescriptor final
-{
-public:
-  OwnedFileDescriptor(int value) : _value{value}
-  {
-    // DO NOTHING
-  }
-
-public:
-  // NOTE Copy is not allowed
-  OwnedFileDescriptor(const OwnedFileDescriptor &) = delete;
-
-public:
-  // NOTE Move is allowed
-  OwnedFileDescriptor(OwnedFileDescriptor &&fd) { _value = fd.release(); }
-
-public:
-  ~OwnedFileDescriptor()
-  {
-    if (_value != -1)
-    {
-      // Close on descturction
-      close(_value);
-    }
-  }
-
-public:
-  int value(void) const { return _value; }
-
-public:
-  int release(void)
-  {
-    auto res = _value;
-    _value = -1;
-    return res;
-  }
-
-private:
-  int _value = -1;
-};
-
-} // namespace
-
 std::unique_ptr<RawModel> load_from(const std::string &path)
 {
-  OwnedFileDescriptor fd = open(path.c_str(), O_RDONLY);
+  cwrap::Fildes fildes{open(path.c_str(), O_RDONLY)};
 
-  if (fd.value() == -1)
+  if (fildes.get() == -1)
   {
     // Return nullptr on open failure
     return nullptr;
   }
 
   struct stat st;
-  if (fstat(fd.value(), &st) == -1)
+  if (fstat(fildes.get(), &st) == -1)
   {
     // Return nullptr on fstat failure
     return nullptr;
index ba46319..656722e 100644 (file)
@@ -3,3 +3,4 @@ require("caffegen")
 require("tflchef")
 require("ann")
 require("nnkit")
+require("cwrap")