Added UDP multicast for plugin discovery (#153)
* Added Timer * Added UDPSocket::GetAddr * Added MessageHandlers::SendBeacon() * PoC of starting a timer on PluginEnable * C++11 * Added Timer to xcode project * C++11 in cmake * added Timer to cmake * use function pointer in Timer * moved Timer to namespace + wait for thread to join when stopping the timer * Windows: changed uint to unisgned short * Windows: Added Timer.h/cpp to project * GetAddr static * Send xplane and plugin version with BECN * SendBeacon with params * fixed file copyrights * Include functional to fix Linux compile error * review fixes * Send plugin receive port in BECN * review fixes
This commit is contained in:
committed by
Jason Watkins
parent
f9bfd6e3b9
commit
50335c4a5c
27
xpcPlugin/Timer.cpp
Normal file
27
xpcPlugin/Timer.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2013-2018 United States Government as represented by the Administrator of the
|
||||
// National Aeronautics and Space Administration. All Rights Reserved.
|
||||
|
||||
#include "Timer.h"
|
||||
using namespace std;
|
||||
|
||||
namespace XPC {
|
||||
void Timer::start(const chrono::milliseconds interval, const Callback &callback) {
|
||||
{
|
||||
running.test_and_set();
|
||||
th = thread([=]()
|
||||
{
|
||||
while (running.test_and_set()) {
|
||||
this_thread::sleep_for(interval);
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::stop() {
|
||||
running.clear();
|
||||
if(th.joinable()) {
|
||||
th.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user