/home/tetron/hack/vos/libs/vos/vos/localsocketsite.hh
Go to the documentation of this file.00001 #ifndef _LOCALSOCKETSITE_HH_
00002 #define _LOCALSOCKETSITE_HH_
00003
00004 #include <stdexcept>
00005 #include <set>
00006
00007 namespace VOS {
00008 class LocalSocketSiteExtension;
00009 }
00010
00011 #include <vos/vos/siteextension.hh>
00012 #include <vos/vos/remotesocketsite.hh>
00013 #include <vos/vos/iterator.hh>
00014 #include <vos/vos/sitepeering.hh>
00015
00016 #define VOS_DEFAULT_PORT 4231
00017
00018 namespace VOS {
00019
00020
00021
00022
00023
00024
00025
00026 class VOS_API RSSEIterator : public VUtil::Iterator<RemoteSocketSiteExtension*>
00027 {
00028 public:
00029 RSSEIterator(const RSSEIterator& i) : VUtil::Iterator<RemoteSocketSiteExtension*>(i) { }
00030 RSSEIterator(const std::set<RemoteSocketSiteExtension*>& rsses) {
00031 items->resize(rsses.size());
00032 int n = 0;
00033 for(std::set<RemoteSocketSiteExtension*>::const_iterator i = rsses.begin();
00034 i != rsses.end();
00035 i++)
00036 {
00037 (*items)[n] = *i;
00038 n++;
00039 }
00040 }
00041
00042 RemoteSocketSiteExtension* operator*() {
00043 if(pos < items->size()) return (*items)[pos];
00044 else return 0;
00045 }
00046 };
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 class VOS_API LocalSocketSiteExtension : public LocalSiteExtension
00057 {
00058 private:
00059 int listensocket;
00060 unsigned short int listenport;
00061
00062 VUtil::read_write_mutex remoteSites_mutex;
00063 std::set<RemoteSocketSiteExtension*> remoteSites;
00064
00065 bool listener_thread_quit;
00066 boost::thread* listener_thread;
00067
00068 void init(const std::string& defaultHostname, unsigned short int port);
00069 public:
00070
00071
00072
00073 static LocalSocketSiteExtension* defaultLocalSocketSite;
00074
00075
00076
00077
00078
00079
00080
00081 LocalSocketSiteExtension();
00082
00083
00084
00085
00086
00087
00088 LocalSocketSiteExtension(const std::string& defaultHostname, unsigned short int port);
00089
00090
00091
00092
00093
00094 LocalSocketSiteExtension(const std::string& defaultHostname);
00095
00096
00097
00098
00099
00100
00101
00102
00103 LocalSocketSiteExtension(unsigned short int port);
00104
00105
00106 virtual ~LocalSocketSiteExtension();
00107
00108
00109
00110 int getListenSocket() { return listensocket; }
00111
00112
00113
00114
00115
00116 virtual void addRemoteSite(RemoteSiteExtension* rs);
00117
00118
00119
00120
00121
00122 virtual void removeRemoteSite(RemoteSiteExtension* rs);
00123
00124
00125 RSSEIterator getRemoteSites();
00126
00127
00128
00129
00130 virtual void siteExtensionAttachedTo(Site* st);
00131 };
00132
00133 #ifndef SWIG
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 class VOS_API ListenerThread
00145 {
00146 private:
00147 Site* localsite;
00148 LocalSocketSiteExtension* lsse;
00149 bool* listener_thread_quit;
00150 public:
00151
00152
00153
00154
00155
00156
00157 ListenerThread(Site* ls, LocalSocketSiteExtension* l, bool* ltq)
00158 : localsite(ls),
00159 lsse(l),
00160 listener_thread_quit(ltq)
00161 { };
00162
00163
00164 void operator()();
00165 };
00166
00167
00168 class SocketSitePeeringThread : public SitePeeringThread
00169 {
00170 private:
00171 std::string host;
00172 int port;
00173 int newsock;
00174 sockaddr_in sockad;
00175
00176 public:
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 SocketSitePeeringThread(LocalSocketSiteExtension* l, int sock, sockaddr_in* sd,
00189 bool isClient = false);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 SocketSitePeeringThread(LocalSocketSiteExtension* l, const std::string& host,
00201 int port, bool isClient = true);
00202
00203
00204
00205
00206 SocketSitePeeringThread(const SocketSitePeeringThread& spt);
00207
00208 virtual void init();
00209 virtual void done() { }
00210 };
00211
00212 #endif // ifndef SWIG
00213
00214 }
00215
00216 #endif