00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
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 }