Nothing to see here. Really.
[amule.git] / src / ExternalConn.h
blobcc118080ec0178f788578467c8dd47d9cc570ed8
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.
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()); // 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;
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();
99 void ResetAllLogs();
101 private:
102 // event handlers (these functions should _not_ be virtual)
103 void OnServerEvent(wxSocketEvent& event);
104 DECLARE_EVENT_TABLE()
107 class ECUpdateMsgSource {
108 public:
109 virtual ~ECUpdateMsgSource()
112 virtual CECPacket *GetNextPacket() = 0;
115 class ECPartFileMsgSource : public ECUpdateMsgSource {
116 typedef struct {
117 bool m_new;
118 bool m_comment_changed;
119 bool m_removed;
120 bool m_finished;
121 bool m_dirty;
122 CPartFile *m_file;
123 } PARTFILE_STATUS;
124 std::map<CMD4Hash, PARTFILE_STATUS> m_dirty_status;
125 public:
126 ECPartFileMsgSource();
128 void SetDirty(CPartFile *file);
129 void SetNew(CPartFile *file);
130 void SetCompleted(CPartFile *file);
131 void SetRemoved(CPartFile *file);
133 virtual CECPacket *GetNextPacket();
137 class ECKnownFileMsgSource : public ECUpdateMsgSource {
138 typedef struct {
139 bool m_new;
140 bool m_comment_changed;
141 bool m_removed;
142 bool m_dirty;
143 CKnownFile *m_file;
144 } KNOWNFILE_STATUS;
145 std::map<CMD4Hash, KNOWNFILE_STATUS> m_dirty_status;
146 public:
147 ECKnownFileMsgSource();
149 void SetDirty(CKnownFile *file);
150 void SetNew(CKnownFile *file);
151 void SetRemoved(CKnownFile *file);
153 virtual CECPacket *GetNextPacket();
156 class ECClientMsgSource : public ECUpdateMsgSource {
157 public:
158 virtual CECPacket *GetNextPacket();
161 class ECStatusMsgSource : public ECUpdateMsgSource {
162 uint32 m_last_ed2k_status_sent;
163 uint32 m_last_kad_status_sent;
164 void *m_server;
166 uint32 GetEd2kStatus();
167 uint32 GetKadStatus();
168 public:
169 ECStatusMsgSource();
171 virtual CECPacket *GetNextPacket();
174 class ECSearchMsgSource : public ECUpdateMsgSource {
175 typedef struct {
176 bool m_new;
177 bool m_child_dirty;
178 bool m_dirty;
179 CSearchFile *m_file;
180 } SEARCHFILE_STATUS;
181 std::map<CMD4Hash, SEARCHFILE_STATUS> m_dirty_status;
182 public:
183 ECSearchMsgSource();
185 void SetDirty(CSearchFile *file);
186 void SetChildDirty(CSearchFile *file);
188 void FlushStatus();
190 virtual CECPacket *GetNextPacket();
193 class ECNotifier {
195 // designated priority for each type of update
197 enum EC_SOURCE_PRIO {
198 EC_PARTFILE = 0,
199 EC_SEARCH,
200 EC_CLIENT,
201 EC_STATUS,
202 EC_KNOWN,
204 EC_STATUS_LAST_PRIO
207 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
208 std::map<CECServerSocket *, ECUpdateMsgSource **> m_msg_source;
210 void NextPacketToSocket();
212 CECPacket *GetNextPacket(ECUpdateMsgSource *msg_source_array[]);
213 // Make class non assignable
214 void operator=(const ECNotifier&);
215 ECNotifier(const ECNotifier&);
216 public:
217 ECNotifier();
218 ~ECNotifier();
220 void Add_EC_Client(CECServerSocket *sock);
221 void Remove_EC_Client(CECServerSocket *sock);
223 CECPacket *GetNextPacket(CECServerSocket *sock);
226 // Interface to notification macros
228 void DownloadFile_SetDirty(CPartFile *file);
229 void DownloadFile_RemoveFile(CPartFile *file);
230 void DownloadFile_RemoveSource(CPartFile *file);
231 void DownloadFile_AddFile(CPartFile *file);
232 void DownloadFile_AddSource(CPartFile *file);
234 void SharedFile_AddFile(CKnownFile *file);
235 void SharedFile_RemoveFile(CKnownFile *file);
236 void SharedFile_RemoveAllFiles();
241 #endif // EXTERNALCONN_H
242 // File_checked_for_headers