OSSIA
Open Scenario System for Interactive Application
osc_packet_processor.hpp
1 #pragma once
3 
4 #include <oscpack/osc/OscReceivedElements.h>
5 
6 namespace ossia::net
7 {
8 template <typename F>
9 struct osc_packet_processor
10 {
11  F on_message;
12 
13  void operator()(const char* data, std::size_t sz) const noexcept
14  try
15  {
16  oscpack::ReceivedPacket p{data, sz};
17  if(!p.IsBundle())
18  on_message(oscpack::ReceivedMessage(p));
19  else
20  on_bundle(oscpack::ReceivedBundle(p));
21  }
22  catch(std::exception& e)
23  {
24  ossia::logger().error("[osc_packet_processor] {}", e.what());
25  }
26  catch(...)
27  {
28  ossia::logger().error("[osc_packet_processor]");
29  }
30 
31 private:
32  void on_bundle(const oscpack::ReceivedBundle& b) const
33  {
34  using namespace oscpack;
35  for(auto i = b.ElementsBegin(); i != b.ElementsEnd(); ++i)
36  {
37  if(!i->IsBundle())
38  on_message(oscpack::ReceivedMessage(*i));
39  else
40  on_bundle(oscpack::ReceivedBundle(*i));
41  }
42  }
43 };
44 }
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition: context.cpp:104