#pragma once
/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   2015/02/07 - 2015/11/13
/// 
/// @brief  ウィンドウズ用転送パイプ関連
/// 
/// ****************************************************************************

#include "../../Core/Memory/CPL_Core_PipeTransceiver.h"
#include "../Net/CPL_WIN_WS_SocketTCP.h"
#include "CPL_WIN_ProcessSharedBuffer.h"

namespace CPL {
namespace WIN {

// _____________________________________________________________________________
/// @brief プロセス間送信用パイプ
///
// *****************************************************************************
class ProcessPipeSender
  : public Core::PipeSender
{
protected:
  ProcessPipeSender()
    : PipeBase( NotCalled_() )
  {}
public:
  // _____________________________________________________________________________
  /// @brief コンストラクタ
  /// 
  /// ※ このコンストラクタは派生クラスから呼んではいけません。
  /// 
  /// @copydetails CPL::Core::PipeController::PipeController(_in<td_tstring>,_in<U64>,sdptr<T_Mutex>,T_SharedBuffer*)
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  template
    < class T_Mutex = Core::ProcessMutex
    , class T_SharedBuffer = ProcessSharedBuffer
    >
  ProcessPipeSender
  ( _in<td_tstring> in_name_pipe
  , _in<U64       > in_size_pipe
  , sdptr<T_Mutex > in_sp_mutex  = sdptr<Core::ProcessMutex>(nullptr)
  , T_SharedBuffer* type_buffer_ = (ProcessSharedBuffer*)nullptr
  ) : Core::PipeBase( in_name_pipe )
    , Core::PipeSender
      ( in_name_pipe
      , in_size_pipe
      , in_sp_mutex
      , type_buffer_
      )
  {
    // 
    //ChangeMode( false, TimePoint::Max() );
  }

  ~ProcessPipeSender(){}
};


// _____________________________________________________________________________
/// @brief プロセス間受信用パイプ
///
// *****************************************************************************
class ProcessPipeReceiver
  : public Core::PipeReceiver
{
protected:
  ProcessPipeReceiver()
    : PipeBase( NotCalled_() )
  {}
public:
  using TypeFlag = Core::NetworkSharedFlag;

  // _____________________________________________________________________________
  /// @brief コンストラクタ
  /// 
  /// ※ このコンストラクタは派生クラスから呼んではいけません。
  /// 
  /// @copydetails CPL::Core::PipeController::PipeController(_in<td_tstring>,_in<U64>,sdptr<T_Mutex>,T_SharedBuffer*)
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  template
    < class T_Mutex = Core::ProcessMutex
    , class T_SharedBuffer = ProcessSharedBuffer
    >
  ProcessPipeReceiver
  ( _in<td_tstring> in_name_pipe
  , _in<U64       > in_size_pipe
  , sdptr<T_Mutex > in_sp_mutex = sdptr<Core::ProcessMutex>(nullptr)
  , T_SharedBuffer* type_buffer_ = (ProcessSharedBuffer*)nullptr
  ) : Core::PipeBase( in_name_pipe )
    , Core::PipeReceiver
      ( in_name_pipe
      , in_size_pipe
      , in_sp_mutex
      , type_buffer_
      )
  {
    // 
    //ChangeMode( false, TimePoint::Max() );
  }

  ~ProcessPipeReceiver(){}
};

// _____________________________________________________________________________
/// @brief プロセス間転送パイプ
///
// *****************************************************************************
class ProcessPipeTransceiver
  : public ProcessPipeSender
  , public ProcessPipeReceiver
{
protected:
  /// @brief 派生用（なのでPipeBaseは呼ばれないはず）
  ProcessPipeTransceiver()
    : PipeBase( NotCalled_() ) // これは呼ばれない。
  {}
public:
  // _____________________________________________________________________________
  /// @brief コンストラクタ
  /// 
  /// ※ このコンストラクタは派生クラスから呼んではいけない。
  /// 
  /// @copydetails CPL::Core::PipeController::PipeController(_in<td_tstring>,_in<U64>,sdptr<T_Mutex>,T_SharedBuffer*)
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  template
    < class T_Mutex = Core::ProcessMutex
    , class T_SharedBuffer = ProcessSharedBuffer
    >
  ProcessPipeTransceiver
  ( _in<td_tstring> in_name_pipe
  , _in<U64       > in_size_pipe
  , sdptr<T_Mutex > in_sp_mutex = sdptr<Core::ProcessMutex>(nullptr)
  , T_SharedBuffer* type_buffer_ = (ProcessSharedBuffer*)nullptr
  ) : Core::PipeBase( in_name_pipe )
    , ProcessPipeSender
      ( in_name_pipe
      , in_size_pipe
      , in_sp_mutex
      , type_buffer_
      )
    , ProcessPipeReceiver
      ( in_name_pipe
      , in_size_pipe
      , in_sp_mutex
      , type_buffer_
      )
  {
    CPL_THROW("まだ未対応です。\n")
  }

  ~ProcessPipeTransceiver()
  {}
};



} // namespace WIN
} // namespace CPL