From: <an...@us...> - 2008-03-30 14:50:16
|
Revision: 1567 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1567&view=rev Author: and-81 Date: 2008-03-30 07:50:10 -0700 (Sun, 30 Mar 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Documentation/new.html Added Paths: ----------- trunk/plugins/TelnetInterface/ trunk/plugins/TelnetInterface/Properties/ trunk/plugins/TelnetInterface/Properties/AssemblyInfo.cs trunk/plugins/TelnetInterface/TelnetInterface.cs trunk/plugins/TelnetInterface/TelnetInterface.csproj Property Changed: ---------------- trunk/plugins/XBMCServer/ Modified: trunk/plugins/IR Server Suite/Documentation/new.html =================================================================== --- trunk/plugins/IR Server Suite/Documentation/new.html 2008-03-30 12:31:45 UTC (rev 1566) +++ trunk/plugins/IR Server Suite/Documentation/new.html 2008-03-30 14:50:10 UTC (rev 1567) @@ -63,6 +63,8 @@ <LI>Input Service Configuration: Added Start and Stop buttons to the toolbar.</LI> <LI>Girder Plugin: Fixed a few bugs.</LI> <LI>Installer: More installer improvements thanks to Chef_Koch.</LI> +<LI>Installer: Added a required file for Technotrend remote.</LI> +<LI>Abstract Remote Model: Corrected a bug in the Abstract Remote Map for MP Control Plugin.</LI> </UL></P> <BR> Property changes on: trunk/plugins/TelnetInterface ___________________________________________________________________ Name: svn:ignore + bin obj Added: trunk/plugins/TelnetInterface/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/TelnetInterface/Properties/AssemblyInfo.cs (rev 0) +++ trunk/plugins/TelnetInterface/Properties/AssemblyInfo.cs 2008-03-30 14:50:10 UTC (rev 1567) @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MediaPortal Telnet Interface")] +[assembly: AssemblyDescription("Provides a telnet interface to interact with MediaPortal")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TelnetInterface")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("189fd744-e73f-4515-b593-e2484f9a9ef0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.4.2")] +[assembly: AssemblyFileVersion("1.0.4.2")] Added: trunk/plugins/TelnetInterface/TelnetInterface.cs =================================================================== --- trunk/plugins/TelnetInterface/TelnetInterface.cs (rev 0) +++ trunk/plugins/TelnetInterface/TelnetInterface.cs 2008-03-30 14:50:10 UTC (rev 1567) @@ -0,0 +1,369 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; + +//using MediaPortal.Dialogs; +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; +using MediaPortal.Util; + + +namespace MediaPortal.Plugins +{ + + public class TelnetInterface : IPlugin, ISetupForm + { + + #region Constant + + const int SocketBacklog = 10; + + #endregion Constant + + #region Variables + + int _serverPort; + Socket _serverSocket; + + IPEndPoint _localEndPoint; + + Thread _connectionThread; + + bool _processConnectionThread; + + #endregion Variables + + #region IPlugin Members + + /// <summary> + /// Starts this instance. + /// </summary> + public void Start() + { + _serverPort = 23; + _processConnectionThread = true; + + try + { + _localEndPoint = new IPEndPoint(IPAddress.Any, _serverPort); + + _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + _serverSocket.Bind(_localEndPoint); + _serverSocket.Listen(SocketBacklog); + + _connectionThread = new Thread(new ThreadStart(ConnectionThread)); + _connectionThread.Name = "TelnetInterface.ConnectionThread"; + _connectionThread.IsBackground = true; + _connectionThread.Start(); + } + catch (Exception ex) + { + Log.Error(ex); + + _processConnectionThread = false; + _serverSocket = null; + _localEndPoint = null; + _connectionThread = null; + } + } + + /// <summary> + /// Stops this instance. + /// </summary> + public void Stop() + { + _processConnectionThread = false; + + if (_serverSocket != null) + _serverSocket.Close(); + + _serverSocket = null; + _localEndPoint = null; + _connectionThread = null; + } + + #endregion IPlugin Members + + #region ISetupForm Members + + public string Author() { return "and-81"; } + public bool CanEnable() { return true; } + public bool DefaultEnabled() { return true; } + public string Description() { return "Provides a telnet interface to control and interact with MediaPortal"; } + + /// <summary> + /// Gets the home screen details for the plugin. + /// </summary> + /// <param name="strButtonText">The button text.</param> + /// <param name="strButtonImage">The button image.</param> + /// <param name="strButtonImageFocus">The button image focus.</param> + /// <param name="strPictureImage">The picture image.</param> + /// <returns>true if the plugin can be seen, otherwise false.</returns> + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = strButtonImage = strButtonImageFocus = strPictureImage = String.Empty; + return false; + } + + public int GetWindowId() { return 0; } + + public bool HasSetup() { return false; } + + public string PluginName() { return "Telnet Interface"; } + + public void ShowPlugin() + { + + } + + #endregion ISetupForm Members + + + void SocketSend(Socket socket, string text) + { + byte[] textBytes = Encoding.ASCII.GetBytes(text + "\n\r"); + socket.Send(textBytes); + } + + void ConnectionThread() + { + try + { + while (_processConnectionThread) + { + Socket socket = _serverSocket.Accept(); + socket.Blocking = true; + + SocketSend(socket, "MediaPortal Telnet Interface"); + + Thread communicationThread = new Thread(new ParameterizedThreadStart(CommunicationThread)); + communicationThread.Name = "TelnetInterface.CommunicationThread"; + communicationThread.IsBackground = true; + communicationThread.Start(socket); + } + } + catch (SocketException ex) + { + Log.Warn(ex.ToString()); + } + catch (Exception ex) + { + Log.Error(ex); + } + } + + + void CommunicationThread(object socketObj) + { + Socket socket = socketObj as Socket; + if (socket == null) + { + Log.Error("TelnetInterface: CommunicationThread received invalid Socket Object"); + return; + } + + try + { + byte[] buffer = new byte[4096]; + + while (socket.Connected) + { + StringBuilder command = new StringBuilder(); + + while (true) + { + int readBytes = socket.Receive(buffer); + string input = Encoding.ASCII.GetString(buffer, 0, readBytes); + + command.Append(input); + + Log.Debug(BitConverter.ToString(buffer, 0, readBytes)); + + if (command[command.Length - 1] == '\r') + { + command.Remove(command.Length - 1, 1); + break; + } + } + + ProcessCommand(socket, command.ToString()); + } + } + catch (SocketException ex) + { + Log.Warn(ex.ToString()); + } + catch (Exception ex) + { + Log.Error(ex); + } + } + + + + void ProcessCommand(Socket socket, string text) + { + string[] words = text.Split(' '); + string keyWord = words[0].ToUpperInvariant(); + + string log = String.Format("Incoming Command: {0}", text); + Log.Debug("TelnetInterface: " + log); + SocketSend(socket, log); + + switch (keyWord) + { + case "GET": CommandGet(socket, words); break; + case "SET": CommandSet(socket, words); break; + + case "GOTO": CommandGoto(socket, words); break; + + case "PLAY": CommandPlay(socket, words); break; + + case "ACTION": CommandAction(socket, words); break; + + case "EXIT": CommandExitMP(socket); break; + + case "HELP": CommandHelp(socket); break; + + case "BYE": CommandClose(socket); break; + + + default: + string message = String.Format("Unknown Command Type: {0}", keyWord); + + Log.Warn("TelnetInterface: " + message); + + SocketSend(socket, message); + break; + } + } + + void CommandHelp(Socket socket) + { + SocketSend(socket, "Available commands:"); + SocketSend(socket, ""); + SocketSend(socket, "GET ACTIONS, GET SCREENS, GOTO <Screen>, PLAY <File>, ACTION <Action>, EXIT, BYE"); + SocketSend(socket, ""); + SocketSend(socket, "GET ACTIONS - Returns a list of MediaPortal actions the ACTION command can trigger"); + SocketSend(socket, "GET SCREENS - Returns a list of MediaPortal screens the GOTO command can use"); + SocketSend(socket, "GOTO <Screen> - Make MediaPortal move to another screen, can be the screen name from the GET SCREENS command, or the screen ID from it's XML file"); + SocketSend(socket, "PLAY <File> - Play the music/video file specified"); + SocketSend(socket, "ACTION <Action> - Trigger a MediaPortal action, this must be one of the actions from the GET ACTIONS command"); + SocketSend(socket, "EXIT - Quit MediaPortal"); + SocketSend(socket, "BYE - Close the Telnet session"); + } + + void CommandGet(Socket socket, string[] words) + { + string value = words[1].ToUpperInvariant(); + + switch (value) + { + case "ACTIONS": + foreach (string type in Enum.GetNames(typeof(Action.ActionType))) + SocketSend(socket, type); + break; + + case "SCREENS": + foreach (string type in Enum.GetNames(typeof(GUIWindow.Window))) + SocketSend(socket, type); + break; + } + + } + + void CommandSet(Socket socket, string[] words) + { + string value = words[1].ToUpperInvariant(); + + } + + void CommandGoto(Socket socket, string[] words) + { + string value = words[1].ToUpperInvariant(); + + int window = (int)GUIWindow.Window.WINDOW_INVALID; + + try + { + window = (int)Enum.Parse(typeof(GUIWindow.Window), value, true); + } + catch (ArgumentException) + { + // Parsing the window id as a GUIWindow.Window failed, so parse it as an int + } + + if (window == (int)GUIWindow.Window.WINDOW_INVALID) + int.TryParse(value, out window); + + if (window == (int)GUIWindow.Window.WINDOW_INVALID) + { + string message = String.Format("Cannot goto screen \"{0}\", not a valid screen name or number", value); + + Log.Warn(message); + SocketSend(socket, message); + } + + GUIGraphicsContext.ResetLastActivity(); + GUIWindowManager.SendThreadMessage(new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, window, 0, null)); + } + + void CommandPlay(Socket socket, string[] words) + { + GUIMessage message = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAY_FILE, 0, 0, 0, 0, 0, null); + message.Label = words[1]; + + GUIGraphicsContext.ResetLastActivity(); + GUIWindowManager.SendThreadMessage(message); + } + + void CommandAction(Socket socket, string[] words) + { + Action.ActionType type; + + try + { + type = (Action.ActionType)Enum.Parse(typeof(Action.ActionType), words[1], true); + } + catch (Exception ex) + { + Log.Error(ex); + + SocketSend(socket, String.Format("Could not convert \"{0}\" to a valid Action", words[1])); + return; + } + + SocketSend(socket, String.Format("Sending MediaPortal Action: {0}", Enum.GetName(typeof(Action.ActionType), type))); + + Action action = new Action(type, 0, 0); + GUIGraphicsContext.OnAction(action); + } + + + + void CommandExitMP(Socket socket) + { + Log.Info("TelnetInterface: Request to close MediaPortal received"); + + SocketSend(socket, "Closing MediaPortal (closing telnet connection)"); + + GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_EXIT, 0, 0)); + + socket.Close(); + } + + + + void CommandClose(Socket socket) + { + SocketSend(socket, "Closing telnet connection"); + socket.Close(); + } + + } + +} Added: trunk/plugins/TelnetInterface/TelnetInterface.csproj =================================================================== --- trunk/plugins/TelnetInterface/TelnetInterface.csproj (rev 0) +++ trunk/plugins/TelnetInterface/TelnetInterface.csproj 2008-03-30 14:50:10 UTC (rev 1567) @@ -0,0 +1,58 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{E8DE467F-0BD7-49CE-A5AC-4F1482EF04B6}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>MediaPortal.Plugins</RootNamespace> + <AssemblyName>TelnetInterface</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <UseVSHostingProcess>false</UseVSHostingProcess> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Core, Version=0.2.3.0, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=0.2.3.0, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Core\bin\Release\Utils.dll</HintPath> + <Private>False</Private> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="TelnetInterface.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Property changes on: trunk/plugins/XBMCServer ___________________________________________________________________ Name: svn:ignore + obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |