Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/typingtweaks/localsite.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 #ifndef _LOCALSITE_HH_
00024 #define _LOCALSITE_HH_
00025 
00026 #ifndef _VOS_HH_
00027 #error Please only include "vos.hh"!
00028 #endif
00029 
00030 /** @file
00031     Defines LocalSite.
00032 */
00033 
00034 typedef MetaObject* (*metaobject_extender_t)(MetaObject* superobject, const string& type);
00035 
00036 /** A site which is local to your application.  It is to one of these
00037     where you will attach all of your own local objects.  It listens
00038     on a single TCP socket for incoming connections from remote sites
00039     (this connection process is called @em site @em peering).
00040 */
00041 class VOS_API LocalSite : public virtual Site, public virtual LocalMetaObject
00042 {
00043 private:
00044     typedef multimap<string, metaobject_extender_t>::iterator MI;
00045     static multimap<string, metaobject_extender_t> localObjectExtensionTable;
00046 public:
00047     class PortBindingError : public runtime_error {
00048     public:
00049         PortBindingError(const string& s) : runtime_error(s) { }
00050     };
00051 protected:
00052     struct SiteTableEntry {
00053         string localPeerName;
00054         MessageBlock* partialMessage;
00055     };
00056     int iteratorsUsingPeerSites;
00057 
00058     /** The following three data structures are used to buffer changes
00059        to peerSites when we have an active iterator using peerSites.
00060        This is to avoid invalidating the iterator (ye gods that was an
00061        obnoxious bug to track down.)  The alternative would have to be
00062        to make a complete copy of the peerSites deque every time we
00063        want to copy it (ewww...)
00064 
00065        @note although peerSitesBuffer_rs and peerSitesBuffer_st could
00066        be combined into a single structure like deque<
00067        pair<RemoteSite*, struct SiteTableEntry*> > BUT that causes an
00068        internal compiler error when compiling site.cc!  So instead we
00069        do it this way.  Bleh.
00070     */
00071     deque<RemoteSite*> peerSitesBuffer_rs;
00072     deque<struct SiteTableEntry*> peerSitesBuffer_st;
00073     deque<RemoteSite*> peerSitesBuffer_remove;
00074 
00075     boost::mutex peerSitesBuffer_mutex;
00076 
00077     /** List of remote sites we are peers with. */
00078     map<RemoteSite*, struct SiteTableEntry*> peerSites;
00079 
00080     /** The current message schedule. */
00081     map<double, list<Message*> > siteMessageQueue;
00082     list<Message*> msgsReady;
00083 
00084     struct ::timeval* selectwait;
00085 
00086     map<string, RemoteSite*> prioritized;
00087 
00088     typedef void (*callback_t)(void* userdata);
00089     struct Callback {
00090         bool repeat;    // callback should be performed repeatedly
00091         double timeout; // amount of time to wait between repeated callbacks
00092         callback_t callback;
00093         void* userdata;
00094     };
00095 
00096     bool callbacklock;
00097     map<double, Callback> callbacks;
00098     queue<pair<double, Callback> > callbackaddqueue;
00099     queue<callback_t> callbackremovequeue;
00100 
00101     queue<NotifyEvent*> notifyEvents;
00102     bool notifyflushlock;
00103 
00104     map<string, string> antiSpoofMap;
00105 
00106     void verifyCheckIDPair(RemoteSocketSite* rss, const string& spoofID);
00107 
00108     struct ValidationEntry
00109     {
00110         string checkid;
00111         string hostalias;
00112         vRef<RemoteSocketSite> realsite;
00113         bool favored;
00114     };
00115     map<RemoteSocketSite*, ValidationEntry> pendingValidations;
00116     set<string> pendingValidationHosts;
00117 
00118     list< pair<string, RemoteSite*> > needSpoofIDreply;
00119 
00120     /** constructor */
00121     LocalSite();
00122 public:
00123     /** destructor */
00124     virtual ~LocalSite();
00125 
00126     virtual void flushIncomingBuffers() = 0;
00127 
00128     /** Schedule a message block for delivery.  Special message types like include
00129         will be processed.
00130         @param mb The message block
00131         @param mc The enclosing message context
00132         @param ss The source site
00133         @param plustime This value will be added to the delivery time
00134         @param extradependency This dependency string will added to each message
00135     */
00136     virtual void scheduleMessageBlock(MessageBlock* mb, MessageContext* mc, Site* ss,
00137                                       double plustime=0.0, const char* extradependency=0);
00138 
00139     /** Execute the current schedule.
00140      */
00141     virtual void runSchedule();
00142 
00143     void doCallbacks();
00144     void addCallback(callback_t callback, void* userdata, double timeout, bool repeat);
00145     void removeCallback(callback_t callback);
00146 
00147     /** Remove the peering relationship with a remote site. */
00148     virtual void removeRemotePeer(RemoteSite* rs);
00149 
00150     virtual bool checkScheduleHoldsSite(Site* site);
00151 
00152     virtual void sendMessage(Message* m);
00153     virtual void sendMessage(MessageBlock* m);
00154     virtual void setURL(const URL& u);
00155 
00156     virtual bool isConnected() {
00157         return true;
00158     }
00159 
00160     virtual Site& getSite() { return Site::getSite(); }
00161 
00162     /** When select() is called to test file descriptors, this sets maximum amount of time
00163         to wait before returning if there is no data available.  This primarily applies
00164         to LocalSite::flushIncomingBuffers().
00165         @param sec the time to wait, in seconds.  This may be zero, in which case
00166         it will return immediately.  If the time is negative, select
00167         will sleep indefinitely until data is received on any of the
00168         sockets or the process catches a signal.
00169     */
00170     void setTimeoutOnSelect(double sec);
00171 
00172     /** Get the select wait time.
00173         @return the maximum time (in seconds) that select will wait, or -1 if select will block indefinately. */
00174     double getTimeoutOnSelect();
00175 
00176     virtual void addPrioritizedNonce(const string& nonce, RemoteSite* source);
00177     virtual void removePrioritizedNonce(const string& nonce, RemoteSite* source);
00178 
00179     static void extendMetaObject(LocalMetaObject* root, const char* type);
00180 //    static void extendMetaObjectV(LocalMetaObject* root, va_list ap);
00181 
00182 
00183     virtual MetaObject* createMetaObject(const char* name, const char* type0, ...);
00184     virtual MetaObject* createMetaObject(const char* name, const deque<string>& typelist);
00185 
00186     /** Create a new local metaobject, with the supplied access control (ar
00187      * defoult site AC if 0).
00188      * @sa createMetaObject(const char*, const char*, ...)
00189      */
00190     virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const char* type0, ...);
00191 
00192 
00193     /** Create a new local metaobject, with the supplied access control (ar
00194      * defoult site AC if 0).
00195      * @sa createMetaObject(const char*, const char*, ...)
00196      */
00197     virtual MetaObject* createMetaObject(const char* name, VobjectAccessControl* ac, const deque<string>& typelist);
00198 
00199     static void addLocalObjectExtension(const char* type, metaobject_extender_t newmethod);
00200     static bool hasLocalObjectExtension(const char* type);
00201     static void removeLocalObjectExtension(const char* type, metaobject_extender_t oldmethod);
00202 
00203     static void printExtensionTable(ostream& stream = std::cerr);
00204 
00205     virtual void addNotification(NotifyEvent* ev);
00206     virtual void flushNotifications();
00207     virtual void lockNotificationFlush();
00208     virtual void unlockNotificationFlush();
00209 
00210     virtual void insertChild(int position, const string& contextual_name, Vobject* child)
00211         throw (AccessControlError, RemoteError);
00212     virtual void setChild(int position, const string& contextual_name, Vobject* child)
00213         throw (AccessControlError, RemoteError);
00214     virtual void removeChild(int position)
00215         throw (AccessControlError, RemoteError);
00216 
00217     /** Maps a received anti-spoof ID to the one sent to that site. */
00218     void setAntiSpoofIDMapping(const string& recv, const string& sent) { antiSpoofMap[recv] = sent; }
00219 
00220     /** Maps a received anti-spoof ID to the one sent to that site. */
00221     const string& getAntiSpoofIDMapping(const string& recv) { return antiSpoofMap[recv]; }
00222 
00223     void takeOverMessages(Site* was, Site* now);
00224 
00225     virtual void setPrimaryHostname(string s);
00226 
00227     friend void Site::doSitePeering(LocalSite* localsite, RemoteSite* remotesite, bool isspooftest, bool waitforhello);
00228 };
00229 
00230 #endif

Generated on Tue Aug 12 03:55:40 2003 for Interreality Project - VOS by doxygen 1.3.2