bundle dispatching
This commit is contained in:
parent
0bfab08041
commit
773375757e
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "server.h"
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
namespace OSC {
|
||||
|
||||
|
@ -43,7 +44,7 @@ Server::~Server()
|
|||
* @brief Server::dispatch
|
||||
* @param msg
|
||||
*/
|
||||
void Server::dispatch(const std::shared_ptr<Message> msg)
|
||||
void Server::dispatch(const std::shared_ptr<Message> msg) const
|
||||
{
|
||||
switch (msg->address_pattern.at(0)) {
|
||||
case '/':
|
||||
|
@ -69,9 +70,40 @@ void Server::dispatch(const std::shared_ptr<Message> msg)
|
|||
* @brief Server::scheduleBundle
|
||||
* @param msg
|
||||
*/
|
||||
void Server::scheduleBundle(const std::shared_ptr<Bundle> msg)
|
||||
void Server::scheduleBundle(const std::shared_ptr<Bundle> msg) const
|
||||
{
|
||||
(void)msg;
|
||||
auto invoke = [&] {
|
||||
for (const auto &element: msg->elements)
|
||||
dispatch(element);
|
||||
};
|
||||
/**
|
||||
* > \cite Spec10 The OSC Bundle’s OSC Time Tag determines when the OSC Bundle’s OSC Messages’
|
||||
* > corresponding OSC Methods should be invoked.
|
||||
*/
|
||||
auto time = msg->time_tag.time();
|
||||
if (time <= std::chrono::system_clock::now())
|
||||
/**
|
||||
* > \cite Spec10 If the time represented by the OSC Time Tag is before or equal to the
|
||||
* > current time, the OSC Server should invoke the methods immediately.
|
||||
*
|
||||
* \warning The 64-bit \cite NTPv4 NTP timestamps rollover in 2036. After which all OSC
|
||||
* Bundles will appear to be in the past and will always be invoked immediately.
|
||||
*/
|
||||
invoke();
|
||||
else
|
||||
{
|
||||
/**
|
||||
* > \cite Spec10 Otherwise the OSC Time Tag represents a time in the future, and the OSC
|
||||
* > server must store the OSC Bundle until the specified time and then invoke the
|
||||
* > appropriate OSC Methods.
|
||||
*/
|
||||
std::thread thread([&] {
|
||||
std::this_thread::sleep_until(time);
|
||||
invoke();
|
||||
});
|
||||
thread.detach();
|
||||
/// \test validate future OSC Bundle scheduling.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue