This interface allows applications to receive events about the state of StreamLink's
connection to the Liberator, the state of any data services the Liberator is using,
and the state of the DataSources providing the data services.
You must define a class that implements this interface and register it with StreamLink
using the AddConnectionListener(IConnectionListener) method of IStreamLinkProvider.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public interface IConnectionListener
Public Interface IConnectionListener
public interface class IConnectionListener
Members
All Members | Methods | ||||
Icon | Member | Description |
---|---|---|
ConnectionStatusUpdated(IConnectionStatusEvent) |
This method is called when the state of the connection to the Liberator changes.
It provides information about the new connection state.
| |
ServiceStatusUpdated(IServiceStatusEvent) |
This method is called when the state of the data service being used by the server changes.
It provides information about the new service state.
| |
SourceStatusUpdated(ISourceStatusEvent) |
This method is called when the state of the DataSource being used by the server changes.
It provides information about the new DataSource state.
|
Remarks
The following table shows how the connection status changes when StreamLink attempts to connect to a Liberator. This is the ConnectionStatus returned by the Status property of IConnectionStatusEvent. IConnectionStatusEvents are passed in successive calls to ConnectionStatusUpdated(IConnectionStatusEvent).
Seq | ConnectionStatus | Notes |
---|---|---|
1. | ConnectionStatus.LoggedOut | Not currently connected or logged in to the Liberator. |
2. | ConnectionStatus.Connecting | |
3. | ConnectionStatus.Connected | |
4. | ConnectionStatus.RetrievingCredentials | At this point the getter for the Credentials property is called. |
5. | ConnectionStatus.CredentialRetrieved | Credentials have been retrieved from the ICredentials instance. |
6. | ConnectionStatus.LoggingIn | The ICredentials are being used to log in. |
7. | ConnectionStatus.LoggedIn | The login succeeded. |
StreamLink queues events in the order they were raised and passes each event in turn to an appropriate callback method of the relevant listener. All listener callbacks execute in the same dedicated worker thread, so while a particular callback method is running no other callbacks will be invoked.
Example:CopyC#
using System; using System.Collections.Generic; using System.Text; using Caplin.StreamLink; using Caplin.StreamLink.Authentication; namespace StreamLinkExamples.Basics { /// <summary> /// Example of an internal class that implements IConnectionListener /// and of how to use the IConnectionListener class. /// </summary> public class AddingAConnectionListener { /// <summary> /// Shows how to create a StreamLink and a connection listener /// and add the listener for connection events. /// </summary> public static void AddingAConnectionListenerExample() { IStreamLink myStreamLink = new StreamLink(); myStreamLink.CredentialsProvider = new PasswordCredentialsProvider("admin", "admin"); IConnectionListener connectionListener = new ExampleConnectionListener(); // Add the new connection listener instance so that it // receives connection related events. myStreamLink.StreamLinkProvider.AddConnectionListener( connectionListener); } /// <summary> /// Example of a class the implements the IConnectionListener. /// </summary> private class ExampleConnectionListener : IConnectionListener { #region IConnectionListener Members // Just log the status update public void ConnectionStatusUpdated(IConnectionStatusEvent ev) { Console.WriteLine("Connection Status Updated: " + ev.Status.ToString()); } // Just log the source update public void SourceStatusUpdated(ISourceStatusEvent ev) { Console.WriteLine( string.Format("Source Status Updated: {0} {1}", ev.Name, ev.Status.ToString())); } // Just log the service update public void ServiceStatusUpdated(IServiceStatusEvent ev) { Console.WriteLine( string.Format("Service Status Updated: {0} {1}", ev.Name, ev.Status.ToString())); } #endregion } } }