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_Simpl_H 00037 #define MPS_Transport_Simpl_H 00038 00039 #include <mps/mps.h> 00040 #include <map> 00041 00042 namespace MPS { 00043 00044 /** 00045 * Implements a Transport class for accessing and 00046 * serving MPS objects via the SIMPL protocol 00047 * (http://www.holoweb.net/~simpl/). */ 00048 class SimplTransport: public MPS::Transport { 00049 private: 00050 static SimplTransport *instance; ///< The single, per-application instance of SimplTransport 00051 00052 //--------------------------------------------------------------------------- 00053 00054 class SimplIOStream; ///< Subclass of MPS::InputStream and MPS::OutputStream 00055 class SimplConnection; ///< Subclass of MPS::Connection - holds FCID 00056 00057 typedef map< int, Server * > serverMap_t; 00058 00059 //--------------------------------------------------------------------------- 00060 00061 int nextOid; ///< Next OID available for registration here. 00062 string simplName; ///< Our local SIMPL server name 00063 serverMap_t serverMap; ///< All OIDs we serve 00064 00065 //--------------------------------------------------------------------------- 00066 00067 SimplTransport(string const &simplName); 00068 00069 protected: 00070 virtual ref<Connection> connectTo(Address const &connectionSpec); 00071 virtual string registerServer(Server *server, Address const &spec); 00072 virtual string deregisterServer(Server *server, Address const &spec); 00073 00074 friend class SimplIOStream; 00075 static void pushMessage(void *sender, char const *msg, int msglen); 00076 static void *popMessage(char *msg, int &msglen); 00077 00078 public: 00079 /** 00080 * Creates the single per-application instance of SimplTransport, and 00081 * registers it using Transport::registerTransport(). 00082 * 00083 * @param namingServerLocation resolved address of the naming server to use 00084 * @param simplName the name to bind to our SIMPL mailbox */ 00085 static void initialise(string const &simplName) { 00086 if (instance == 0) { 00087 instance = new SimplTransport(simplName); 00088 } 00089 } 00090 00091 static void mainloop(); 00092 }; 00093 00094 } 00095 00096 #endif