[openweave] Add Log and CriticalSection to minimal

Adds the "Log" and "CriticalSection" implementations to the minimal
build target as these are required to satisfy the linker as well in
certain build configurations.

Change-Id: I1f94b1bb5a25d12836f076612789a9f051f2245f
diff --git a/BUILD.gn b/BUILD.gn
index c7644f2..0802801 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -23,5 +23,9 @@
 # Provides OpenWeave plus the minimal dependencies to build.
 source_set("openweave-core-minimal") {
   public_deps = [ ":openweave-core" ]
-  sources = [ "src/adaptations/device-layer/PersistedStorage-Stub.cpp" ]
+  sources = [
+    "src/adaptations/device-layer/Fuchsia/minimal/CriticalSection-Stub.cpp",
+    "src/adaptations/device-layer/Fuchsia/minimal/Logging.cpp",
+    "src/adaptations/device-layer/Fuchsia/minimal/PersistedStorage-Stub.cpp",
+  ]
 }
diff --git a/src/adaptations/device-layer/Fuchsia/minimal/CriticalSection-Stub.cpp b/src/adaptations/device-layer/Fuchsia/minimal/CriticalSection-Stub.cpp
new file mode 100644
index 0000000..48cf0d6
--- /dev/null
+++ b/src/adaptations/device-layer/Fuchsia/minimal/CriticalSection-Stub.cpp
@@ -0,0 +1,28 @@
+// Copyright 2021 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+namespace nl {
+namespace Weave {
+namespace Profiles {
+namespace DataManagement_Current {
+namespace Platform {
+
+// Dummy implementations of CriticalSection platform methods. When using the
+// subset of openweave that does not require CriticalSection to operate, but
+// must still satisfy the linker, these implementations can be used instead.
+//
+// NOTE: Do *NOT* use this implementation if the full functionality of
+// OpenWeave is used, this is intended only as a way to satisfy the linker
+// for uses that use a small, limited subset of OpenWeave that do not require
+// these to be implemented.
+
+void CriticalSectionEnter() {}
+void CriticalSectionExit() {}
+
+}  // namespace Platform
+}  // namespace DataManagement_Current
+}  // namespace Profiles
+}  // namespace Weave
+}  // namespace nl
+
diff --git a/src/adaptations/device-layer/Fuchsia/minimal/Logging.cpp b/src/adaptations/device-layer/Fuchsia/minimal/Logging.cpp
new file mode 100644
index 0000000..ed831b2
--- /dev/null
+++ b/src/adaptations/device-layer/Fuchsia/minimal/Logging.cpp
@@ -0,0 +1,70 @@
+// Copyright 2021 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <lib/syslog/cpp/macros.h>
+
+#include <Weave/Support/logging/WeaveLogging.h>
+
+#if WEAVE_LOGGING_STYLE_EXTERNAL
+using namespace ::nl::Weave;
+
+namespace nl {
+namespace Weave {
+namespace Logging {
+namespace {
+constexpr size_t kFormattedMessageSize = 256;
+}  // namespace
+
+void Log(uint8_t module, uint8_t category, const char * file, uint32_t line, const char * msg,
+         va_list v)
+{
+    if (IsCategoryEnabled(category))
+    {
+        char formattedMsg[kFormattedMessageSize];
+        vsnprintf(formattedMsg, sizeof(formattedMsg), msg, v);
+
+        char module_name[nlWeaveLoggingModuleNameLen + 1];
+        GetModuleName(module_name, module);
+
+        syslog::LogSeverity severity = syslog::LOG_INFO;
+        switch (category)
+        {
+        case kLogCategory_Error:
+            severity = syslog::LOG_ERROR;
+            break;
+        case kLogCategory_Progress:
+        case kLogCategory_Retain:
+        case kLogCategory_Detail:
+            severity = syslog::LOG_INFO;
+            break;
+        }
+
+        const char * file_basename = strrchr(file, '/');
+        file_basename = file_basename ? file_basename + 1 : file;
+        syslog::LogMessage(severity, file_basename, line, nullptr, nullptr).stream()
+            << "[" << module_name << "] " << formattedMsg;
+    }
+}
+
+void Log(uint8_t module, uint8_t category, const char * msg, ...)
+{
+    va_list vargs;
+    va_start(vargs, msg);
+    Log(module, category, "", 0, msg, vargs);
+    va_end(vargs);
+}
+
+void Log(uint8_t module, uint8_t category, const char * file, uint32_t line, const char * msg, ...)
+{
+    va_list vargs;
+    va_start(vargs, msg);
+    Log(module, category, file, line, msg, vargs);
+    va_end(vargs);
+}
+
+}  // namespace Logging
+}  // namespace Weave
+}  // namespace nl
+
+#endif  // WEAVE_LOGGING_STYLE_EXTERNAL
diff --git a/src/adaptations/device-layer/PersistedStorage-Stub.cpp b/src/adaptations/device-layer/Fuchsia/minimal/PersistedStorage-Stub.cpp
similarity index 100%
rename from src/adaptations/device-layer/PersistedStorage-Stub.cpp
rename to src/adaptations/device-layer/Fuchsia/minimal/PersistedStorage-Stub.cpp