gwnavruntime/visualdebug/messages/messageblob.h Source File

messageblob.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
15 
16 namespace Kaim
17 {
18 
19 // Message that includes a blob field
20 class MessageBlob : public Net::AMP::Message
21 {
22 public:
23  static const char* GetTypeName() { return "MessageBlob"; }
24  static UInt32 GetLatestVersion() { return Net::AMP::Message::GetLatestVersion(); }
25 
26  MessageBlob() : Message()
27  , m_blobTypeId(0)
28  , m_shallowBlobSize(0)
29  , m_blobHandler(nullptr)
30  {
31  Version = GetLatestVersion();
32  }
33 
34  virtual ~MessageBlob() {}
35 
36  virtual void Read(File& str);
37  virtual void Write(File& str) const;
38 
39  virtual String ToString() const;
40 
41  virtual const char* GetMessageTypeName() const { return MessageBlob::GetTypeName(); }
42 
43  UInt32 GetBlobTypeId() const { return m_blobTypeId; }
44  UInt32 GetShallowBlobSize() const { return m_shallowBlobSize; }
45  UInt32 GetDeepBlobSize() const { return (m_blobHandler ? m_blobHandler->GetDeepBlobSize() : (UInt32)m_blob.Data.GetSize()); }
46  const void* GetBlob() const { return (m_blobHandler ? m_blobHandler->GetMutableBlob() : m_blob.Data.GetDataPtr()); }
47 
48  void Init(KyUInt32 blobtypeId, KyUInt32 shallowBlobSize, KyUInt32 deepBlobSize, char* blob);
49  void Init(Ptr<BaseBlobHandler> blobHandler);
50 
51 protected:
52  void SwapBlobEndianness(Endianness::Target target) const; // not really const since it modifies m_blob.Data
53 
54  UInt32 m_blobTypeId;
55  UInt32 m_shallowBlobSize;
56 
57  // m_blobHandler or m_blob are used when sending
58  // m_blob is always the one used at reception
59  Ptr<BaseBlobHandler> m_blobHandler;
60  mutable Net::AMP::RawData m_blob; // mutable so that endianness of m_blob.Data can be swapped in Write, in the socket thread.
61 };
62 
63 
64 // Message that includes a buffer that contains several blobs
65 class MessageAggregatedBlob : public Net::AMP::Message
66 {
67 public:
68  static const char* GetTypeName() { return "MessageAggregatedBlob"; }
69  static UInt32 GetLatestVersion() { return Net::AMP::Message::GetLatestVersion(); }
70 
71  MessageAggregatedBlob() : Message()
72  , m_currentIndex(0)
73  {
74  Version = GetLatestVersion();
75  }
76 
77  virtual ~MessageAggregatedBlob() {}
78 
79  virtual void Read(File& str);
80  virtual void Write(File& str) const;
81 
82  virtual String ToString() const;
83 
84  virtual const char* GetMessageTypeName() const { return MessageAggregatedBlob::GetTypeName(); }
85 
86  bool GoFirst();
87  bool GoNext();
88 
89  KyUInt32 GetCurrentBlobTypeId();
90  KyUInt32 GetCurrentShallowBlobSize();
91  KyUInt32 GetCurrentDeepBlobSize();
92  const void* GetCurrentBlob();
93 
94 
95  void Init(KyUInt32 bufferSize);
96  KyResult Add(KyUInt32 blobTypeId, KyUInt32 shallowBlobSize, KyUInt32 deepBlobSize, char* blob);
97  KyResult Add(Ptr<BaseBlobHandler> blobHandler)
98  { return Add(blobHandler->GetBlobTypeId(), blobHandler->GetShallowBlobSize(), blobHandler->GetDeepBlobSize(), (char*)blobHandler->GetMutableBlob()); }
99 
100  UInt32 GetAggregateSize() { return (UInt32) m_data.Data.GetSize(); }
101 
102 protected:
103  void SwapBlobEndianness(Endianness::Target target, void* blob, KyUInt32 blobTypeId) const; // not really const since it modifies m_blob.Data
104  mutable Net::AMP::RawData m_data; // mutable so that endianness of can be swapped in Write, in the socket thread.
105 
106  UInt32 m_currentIndex;
107 };
108 
109 
110 } // namespace Kaim
111 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
std::uint32_t UInt32
uint32_t
Definition: SF_Types.h:137
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17