/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_HioPacketChannel.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: $ *---------------------------------------------------------------------------*/ #ifndef NW_DEMO_HIOPACKETCHANNEL_H_ #define NW_DEMO_HIOPACKETCHANNEL_H_ #include #include #include #if defined(NN_SWITCH_ENABLE_HOST_IO) #include #include namespace nw { namespace demo { //--------------------------------------------------------------------------- //! @brief HOST IO を経由して PC とパケットの送受信をするためのクラスです。 //--------------------------------------------------------------------------- class HioPacketChannel { private: static const s32 PACKET_HEADER_ID; static const size_t BUFFER_SIZE; public: //! @brief 送受信クラスの設定内容です。 struct Description { s32 channelNumber; //!< シリアル通信のチャンネル番号です。 //! @brief コンストラクタです。 Description() : channelNumber(1) {} }; //! @brief 送受信クラスを構築するためのクラスです。 class Builder { public: //! @brief 構築する送受信クラスを設定します。 Builder& HioPacketChannelDescription(const Description& description) { m_Description = description; return *this; } //! @brief シリアル通信のチャンネル番号を設定します。 Builder& ChannelNumber(s32 channelNumber) { NW_MINMAX_ASSERT(channelNumber, 0, nn::hio::CTR::MAX_CHANNEL_NUM); m_Description.channelNumber = channelNumber; return *this; } //--------------------------------------------------------------------------- //! @brief 送受信クラスを生成し、シリアル通信のチャンネルを開きます。 //! //! 事前に HIO ライブラリを初期化しておく必要があります。 //! //! @param[in] allocator 送受信クラスで使用するアロケータです。 //! @param[in] deviceAllocator 送受信クラスで使用するデバイスメモリアロケータです。 //--------------------------------------------------------------------------- HioPacketChannel* Create( os::IAllocator* allocator, os::IAllocator* deviceAllocator ); private: Description m_Description; }; //---------------------------------------- //! @name 生成/破棄 //@{ //! @brief 送受信クラスを削除します。 void Destroy(); //} //---------------------------------------- //! @name Host IO 接続の初期化 //@{ //! @brief Host IO 接続を開始します。 //! //! @param[in] deviceAllocator デバイスメモリアロケータです。 static bool Initialize(os::IAllocator* deviceAllocator); //! @brief Host IO 接続を終了します。 static void Finalize(); //} //---------------------------------------- //! @name 接続の確立/切断 //@{ //--------------------------------------------------------------------------- //! @brief PC からの接続を待ちます。 //! //! PC 側で Connect により接続が行われるのをタイムアウト時間が経過するまで待ちます。 //! タイムアウト時間が経過しても接続が無い場合、この関数は false を返します。 //! timeOut に負の値を設定すると、接続が行われるまで待ち続けます。 //! //! 現在 0 と負の値以外のタイムアウト時間はサポートされていません。 //! //! @param[in] timeOut ミリ秒単位のタイムアウト時間です。 //! //! @return 接続が確立されたら true を返します。 //--------------------------------------------------------------------------- bool Listen(s32 timeOut); //--------------------------------------------------------------------------- //! @brief PC へ接続します。 //! //! PC 側で Listen により接続待ちが行われるまで待機します。 //! //! @return 接続が確立されたら true を返します。 //--------------------------------------------------------------------------- bool Connect(); //--------------------------------------------------------------------------- //! @brief PC との接続を切断します。 //! //! @return 成功したら true を返します。 //--------------------------------------------------------------------------- bool Disconnect(); //} //---------------------------------------- //! @name 送受信 //@{ //--------------------------------------------------------------------------- //! @brief パケットを PC へ送信します。 //! //! @param[in] headerBuffer ヘッダ情報へのポインタです。 //! @param[in] headerLength ヘッダ情報のサイズです。 //! @param[in] dataBuffer データへのポインタです。 //! @param[in] dataLength データのサイズです。 //--------------------------------------------------------------------------- size_t SendPacket( const void* headerBuffer, size_t headerLength, const void* dataBuffer, size_t dataLength ); //--------------------------------------------------------------------------- //! @brief パケットを PC から受信します。 //! //! タイムアウト時間が経過してもパケットが受信できないときは NULL を返します。 //! timeOut に負の値を設定すると、パケットが受信できるまで待ち続けます。 //! //! 受信パケットのヘッダ、あるいはデータのサイズが 0 のときのみ、 //! headerBuffer と dataBuffer に NULL を指定できます。 //! //! 現在 0 と負の値以外のタイムアウト時間はサポートされていません。 //! //! @param[out] headerWrittenSize 書き込まれたヘッダ情報のサイズを代入するポインタです。 //! @param[out] dataWrittenSize 書き込まれたヘッダ情報のサイズを代入するポインタです。 //! @param[in] headerBuffer ヘッダ情報バッファへのポインタです。 //! @param[in] headerLength ヘッダ情報バッファのサイズです。 //! @param[in] dataBuffer データバッファへのポインタです。 //! @param[in] dataLength データバッファのサイズです。 //! @param[in] timeOut ミリ秒単位のタイムアウト時間です。 //--------------------------------------------------------------------------- bool ReceivePacket( size_t* headerWrittenSize, size_t* dataWrittenSize, void* headerBuffer, size_t headerLength, void* dataBuffer, size_t dataLength, int timeOut ); //} private: HioPacketChannel( os::IAllocator* allocator, os::IAllocator* deviceAllocator, const Description& description ); ~HioPacketChannel(); nw::os::IAllocator* m_Allocator; nw::os::IAllocator* m_DeviceAllocator; static nw::os::IAllocator* s_DeviceAllocatorForHioWorkMemory; static void* s_HioWorkMemory; void* m_SerialWorkMemory; nn::hio::CTR::SerialChannel m_Serial; }; } // namespace nw::demo } // namespace nw #else namespace nw { namespace os { class IAllocator; } namespace demo { //! @details :private class HioPacketChannel { private: static const s32 PACKET_HEADER_ID; static const size_t BUFFER_SIZE; public: struct Description { Description() {} }; class Builder { public: Builder& HioPacketChannelDescription(const Description&){return *this;} Builder& ChannelNumber(s32 ){return *this;} HioPacketChannel* Create(os::IAllocator* ,os::IAllocator* ) { return NULL; } }; void Destroy() {} static bool Initialize(os::IAllocator*) { return false; } static void Finalize() {} bool Listen(s32 ) { return false; } bool Connect() { return false; } bool Disconnect() { return false; } size_t SendPacket(const void* ,size_t ,const void* ,size_t ) { return 0; } bool ReceivePacket(size_t* ,size_t* ,void* ,size_t ,void* ,size_t ,int ){ return false; } private: HioPacketChannel(os::IAllocator* ,os::IAllocator* ,const Description& ){ } ~HioPacketChannel() { } static nw::os::IAllocator* s_DeviceAllocatorForHioWorkMemory; static void* s_HioWorkMemory; }; } // namespace nw::demo } // namespace nw #endif #endif // NW_DEMO_HIOPACKETCHANNEL_H_