/// <summary>
/// Create a dynamic virtual channel
/// </summary>
/// <param name="priority">Priority</param>
/// <param name="channelName">Channel name</param>
/// <param name="transportType">Transport type</param>
/// <param name="receiveCallBack">Callback method called when received data</param>
/// <returns>DVC created</returns>
public DynamicVirtualChannel CreateChannel(TimeSpan timeout, ushort priority, string channelName, DynamicVC_TransportType transportType, ReceiveData receiveCallBack = null)
{
if (!transportDic.ContainsKey(transportType))
{
throw new InvalidOperationException("Not create DVC transport:" + transportType);
}
UInt32 channelId = DynamicVirtualChannel.NewChannelId();
DynamicVirtualChannel channel = new DynamicVirtualChannel(channelId, channelName, priority, transportDic[transportType]);
if (receiveCallBack != null)
{
// Add event method here can make sure processing the first DVC data packet
channel.Received += receiveCallBack;
}
channelDicbyId.Add(channelId, channel);
this.SendDVCCreateRequestPDU(priority, channelId, channelName, transportType);
CreateRespDvcPdu createResp = this.ExpectDVCCreateResponsePDU(timeout, channelId, transportType);
if (createResp == null)
{
throw new System.IO.IOException("Creation of channel: " + channelName + " failed, cannot receive a Create Response PDU");
}
if (createResp.CreationStatus < 0)
{
//Create failed
throw new System.IO.IOException("Creation of DVC failed with error code: " + createResp.CreationStatus + ", channel name is " + channelName);
}
return(channel);
}