summaryrefslogtreecommitdiff
path: root/plugins/chrony
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/chrony')
-rw-r--r--plugins/chrony/CMakeLists.txt16
-rw-r--r--plugins/chrony/README24
-rw-r--r--plugins/chrony/chrony.cpp85
-rw-r--r--plugins/chrony/chrony.h47
4 files changed, 172 insertions, 0 deletions
diff --git a/plugins/chrony/CMakeLists.txt b/plugins/chrony/CMakeLists.txt
new file mode 100644
index 00000000..a66a1965
--- /dev/null
+++ b/plugins/chrony/CMakeLists.txt
@@ -0,0 +1,16 @@
+if(chrony_plugin)
+
+set(chrony_headers chrony.h)
+set(chrony_sources chrony.cpp )
+
+add_library(chrony MODULE ${chrony_sources})
+set_target_properties(chrony PROPERTIES PREFIX "")
+target_link_libraries(chrony amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES})
+
+install(TARGETS chrony LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/chrony.README @ONLY)
+
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/chrony.README DESTINATION ${DOC_INSTALL_DIR}/plugins)
+
+endif(chrony_plugin)
diff --git a/plugins/chrony/README b/plugins/chrony/README
new file mode 100644
index 00000000..a9f28c24
--- /dev/null
+++ b/plugins/chrony/README
@@ -0,0 +1,24 @@
+CHRONY plugin
+Version: @PROJECT_VERSION@
+
+This plugin will forward the GpsTime property to the CHRONYD daemon.
+
+To enable the CHRONY plugin, run cmake and enable the chrony_plugin option:
+
+cmake -Dchrony_plugin=On ..
+
+To use this plugin, add the following to the "sinks" array in /etc/ambd/config:
+
+{
+ "name" : "chrony",
+ "path" : "@PLUGIN_INSTALL_PATH@/chrony.so",
+}
+
+Configuration Key Definitions:
+
+"name"
+name of plugin. This key is not used by the plugin at this moment.
+
+"path"
+path to plugin on the filesystem.
+
diff --git a/plugins/chrony/chrony.cpp b/plugins/chrony/chrony.cpp
new file mode 100644
index 00000000..0674427e
--- /dev/null
+++ b/plugins/chrony/chrony.cpp
@@ -0,0 +1,85 @@
+/*
+ Copyright (C) 2012 Intel Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "chrony.h"
+#include "abstractroutingengine.h"
+#include "debugout.h"
+#include "listplusplus.h"
+
+#include <glib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/time.h>
+#include <math.h>
+
+#define GPSTIME "GpsTime"
+
+extern "C" void create(AbstractRoutingEngine* routingEngine, map<string, string> config)
+{
+ new ChronySink(routingEngine, config);
+}
+
+ChronySink::ChronySink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
+{
+ routingEngine->subscribeToProperty(GPSTIME, this);
+ supportedChanged(engine->supported());
+}
+
+PropertyList ChronySink::subscriptions()
+{
+}
+
+void ChronySink::supportedChanged(const PropertyList & supportedProperties)
+{
+ DebugOut()<<"Support changed!"<<endl;
+}
+
+void ChronySink::propertyChanged(AbstractPropertyType *value)
+{
+ int sockfd;
+ struct sockaddr_un s;
+ struct chrony_sock_sample chronydata;
+
+ sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
+ if (sockfd < 0) return;
+
+ s.sun_family = AF_UNIX;
+ strcpy(s.sun_path, CHRONYD_SOCKET );
+
+ if(connect(sockfd, (struct sockaddr *)&s, sizeof(s)) == -1)
+ {
+ return;
+ }
+
+ gettimeofday(&(chronydata.tv), NULL);
+ chronydata.offset = (value->value<double>() - chronydata.tv.tv_sec) - (chronydata.tv.tv_usec / 1000000.0);
+ chronydata.offset -= (amb::currentTime()-value->timestamp);
+ chronydata.pulse = 0;
+ chronydata.leap = 0;
+ chronydata.magic = 0x534f434b;
+ send(sockfd,&chronydata,sizeof(chronydata),0);
+
+ close(sockfd);
+}
+
+const string ChronySink::uuid()
+{
+ return "35324592-db72-11e4-b432-0022684a4a24";
+}
diff --git a/plugins/chrony/chrony.h b/plugins/chrony/chrony.h
new file mode 100644
index 00000000..aca57a3a
--- /dev/null
+++ b/plugins/chrony/chrony.h
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2012 Intel Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef CHRONYSINK_H
+#define CHRONYSINK_H
+
+#include "abstractsink.h"
+
+#define CHRONYD_SOCKET "/tmp/chrony.gps.sock"
+
+struct chrony_sock_sample {
+ struct timeval tv;
+ double offset;
+ int pulse;
+ int leap;
+ int _pad;
+ int magic;
+};
+
+class ChronySink : public AbstractSink
+{
+
+public:
+ ChronySink(AbstractRoutingEngine* engine, map<string, string> config);
+ virtual PropertyList subscriptions();
+ virtual void supportedChanged(const PropertyList & supportedProperties);
+ virtual void propertyChanged( AbstractPropertyType* value);
+ virtual const std::string uuid();
+};
+
+#endif // CHRONYSINK_H