CTR Pia  4.11.3
Game Communication Engine
transport_Protocol.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: transport_Protocol.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/transport/transport_definitions.h>
18 
19 #include <pia/common/common_ListNode.h>
20 #include <pia/transport/transport_ProtocolID.h>
21 #include <pia/transport/transport_ProtocolEvent.h>
22 
23 #define PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE 0
24 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
25 #include <pia/common/private/common_Statistic.h>
26 #include <pia/common/common_TimeSpan.h>
27 #endif
28 
29 namespace nn
30 {
31 namespace pia
32 {
33 namespace transport
34 {
35 
36 class PacketHandler;
37 
38 /*!
39 @brief Protocol base class.
40 
41 @date 2013-03-28 Moved namespace from \c nn::pia::common to \c nn::pia::transport.
42 @date 2012-04-04 Initial version.
43 */
45 {
46 public:
47 /*!
48 @brief Instantiates the object.
49 */
50  Protocol(void);
51 
52 
53 /*!
54 @brief Destroys the object.
55 */
56  virtual ~Protocol(void);
57 
58 
59 /*!
60 @cond PRIVATE
61 @brief Configures the packet handler to use.
62 
63 @param[in] pPacketHandler The packet handler.
64 */
65  void SetPacketHandler(PacketHandler* pPacketHandler)
66  {
67  m_pPacketHandler = pPacketHandler;
68  }
69  //! @endcond
70 
71 
72 /*!
73 @brief Prints information useful for debugging.
74 
75 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
76 
77 */
78  virtual void Trace(u64 flag) const;
79 
80 
81 /*!
82 @cond PRIVATE
83 @brief Gets the offset to the list node.
84 
85 @return The offset to the list node.
86 */
87  static u32 GetListNodeOffset()
88  {
89  return offsetof(Protocol, m_ListNode);
90  }
91  //! @endcond
92 
93 
94 /*!
95 @cond PRIVATE
96 @brief Sets the port.
97 
98 @param[in] port The port number.
99 */
100  void SetPort(u16 port);
101  //! @endcond
102 
103 
104 /*!
105 @cond PRIVATE
106 @brief Gets the protocol ID.
107 
108 @return The protocol ID.
109 */
110  ProtocolId GetProtocolId() const
111  {
112  return m_ProtocolId;
113  }
114  //! @endcond
115 
116 
117 /*!
118 @cond PRIVATE
119 @brief Gets the protocol type.
120 
121 @return The protocol type.
122 */
123  virtual u16 GetProtocolType() const = 0;
124  //! @endcond
125 
126 
127 /*!
128 @cond PRIVATE
129 @brief Starts communication.
130 
131 @param[in] myStationIndex The <tt>StationID</tt> value of the local station. Specify a value in the range from <tt>STATION_INDEX_1</tt> to <span class="argument">maxConnections</span>.
132 
133 @return If execution succeeds, returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt>.
134 */
135  virtual nn::Result Startup(StationIndex myStationIndex);
136  //! @endcond
137 
138 
139 /*!
140 @cond PRIVATE
141 @brief Ends communication.
142 */
143  virtual void Cleanup();
144  //! @endcond
145 
146 
147 /*!
148 @cond PRIVATE
149 @brief The main process.
150 
151 @return If execution succeeds, returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt>.
152 */
153  virtual nn::Result Dispatch();
154  //! @endcond
155 
156 
157 /*!
158 @cond PRIVATE
159 @brief Switches connection status.
160 
161 @param[in] event Specifies the event representing the operation.
162 
163 @return If execution succeeds, returns a <tt>Result</tt> value for which the <tt>IsSuccess</tt> function returns <tt>true</tt>.
164 */
165  virtual nn::Result UpdateProtocolEvent(const ProtocolEvent& event);
166 //! @endcond
167 
168 
169 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
170  Statistic<TimeSpan>* GetBlockTimeStatistic()
171  {
172  return &m_BlockTimeStatistic;
173  }
174 #endif
175 
176 #if NN_PIA_EXPERIMENT_PROTOCOL_FILTERING
177 /*!
178 @cond PRIVATE
179 @brief Function for controlling whether to filter out messages received from old stations.
180 
181 
182 @return Returns <tt>true</tt> (allow filtering) by default.
183 Override this function so that it returns <tt>false</tt> in classes that inherit from the <tt>Protocol</tt> class that do not normally allow filtering.
184 
185 */
186  virtual bool IsEnableProtocolFiltering() const;
187 //! @endcond
188 #endif
189 
190 protected:
191 /*!
192 @cond PRIVATE
193 @brief Gets the packet handler.
194 
195 @return A pointer to the packet handler.
196 */
197  PacketHandler* GetPacketHandler()
198  {
199  return m_pPacketHandler;
200  }
201  //! @endcond
202 
203 
204 /*!
205 @cond PRIVATE
206 @brief Gets the packet handler (<tt>const</tt> version).
207 
208 @return A \c const pointer to the packet handler.
209 */
210  const PacketHandler* GetPacketHandler() const
211  {
212  return m_pPacketHandler;
213  }
214  //! @endcond
215 
216 
217 private:
218  common::ListNode m_ListNode;
219  ProtocolId m_ProtocolId;
220  PacketHandler* m_pPacketHandler;
221 
222 #if PIA_STATISTIC_PROTOCOL_BLOCK_TIME_ENABLE
223  Statistic<TimeSpan> m_BlockTimeStatistic;
224 #endif
225 };
226 }
227 }
228 } // end of namespace nn::pia::transport
229 
230 
231 #define PIA_PROTOCOL_TYPE_INFO(protocolType) \
232  static u16 GetProtocolTypeStatic() \
233  { \
234  return protocolType; \
235  } \
236  virtual u16 GetProtocolType() const \
237  { \
238  return GetProtocolTypeStatic(); \
239  }
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition: assert.h:115
virtual void Trace(u64 flag) const
Prints information useful for debugging.
virtual ~Protocol(void)
Destroys the object.
Protocol base class.
Definition: transport_Protocol.h:44
Protocol(void)
Instantiates the object.
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40