NAP
oscsender.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // External Includes
8 #include <ip/UdpSocket.h>
9 #include <nap/resource.h>
10 #include <rtti/factory.h>
11 #include <queue>
12 #include <nap/device.h>
13 
14 // Local Includes
15 #include "oscevent.h"
16 
17 // Forward declares
18 class UdpTransmitSocket;
19 namespace nap
20 {
21  class OSCService;
22 }
23 namespace osc
24 {
25  class OutboundPacketStream;
26 }
27 
28 
29 namespace nap
30 {
35  class NAPAPI OSCSender : public Device
36  {
37  friend class OSCService;
38  RTTI_ENABLE(Device)
39  public:
40  OSCSender() = default;
41 
42  // Constructor used by factory
43  OSCSender(OSCService& service);
44 
45  std::string mIPAddress = "127.0.0.1";
46  int mPort = 8000;
47  int mBufferScale = 2;
48 
49 
53  virtual bool start(utility::ErrorState& errorState) override;
54 
58  virtual void stop() override;
59 
65  bool send(const OSCEvent& oscEvent);
66 
74  void addEvent(OSCEventPtr oscEvent);
75 
80  void sendQueuedEvents();
81 
82  private:
83  // Socket used for sending messages
84  std::unique_ptr<UdpTransmitSocket> mSocket = nullptr;
85 
90  void writeToPacket(const OSCEvent& oscEvent, osc::OutboundPacketStream& outPacket);
91 
92  // Queue that holds all the events to be send over as a bundle
93  std::queue<OSCEventPtr> mEventQueue;
94 
95  // The number of bytes represented by the values in the event queue
96  std::size_t mEventQueueDataSize;
97 
98  // Vector that holds osc data to be send over
99  std::vector<char> mBuffer;
100  };
101 }
nap::OSCEvent
Definition: oscevent.h:25
nap::OSCSender
Definition: oscsender.h:35
nap::utility::ErrorState
Definition: errorstate.h:19
nap
Definition: templateapp.h:17
nap::OSCService
Definition: oscservice.h:28
nap::Device
Definition: device.h:20
nap::OSCEventPtr
std::unique_ptr< nap::OSCEvent > OSCEventPtr
Definition: oscevent.h:156