Using AmbPlugin instead of AbstractSink for the chrony plugin
authorOlivier Delbeke <olivier.delbeke@awtce.be>
Wed, 8 Apr 2015 15:29:14 +0000 (17:29 +0200)
committerOlivier Delbeke <olivier.delbeke@gmail.com>
Wed, 15 Apr 2015 18:15:41 +0000 (20:15 +0200)
plugins/chrony/chrony.cpp
plugins/chrony/chrony.h

index 0674427..8f12248 100644 (file)
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2012  Intel Corporation
+    Copyright (C) 2015  AWTC Europe
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -18,6 +19,7 @@
 
 
 #include "chrony.h"
+#include "ambplugin.h"
 #include "abstractroutingengine.h"
 #include "debugout.h"
 #include "listplusplus.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);
+        auto plugin = new AmbPlugin<ChronySink>(routingEngine, config);
+        plugin->init();
+}
+
+ChronySink::ChronySink(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config, AbstractSource& parent)
+       :AmbPluginImpl(re, config, parent)
+{
+       supportedChanged(re->supported());
 }
 
-ChronySink::ChronySink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
+void ChronySink::init()
 {
-       routingEngine->subscribeToProperty(GPSTIME, this);
-       supportedChanged(engine->supported());
+       routingEngine->subscribeToProperty("GpsTime", &source);
 }
 
 PropertyList ChronySink::subscriptions()
@@ -79,7 +85,3 @@ void ChronySink::propertyChanged(AbstractPropertyType *value)
        close(sockfd);
 }
 
-const string ChronySink::uuid()
-{
-       return "35324592-db72-11e4-b432-0022684a4a24";
-}
index aca57a3..25da7e0 100644 (file)
@@ -1,5 +1,6 @@
 /*
     Copyright (C) 2012  Intel Corporation
+    Copyright (C) 2015  AWTC Europe
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
@@ -20,7 +21,7 @@
 #ifndef CHRONYSINK_H
 #define CHRONYSINK_H
 
-#include "abstractsink.h"
+#include "ambpluginimpl.h"
 
 #define CHRONYD_SOCKET "/tmp/chrony.gps.sock"
 
@@ -33,15 +34,18 @@ struct chrony_sock_sample {
   int magic;
 };
 
-class ChronySink : public AbstractSink
+class ChronySink : public AmbPluginImpl
 {
 
 public:
-       ChronySink(AbstractRoutingEngine* engine, map<string, string> config);
+       ChronySink(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config, AbstractSource& parent);
+       ~ChronySink() { };
+       const std::string uuid() const { return "35324592-db72-11e4-b432-0022684a4a24"; }
+       virtual void init();
        virtual PropertyList subscriptions();
        virtual void supportedChanged(const PropertyList & supportedProperties);
        virtual void propertyChanged( AbstractPropertyType* value);
-       virtual const std::string uuid();
+
 };
 
 #endif // CHRONYSINK_H