Move ScopedPipe/Application classes out of starterd_lib.*

Change-Id: I1b66ef343b6d4d1129fdc8d40781d1e5b711d2b2
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/util/scoped_pipe.h b/aos/util/scoped_pipe.h
new file mode 100644
index 0000000..5f86510
--- /dev/null
+++ b/aos/util/scoped_pipe.h
@@ -0,0 +1,56 @@
+#ifndef AOS_UTIL_SCOPED_PIPE_H_
+#define AOS_UTIL_SCOPED_PIPE_H_
+
+#include <stdint.h>
+
+#include <optional>
+#include <tuple>
+
+namespace aos::util {
+
+// RAII Pipe for sending individual ints between reader and writer.
+class ScopedPipe {
+ public:
+  class ScopedReadPipe;
+  class ScopedWritePipe;
+
+  static std::tuple<ScopedReadPipe, ScopedWritePipe> MakePipe();
+
+  virtual ~ScopedPipe();
+
+  int fd() const { return fd_; }
+
+ private:
+  ScopedPipe(int fd = -1);
+
+  int fd_;
+
+  ScopedPipe(const ScopedPipe &) = delete;
+  ScopedPipe &operator=(const ScopedPipe &) = delete;
+  ScopedPipe(ScopedPipe &&);
+  ScopedPipe &operator=(ScopedPipe &&);
+};
+
+class ScopedPipe::ScopedReadPipe : public ScopedPipe {
+ public:
+  std::optional<uint32_t> Read();
+
+ private:
+  using ScopedPipe::ScopedPipe;
+
+  friend class ScopedPipe;
+};
+
+class ScopedPipe::ScopedWritePipe : public ScopedPipe {
+ public:
+  void Write(uint32_t data);
+
+ private:
+  using ScopedPipe::ScopedPipe;
+
+  friend class ScopedPipe;
+};
+
+}  //  namespace aos::util
+
+#endif  // AOS_UTIL_SCOPED_PIPE_H_