[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Net.IrDA .cvsignore,NONE,1.1 I
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Net.IrDA .cvsignore,NONE,1.1 IrDA.build,NONE,1.1 IrDACharacterSet.cs,NONE,1.1 IrDAClient.cs,NONE,1.1 IrDADeviceInfo.cs,NONE,1.1 IrDAEndPoint.cs,NONE,1.1 IrDAHints.cs,NONE,1.1 IrDAListener.cs,NONE,1.1 Makefile.am,NONE,1.1 S.cs,NONE,1.1 |
Date: |
Mon, 26 May 2003 03:43:02 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Net.IrDA
In directory subversions:/tmp/cvs-serv9449/System.Net.IrDA
Added Files:
.cvsignore IrDA.build IrDACharacterSet.cs IrDAClient.cs
IrDADeviceInfo.cs IrDAEndPoint.cs IrDAHints.cs IrDAListener.cs
Makefile.am S.cs
Log Message:
Implement the "System.Net.IrDA" assembly, which is found in the
.NET Compact Framework.
--- NEW FILE ---
Makefile
Makefile.in
.deps
*.dll
--- NEW FILE ---
<?xml version="1.0"?>
<project name="pnetlib System.Net.IrDA" default="all">
<target name="all">
<!-- Build the primary System.Net.IrDA.dll library -->
<compile output="System.Net.IrDA.dll"
target="library"
unsafe="true"
nostdlib="true"
debug="${CONFIG_DEBUG_LINES}"
optimize="true">
<sources>
<includes name="**/*.cs"/>
</sources>
<references>
<file name="../System/System.dll"/>
<file name="../runtime/mscorlib.dll"/>
</references>
<resources>
<includes if="${CONFIG_RUNTIME_INFRA}"
name="../resources/en_US/System.Net.IrDA/System.Net.IrDA.resources"/>
</resources>
<arg compiler="cscc" value="-Wno-empty-input"/>
<arg compiler="cscc" value="-fminimize-parameters"/>
<arg compiler="csc" value="/nowarn:626"/>
<arg compiler="csc" value="/nowarn:649"/>
<arg compiler="csc" value="/nowarn:168"/>
<arg compiler="csc" value="/nowarn:67"/>
<arg compiler="csc" value="/nowarn:169"/>
<arg compiler="csc" value="/nowarn:679"/>
</compile>
</target>
</project>
--- NEW FILE ---
/*
* IrDACharacterSet.cs - Implementation of the
* "System.Net.IrDACharacterSet" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net.Sockets
{
public enum IrDACharacterSet
{
ASCII = 0,
ISO8859Latin1 = 1,
ISO8859Latin2 = 2,
ISO8859Latin3 = 3,
ISO8859Latin4 = 4,
ISO8859Cyrillic = 5,
ISO8859Arabic = 6,
ISO8859Greek = 7,
ISO8859Hebrew = 8,
ISO8859Latin5 = 9,
Unicode = 10
}; // enum IrDACharacterSet
}; // namespace System.Net.Sockets
--- NEW FILE ---
/*
* IrDAClient.cs - Implementation of the
* "System.Net.IrDAClient" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net.Sockets
{
using System.IO;
public class IrDAClient
{
// Internal state.
private Socket socket;
// Constructors.
public IrDAClient()
{
socket = new Socket(AddressFamily.Irda,
SocketType.Stream,
ProtocolType.Unspecified);
}
public IrDAClient(IrDAEndPoint remoteEP) : this()
{
Connect(remoteEP);
}
public IrDAClient(String service) : this()
{
Connect(service);
}
internal IrDAClient(Socket socket)
{
this.socket = socket;
}
// Get the name of the device that we are connected to.
public String RemoteMachineName
{
get
{
return GetRemoteMachineName(socket);
}
}
// Close the connection.
public void Close()
{
socket.Close();
}
// Connect to a remote end point.
public void Connect(IrDAEndPoint remoteEP)
{
socket.Connect(remoteEP);
}
public void Connect(String service)
{
// Discover a device that we can connect to.
IrDADeviceInfo[] devices = DiscoverDevices(1);
if(devices.Length == 0)
{
throw new InvalidOperationException
(S._("IrDA_NoDeviceAvailable"));
}
Connect(new IrDAEndPoint(devices[0].DeviceID,
service));
}
// Discover information about the available IrDA devices.
public IrDADeviceInfo[] DiscoverDevices(int maxDevices)
{
return DiscoverDevices(maxDevices, socket);
}
public static IrDADeviceInfo[] DiscoverDevices
(int maxDevices, Socket irdaSocket)
{
// Fetch the option data from the socket.
int maxSize = 4 + maxDevices * 32;
byte[] data = irdaSocket.GetSocketOption
((SocketOptionLevel)255,
(SocketOptionName)16, maxSize);
if(data == null || data.Length < 4)
{
return new IrDADeviceInfo [0];
}
// Construct the device array.
int num = IrDADeviceInfo.FetchInt32(data, 0);
if(num < 0)
{
num = 0;
}
else if(num > maxDevices)
{
num = maxDevices;
}
IrDADeviceInfo[] devs = new IrDADeviceInfo
[num];
int posn;
for(posn = 0; posn < num; ++posn)
{
devs[posn] = new IrDADeviceInfo(data, 4
+ posn * 32);
}
return devs;
}
// Get the name of a remote machine from an IrDA socket.
public static String GetRemoteMachineName(Socket s)
{
// Find a device that has a matching device ID.
byte[] remoteID =
((IrDAEndPoint)(s.RemoteEndPoint)).DeviceID;
IrDADeviceInfo[] devices = DiscoverDevices(10,
s);
byte[] id;
foreach(IrDADeviceInfo dev in devices)
{
id = dev.DeviceID;
if(remoteID[0] == id[0] && remoteID[1]
== id[1] &&
remoteID[2] == id[2] && remoteID[3]
== id[3])
{
return dev.DeviceName;
}
}
throw new InvalidOperationException
(S._("IrDA_NoMatchingDevice"));
}
// Get the underlying data stream for the connection.
public Stream GetStream()
{
return new NetworkStream(socket);
}
}; // class IrDAClient
}; // namespace System.Net.Sockets
--- NEW FILE ---
/*
* IrDADeviceInfo.cs - Implementation of the
* "System.Net.IrDADeviceInfo" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net.Sockets
{
using System.Text;
public class IrDADeviceInfo
{
// Internal state.
internal IrDACharacterSet characterSet;
internal byte[] deviceID;
internal String deviceName;
internal IrDAHints hints;
// Constructor.
internal IrDADeviceInfo(byte[] data, int posn)
{
deviceID = new byte [4];
deviceID[0] = data[posn];
deviceID[1] = data[posn + 1];
deviceID[2] = data[posn + 2];
deviceID[3] = data[posn + 3];
int offset = posn + 4;
StringBuilder builder = new StringBuilder();
while(offset < (posn + 26) && data[offset] != 0)
{
builder.Append((char)(data[offset]));
++offset;
}
deviceName = builder.ToString();
hints = (IrDAHints)(data[posn + 26] |
(data[posn + 27] << 8));
characterSet = (IrDACharacterSet)(data[posn +
28]);
}
// Fetch a host byte order Int32 from an array.
internal static int FetchInt32(byte[] data, int posn)
{
return ((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | data[3]);
}
// Get the device's properties.
public IrDACharacterSet CharacterSet
{
get
{
return characterSet;
}
}
public byte[] DeviceID
{
get
{
return deviceID;
}
}
public String DeviceName
{
get
{
return deviceName;
}
}
public IrDAHints Hints
{
get
{
return hints;
}
}
}; // class IrDADeviceInfo
}; // namespace System.Net.Sockets
--- NEW FILE ---
/*
* IrDAEndPoint.cs - Implementation of the
* "System.Net.IrDAEndPoint" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net
{
using System.Net.Sockets;
using System.Text;
public class IrDAEndPoint : EndPoint
{
// Internal state.
private byte[] deviceID;
private String serviceName;
// Constructor.
public IrDAEndPoint(byte[] irdaDeviceID, String serviceName)
{
// Validate the parameters.
ValidateDeviceID(irdaDeviceID);
ValidateServiceName(serviceName);
// Save the parameters for later.
this.deviceID = new byte [4];
Array.Copy(irdaDeviceID, 0, this.deviceID, 0,
4);
this.serviceName = serviceName;
}
// Get the address family for this end point.
public override AddressFamily AddressFamily
{
get
{
return AddressFamily.Irda;
}
}
// Get or set the device identifier for this end point.
public byte[] DeviceID
{
get
{
return deviceID;
}
set
{
ValidateDeviceID(value);
Array.Copy(value, 0, deviceID, 0, 4);
}
}
// Get or set the service name for this end point.
public String ServiceName
{
get
{
return serviceName;
}
set
{
ValidateServiceName(value);
serviceName = value;
}
}
// Create an end point from a socket address.
public override EndPoint Create(SocketAddress sockaddr)
{
// Extract the device ID [2..5] from the socket
address.
byte[] deviceID = new byte [4];
deviceID[0] = sockaddr[2];
deviceID[1] = sockaddr[3];
deviceID[2] = sockaddr[4];
deviceID[3] = sockaddr[5];
// Extract the service name [6..] from the
socket address.
int posn = 6;
StringBuilder builder = new StringBuilder();
while(posn < sockaddr.Size && sockaddr[posn] !=
0)
{
builder.Append((char)(sockaddr[posn]));
++posn;
}
// Build and return the new end point.
return new IrDAEndPoint(deviceID,
builder.ToString());
}
// Serialize the end point into a socket address.
public override SocketAddress Serialize()
{
SocketAddress addr = new
SocketAddress(AddressFamily.Irda, 32);
addr[2] = deviceID[0];
addr[3] = deviceID[1];
addr[4] = deviceID[2];
addr[5] = deviceID[3];
int posn = 0;
while(posn < 24 && posn < serviceName.Length)
{
addr[posn + 6] =
(byte)(serviceName[posn]);
++posn;
}
addr[posn + 6] = 0;
return addr;
}
// Validate an IrDA device identifier.
private static void ValidateDeviceID(byte[] irdaDeviceID)
{
if(irdaDeviceID == null)
{
throw new
ArgumentNullException("irdaDeviceID");
}
if(irdaDeviceID.Length != 4)
{
throw new ArgumentException
(S._("IrDA_InvalidDeviceID"),
"irdaDeviceID");
}
}
// Validate an IrDA service name.
private static void ValidateServiceName(String serviceName)
{
// Must not be null, empty, or greater than 24
characters long.
if(serviceName == null)
{
throw new
ArgumentNullException("serviceName");
}
if(serviceName.Length <= 0 ||
serviceName.Length >= 25)
{
throw new ArgumentException
(S._("IrDA_InvalidServiceName"), "serviceName");
}
// Must only contain Latin1 characters.
foreach(char ch in serviceName)
{
if(ch >= '\u0100')
{
throw new ArgumentException
(S._("IrDA_InvalidServiceName"), "serviceName");
}
}
}
}; // class IrDAEndPoint
}; // namespace System.Net
--- NEW FILE ---
/*
* IrDAHints.cs - Implementation of the
* "System.Net.IrDAHints" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net.Sockets
{
[Flags]
public enum IrDAHints
{
None = 0x0000,
PnP = 0x0001,
PdaAndPalmtop = 0x0002,
Computer = 0x0004,
Printer = 0x0008,
Modem = 0x0010,
Fax = 0x0020,
LanAccess = 0x0040,
Telephony = 0x0100,
FileServer = 0x0200
}; // enum IrDAHints
}; // namespace System.Net.Sockets
--- NEW FILE ---
/*
* IrDAListener.cs - Implementation of the
* "System.Net.IrDAListener" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net.Sockets
{
using System.IO;
public class IrDAListener
{
// Internal state.
private IrDAEndPoint localEP;
private Socket socket;
// Constructor.
public IrDAListener(IrDAEndPoint ep)
{
if(ep == null)
{
throw new ArgumentNullException("ep");
}
this.localEP = ep;
}
public IrDAListener(String service)
{
this.localEP = new IrDAEndPoint(new byte [4],
service);
}
// Get the local end point that is being used by this listener.
public IrDAEndPoint LocalEndpoint
{
get
{
return localEP;
}
}
// Accept an incoming connection and create a client object.
public IrDAClient AcceptIrDAClient()
{
return new IrDAClient(AcceptSocket());
}
// Accept an incoming connection and create a socket object.
public Socket AcceptSocket()
{
if(socket != null)
{
return socket.Accept();
}
else
{
throw new InvalidOperationException
(S._("IrDA_ListenerNotStarted"));
}
}
// Determine if there is a connection pending.
public bool Pending()
{
if(socket != null)
{
return socket.Poll(0,
SelectMode.SelectRead);
}
else
{
throw new InvalidOperationException
(S._("IrDA_ListenerNotStarted"));
}
}
// Start listening for incoming connections.
public void Start()
{
if(socket == null)
{
socket = new Socket(AddressFamily.Irda,
SocketType.Stream,
ProtocolType.Unspecified);
socket.Bind(localEP);
socket.Listen(Int32.MaxValue);
}
}
// Stop listening for incoming connections.
public void Stop()
{
if(socket != null)
{
socket.Close();
socket = null;
}
}
}; // class IrDAListener
}; // namespace System.Net.Sockets
--- NEW FILE ---
.PHONY: System.Net.IrDA.dll
all-local: System.Net.IrDA.dll
System.Net.IrDA.dll:
"$(CSANT)" $(CSANT_FLAGS) -f IrDA.build all
CLEANFILES = System.Net.IrDA.dll
pnetassembliesdir = $(libdir)/cscc/lib
pnetassemblies_DATA = System.Net.IrDA.dll
--- NEW FILE ---
/*
* S.cs - Implementation of string resource handling.
*
* Copyright (C) 2002, 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Net
{
using System.Reflection;
using System.Resources;
// This class provides string resource support to the rest
// of the System.Drawing library assembly. It is accessed using
// the "S._(tag)" convention.
internal sealed class S
{
#if CONFIG_RUNTIME_INFRA
// Cached copy of the resources for this assembly and mscorlib.
#if ECMA_COMPAT
private static ECMAResourceManager ourResources = null;
private static ECMAResourceManager runtimeResources = null;
#else
private static ResourceManager ourResources = null;
private static ResourceManager runtimeResources = null;
#endif
// Helper for obtaining string resources for this assembly.
public static String _(String tag)
{
lock(typeof(S))
{
String value;
// Try the resources in this assembly
first.
if(ourResources == null)
{
#if ECMA_COMPAT
ourResources = new
ECMAResourceManager
("System.Net.IrDA",
(typeof(S)).Assembly);
#else
ourResources = new
ResourceManager
("System.Net.IrDA",
(typeof(S)).Assembly);
#endif
}
value = ourResources.GetString(tag,
null);
if(value != null)
{
return value;
}
// Try the fallbacks in the runtime
library.
if(runtimeResources == null)
{
#if ECMA_COMPAT
runtimeResources = new
ECMAResourceManager
("runtime",
(typeof(String)).Assembly);
#else
runtimeResources = new
ResourceManager
("runtime",
(typeof(String)).Assembly);
#endif
}
return runtimeResources.GetString(tag,
null);
}
}
#else // !CONFIG_RUNTIME_INFRA
// We don't have sufficient runtime infrastructure to load resources.
public static String _(String tag)
{
return tag;
}
#endif // !CONFIG_RUNTIME_INFRA
}; // class S
}; // namespace System.Net
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Net.IrDA .cvsignore,NONE,1.1 IrDA.build,NONE,1.1 IrDACharacterSet.cs,NONE,1.1 IrDAClient.cs,NONE,1.1 IrDADeviceInfo.cs,NONE,1.1 IrDAEndPoint.cs,NONE,1.1 IrDAHints.cs,NONE,1.1 IrDAListener.cs,NONE,1.1 Makefile.am,NONE,1.1 S.cs,NONE,1.1,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/System.Net.IrDA .cvsignore,NONE,1.1 IrDA.txt,NONE,1.1 Makefile.am,NONE,1.1
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.937,1.938 Makefile.am,1.17,1.18 configure.in,1.71,1.72
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib/resources/en_US/System.Net.IrDA .cvsignore,NONE,1.1 IrDA.txt,NONE,1.1 Makefile.am,NONE,1.1
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.937,1.938 Makefile.am,1.17,1.18 configure.in,1.71,1.72
- Index(es):