AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WebSocketTrack.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXDATA_WEBSOCKET_STREAM_H
18 #define AGXDATA_WEBSOCKET_STREAM_H
19 
21 #include <agx/config.h>
22 #if AGX_USE_WEBSOCKETS()
23 
24 #include <agxNet/SocketTrack.h>
25 #include <agxNet/WebSocket.h>
26 
27 namespace agxNet
28 {
29 
32  {
33  public:
34  explicit WebSocketFrameWriter(agx::UInt16 port);
35  explicit WebSocketFrameWriter(agxNet::WebSocket* client);
36 
37  virtual void writeFrame(const agxData::Frame* frame);
38 
39  agx::UInt16 getPort() const;
40 
41  bool service(agx::Real timeoutMs = 0);
42 
43  protected:
44  virtual ~WebSocketFrameWriter() {}
45 
46  void clientConnectedCallback(agxNet::WebSocket* client);
47  void clientDisconnectedCallback(agxNet::WebSocket* client);
48  void messageReceivedCallback(agxNet::WebSocket *socket, agx::UInt8* payload, size_t size);
49 
50  private:
51  agxNet::WebSocketServerRef m_serverSocket;
52  agxNet::WebSocketPtrVector m_clientSockets;
53  agx::Mutex m_mutex;
54  };
55 
56 
57 
60  {
61  public:
63 
64  void messageReceivedCallback(agxNet::WebSocket *socket, agx::UInt8* payload, size_t size);
65 
66  virtual agxData::Frame* readFrame();
67 
68  protected:
69  virtual ~WebSocketFrameReader();
70 
71  private:
72  agxNet::WebSocket* m_socket;
73 
74 
75  // Cannot use reference counting pointers here since 'readFrame' is required to
76  // return Frames by raw pointer, and a vector of reference counted pointers would
77  // then delete the Frames before they are passed to the caller.
78  agx::Vector<agxData::Frame*> m_storedFrames;
79  };
80 
81 
82  /* Implementation */
83  AGX_FORCE_INLINE agx::UInt16 WebSocketFrameWriter::getPort() const { return m_serverSocket->getPort(); }
84 
85 }
86 
87 
88 // AGX_USE_WEBSOCKETS
89 #endif
90 
91 
92 // AGXDATA_WEBSOCKET_STREAM_H
93 #endif
A socket that connects to a client.
Definition: WebSocket.h:54
uint8_t UInt8
Definition: Integer.h:38
The FrameReader reads frames from an external source.
Definition: FrameIO.h:126
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGX_FORCE_INLINE
Definition: Object.h:62
The FrameWriter writes frames to an external target.
Definition: FrameIO.h:168
agx::UInt16 getPort() const
std::mutex Mutex
Definition: Referenced.h:93
uint16_t UInt16
Definition: Integer.h:39
double Real
Definition: Real.h:42
#define AGXCORE_EXPORT