From ca2ae81cc4ad86b8191ad57e00a8dfd03f14e7f1 Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Thu, 1 Mar 2007 21:56:28 +0000 Subject: [PATCH] Check point code for brainshare demo --- .../lib/communication/server/RequestParser.cs | 88 +++++++++++++++ .../communication/server/WinCommunication.cs | 60 +++++++++++ .../lib/communication/server/WinIPCChannel.cs | 102 ++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 CASA/micasad/lib/communication/server/RequestParser.cs create mode 100644 CASA/micasad/lib/communication/server/WinCommunication.cs create mode 100644 CASA/micasad/lib/communication/server/WinIPCChannel.cs diff --git a/CASA/micasad/lib/communication/server/RequestParser.cs b/CASA/micasad/lib/communication/server/RequestParser.cs new file mode 100644 index 00000000..9d931d1c --- /dev/null +++ b/CASA/micasad/lib/communication/server/RequestParser.cs @@ -0,0 +1,88 @@ +/*********************************************************************** + * + * Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, + * you may find current contact information at www.novell.com. + * + ***********************************************************************/ + +using System; +using System.Collections; +using System.Text; +using System.Threading; + + +/* + * After the bytes format is finalized for Windows this class might need to + * be modified.. + * Depending upon impact either a new method can be invoked after platfrom + * check or a Factory pattern can be used to redesign this class. + */ + + +namespace Novell.CASA.MiCasa.Communication.Server +{ + /* This class will be used to convert raw bytes to one of the SecretStore + * Verbs. Although there is no need to have many instances, + * this class will NOT be singleton class since we + * do not want a hit on performance (synchronization, obtaining locks, + * releasing locks...etc ) + * Making it singleton is not giving us any advantage versus performance. + */ + internal class RequestParser + { + Hashtable msgIdMap = new Hashtable(); + + internal RequestParser() + { + msgIdMap.Add(0,"casa.verbs.SelectCard"); + msgIdMap.Add(1, "casa.verbs.SelectCard"); + } + + /* Processes the request and returns the corrrect SSverb. + * This interface works on the class member rawbytes and + * returns the result. + */ + internal SSVerb ParseRequest(byte[] rawbytes) + { + if (rawbytes == null) + throw new FormatException("Message format incorrect"); + + String className = GetClassName(rawbytes); + + SSVerb theVerb = (SSVerb)Activator.CreateInstance(null, className ).Unwrap(); + theVerb.SetMessageContent(rawbytes); + + /* + * TBD: We can send the activation params in the same call. + */ + //SSVerb theVerb = (SSVerb)Activator.CreateInstance(Type.GetType(className)).Unwrap(); + + return theVerb; + } + + private string GetClassName(byte[] ipcbytes) + { + /* + * Read first two bytes and get ushort + * Look up table and send class name + */ + ushort msgId = BitConverter.ToUInt16(ipcbytes,0); + return ((String)(msgIdMap[(int)msgId])); + } + } +} diff --git a/CASA/micasad/lib/communication/server/WinCommunication.cs b/CASA/micasad/lib/communication/server/WinCommunication.cs new file mode 100644 index 00000000..79aab51e --- /dev/null +++ b/CASA/micasad/lib/communication/server/WinCommunication.cs @@ -0,0 +1,60 @@ +/*********************************************************************** + * + * Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, + * you may find current contact information at www.novell.com. + * z + ***********************************************************************/ + +using System; + +using AppModule.InterProcessComm; +using AppModule.NamedPipes; +using Novell.CASA.MiCasa.Communication.win; + + +namespace Novell.CASA.MiCasa.Communication.Server +{ + /// + /// Summary description for WinCommunication. + /// + public class WinCommunication : Server.Communication + { + + public static IChannelManager PipeManager; + + public WinCommunication() + { + PipeManager = new PipeManager(); + PipeManager.Initialize(); + } + + public void StartCommunicationEndPoint() + { + Console.WriteLine("StartCommunctionEndPointed called"); + //PipeManager = new PipeManager(); + //PipeManager.Initialize(); + //PipeManager.Start(); + PipeManager.Start(); + } + + public void CloseCommunicationEndPoint() + { + PipeManager.Stop(); + } + } +} diff --git a/CASA/micasad/lib/communication/server/WinIPCChannel.cs b/CASA/micasad/lib/communication/server/WinIPCChannel.cs new file mode 100644 index 00000000..dcf69760 --- /dev/null +++ b/CASA/micasad/lib/communication/server/WinIPCChannel.cs @@ -0,0 +1,102 @@ +/*********************************************************************** + * + * Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, + * you may find current contact information at www.novell.com. + * + ***********************************************************************/ + + +using System; +using System.IO; +using System.Text; + +using AppModule.NamedPipes; +using Novell.CASA.MiCasa.Communication.win; + +namespace Novell.CASA.MiCasa.Communication.Server +{ + + class WinIPCChannel : IPCChannel + { + // Data + private ServerPipeConnection m_serverPipeConnection; + + //Methods + public WinIPCChannel(ServerPipeConnection serverPipeConnection) + { + m_serverPipeConnection = serverPipeConnection; + } + + private WinIPCChannel() + { + //CSSSLogger.DbgLog("WinIPCChannel constructor must be called with a serverPipe"); + + } + ~WinIPCChannel() + { + // Console.WriteLine("WinIPCChannel::~~WinIPCChannel"); + } + + override internal byte[] Read() + { + + + byte[] incoming = null; + try + { + incoming = m_serverPipeConnection.ReadBytes(); + return incoming; + } + catch(Exception) + { + return null; + //CSSSLogger.DbgLog("Exception in reading data from client" + e.ToString()); + //throw new CommunicationException(e.ToString()); + } + } + + override internal int Read(byte[] buf) + { + return 0; + } + + override internal int Write(byte[] buf) + { + + int bytesSent = 0; + try + { + m_serverPipeConnection.WriteBytes(buf); + bytesSent = buf.Length; + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + } + //CSSSLogger.DbgLog("WinIPCChannel::Write - Bytes sent is {0}" +bytesSent); + return bytesSent; + + } + override internal void Close() + { + //CSSSLogger.DbgLog("WinIPCChannel Closed"); + //clientSocket.Close(); + m_serverPipeConnection.Close(); + } + } +}