NAP
artnetreceiver.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  // Local Includes
8 #include "artnetlistener.h"
9 #include "artnetevent.h"
10 
11 // External Includes
12 #include <nap/device.h>
13 #include <rtti/factory.h>
14 #include <asio/io_service.hpp>
15 #include <thread>
16 #include <mutex>
17 #include <queue>
18 #include <memory>
19 #include <cstdint>
20 
21 namespace nap
22 {
23  // Forward Declares
24  class ArtNetService;
25 
29  class NAPAPI ArtNetReceiver : public Device
30  {
31  RTTI_ENABLE(Device)
32 
33  public:
34 
35  // Default constructor
36  ArtNetReceiver() = default;
37 
38  // Constructor used by factory
39  ArtNetReceiver(ArtNetService & service);
40 
46  virtual bool start(utility::ErrorState& errorState) override;
47 
51  virtual void stop() override;
52 
57  void addEvent(ArtNetEventPtr event);
58 
64  void consumeEvents(std::queue<ArtNetEventPtr>& outEvents);
65 
66  std::string mIpAddress = "";
67  uint16 mPort = 6454;
68 
69  private:
70  friend class ArtNetService;
71 
72  // Art-Net service that consumes the events
73  ArtNetService* mService = nullptr;
74 
75  // The ASIO I/O service
76  asio::io_service mIOService;
77 
78  // The thread used for running the I/O service
79  std::thread mRunThread;
80 
81  // The UDP socket server used for receiving Art-Net
82  std::unique_ptr<ArtNetListener> mListener = nullptr;
83 
84  // Queue that holds all the consumed events
85  std::queue<ArtNetEventPtr> mEvents;
86 
87  // Mutex associated with setting / getting events
88  std::mutex mEventMutex;
89  };
90 
92 }
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::utility::ErrorState
Definition: errorstate.h:19
nap::ArtNetEventPtr
std::unique_ptr< nap::ArtNetEvent > ArtNetEventPtr
Definition: artnetevent.h:138
nap::ArtNetService
Definition: artnetservice.h:39
nap
Definition: templateapp.h:17
nap::uint16
uint16_t uint16
Definition: numeric.h:18
nap::ArtNetReceiver
Definition: artnetreceiver.h:29
nap::Device
Definition: device.h:20