Upstream tarball 10059
[amule.git] / src / ExternalConn.h
blob6e54feb182c0b18d73854cd697e365d362c4016d
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 (unsigned int i = 0;i < request->GetTagCount();i++) {
56 const CECTag *tag = request->GetTagByIndex(i);
57 if ( tag->GetTagName() == OP ) {
58 this->InSet(tag, T());
65 class CObjTagMap {
66 std::map<const void *, CValueMap> m_obj_map;
67 public:
68 CValueMap &GetValueMap(const void *object)
70 return m_obj_map[object];
73 size_t size()
75 return m_obj_map.size();
78 void RemoveDeleted(std::set<void *>& WXUNUSED(current_set))
79 {/*
80 for(std::map<void *, CValueMap>::iterator i = m_obj_map.begin(); i != m_obj_map.end(); i++) {
81 if ( !current_set.count(i->first) ) {
82 m_obj_map.erase(i->first);
90 class CECServerSocket;
91 class ECNotifier;
93 class ExternalConn : public wxEvtHandler
95 private:
96 typedef std::set<CECServerSocket *> SocketSet;
97 SocketSet socket_list;
99 public:
100 ExternalConn(amuleIPV4Address addr, wxString *msg);
101 ~ExternalConn();
103 wxSocketServer *m_ECServer;
104 ECNotifier *m_ec_notifier;
106 void AddSocket(CECServerSocket *s);
107 void RemoveSocket(CECServerSocket *s);
108 void KillAllSockets();
110 private:
111 // event handlers (these functions should _not_ be virtual)
112 void OnServerEvent(wxSocketEvent& event);
113 DECLARE_EVENT_TABLE()
116 class ECUpdateMsgSource {
117 public:
118 virtual ~ECUpdateMsgSource()
121 virtual CECPacket *GetNextPacket() = 0;
124 class ECPartFileMsgSource : public ECUpdateMsgSource {
125 typedef struct {
126 bool m_new;
127 bool m_comment_changed;
128 bool m_removed;
129 bool m_finished;
130 bool m_dirty;
131 CPartFile *m_file;
132 } PARTFILE_STATUS;
133 std::map<CMD4Hash, PARTFILE_STATUS> m_dirty_status;
134 public:
135 ECPartFileMsgSource();
137 void SetDirty(CPartFile *file);
138 void SetNew(CPartFile *file);
139 void SetCompleted(CPartFile *file);
140 void SetRemoved(CPartFile *file);
142 virtual CECPacket *GetNextPacket();
146 class ECKnownFileMsgSource : public ECUpdateMsgSource {
147 typedef struct {
148 bool m_new;
149 bool m_comment_changed;
150 bool m_removed;
151 bool m_dirty;
152 CKnownFile *m_file;
153 } KNOWNFILE_STATUS;
154 std::map<CMD4Hash, KNOWNFILE_STATUS> m_dirty_status;
155 public:
156 ECKnownFileMsgSource();
158 void SetDirty(CKnownFile *file);
159 void SetNew(CKnownFile *file);
160 void SetRemoved(CKnownFile *file);
162 virtual CECPacket *GetNextPacket();
165 class ECClientMsgSource : public ECUpdateMsgSource {
166 public:
167 virtual CECPacket *GetNextPacket();
170 class ECStatusMsgSource : public ECUpdateMsgSource {
171 uint32 m_last_ed2k_status_sent;
172 uint32 m_last_kad_status_sent;
173 void *m_server;
175 uint32 GetEd2kStatus();
176 uint32 GetKadStatus();
177 public:
178 ECStatusMsgSource();
180 virtual CECPacket *GetNextPacket();
183 class ECSearchMsgSource : public ECUpdateMsgSource {
184 typedef struct {
185 bool m_new;
186 bool m_child_dirty;
187 bool m_dirty;
188 CSearchFile *m_file;
189 } SEARCHFILE_STATUS;
190 std::map<CMD4Hash, SEARCHFILE_STATUS> m_dirty_status;
191 public:
192 ECSearchMsgSource();
194 void SetDirty(CSearchFile *file);
195 void SetChildDirty(CSearchFile *file);
197 void FlushStatus();
199 virtual CECPacket *GetNextPacket();
202 class ECNotifier {
204 // designated priority for each type of update
206 enum EC_SOURCE_PRIO {
207 EC_PARTFILE = 0,
208 EC_SEARCH,
209 EC_CLIENT,
210 EC_STATUS,
211 EC_KNOWN,
213 EC_STATUS_LAST_PRIO
216 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
217 std::map<CECServerSocket *, ECUpdateMsgSource **> m_msg_source;
219 void NextPacketToSocket();
221 CECPacket *GetNextPacket(ECUpdateMsgSource *msg_source_array[]);
222 // Make class non assignable
223 void operator=(const ECNotifier&);
224 ECNotifier(const ECNotifier&);
225 public:
226 ECNotifier();
227 ~ECNotifier();
229 void Add_EC_Client(CECServerSocket *sock);
230 void Remove_EC_Client(CECServerSocket *sock);
232 CECPacket *GetNextPacket(CECServerSocket *sock);
235 // Interface to notification macros
237 void DownloadFile_SetDirty(CPartFile *file);
238 void DownloadFile_RemoveFile(CPartFile *file);
239 void DownloadFile_RemoveSource(CPartFile *file);
240 void DownloadFile_AddFile(CPartFile *file);
241 void DownloadFile_AddSource(CPartFile *file);
243 void Status_ConnectionState();
244 void Status_QueueCount();
245 void Status_UserCount();
247 void SharedFile_AddFile(CKnownFile *file);
248 void SharedFile_RemoveFile(CKnownFile *file);
249 void SharedFile_RemoveAllFiles();
254 #endif // EXTERNALCONN_H
255 // File_checked_for_headers