CTR Pia  4.11.3
Game Communication Engine
inet_LanFacade.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: inet_LanFacade.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/inet/inet_definitions.h>
18 #include <pia/inet/inet_LanNetworkFactory.h>
19 
20 namespace nn
21 {
22 namespace pia
23 {
24 namespace transport
25 {
26 class StationConnectionInfo;
27 }
28 }
29 }
30 
31 namespace nn
32 {
33 namespace pia
34 {
35 namespace inet
36 {
37 class SocketOutputStream;
38 class SocketInputStream;
39 class Socket;
40 class LanMatchmakeUpdateJob;
41 
42 //! @cond CAFE_DOC
43 
44 /*!
45 @brief Represents the LAN matchmaking facade (<tt>facade</tt>, interface wrapper) class.
46 @details This feature is for library developers. It is normally not available to application developers.
47 When in a LAN environment within a single subnet, the network-related processes (such as sending/receiving or session management) do not use the NEX library.
48 @date 2014-09-18 Changed the specifications so that <tt>ResultAlreadyExists</tt> is returned if you call <tt>CreateInstance</tt> when an instance already exists.
49 @date 2014-04-30 Initial version.
50 
51 */
52 class LanFacade : public nn::pia::common::RootObject
53 {
54 public:
55 /*!
56 @brief Creates an instance (singleton pattern).
57 @return Returns the result of the function. If this function call fails, one or more of the following <tt>Result</tt> values is returned. You must make sure that the implementation of this function in your application does not return any errors.
58 @retval nn::pia::ResultNotInitialized Indicates that the <tt>inet</tt> module is not initialized. Programming error. Fix your program so that this error is not returned.
59 @retval nn::pia::ResultInvalidState Indicates that the function was called at the wrong time. Programming error. Fix your program so that this error is not returned.
60 @retval nn::pia::ResultAlreadyExists Indicates that an instance has already been created. Programming error. Fix your program so that this error is not returned.
61 
62 */
63  static nn::Result CreateInstance(void);
64 
65 /*!
66 @brief Destroys the instance (singleton pattern).
67 @details This function does nothing and returns if called when an instance has not been created.
68 
69 
70 */
71  static void DestroyInstance(void);
72 
73 /*!
74 @brief Gets the pointer to the <tt>LanFacade</tt> instance (singleton pattern).
75 @return Returns a <tt>NULL</tt> pointer if the instance cannot be created.
76 
77 */
78  static LanFacade* GetInstance(void)
79  {
80  return s_pInstance;
81  }
82 
83 /*!
84 @cond PRIVATE
85 @brief Starts the <tt>LanFacade</tt> feature.
86 @return Returns the result of the function. If this function call fails, one or more of the following <tt>Result</tt> values is returned. You must make sure that the implementation of this function in your application does not return any errors.
87 @retval nn::pia::ResultInvalidState Indicates that the function was called at the wrong time. Programming error. Fix your program so that this error is not returned.
88 
89 */
90  virtual nn::Result Startup();
91  //! @endcond
92 
93 /*!
94 @cond PRIVATE
95 @brief Cleans up the <tt>LanFacade</tt> feature.
96 */
97  virtual void Cleanup();
98  //! @endcond
99 
100 /*!
101 @cond PRIVATE
102 @brief Starts a LAN session.
103 */
104  virtual nn::Result StartLanSession();
105  //! @endcond
106 
107 /*!
108 @cond PRIVATE
109 @brief Terminates a LAN session.
110 */
111  virtual void StopLanSession();
112  //! @endcond
113 
114 /*!
115 @brief Registers a local address.
116 @details Registers the IP address assigned locally. Call this function before calling the <tt>@ref session::Session::Startup</tt> function.
117 @return Returns the result of the function. If this function call fails, one or more of the following <tt>Result</tt> values is returned. You must make sure that the implementation of this function in your application does not return any errors.
118 @retval nn::pia::ResultInvalidArgument Indicates that there is an error in an argument. Programming error. Fix your program so that this error is not returned.
119 */
120  nn::Result Bind(u32 localAddress);
121 
122 /*!
123 @brief Deletes the information on the registered local address.
124 @details Call this function after calling the <tt>@ref session::Session::Cleanup</tt> function.
125 */
126  void Unbind();
127 
128 /*!
129 @cond PRIVATE
130 @brief Gets the local address.
131 */
132  u32 GetLocalAddress() const
133  {
134  return m_LocalAddress;
135  }
136  //! @endcond
137 
138 /*!
139 @cond PRIVATE
140 @brief Gets the local <tt>PrincipalId</tt>.
141 */
142  u32 GetLocalPrincipalId() const;
143  //! @endcond
144 
145 /*!
146 @cond PRIVATE
147 @brief Gets the local <tt>StationConnectionInfo</tt>.
148 */
149  transport::StationConnectionInfo& GetLocalStationConnectionInfo();
150  //! @endcond
151 
152 /*!
153 @cond PRIVATE
154 @brief Gets the LAN session update job.
155 */
156  LanMatchmakeUpdateJob* GetUpdateJob()
157  {
158  return m_pUpdateJob;
159  }
160  //! @endcond
161 
162 /*!
163 @cond PRIVATE
164 @brief Prints information that is useful for debugging.
165 
166 @param[in] flag Specifies the trace flag. For more information, see the <tt>@ref TraceFlag</tt> type.
167 */
168  virtual void Trace(u64 flag) const;
169  //! @endcond
170 
171 private:
172  // A pointer to a singleton instance.
173  static LanFacade* s_pInstance;
174 
175 /*!
176 @brief This constructor is private because the singleton pattern is used.
177 */
178  LanFacade(void);
179 
180 /*!
181 @brief This destructor is private because the singleton pattern is used.
182 */
183  virtual ~LanFacade(void);
184 
185 /*!
186 @brief This copy constructor is private because the singleton pattern is used.
187 */
188  LanFacade(const LanFacade&);
189 
190 /*!
191 @brief This assignment operator is private because the singleton pattern is used.
192 */
193  LanFacade& operator=(const LanFacade&);
194 
195  virtual nn::Result Initialize();
196  virtual void Finalize();
197 
198  nn::Result BindRandomPort();
199  u16 GetRandomPort();
200 
201  bool m_IsStartedLanMesh;
202  u32 m_LocalAddress;
203  Socket* m_pSocket;
204  SocketOutputStream* m_pOutputStream;
205  SocketInputStream* m_pInputStream;
206 
207  LanMatchmakeUpdateJob* m_pUpdateJob;
208 };
209 
210 //! @endcond
211 }
212 }
213 } // end of namespace nn::pia::inet
Definition: assert.h:115
void Unbind()
Deletes the information on the registered local address.
nn::Result Bind(u32 localAddress)
Registers a local address.
virtual void Trace(u64 flag) const
Prints information that is useful for debugging.
void Finalize(void)
Initializes the transport module. This function does nothing and returns if it is called before the I...
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40
nn::Result Initialize(void)
Initializes the transport module.