Initial check-in of LPC Snoop Broadcast Daemon
This is a simple daemon which reads a file interface
from an lpc-snoop driver and broadcasts the values read.
It presently assumes there's /dev/aspeed-lpc-snoop0, however
this could be made a command line parameter.
Change-Id: Ic8e7511de619d93bf1cffd9a096c92315f870946
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/example.cpp b/example.cpp
new file mode 100644
index 0000000..2fb1e83
--- /dev/null
+++ b/example.cpp
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2017 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cstdio>
+#include <iostream>
+#include <memory>
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/message.hpp>
+#include <sdbusplus/server.hpp>
+
+#include "lpcsnoop/snoop.hpp"
+
+/*
+ * Handle incoming dbus signal we care about.
+ */
+static int DbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);
+
+/*
+ * Get the match signal for dbus.
+ */
+static std::string GetMatch(void);
+
+// Example object that listens for dbus updates.
+class SnoopListen
+{
+ public:
+ SnoopListen(sdbusplus::bus::bus& bus) :
+ _bus(bus), _signal(bus, GetMatch().c_str(), DbusHandleSignal, this)
+ {
+ }
+
+ private:
+ sdbusplus::bus::bus& _bus;
+ sdbusplus::server::match::match _signal;
+};
+
+/*
+ * This is the entry point for the application.
+ *
+ * This application simply creates an object that registers for incoming value
+ * updates for the POST code dbus object.
+ */
+int main(int argc, char* argv[])
+{
+ auto ListenBus = sdbusplus::bus::new_default();
+ SnoopListen snoop(ListenBus);
+
+ while (true)
+ {
+ ListenBus.process_discard();
+ ListenBus.wait();
+ }
+
+ return 0;
+}
+
+static int DbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err)
+{
+ auto sdbpMsg = sdbusplus::message::message(msg);
+
+ std::string msgSensor, busName{SNOOP_BUSNAME};
+ std::map<std::string, sdbusplus::message::variant<uint64_t>> msgData;
+ sdbpMsg.read(msgSensor, msgData);
+
+ if (msgSensor == busName)
+ {
+ auto valPropMap = msgData.find("Value");
+ if (valPropMap != msgData.end())
+ {
+ uint64_t rawValue = sdbusplus::message::variant_ns::get<uint64_t>(
+ valPropMap->second);
+
+ /* Print output to verify the example program is receiving values.
+ */
+ std::printf("recv: 0x%x\n", static_cast<uint8_t>(rawValue));
+ }
+ }
+
+ return 0;
+}
+
+static std::string GetMatch(void)
+{
+ return "type='signal',interface='org.freedesktop.DBus.Properties',"
+ "member='PropertiesChanged',path='" SNOOP_OBJECTPATH "'";
+}