/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* 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 */ /* 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, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ using System; using System.Net; using System.Collections; using AgentService.Interop; namespace AgentService.Interop.Implementation { /// /// Class PlatformBinder. Defualt platform binder. /// Connects to an instance of the AgentService /// platform by using the platform access point /// provided by the RemoteControlModule. /// /// the class is thread safe public class PlatformBinder : IPlatformBinder { /// /// synchronization flag. /// private object handle = new object(); /// /// ArrayList containing the active connections. /// private ArrayList activeConnections; /// /// Cached array of active platform connections. /// private IPlatformChannel[] cached; /// /// Gets an array of the active connections managed /// by the platform binder. /// public IPlatformChannel[] ActiveConnections { get { if (cached != null) return cached; lock(this.handle) { this.cached = (IPlatformChannel[]) this.activeConnections.ToArray(typeof(IPlatformChannel)); return this.cached; } } } /// /// Connects to an instance of the AgentService platform. Connection is /// performed asynchronously and by useing the given user credentials. /// /// user name /// user password /// platform TCP address (IP address, port) /// platform public key /// a connection channel with the platform. public IPlatformChannel Connect(string user, string pwd, TCPAddress address, byte[] publicKey) { PlatformChannel channel = new PlatformChannel(this, new User(user, pwd, UserGroup.Anonymous), address, publicKey); return channel; } /// /// Closes all the active connections managed by this /// binder. /// public void CloseAllChannels() { lock(this.handle) { foreach(PlatformChannel channel in this.activeConnections) { channel.Close(false); } this.activeConnections.Clear(); this.cached = null; } } /// /// Signals to this instancs of the PlatformBinder /// that the given channel has been closed. /// /// signaling channel internal void SignalClose(IPlatformChannel channel) { lock(this.handle) { if (this.activeConnections.Contains(channel) == false) { this.activeConnections.Remove(channel); this.cached = null; } } } /// /// Signals to the PlatformBinder that the given /// channel has become active. /// /// signaling channel internal void SignalActive(IPlatformChannel channel) { lock(this.handle) { if (this.activeConnections.Contains(channel) == false) { this.activeConnections.Add(channel); this.cached = null; } } } } }