Fix build with Boost from source
[amule.git] / src / ExternalConn.h
bloba7852ba737dcb6ea8220236cf7762583f19c010b
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 Kry ( elkry@users.sourceforge.net / http://www.amule.org )
5 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2008-2011 Froenchenko Leonid (lfroen@gmail.com)
7 //
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #ifndef EXTERNALCONN_H
28 #define EXTERNALCONN_H
32 #include <ec/cpp/ECSpecialTags.h>
34 #include "amuleIPV4Address.h" // for amuleIPV4Address
35 #include "RLE.h" // for RLE
36 #include "DownloadQueue.h"
37 #include "PartFile.h" // for SourcenameItemMap
39 class wxSocketServer;
40 class wxSocketEvent;
42 template <class T, ec_tagname_t OP>
43 class CTagSet : public std::set<T> {
44 void InSet(const CECTag *tag, uint32)
46 this->insert(tag->GetInt()); // don't remove this->
48 void InSet(const CECTag *tag, const CMD4Hash&)
50 this->insert(tag->GetMD4Data()); // don't remove this->
52 public:
53 CTagSet(const CECPacket *request) : std::set<T>()
55 for (CECPacket::const_iterator it = request->begin(); it != request->end(); ++it) {
56 const CECTag *tag = & *it;
57 if ( tag->GetTagName() == OP ) {
58 InSet(tag, T());
65 class CObjTagMap {
66 std::map<uint32, CValueMap> m_obj_map;
67 public:
68 CValueMap &GetValueMap(uint32 ECID)
70 return m_obj_map[ECID];
73 size_t size()
75 return m_obj_map.size();
80 class CECServerSocket;
81 class ECNotifier;
82 class ExternalConn;
84 class CExternalConnListener : public CLibSocketServer
86 public:
87 CExternalConnListener(const amuleIPV4Address& adr, int flags, ExternalConn * conn)
88 : CLibSocketServer(adr, flags), m_conn(conn) {}
89 void OnAccept();
90 private:
91 ExternalConn * m_conn;
95 class ExternalConn : public wxEvtHandler
97 private:
98 typedef std::set<CECServerSocket *> SocketSet;
99 SocketSet socket_list;
101 public:
102 ExternalConn(amuleIPV4Address addr, wxString *msg);
103 ~ExternalConn();
105 CExternalConnListener *m_ECServer;
106 ECNotifier *m_ec_notifier;
108 void AddSocket(CECServerSocket *s);
109 void RemoveSocket(CECServerSocket *s);
110 void KillAllSockets();
111 void ResetAllLogs();
113 private:
114 // event handlers (these functions should _not_ be virtual)
115 void OnServerEvent(wxSocketEvent& event);
116 DECLARE_EVENT_TABLE()
119 class ECUpdateMsgSource {
120 public:
121 virtual ~ECUpdateMsgSource()
124 virtual CECPacket *GetNextPacket() = 0;
127 class ECPartFileMsgSource : public ECUpdateMsgSource {
128 typedef struct {
129 bool m_new;
130 bool m_comment_changed;
131 bool m_removed;
132 bool m_finished;
133 bool m_dirty;
134 const CPartFile *m_file;
135 } PARTFILE_STATUS;
136 std::map<CMD4Hash, PARTFILE_STATUS> m_dirty_status;
137 public:
138 ECPartFileMsgSource();
140 void SetDirty(const CPartFile *file);
141 void SetNew(const CPartFile *file);
142 void SetCompleted(const CPartFile *file);
143 void SetRemoved(const CPartFile *file);
145 virtual CECPacket *GetNextPacket();
149 class ECKnownFileMsgSource : public ECUpdateMsgSource {
150 typedef struct {
151 bool m_new;
152 bool m_comment_changed;
153 bool m_removed;
154 bool m_dirty;
155 const CKnownFile *m_file;
156 } KNOWNFILE_STATUS;
157 std::map<CMD4Hash, KNOWNFILE_STATUS> m_dirty_status;
158 public:
159 ECKnownFileMsgSource();
161 void SetDirty(const CKnownFile *file);
162 void SetNew(const CKnownFile *file);
163 void SetRemoved(const CKnownFile *file);
165 virtual CECPacket *GetNextPacket();
168 class ECClientMsgSource : public ECUpdateMsgSource {
169 public:
170 virtual CECPacket *GetNextPacket();
173 class ECStatusMsgSource : public ECUpdateMsgSource {
174 uint32 m_last_ed2k_status_sent;
175 uint32 m_last_kad_status_sent;
176 void *m_server;
178 uint32 GetEd2kStatus();
179 uint32 GetKadStatus();
180 public:
181 ECStatusMsgSource();
183 virtual CECPacket *GetNextPacket();
186 class ECSearchMsgSource : public ECUpdateMsgSource {
187 typedef struct {
188 bool m_new;
189 bool m_child_dirty;
190 bool m_dirty;
191 const CSearchFile *m_file;
192 } SEARCHFILE_STATUS;
193 std::map<CMD4Hash, SEARCHFILE_STATUS> m_dirty_status;
194 public:
195 ECSearchMsgSource();
197 void SetDirty(const CSearchFile *file);
198 void SetChildDirty(const CSearchFile *file);
200 void FlushStatus();
202 virtual CECPacket *GetNextPacket();
205 class ECNotifier {
207 // designated priority for each type of update
209 enum EC_SOURCE_PRIO {
210 EC_PARTFILE = 0,
211 EC_SEARCH,
212 EC_CLIENT,
213 EC_STATUS,
214 EC_KNOWN,
216 EC_STATUS_LAST_PRIO
219 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
220 std::map<CECServerSocket *, ECUpdateMsgSource **> m_msg_source;
222 void NextPacketToSocket();
224 CECPacket *GetNextPacket(ECUpdateMsgSource *msg_source_array[]);
225 // Make class non assignable
226 void operator=(const ECNotifier&);
227 ECNotifier(const ECNotifier&);
228 public:
229 ECNotifier();
230 ~ECNotifier();
232 void Add_EC_Client(CECServerSocket *sock);
233 void Remove_EC_Client(CECServerSocket *sock);
235 CECPacket *GetNextPacket(CECServerSocket *sock);
238 // Interface to notification macros
240 void DownloadFile_SetDirty(const CPartFile *file);
241 void DownloadFile_RemoveFile(const CPartFile *file);
242 void DownloadFile_RemoveSource(const CPartFile *file);
243 void DownloadFile_AddFile(const CPartFile *file);
244 void DownloadFile_AddSource(const CPartFile *file);
246 void SharedFile_AddFile(const CKnownFile *file);
247 void SharedFile_RemoveFile(const CKnownFile *file);
248 void SharedFile_RemoveAllFiles();
253 #endif // EXTERNALCONN_H
254 // File_checked_for_headers