Free Electron
EnetCatalog.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __enet_EnetCatalog_h__
8 #define __enet_EnetCatalog_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief ConnectedCatalog over Enet
17 
18  @ingroup Enet
19 *//***************************************************************************/
20 class FE_DL_EXPORT EnetCatalog:
21  public ConnectedCatalog,
22  public Initialize<EnetCatalog>
23 {
24  public:
25 
26  EnetCatalog(void);
27 virtual ~EnetCatalog(void);
28 
29  void initialize(void);
30 
31  protected:
32 
33 virtual Result disconnect(void) override;
34 
35 virtual Result connectAsServer(String a_address,U16 a_port) override;
36 virtual Result connectAsClient(String a_address,U16 a_port) override;
37 
38  private:
39 
40  void broadcastSelect(String a_name,String a_property,
41  String a_message,
42  I32 a_includeCount,const String* a_pIncludes,
43  I32 a_excludeCount,const String* a_pExcludes,
44  const U8* a_pRawBytes=NULL,I32 a_byteCount=0) override;
45 
46  void sendString(String a_textD);
47  void sendBytes(const U8* a_pByteBlock,const I32 a_byteCountD);
48 
49  class MessageBuffer
50  {
51  public:
52  MessageBuffer(void) { m_currentOffset = 0; }
53 
54  void AddString(const String &str);
55  void GetString(String &str);
56 
57  void AddBytes(const U8 *data, const int size);
58  I32 GetBytes(U8 *data, const int size);
59 
60  void AddArray(const Array<U8> &data);
61  I32 GetArray(Array<U8> &data);
62 
63  const U8* Data(void) { return m_data.data(); }
64  Array<U8>& DataArray(void) { return m_data; }
65  I32 Size(void) { return m_data.size(); }
66 
67  void Reset();
68 
69  private:
70  int m_currentOffset;
71  Array<U8> m_data;
72  };
73 
74  class FE_DL_EXPORT ReceiverTask: public Thread::Functor
75  {
76  public:
77  ReceiverTask(void):
78  m_terminate(FALSE) {}
79  virtual void operate(void);
80 
81  I32 readString(String& a_rString);
82  I32 readBytes(Array<U8>& a_rByteArray);
83  I32 readIdentity(Identity& a_identity);
84 
85  EnetCatalog* m_pEnetCatalog;
86  void* m_pEnetConnection;
87  BWORD m_terminate;
88 
89  private:
90  I32 readBuffer(Array<U8>& a_pMsg);
91 
92  MessageBuffer m_receiveMessage;
93  };
94 
95  MessageBuffer m_message;
96  Thread* m_pReceiverThread;
97  ReceiverTask m_receiverTask;
98 
99  void* m_pEnetConnection;
100 };
101 
102 } /* namespace ext */
103 } /* namespace fe */
104 
105 #endif /* __enet_EnetCatalog_h__ */
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
StateCatalog with connected mirroring.
Definition: ConnectedCatalog.h:70
Automatically reference-counted string container.
Definition: String.h:128
Result
Generalized return value indicating success or failure, and why.
Definition: Result.h:24
ConnectedCatalog over Enet.
Definition: EnetCatalog.h:20