Check point code for brainshare demo
This commit is contained in:
parent
275f11c089
commit
ca2ae81cc4
88
CASA/micasad/lib/communication/server/RequestParser.cs
Normal file
88
CASA/micasad/lib/communication/server/RequestParser.cs
Normal file
@ -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]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
CASA/micasad/lib/communication/server/WinCommunication.cs
Normal file
60
CASA/micasad/lib/communication/server/WinCommunication.cs
Normal file
@ -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>
|
||||||
|
/// Summary description for WinCommunication.
|
||||||
|
/// </summary>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
102
CASA/micasad/lib/communication/server/WinIPCChannel.cs
Normal file
102
CASA/micasad/lib/communication/server/WinIPCChannel.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user