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

transport.cc

Go to the documentation of this file.
00001 /**************************************************************************
00002  Copyright (c) 2000-2001, Tony Garnock-Jones
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without
00006  modification, are permitted provided that the following conditions are
00007  met:
00008 
00009      * Redistributions of source code must retain the above copyright
00010        notice, this list of conditions and the following disclaimer.
00011 
00012      * Redistributions in binary form must reproduce the above
00013        copyright notice, this list of conditions and the following
00014        disclaimer in the documentation and/or other materials provided
00015        with the distribution.
00016 
00017      * Neither the names of the copyright holders nor the names of this
00018        software's contributors may be used to endorse or promote
00019        products derived from this software without specific prior
00020        written permission.
00021 
00022  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
00026  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 **************************************************************************/
00034 
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <assert.h>
00039 
00040 #include <mps/mps.h>
00041 
00042 namespace MPS {
00043 
00044 Transport::transportVec_t Transport::allTransports;
00045 
00046 Transport *Transport::findTransport(string const &name) {
00047   for (transportVec_t::iterator i = allTransports.begin();
00048        i != allTransports.end();
00049        i++) {
00050     if ((*i)->name == name)
00051       return (*i);
00052   }
00053 
00054   throw MPSException("Transport " + name + " not registered");
00055 }
00056 
00057 void Transport::registerTransport(Transport *t) {
00058   allTransports.push_back(t);
00059 }
00060 
00061 ref<Connection> Transport::getConnectionTo(Address const &connectionSpec) {
00062   return findTransport(connectionSpec.getTransport())->connectTo(connectionSpec);
00063 }
00064 
00065 string Transport::bindServer(Server *server, string const &bindingSpec) {
00066   Address spec(bindingSpec);
00067   string boundName = findTransport(spec.getTransport())->registerServer(server, spec);
00068   if (!boundName.empty())
00069     server->bindName(Address(boundName));
00070   return boundName;
00071 }
00072 
00073 void Transport::bindServer(Server *server) {
00074   for (transportVec_t::iterator i = allTransports.begin();
00075        i != allTransports.end();
00076        i++) {
00077     Transport *t(*i);
00078     Address spec("mps:" + t->getName());
00079     if (server->getBoundName(t->getName()).empty()) {
00080       // Not bound to this one yet.
00081       string boundName = t->registerServer(server, spec);
00082       if (!boundName.empty())
00083         server->bindName(Address(boundName));
00084     }
00085   }
00086 }
00087 
00088 string Transport::unbindServer(Server *server, string const &bindingSpec) {
00089   Address spec(bindingSpec);
00090   string boundName = findTransport(spec.getTransport())->deregisterServer(server, spec);
00091   if (!boundName.empty())
00092     server->unbindName(spec.getTransport());
00093   return boundName;
00094 }
00095 
00096 void Transport::unbindServer(Server *server) {
00097   for (transportVec_t::iterator i = allTransports.begin();
00098        i != allTransports.end();
00099        i++) {
00100     Transport *t(*i);
00101     Address spec("mps:" + t->getName());
00102     if (!server->getBoundName(t->getName()).empty()) {
00103       // We're bound to this one.
00104       string boundName = t->deregisterServer(server, spec);
00105       if (!boundName.empty())
00106         server->unbindName(t->getName());
00107     }
00108   }
00109 }
00110 
00111 Transport::Transport(string const &_name)
00112   : name(_name)
00113 {
00114   registerTransport(this);
00115 }
00116 
00117 Transport::~Transport()
00118 {
00119 }
00120 
00121 string const &Transport::getName() const {
00122   return name;
00123 }
00124 
00125 }

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