Upstream tarball 10085
[amule.git] / src / ExternalConn.h
blob22b894995f711198c6ae699812df168ba40324e4
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 Kry ( elkry@users.sourceforge.net / http://www.amule.org )
5 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2008 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.
21 //
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());
48 void InSet(const CECTag *tag, CMD4Hash)
50 this->insert(tag->GetMD4Data());
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 this->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;
83 class ExternalConn : public wxEvtHandler
85 private:
86 typedef std::set<CECServerSocket *> SocketSet;
87 SocketSet socket_list;
89 public:
90 ExternalConn(amuleIPV4Address addr, wxString *msg);
91 ~ExternalConn();
93 wxSocketServer *m_ECServer;
94 ECNotifier *m_ec_notifier;
96 void AddSocket(CECServerSocket *s);
97 void RemoveSocket(CECServerSocket *s);
98 void KillAllSockets();
100 private:
101 // event handlers (these functions should _not_ be virtual)
102 void OnServerEvent(wxSocketEvent& event);
103 DECLARE_EVENT_TABLE()
106 class ECUpdateMsgSource {
107 public:
108 virtual ~ECUpdateMsgSource()
111 virtual CECPacket *GetNextPacket() = 0;
114 class ECPartFileMsgSource : public ECUpdateMsgSource {
115 typedef struct {
116 bool m_new;
117 bool m_comment_changed;
118 bool m_removed;
119 bool m_finished;
120 bool m_dirty;
121 CPartFile *m_file;
122 } PARTFILE_STATUS;
123 std::map<CMD4Hash, PARTFILE_STATUS> m_dirty_status;
124 public:
125 ECPartFileMsgSource();
127 void SetDirty(CPartFile *file);
128 void SetNew(CPartFile *file);
129 void SetCompleted(CPartFile *file);
130 void SetRemoved(CPartFile *file);
132 virtual CECPacket *GetNextPacket();
136 class ECKnownFileMsgSource : public ECUpdateMsgSource {
137 typedef struct {
138 bool m_new;
139 bool m_comment_changed;
140 bool m_removed;
141 bool m_dirty;
142 CKnownFile *m_file;
143 } KNOWNFILE_STATUS;
144 std::map<CMD4Hash, KNOWNFILE_STATUS> m_dirty_status;
145 public:
146 ECKnownFileMsgSource();
148 void SetDirty(CKnownFile *file);
149 void SetNew(CKnownFile *file);
150 void SetRemoved(CKnownFile *file);
152 virtual CECPacket *GetNextPacket();
155 class ECClientMsgSource : public ECUpdateMsgSource {
156 public:
157 virtual CECPacket *GetNextPacket();
160 class ECStatusMsgSource : public ECUpdateMsgSource {
161 uint32 m_last_ed2k_status_sent;
162 uint32 m_last_kad_status_sent;
163 void *m_server;
165 uint32 GetEd2kStatus();
166 uint32 GetKadStatus();
167 public:
168 ECStatusMsgSource();
170 virtual CECPacket *GetNextPacket();
173 class ECSearchMsgSource : public ECUpdateMsgSource {
174 typedef struct {
175 bool m_new;
176 bool m_child_dirty;
177 bool m_dirty;
178 CSearchFile *m_file;
179 } SEARCHFILE_STATUS;
180 std::map<CMD4Hash, SEARCHFILE_STATUS> m_dirty_status;
181 public:
182 ECSearchMsgSource();
184 void SetDirty(CSearchFile *file);
185 void SetChildDirty(CSearchFile *file);
187 void FlushStatus();
189 virtual CECPacket *GetNextPacket();
192 class ECNotifier {
194 // designated priority for each type of update
196 enum EC_SOURCE_PRIO {
197 EC_PARTFILE = 0,
198 EC_SEARCH,
199 EC_CLIENT,
200 EC_STATUS,
201 EC_KNOWN,
203 EC_STATUS_LAST_PRIO
206 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
207 std::map<CECServerSocket *, ECUpdateMsgSource **> m_msg_source;
209 void NextPacketToSocket();
211 CECPacket *GetNextPacket(ECUpdateMsgSource *msg_source_array[]);
212 // Make class non assignable
213 void operator=(const ECNotifier&);
214 ECNotifier(const ECNotifier&);
215 public:
216 ECNotifier();
217 ~ECNotifier();
219 void Add_EC_Client(CECServerSocket *sock);
220 void Remove_EC_Client(CECServerSocket *sock);
222 CECPacket *GetNextPacket(CECServerSocket *sock);
225 // Interface to notification macros
227 void DownloadFile_SetDirty(CPartFile *file);
228 void DownloadFile_RemoveFile(CPartFile *file);
229 void DownloadFile_RemoveSource(CPartFile *file);
230 void DownloadFile_AddFile(CPartFile *file);
231 void DownloadFile_AddSource(CPartFile *file);
233 void Status_ConnectionState();
234 void Status_QueueCount();
235 void Status_UserCount();
237 void SharedFile_AddFile(CKnownFile *file);
238 void SharedFile_RemoveFile(CKnownFile *file);
239 void SharedFile_RemoveAllFiles();
244 #endif // EXTERNALCONN_H
245 // File_checked_for_headers