Initial commit for phosphor-nvme

Add initial build files and the main module

Signed-off-by: Tony Lee <tony.lee@quantatw.com>
Change-Id: I80ed7acc369adee881b70e68c326049056589dcd
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..8c5278e
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,98 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+  - Regex:           '^[<"](gtest|gmock)'
+    Priority:        5
+  - Regex:           '^"config.h"'
+    Priority:        -1
+  - Regex:           '^".*\.hpp"'
+    Priority:        1
+  - Regex:           '^<.*\.h>'
+    Priority:        2
+  - Regex:           '^<.*'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        4
+IndentCaseLabels: true
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..07b1dd5
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,33 @@
+project(
+    'phosphor-nvme',
+    'cpp',
+    version: '1.0',
+    default_options: [
+        'cpp_std=c++17',
+    ],
+)
+
+executable(
+    'nvme_main',
+    [
+        'nvme_main.cpp',
+        'nvme_manager.cpp',
+    ],
+    dependencies: [
+        dependency('phosphor-logging'),
+        dependency('sdbusplus'),
+        dependency('phosphor-dbus-interfaces'),
+        dependency('sdeventplus'),
+    ],
+    install: true,
+    install_dir: get_option('bindir')
+)
+
+conf_data = configuration_data()
+conf_data.set('NVME_REQUEST_NAME', '"xyz.openbmc_project.nvme.manager"')
+conf_data.set('NVME_OBJ_PATH_ROOT', '"/xyz/openbmc_project/sensors/temperature"')
+conf_data.set('NVME_OBJ_PATH', '"/xyz/openbmc_project/sensors/temperature/nvme"')
+conf_data.set('DBUS_PROPERTY_IFACE', '"org.freedesktop.DBus.Properties"')
+
+configure_file(output : 'config.h',
+               configuration : conf_data)
diff --git a/nvme_main.cpp b/nvme_main.cpp
new file mode 100644
index 0000000..956e374
--- /dev/null
+++ b/nvme_main.cpp
@@ -0,0 +1,37 @@
+#include "nvme_manager.hpp"
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/sdbus.hpp>
+#include <sdbusplus/server/manager.hpp>
+
+int main(void)
+{
+
+    sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
+
+    sd_event* event = nullptr;
+    auto eventDeleter = [](sd_event* e) { e = sd_event_unref(e); };
+    using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>;
+    // acquire a reference to the default event loop
+    sd_event_default(&event);
+    SdEvent sdEvent{event, eventDeleter};
+    event = nullptr;
+    // attach bus to this event loop
+    bus.attach_event(sdEvent.get(), SD_EVENT_PRIORITY_NORMAL);
+
+    sdbusplus::server::manager::manager objManager(bus, NVME_OBJ_PATH_ROOT);
+
+    phosphor::nvme::Nvme objMgr(bus);
+
+    bus.request_name(NVME_REQUEST_NAME);
+
+    objMgr.run();
+
+    // Start event loop for all sd-bus events
+
+    sd_event_loop(bus.get_event());
+
+    bus.detach_event();
+
+    return 0;
+}
\ No newline at end of file
diff --git a/nvme_manager.cpp b/nvme_manager.cpp
new file mode 100644
index 0000000..1f946f4
--- /dev/null
+++ b/nvme_manager.cpp
@@ -0,0 +1,40 @@
+#include "nvme_manager.hpp"
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/log.hpp>
+
+#define MONITOR_INTERVAL_SECONDS 1
+namespace phosphor
+{
+namespace nvme
+{
+
+using namespace std;
+using namespace phosphor::logging;
+
+void Nvme::run()
+{
+    init();
+
+    std::function<void()> callback(std::bind(&Nvme::read, this));
+    try
+    {
+        u_int64_t interval = MONITOR_INTERVAL_SECONDS * 1000000;
+        _timer.restart(std::chrono::microseconds(interval));
+    }
+    catch (const std::exception& e)
+    {
+        log<level::ERR>("Error in polling loop. "),
+            entry("ERROR = %s", e.what());
+    }
+}
+
+void Nvme::init()
+{
+}
+
+void Nvme::read()
+{
+}
+} // namespace nvme
+} // namespace phosphor
diff --git a/nvme_manager.hpp b/nvme_manager.hpp
new file mode 100644
index 0000000..b6f32c3
--- /dev/null
+++ b/nvme_manager.hpp
@@ -0,0 +1,43 @@
+#include "config.h"
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <sdeventplus/clock.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+
+namespace phosphor
+{
+namespace nvme
+{
+
+class Nvme
+{
+  public:
+    Nvme() = delete;
+    Nvme(const Nvme&) = delete;
+    Nvme& operator=(const Nvme&) = delete;
+    Nvme(Nvme&&) = delete;
+    Nvme& operator=(Nvme&&) = delete;
+
+    Nvme(sdbusplus::bus::bus& bus) :
+        bus(bus), _event(sdeventplus::Event::get_default()),
+        _timer(_event, std::bind(&Nvme::read, this))
+    {
+    }
+
+    void run();
+
+  private:
+    sdbusplus::bus::bus& bus;
+
+    sdeventplus::Event _event;
+    /** @brief Read Timer */
+    sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> _timer;
+
+    void init();
+    void read();
+};
+} // namespace nvme
+} // namespace phosphor
\ No newline at end of file