# HG changeset patch # User StephaneLenclud # Date 1449596942 -3600 # Node ID b4df02a92dff2869e2e6d0e6142e886eeda3788c # Parent 99720d48e299cc4210b4f848796806d5da8f8bf1 Adding basic display client connection. diff -r 99720d48e299 -r b4df02a92dff NotificationPlugin.cs --- a/NotificationPlugin.cs Tue Dec 08 13:52:15 2015 +0100 +++ b/NotificationPlugin.cs Tue Dec 08 18:49:02 2015 +0100 @@ -12,6 +12,10 @@ using System.IO; using TvLibrary.Log; +// +using SharpLib.Display; +using TvEngine.Events; +using TvLibrary.Interfaces; namespace TvServerPlugin { @@ -20,6 +24,8 @@ public class RecordSatus : ITvServerPlugin { + Client iClient; + /// /// Reference to the tvservice's TVcontroller /// @@ -31,7 +37,120 @@ /// public RecordSatus() { } - + /// + /// + /// + public void OnCloseOrder() + { + CloseClient(); + } + + /// + /// + /// + public void CloseClient() + { + iClient.Close(); + iClient = null; + } + + void OpenClient() + { + iClient = new Client(); + //iClient.CloseOrderEvent += OnCloseOrder; + iClient.Open(); + + //Connect using unique name + //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); + string name = "Client-" + (iClient.ClientCount() - 1); + iClient.SetName(name); + + + + //iClient.Open(/*"net.tcp://localhost:8111/DisplayService"*/); + + //Connect using unique name + //string name = "Client-" + (iClient.ClientCount() - 1); + //iClient.SetName(name); + //Console.WriteLine("Name: " + name); + } + + /// + /// + /// + public void SetLayout() + { + TableLayout layout = new TableLayout(1, 1); + iClient.SetLayout(layout); + //We need to create our fields + DataField field = new TextField(); + iClient.CreateFields(new DataField[] + { + field + }); + } + + /// + /// + /// + public void SetTextField() + { + TextField field = new TextField(); + field.Text = "Notification TV Server Plugin"; + iClient.SetField(field); + } + + + private void UpdateRecordingStatus() + { + RecordingField field = new RecordingField(); + field.IsActive = _controller.IsAnyCardRecording(); + iClient.SetField(field); + } + + private void OnTvServerEvent(object sender, EventArgs eventArgs) + { + if (iClient==null) + { + //TODO: Try reconnect + return; + } + + TvServerEventArgs tvArgs = eventArgs as TvServerEventArgs; + switch (tvArgs.EventType) + { + case TvServerEventType.RecordingStarted: + UpdateRecordingStatus(); + break; + + case TvServerEventType.RecordingEnded: + + break; + } + + + /* + if (_state == EpgState.Idle) + return; + TvServerEventArgs tvArgs = eventArgs as TvServerEventArgs; + if (eventArgs == null) + return; + if (tvArgs != null) + switch (tvArgs.EventType) + { + case TvServerEventType.StartTimeShifting: + Log.Epg("epg cancelled due to start timeshifting"); + OnEpgCancelled(); + break; + + case TvServerEventType.StartRecording: + Log.Epg("epg cancelled due to start recording"); + OnEpgCancelled(); + break; + } + */ + } + /// /// Called by the tvservice PluginLoader to start this plugin /// @@ -42,6 +161,17 @@ _controller = controller; + + //Open Display Client Connection + OpenClient(); + SetLayout(); + SetTextField(); + UpdateRecordingStatus(); + + // + ITvServerEvent events = GlobalServiceProvider.Instance.Get(); + events.OnTvServerEvent += new TvServerEventHandler(OnTvServerEvent); + Log.Debug(Name + " start - ends"); } @@ -52,6 +182,7 @@ { Log.Debug(Name + " stop"); _controller = null; + CloseClient(); //PowerScheduler.Instance.Stop(); }