2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "abstractroutingengine.h"
23 #include "listplusplus.h"
26 #include <sys/types.h>
27 #include <sys/socket.h>
32 #define GPSTIME "GpsTime"
34 extern "C" void create(AbstractRoutingEngine* routingEngine, map<string, string> config)
36 new ChronySink(routingEngine, config);
39 ChronySink::ChronySink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config)
41 routingEngine->subscribeToProperty(GPSTIME, this);
42 supportedChanged(engine->supported());
45 PropertyList ChronySink::subscriptions()
49 void ChronySink::supportedChanged(const PropertyList & supportedProperties)
51 DebugOut()<<"Support changed!"<<endl;
54 void ChronySink::propertyChanged(AbstractPropertyType *value)
58 struct chrony_sock_sample chronydata;
60 sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
61 if (sockfd < 0) return;
63 s.sun_family = AF_UNIX;
64 strcpy(s.sun_path, CHRONYD_SOCKET );
66 if(connect(sockfd, (struct sockaddr *)&s, sizeof(s)) == -1)
71 gettimeofday(&(chronydata.tv), NULL);
72 chronydata.offset = (value->value<double>() - chronydata.tv.tv_sec) - (chronydata.tv.tv_usec / 1000000.0);
73 chronydata.offset -= (amb::currentTime()-value->timestamp);
76 chronydata.magic = 0x534f434b;
77 send(sockfd,&chronydata,sizeof(chronydata),0);
82 const string ChronySink::uuid()
84 return "35324592-db72-11e4-b432-0022684a4a24";