00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SITE_HH_
00024 #define _SITE_HH_
00025
00026
00027
00028
00029
00030 #include <vos/corelibs/vos/vosdefs.hh>
00031 #include <vos/corelibs/vos/messagecontext.hh>
00032 #include <vos/corelibs/vos/metaobject.hh>
00033
00034 #define VOS_DEFAULT_PORT 4231
00035
00036 namespace VOS
00037 {
00038
00039 class Message;
00040 class MessageBlock;
00041 class MessageContext;
00042
00043 class VOS_API NotifyEvent
00044 {
00045 public:
00046 virtual ~NotifyEvent() {};
00047 virtual void notify() = 0;
00048 };
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class VOS_API MessageFilter
00059 {
00060 public:
00061 virtual ~MessageFilter();
00062
00063
00064
00065
00066
00067
00068 virtual bool checkMessage(Message* m) = 0;
00069 virtual bool checkMessage(MessageBlock* m);
00070 };
00071
00072 class ChildChangeListener;
00073 class ParentChangeListener;
00074 class TypeChangeListener;
00075 class VobjectEvent;
00076 class LocalSite;
00077 class RemoteSite;
00078
00079 class VOS_API VobjectNotifyEvent : public NotifyEvent
00080 {
00081 private:
00082 ChildChangeListener* childlistener;
00083 ParentChangeListener* parentlistener;
00084 TypeChangeListener* typelistener;
00085 VobjectEvent& event;
00086
00087 public:
00088 VobjectNotifyEvent(ChildChangeListener* cl, VobjectEvent& e);
00089 VobjectNotifyEvent(ParentChangeListener* pl, VobjectEvent& e);
00090 VobjectNotifyEvent(TypeChangeListener* tl, VobjectEvent& e);
00091
00092 virtual ~VobjectNotifyEvent();
00093 virtual void notify();
00094 };
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 class VOS_API Site : public virtual MetaObject
00105 {
00106 private:
00107 set<string> hostnames;
00108 boost::mutex hostnames_mutex;
00109
00110 static map<string, Site*> siteTable;
00111 static boost::mutex siteTable_mutex;
00112
00113 static LocalSite* defaultPeer;
00114 map<string, MessageBlock*> messageBlockTable;
00115 map<string, Message*> outgoingTraps;
00116 bool greeted;
00117
00118 protected:
00119 Site();
00120 Site(MetaObject* superobject);
00121 deque<MessageFilter*> messagefilters;
00122
00123 public:
00124 class NoSuchMessageBlockError : public runtime_error {
00125 public:
00126 NoSuchMessageBlockError(const string& s) : runtime_error(s) { };
00127 };
00128
00129 MessageContext defaultContext;
00130
00131
00132
00133
00134
00135 static set<int> allOpenSockets;
00136
00137 public:
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 virtual MetaObject* createMetaObject(const char* name, const char* firstType, ...) = 0;
00158
00159
00160
00161
00162
00163 virtual MetaObject* createMetaObject(const char* name, const deque<string>& typelist) = 0;
00164
00165
00166
00167
00168
00169 template<class T> T* createMetaObjectT(const char* name = 0) {
00170 return meta_cast<T*>(createMetaObject(name, typeid(T).name(), 0));
00171 }
00172
00173
00174 MetaObject* createMetaObject(const char* name = 0) {
00175 return createMetaObject(name, 0);
00176 }
00177
00178
00179
00180
00181 virtual string uniqueName(const char* base);
00182
00183
00184 virtual string generateUniqueName();
00185
00186
00187
00188 virtual void flushIncomingBuffers() = 0;
00189
00190
00191
00192
00193
00194
00195 virtual void addHostAlias(const string& h);
00196
00197
00198
00199
00200 virtual void removeHostAlias(const string& h);
00201
00202
00203
00204
00205
00206 virtual bool hasHostAlias(const string& h);
00207
00208
00209
00210
00211 virtual set<string>& getHostAliases();
00212
00213
00214
00215
00216 virtual void setURL(const URL& u) = 0;
00217
00218
00219
00220
00221 static void addSite(Site* s);
00222
00223
00224
00225
00226 static void removeSite(Site& s);
00227
00228
00229
00230
00231
00232
00233
00234
00235 static Site& findSite(const string& s) throw (NoSuchSiteError);
00236
00237
00238
00239
00240 static LocalSite* getDefaultPeer();
00241
00242
00243
00244
00245 static void setDefaultPeer(LocalSite* localsite);
00246
00247
00248
00249
00250 static const map<string,Site*>& getAllSites();
00251
00252
00253
00254
00255
00256 virtual void addMessageBlock(MessageBlock* m);
00257
00258
00259
00260
00261 virtual void removeMessageBlock(MessageBlock* m);
00262
00263
00264
00265
00266
00267 virtual MessageBlock* getMessageBlock(const string& s) throw (NoSuchMessageBlockError);
00268
00269 virtual bool isConnected() = 0;
00270
00271 virtual void sendMessage(Message* m);
00272 virtual void sendMessage(MessageBlock* m);
00273
00274 virtual void trapOutgoingReply(Message* m);
00275 virtual bool getGreeted();
00276 virtual void setGreeted(bool g);
00277 virtual void addNotification(NotifyEvent* ev) = 0;
00278 virtual void flushNotifications() = 0;
00279 virtual void lockNotificationFlush() = 0;
00280 virtual void unlockNotificationFlush() = 0;
00281
00282 virtual const string getType();
00283 virtual Site& getSite();
00284
00285 virtual void insertMessageFilter(int pos, MessageFilter* mf);
00286 virtual void removeMessageFilter(int pos);
00287 virtual void removeMessageFilter(MessageFilter* m);
00288 virtual const deque<MessageFilter*>& getMessageFilters();
00289
00290 static string detectHostname(int fd, unsigned char ipaddr[4]);
00291 static struct hostent* gethostbyaddr_locked(const char *addr, int len, int type);
00292 static struct hostent* gethostbyname_locked(const char *addr);
00293 static struct hostent* hostent_deepcopy(struct hostent* hp);
00294 static void freeHostEnt(struct hostent* hp);
00295
00296 static void doSitePeering(LocalSite* ls, RemoteSite* rs, bool isspooftest, bool waitforhello);
00297
00298 virtual ~Site();
00299 };
00300 }
00301
00302 #endif