p2p: Add P2PManager class
This class makes it simple to use p2p both as a client and a server.
For now, this feature is hidden behind a flag. The intent is that this
flag can be toggled with the crosh command - for now, only the reading
of the flag is implemented - see chromium:260441 for the remaining
work.
BUG=chromium:260426,chromium:260441
TEST=New unit tests + unit tests pass
Change-Id: If1879f4535c8e7e3af7c6d378e6df4054264b794
Reviewed-on: https://chromium-review.googlesource.com/64824
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/utils.h b/utils.h
index 412252c..79b6917 100644
--- a/utils.h
+++ b/utils.h
@@ -35,6 +35,20 @@
// boot mode. Returns false if the boot mode is developer.
bool IsNormalBootMode();
+// Converts a struct timespec representing a number of seconds since
+// the Unix epoch to a base::Time. Sub-microsecond time is rounded
+// down.
+base::Time TimeFromStructTimespec(struct timespec *ts);
+
+// Converts a vector of strings to a NULL-terminated array of
+// strings. The resulting array should be freed with g_strfreev()
+// when are you done with it.
+gchar** StringVectorToGStrv(const std::vector<std::string> &vector);
+
+// Formats |vector| as a string of the form ["<elem1>", "<elem2>"].
+// Does no escaping, only use this for presentation in error messages.
+std::string StringVectorToString(const std::vector<std::string> &vector);
+
// Returns the HWID or an empty string on error.
std::string GetHardwareClass();
@@ -470,6 +484,24 @@
DISALLOW_COPY_AND_ASSIGN(ScopedActionCompleter);
};
+// A base::FreeDeleter that frees memory using g_free(). Useful when
+// integrating with GLib since it can be used with scoped_ptr to
+// automatically free memory when going out of scope.
+struct GLibFreeDeleter : public base::FreeDeleter {
+ inline void operator()(void *ptr) const {
+ g_free(reinterpret_cast<gpointer>(ptr));
+ }
+};
+
+// A base::FreeDeleter that frees memory using g_strfreev(). Useful
+// when integrating with GLib since it can be used with scoped_ptr to
+// automatically free memory when going out of scope.
+struct GLibStrvFreeDeleter : public base::FreeDeleter {
+ inline void operator()(void *ptr) const {
+ g_strfreev(reinterpret_cast<gchar**>(ptr));
+ }
+};
+
} // namespace chromeos_update_engine
#define TEST_AND_RETURN_FALSE_ERRNO(_x) \