AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FramePacket.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 AGXNET_FRAMEPACKET_H
18 #define AGXNET_FRAMEPACKET_H
19 
20 #include <agxData/Frame.h>
21 #include <agxData/BinaryData.h>
22 #include <agx/Json.h>
24 
25 namespace agxNet
26 {
27 
57  {
58  public:
59  struct PreHeader;
60  static const agx::UInt32 BINARY_SEGMENT_ALIGNMENT = 32;
61 
62  static StructuredMessage* parse(const agx::UInt8* data, size_t numBytes, bool copyBinaryData = false);
63  public:
65  StructuredMessage(const agx::String& uri);
66  StructuredMessage(const agx::String& uri, const agxJson::Value& header, agxData::BinaryData *binarySegment = nullptr);
67 
68  StructuredMessage *createResponse() const;
69 
70  void setResponseId(agx::UInt32 id);
71  void setUri(const agx::String& uri);
72  void setHeader(const agxJson::Value& header);
73  void setBinarySegment(agxData::BinaryData *binarySegment);
74 
76  agx::UInt32 getMessageId() const;
77 
79  agx::UInt32 getResponseId() const;
80 
81  const agx::String& getUri() const;
82 
83  agxJson::Value& getHeader();
84  const agxJson::Value& getHeader() const;
85 
86  agxData::BinaryData *getBinarySegment();
87  const agxData::BinaryData *getBinarySegment() const;
88 
89  // PreHeader getPreHeader() const;
90 
91  protected:
92  virtual ~StructuredMessage();
93 
94  friend class WebSocket;
95  void setMessageId( agx::UInt32 id ) const;
96 
97  private:
98  agx::String m_uri;
99  agxJson::Value m_header;
100  agxData::BinaryDataRef m_binarySegment;
101  agx::UInt32 m_messageId;
102  agx::UInt32 m_responseId;
103  };
104 
105  // Used for parsing a structured message
106  struct AGXCORE_EXPORT StructuredMessage::PreHeader
107  {
108  PreHeader();
109 
116 
117  static const agx::UInt32 STREAM_END_OF_FILE = 0;
118  };
119 
120 
121 
122 
123 
124 
125 
126 
129  {
130  public:
131  FramePacket(const agxData::Frame* frame);
132 
134  const StructuredMessage::PreHeader& getPreHeader() const;
135 
137  agx::UInt32 getBinarySegmentOffset() const;
138 
140  agx::UInt32 getBinarySegmentSize() const;
141 
142  const agx::String& getUri() const;
143  const agxJson::Value& getHeader() const;
144  const agx::String& getHeaderString() const;
145 
147  agx::UInt32 getPostHeaderPaddingSize() const;
148 
149 
150  static agxData::Frame* parseFrame(agx::UInt8* data, size_t size);
151  static agxData::Frame* parseFrame(const agxJson::Value& eFrame, agxData::BinaryData* binaryData);
152 
153  protected:
154  virtual ~FramePacket() {}
155 
156  private:
157  // agxJson::Value& createNode(agxJson::Value& eParent, const char *componentName);
158 
159  void addChildren(agxJson::Value& eParent, agxData::SerializedFrame::Component *component);
160 
161  void add(agxJson::Value& eParent, agxData::SerializedFrame::Node *node);
162  void add(agxJson::Value& eParent, agxData::SerializedFrame::Component *component);
163  void add(agxJson::Value& eParent, agxData::SerializedFrame::Value *value);
164  void add(agxJson::Value& eParent, agxData::SerializedFrame::Buffer *buffer);
165  void add(agxJson::Value& eParent, agxData::SerializedFrame::CustomBuffer *buffer);
166  void add(agxJson::Value& eParent, agxData::SerializedFrame::PartialBuffer *buffer);
167  void add(agxJson::Value& eParent, agxData::SerializedFrame::EntityStorage *storage);
168 
169  static agxData::SerializedFrame::Component *createComponent(const agxJson::Value& eComponent, agxData::BinaryData *binaryData);
170  static agxData::SerializedFrame::Node *createStorage(const agxJson::Value& eStorage, agxData::BinaryData *binaryData);
171  static agxData::SerializedFrame::Node *createBuffer(const agxJson::Value& eBuffer, agxData::BinaryData *binaryData);
172  static agxData::SerializedFrame::Node *createValue(const agxJson::Value& eValue, agxData::BinaryData *binaryData);
173  static void addChildren(agxData::SerializedFrame::Component *parent, const agxJson::Value& eComponent, agxData::BinaryData *binaryData);
174 
175 
176  private:
177  StructuredMessage::PreHeader m_preHeader;
178  agxJson::Value m_header;
179  agx::String m_uri;
180  agx::String m_headerString;
181  agx::UInt32 m_postHeaderPaddingSize;
182  };
183 
184 
185  /* Implementation */
186 
187  //---------------------------------------------------------------
188  AGX_FORCE_INLINE const agx::String& StructuredMessage::getUri() const { return m_uri; }
189  AGX_FORCE_INLINE agxJson::Value& StructuredMessage::getHeader() { return m_header; }
190  AGX_FORCE_INLINE const agxJson::Value& StructuredMessage::getHeader() const { return m_header; }
191 
194 
195  //---------------------------------------------------------------
197  AGX_FORCE_INLINE agx::UInt32 FramePacket::getBinarySegmentOffset() const { return m_preHeader.binarySegmentOffset; }
198  AGX_FORCE_INLINE agx::UInt32 FramePacket::getBinarySegmentSize() const { return m_preHeader.binarySegmentSize; }
199 
200  AGX_FORCE_INLINE const agx::String& FramePacket::getUri() const { return m_uri; }
201  AGX_FORCE_INLINE const agxJson::Value& FramePacket::getHeader() const { return m_header; }
202  AGX_FORCE_INLINE const agx::String& FramePacket::getHeaderString() const { return m_headerString; }
203  AGX_FORCE_INLINE agx::UInt32 FramePacket::getPostHeaderPaddingSize() const { return m_postHeaderPaddingSize; }
204 
205 }
206 
207 
208 #endif /* AGXNET_FRAMEPACKET_H */
const agx::String & getUri() const
Definition: FramePacket.h:200
agxData::BinaryData * getBinarySegment()
Definition: FramePacket.h:192
Node(const agx::Name &name, agx::Index id)
const agx::String & getUri() const
Definition: FramePacket.h:188
const agx::String & getHeaderString() const
Definition: FramePacket.h:202
A socket that connects to a client.
Definition: WebSocket.h:54
const agxJson::Value & getHeader() const
Definition: FramePacket.h:201
uint8_t UInt8
Definition: Integer.h:38
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGX_FORCE_INLINE
Definition: Object.h:62
agx::UInt32 getBinarySegmentSize() const
Definition: FramePacket.h:198
Base class providing referencing counted objects.
Definition: Referenced.h:113
const StructuredMessage::PreHeader & getPreHeader() const
Definition: FramePacket.h:196
PartialBuffer(agxData::Frame::PartialBuffer *buffer)
agx::UInt32 getPostHeaderPaddingSize() const
Definition: FramePacket.h:203
agx::UInt32 binarySegmentOffset
Definition: FramePacket.h:114
virtual ~FramePacket()
Definition: FramePacket.h:154
CustomBuffer(const agx::Name &name, agx::Index id, const Format *format, size_t numElements)
EntityStorage(const agxData::Frame::EntityStorage *storage)
Buffer(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t numElements, size_t byteOffset)
Value(const agx::Name &name, agx::Index id, BinaryData *data, const Format *format, size_t offset)
agxJson::Value & getHeader()
Definition: FramePacket.h:189
agx::UInt32 binarySegmentSize
Definition: FramePacket.h:115
agx::UInt32 getBinarySegmentOffset() const
Definition: FramePacket.h:197
uint32_t UInt32
Definition: Integer.h:40
#define AGXCORE_EXPORT