//---------------------------------------------------------------------------- // // Copyright (C) Intel Corporation, 2006 - 2007. // // File: ChannelManager.h // // Contents: Manages the channels in the MPS // // Notes: //---------------------------------------------------------------------------- #ifndef CHANNEL_MGR #define CHANNEL_MGR #include #include #include #include #include #include #include "global.h" using namespace std; // FW declaration class AMT_Channel; class Channel_Consumer; class Tcp_Consumer; // ============================================================================ // = TITLE // Channel container // // = DESCRIPTION // The Channel_Manager hold instances of AMT_Channel // Each channel has two keys: AMT endpoint and MPS endpoint. // // ============================================================================ class Channel_Manager { public: typedef enum { MPS_ENDPOINT = 0 , AMT_ENDPOINT = 1 } CHANNEL_ENDPOINT; typedef enum { ACTIVE , NOT_ACTIVE } CHANNEL_MGR_STATE; // = Initialization and termination methods. Channel_Manager (int size); ~Channel_Manager (void); //=================================================== // Public Function //=================================================== // Create a new channel with the next available mps id. AMT_Channel* create_channel (); //Create channel holding @amt_id and the next available mps id: AMT_Channel* create_channel (const ACE_UINT32 id); // Add a new key to a given channel, this method is called after open reply. int add_amt_id ( const ACE_UINT32 mps_id, const ACE_UINT32 amt_id); // Find a channel according to ID and endpoint AMT_Channel* find_channel(const ACE_UINT32 id, CHANNEL_ENDPOINT endpoint); // Delete channel from only one map (according to endpoint) int remove_channel_from_endpoint(const ACE_UINT32 id, CHANNEL_ENDPOINT endpoint); // Delete channel from all maps int remove_channel(const ACE_UINT32 id, CHANNEL_ENDPOINT endpoint); // Get next available mps id ACE_INT32 get_available_mps_handle(); // Read/Write guard ACE_Recursive_Thread_Mutex& guard() {return mutex_;} void close_all_channels(); private: // Read/Write lock of this container ACE_Recursive_Thread_Mutex mutex_; // Vector of availability vector all_channels_; // = Make life easier by defining typedefs. typedef map CHANNEL_MAP; // Two table that maps amt and mps handles to channel CHANNEL_MAP channel_map_[2]; CHANNEL_MGR_STATE _state; }; /*************************************************************** // class AMT_Channel // // Channels are identified by numbers at each end. This class // holds the information on a channel. /**************************************************************/ class AMT_Channel { public: typedef enum { CLOSED, PENDING_OPEN, OPEN, TUNNEL_CLOSED, MC_CLOSED, CLOSE } CHANNEL_STATE; //= CTOR/DTOR AMT_Channel(): _channel_consumer(NULL), _tcp_consumer(NULL), _MPS_ID(DFLT_NEGETIVE_VALUE), _AMT_ID(DFLT_ZERO), _window_size(DFLT_ZERO), _state(PENDING_OPEN) {}; ~AMT_Channel(void) {}; //=================================================== // Public Functions //=================================================== Channel_Consumer* getChannelConsumer() {return _channel_consumer;} Tcp_Consumer* getTcpConsumer() {return _tcp_consumer;} ACE_UINT32 getAMTid() { return _AMT_ID; } ACE_UINT32 getMPSid() { return _MPS_ID; } ACE_UINT32 getWindowSize() { return _window_size; } CHANNEL_STATE getState() { return _state; } void setChannelConsumer(Channel_Consumer* consumer){ _channel_consumer = consumer;} void setTcpConsumer (Tcp_Consumer *tcp_consumer){ _tcp_consumer = tcp_consumer;} void setAMTid (ACE_UINT32 amtID ) { _AMT_ID = amtID; } void setMPSid (ACE_UINT32 mpsID ) { _MPS_ID = mpsID; } void setWindowSize (ACE_UINT32 windowSize) { _window_size = windowSize;} void setState (CHANNEL_STATE state) { _state = state; } private: //=================================================== // Data Members //=================================================== // This channel consumer MUST exists until it gets a 'channel close' message // from the tunnel supplier. Channel_Consumer* _channel_consumer; // Pointer to this channel consumer Tcp_Consumer* _tcp_consumer; // Pointer to this channel tcp consumer int _MPS_ID; // This is MC ID ACE_UINT32 _AMT_ID; // This is AMT ID ACE_UINT32 _window_size; // Number of bytes in the recipient window (MPS) CHANNEL_STATE _state; // Channel state }; #endif /* CHANNEL_MGR */