Add thin abstraction layer for processes and filesystem

This is used instead of some hardcoded Unix calls and means this code
now works on Windows

(This is a rework of a previous patch which used boost, now that I have
been informed that we are trying to move towards removing boost).

Change-Id: Ib0d11055279bbd7b710f086e9890369e3ecbfe9a
Signed-off-by: Robert Hughes <robert.hughes@arm.com>
diff --git a/Android.mk b/Android.mk
index 8f348d9..60d1f7b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -118,6 +118,8 @@
         src/armnnUtils/TensorUtils.cpp \
         src/armnnUtils/VerificationHelpers.cpp \
         src/armnnUtils/NetworkSockets.cpp \
+        src/armnnUtils/Filesystem.cpp \
+        src/armnnUtils/Processes.cpp \
         src/armnn/layers/AbsLayer.cpp \
         src/armnn/layers/ActivationLayer.cpp \
         src/armnn/layers/AdditionLayer.cpp \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e39c2b8..14c2c0c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,10 @@
     include/armnnUtils/Permute.hpp
     include/armnnUtils/FloatingPointConverter.hpp
     include/armnnUtils/TensorUtils.hpp
+    src/armnnUtils/Filesystem.hpp
+    src/armnnUtils/Filesystem.cpp
+    src/armnnUtils/Processes.hpp
+    src/armnnUtils/Processes.cpp
     src/armnnUtils/GraphTopologicalSort.hpp
     src/armnnUtils/Half.hpp
     src/armnnUtils/Permute.cpp
diff --git a/src/armnnUtils/Filesystem.cpp b/src/armnnUtils/Filesystem.cpp
new file mode 100644
index 0000000..08c447b
--- /dev/null
+++ b/src/armnnUtils/Filesystem.cpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "Filesystem.hpp"
+
+#if defined(__unix__)
+#include <sys/stat.h>
+#include <stdio.h>
+#elif defined(_MSC_VER)
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+#endif
+
+namespace armnnUtils
+{
+namespace Filesystem
+{
+
+long GetFileSize(const char* path)
+{
+#if defined(__unix__)
+    struct stat statusBuffer;
+    if (stat(path, & statusBuffer) != 0)
+    {
+        return -1;
+    }
+    return statusBuffer.st_size;
+#elif defined(_MSC_VER)
+    WIN32_FILE_ATTRIBUTE_DATA attr;
+    if (::GetFileAttributesEx(path, GetFileExInfoStandard, &attr) == 0)
+    {
+        return -1;
+    }
+    return attr.nFileSizeLow;
+#endif
+}
+
+bool Remove(const char* path)
+{
+#if defined(__unix__)
+    return remove(path) == 0;
+#elif defined(_MSC_VER)
+    return ::DeleteFile(path);
+#endif
+}
+
+}
+}
diff --git a/src/armnnUtils/Filesystem.hpp b/src/armnnUtils/Filesystem.hpp
new file mode 100644
index 0000000..d6dc5b9
--- /dev/null
+++ b/src/armnnUtils/Filesystem.hpp
@@ -0,0 +1,18 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+namespace armnnUtils
+{
+namespace Filesystem
+{
+
+long GetFileSize(const char* path);
+
+bool Remove(const char* path);
+
+}
+}
diff --git a/src/armnnUtils/Processes.cpp b/src/armnnUtils/Processes.cpp
new file mode 100644
index 0000000..0e43e8c
--- /dev/null
+++ b/src/armnnUtils/Processes.cpp
@@ -0,0 +1,30 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "Processes.hpp"
+
+#if defined(__unix__)
+#include <unistd.h>
+#elif defined(_MSC_VER)
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+#endif
+
+namespace armnnUtils
+{
+namespace Processes
+{
+
+int GetCurrentId()
+{
+#if defined(__unix__)
+    return getpid();
+#elif defined(_MSC_VER)
+    return ::GetCurrentProcessId();
+#endif
+}
+
+}
+}
diff --git a/src/armnnUtils/Processes.hpp b/src/armnnUtils/Processes.hpp
new file mode 100644
index 0000000..0f1d955
--- /dev/null
+++ b/src/armnnUtils/Processes.hpp
@@ -0,0 +1,16 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+namespace armnnUtils
+{
+namespace Processes
+{
+
+int GetCurrentId();
+
+}
+}
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index 5128331..4d305af 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -9,6 +9,7 @@
 
 #include <armnn/Exceptions.hpp>
 #include <armnn/Conversion.hpp>
+#include <Processes.hpp>
 
 #include <boost/format.hpp>
 #include <boost/numeric/conversion/cast.hpp>
@@ -90,7 +91,8 @@
         offset += sizeUint32;
         WriteUint32(writeBuffer, offset, MAX_METADATA_PACKET_LENGTH); // max_data_length
         offset += sizeUint32;
-        WriteUint32(writeBuffer, offset, numeric_cast<uint32_t>(getpid())); // pid
+        int pid = armnnUtils::Processes::GetCurrentId();
+        WriteUint32(writeBuffer, offset, numeric_cast<uint32_t>(pid)); // pid
         offset += sizeUint32;
         uint32_t poolOffset = bodySize;
         WriteUint32(writeBuffer, offset, infoSize ? poolOffset : 0); // offset_info
diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
index 2663470..4112dba 100644
--- a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
+++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp
@@ -7,6 +7,7 @@
 
 #include <ProfilingService.hpp>
 #include <Runtime.hpp>
+#include <Filesystem.hpp>
 
 #include <boost/core/ignore_unused.hpp>
 #include <boost/filesystem.hpp>
@@ -94,12 +95,10 @@
     profilingService.ResetExternalProfilingOptions(options, true);
 
     // The output file size should be greater than 0.
-    struct stat statusBuffer;
-    BOOST_CHECK(stat(tempPath.c_str(), &statusBuffer) == 0);
-    BOOST_CHECK(statusBuffer.st_size > 0);
+    BOOST_CHECK(armnnUtils::Filesystem::GetFileSize(tempPath.string().c_str()) > 0);
 
     // Delete the tmp file.
-    BOOST_CHECK(remove(tempPath.c_str()) == 0);
+    BOOST_CHECK(armnnUtils::Filesystem::Remove(tempPath.string().c_str()));
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp
index 1942316..83bffe4 100644
--- a/src/profiling/test/SendCounterPacketTests.cpp
+++ b/src/profiling/test/SendCounterPacketTests.cpp
@@ -10,6 +10,7 @@
 #include <EncodeVersion.hpp>
 #include <ProfilingUtils.hpp>
 #include <SendCounterPacket.hpp>
+#include <Processes.hpp>
 
 #include <armnn/Exceptions.hpp>
 #include <armnn/Conversion.hpp>
@@ -335,7 +336,8 @@
     offset += sizeUint32;
     BOOST_TEST(ReadUint32(readBuffer2, offset) == MAX_METADATA_PACKET_LENGTH); // max_data_len
     offset += sizeUint32;
-    BOOST_TEST(ReadUint32(readBuffer2, offset) == numeric_cast<uint32_t>(getpid())); // pid
+    int pid = armnnUtils::Processes::GetCurrentId();
+    BOOST_TEST(ReadUint32(readBuffer2, offset) == numeric_cast<uint32_t>(pid));
     offset += sizeUint32;
     uint32_t poolOffset = 10 * sizeUint32;
     BOOST_TEST(ReadUint32(readBuffer2, offset) == (infoSize ? poolOffset : 0)); // offset_info