//****************************************************************************************************** // IServer.cs - Gbtc // // Copyright © 2010, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/eclipse-1.0.php // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 07/26/2006 - Pinal C. Patel // Original version of source code generated. // 09/06/2006 - J. Ritchie Carroll // Added ReceiveRawDataFunction delegate to allow bypass optimizations for high-speed data access. // 09/29/2008 - J. Ritchie Carroll // Converted to C#. // 11/07/2008 - Pinal C. Patel // Edited code comments. // 09/14/2009 - Stephen C. Wills // Added new header and license agreement. // 10/8/2012 - Danyelle Gilliam // Modified Header // //****************************************************************************************************** using GSF.Units; using System; using System.Text; using System.Threading; namespace GSF.Communication { #region [ Enumerations ] /// /// Indicates the current state of the server. /// public enum ServerState { /// /// Server is running. /// Running, /// /// Server is not running. /// NotRunning } #endregion /// /// Defines a server involved in server-client communication. /// public interface IServer : ISupportLifecycle, IProvideStatus { #region [ Members ] // Events /// /// Occurs when the server is started. /// event EventHandler ServerStarted; /// /// Occurs when the server is stopped. /// event EventHandler ServerStopped; /// /// Occurs when a client connects to the server. /// /// /// is the ID of the client that connected to the server. /// event EventHandler> ClientConnected; /// /// Occurs when a client disconnects from the server. /// /// /// is the ID of the client that disconnected from the server. /// event EventHandler> ClientDisconnected; /// /// Occurs when data is being sent to a client. /// /// /// is the ID of the client to which the data is being sent. /// event EventHandler> SendClientDataStart; /// /// Occurs when data has been sent to a client. /// /// /// is the ID of the client to which the data has been sent. /// event EventHandler> SendClientDataComplete; /// /// Occurs when an is encountered when sending data to a client. /// /// /// is the ID of the client to which the data was being sent.
/// is the encountered when sending data to a client. ///
event EventHandler> SendClientDataException; /// /// Occurs when unprocessed data has been received from a client. /// /// /// /// This event can be used to receive a notification that client data has arrived. The method can then be used /// to copy data to an existing buffer. In many cases it will be optimal to use an existing buffer instead of subscribing to the /// event, however, the data that is available after calling the method /// will be the original unprocessed data received by the client, i.e., not optionally decrypted or decompressed data. /// /// /// is the ID of the client from which data is received.
/// is the number of bytes received in the buffer from the client. ///
///
event EventHandler> ReceiveClientData; /// /// Occurs when data received from a client has been processed and is ready for consumption. /// /// /// is the ID of the client from which data is received.
/// is a new buffer containing post-processed data received from the client starting at index zero.
/// is the number of post-processed bytes received in the buffer from the client. ///
event EventHandler> ReceiveClientDataComplete; /// /// Occurs when an is encountered when receiving data from a client. /// /// /// is the ID of the client from which the data was being received.
/// is the encountered when receiving data from a client. ///
event EventHandler> ReceiveClientDataException; /// /// Occurs when an is encountered in a user-defined function via an event dispatch. /// /// /// is the thrown by the user-defined function. /// event EventHandler> UnhandledUserException; #endregion #region [ Properties ] /// /// Gets or sets the data required by the server to initialize. /// string ConfigurationString { get; set; } /// /// Gets or sets the maximum number of clients that can connect to the server. /// int MaxClientConnections { get; set; } /// /// Gets or sets the size of the buffer used by the client for receiving data from the server. /// int SendBufferSize { get; set; } /// /// Gets or sets the size of the buffer used by the server for receiving data from the clients. /// int ReceiveBufferSize { get; set; } /// /// Gets or sets the to be used for the text sent to the connected clients. /// Encoding TextEncoding { get; set; } /// /// Gets the current . /// ServerState CurrentState { get; } /// /// Gets the used by the server for the transportation of data with the clients. /// TransportProtocol TransportProtocol { get; } /// /// Gets the server's ID. /// Guid ServerID { get; } /// /// Gets the IDs of clients connected to the server. /// Guid[] ClientIDs { get; } /// /// Gets the for which the server has been running. /// Time RunTime { get; } #endregion #region [ Methods ] /// /// Starts the server. /// void Start(); /// /// Stops the server. /// void Stop(); /// /// Disconnects all of the connected clients. /// void DisconnectAll(); /// /// Disconnects a connected client. /// /// ID of the client to be disconnected. void DisconnectOne(Guid clientID); /// /// Sends data to the specified client synchronously. /// /// ID of the client to which the data is to be sent. /// The buffer that contains the binary data to be sent. /// The zero-based position in the at which to begin sending data. /// The number of bytes to be sent from starting at the . void SendTo(Guid clientID, byte[] data, int offset, int length); /// /// Sends data to all of the connected clients synchronously. /// /// The buffer that contains the binary data to be sent. /// The zero-based position in the at which to begin sending data. /// The number of bytes to be sent from starting at the . void Multicast(byte[] data, int offset, int length); /// /// Sends data to the specified client asynchronously. /// /// ID of the client to which the data is to be sent. /// The buffer that contains the binary data to be sent. /// The zero-based position in the at which to begin sending data. /// The number of bytes to be sent from starting at the . /// for the asynchronous operation. WaitHandle SendToAsync(Guid clientID, byte[] data, int offset, int length); /// /// Sends data to all of the connected clients asynchronously. /// /// The buffer that contains the binary data to be sent. /// The zero-based position in the at which to begin sending data. /// The number of bytes to be sent from starting at the . /// Array of for the asynchronous operation. WaitHandle[] MulticastAsync(byte[] data, int offset, int length); /// /// Reads a number of bytes from the current received data buffer and writes those bytes into a byte array at the specified offset. /// /// ID of the client from which data buffer should be read. /// Destination buffer used to hold copied bytes. /// 0-based starting index into destination to begin writing data. /// The number of bytes to read from current received data buffer and write into . /// The number of bytes read. /// /// This function should only be called from within the event handler. Calling this method outside this /// event will have unexpected results. /// int Read(Guid clientID, byte[] buffer, int startIndex, int length); #endregion } }