Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

transport.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /**************************************************************************
00003  Copyright (c) 2000-2001, Tony Garnock-Jones
00004  All rights reserved.
00005 
00006  Redistribution and use in source and binary forms, with or without
00007  modification, are permitted provided that the following conditions are
00008  met:
00009 
00010      * Redistributions of source code must retain the above copyright
00011        notice, this list of conditions and the following disclaimer.
00012 
00013      * Redistributions in binary form must reproduce the above
00014        copyright notice, this list of conditions and the following
00015        disclaimer in the documentation and/or other materials provided
00016        with the distribution.
00017 
00018      * Neither the names of the copyright holders nor the names of this
00019        software's contributors may be used to endorse or promote
00020        products derived from this software without specific prior
00021        written permission.
00022 
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
00027  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00028  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00029  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00030  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00031  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00032  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 **************************************************************************/
00035 
00036 #ifndef MPS_Transport_H
00037 #define MPS_Transport_H
00038 
00039 namespace MPS {
00040 
00041 /**
00042  * Represents a method of resolving names for, and connecting to
00043  * remote objects. Subclasses implement name-resolution and connection
00044  * facilities according to a particular transport protocol; examples
00045  * include InetTransport, SleeTransport, and FastmsgTransport. */
00046 class Transport {
00047 private:
00048   typedef vector<Transport *> transportVec_t;           ///< A list of Transports.
00049   static transportVec_t allTransports;                  ///< All registered Transports
00050 
00051 private:
00052   string name;                          ///< Registered name of this transport ("inet", "slee", ..)
00053 
00054 private:
00055   /**
00056    * Locate a Transport by name.
00057    *
00058    * @return a pointer to the named Transport.
00059    * @exception MPSException if the Transport name is not registered. */
00060   static Transport *findTransport(string const &name);
00061 
00062 public:
00063   /// Register a transport.
00064   static void registerTransport(Transport *t);
00065 
00066   /**
00067    * Returns a message source/sink that can be used for communication
00068    * with the object at the address described by the
00069    * connectionSpec. Selects an appropriate Transport based on the
00070    * "transport" field of the Address.
00071    *
00072    * @param connectionSpec the address of the remote object
00073    * @return a connection handle for remote communication, or NULL if
00074    * none could be created
00075    * @exception MPSException if the transport name given is not
00076    * registered */
00077   static ref<Connection> getConnectionTo(Address const &connectionSpec);
00078 
00079   /**
00080    * Bind an object server to an interface provided by a transport.
00081    *
00082    * @param server the server to bind to the (about-to-be-created) transport-interface
00083    *
00084    * @param bindingSpec the suggested resolved name to bind to -
00085    * should be of the form "mps:transportname" or, if a greater degree
00086    * of control over the bind is desired,
00087    * "mps:transportname:param:param:..." (for instance, with the
00088    * "inet" transport, you use "mps:inet:hostname:portnumber").
00089    *
00090    * @return the string of the newly-bound address, or empty-string if the bind failed */
00091   static string bindServer(Server *server, string const &bindingSpec);
00092 
00093   /**
00094    * Bind an object server to all available transports that currently
00095    * do not have a binding for this server.
00096    *
00097    * @param server the server to bind */
00098   static void bindServer(Server *server);
00099 
00100   /**
00101    * Unbind an object server from an interface provided by a transport.
00102    *
00103    * @param server the server to unbind to the (about-to-be-removed) transport-interface
00104    *
00105    * @param bindingSpec the suggested resolved name to unbind from - cf. bindServer()
00106    * @return the string of the newly-unbound address, or empty-string if the unbind failed */
00107   static string unbindServer(Server *server, string const &bindingSpec);
00108 
00109   /**
00110    * Unbind a previously-bound server.
00111    * @param server the server to unbind. */
00112   static void unbindServer(Server *server);
00113 
00114 protected:
00115   /**
00116    * For access by subclasses - initialises this class
00117    *
00118    * @param _name name to register the transport under
00119    */
00120   Transport(string const &_name);
00121 
00122 public:
00123   virtual ~Transport();
00124 
00125   /// Retrieves the transport's registered name.
00126   string const &getName() const;
00127 
00128 protected:
00129   /**
00130    * Returns a message source/sink that can be used for communication
00131    * with the object at the address described by the
00132    * connectionSpec. The connectionSpec is the broken-down resolved
00133    * name of the remote object, and <b>must</b> match the address
00134    * format that this transport expects.
00135    *
00136    * @param connectionSpec the address of the remote object
00137    * @return a connection handle for remote communication, or NULL if
00138    * none could be created */
00139   virtual ref<Connection> connectTo(Address const &connectionSpec) = 0;
00140 
00141   /**
00142    * Attempt to register a server interface for access using this transport.
00143    *
00144    * @param server the server to register
00145    * @param spec the connection specification that the transport may
00146    * use as a hint in determining the final resolved name to use when
00147    * binding this object.
00148    * @return the canonical name of the server-bound-to-this-transport,
00149    * or "" if binding to this transport fails. */
00150   virtual string registerServer(Server *server, Address const &spec) = 0;
00151 
00152   /**
00153    * Attempt to deregister a server interface.
00154    *
00155    * @param server the server to deregister
00156    * @param spec the connection specification that the transport may
00157    * use as a hint in determining the final resolved name to use when
00158    * unbinding this object.
00159    * @return the canonical name of the server-that-was-bound-to-this-transport,
00160    * or "" if unbinding from this transport fails. */
00161   virtual string deregisterServer(Server *server, Address const &spec) = 0;
00162 };
00163 
00164 }
00165 
00166 #endif

Generated at Wed Aug 15 01:05:16 2001 for mps-cpp by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001