Remove do-nothing command and add warning about it
[amule.git] / src / ExternalConn.h
blob897de15768e21c552444f243ae8317a24ee591d7
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 #ifndef ASIO_SOCKETS
40 class wxSocketEvent;
41 #endif
43 template <class T, ec_tagname_t OP>
44 class CTagSet : public std::set<T> {
45 void InSet(const CECTag *tag, uint32)
47 this->insert(tag->GetInt()); // don't remove this->
49 void InSet(const CECTag *tag, const CMD4Hash&)
51 this->insert(tag->GetMD4Data()); // don't remove this->
53 public:
54 CTagSet(const CECPacket *request) : std::set<T>()
56 for (CECPacket::const_iterator it = request->begin(); it != request->end(); ++it) {
57 const CECTag *tag = & *it;
58 if ( tag->GetTagName() == OP ) {
59 InSet(tag, T());
66 class CObjTagMap {
67 std::map<uint32, CValueMap> m_obj_map;
68 public:
69 CValueMap &GetValueMap(uint32 ECID)
71 return m_obj_map[ECID];
74 size_t size()
76 return m_obj_map.size();
81 class CECServerSocket;
82 class ECNotifier;
83 class ExternalConn;
85 class CExternalConnListener : public CLibSocketServer
87 public:
88 CExternalConnListener(const amuleIPV4Address& adr, int flags, ExternalConn * conn)
89 : CLibSocketServer(adr, flags), m_conn(conn) {}
90 void OnAccept();
91 private:
92 ExternalConn * m_conn;
96 class ExternalConn : public wxEvtHandler
98 private:
99 typedef std::set<CECServerSocket *> SocketSet;
100 SocketSet socket_list;
102 public:
103 ExternalConn(amuleIPV4Address addr, wxString *msg);
104 ~ExternalConn();
106 CExternalConnListener *m_ECServer;
107 ECNotifier *m_ec_notifier;
109 void AddSocket(CECServerSocket *s);
110 void RemoveSocket(CECServerSocket *s);
111 void KillAllSockets();
112 void ResetAllLogs();
114 #ifndef ASIO_SOCKETS
115 private:
116 // event handlers (these functions should _not_ be virtual)
117 void OnServerEvent(wxSocketEvent& event);
118 DECLARE_EVENT_TABLE()
119 #endif
122 class ECUpdateMsgSource {
123 public:
124 virtual ~ECUpdateMsgSource()
127 virtual CECPacket *GetNextPacket() = 0;
130 class ECPartFileMsgSource : public ECUpdateMsgSource {
131 typedef struct {
132 bool m_new;
133 bool m_comment_changed;
134 bool m_removed;
135 bool m_finished;
136 bool m_dirty;
137 const CPartFile *m_file;
138 } PARTFILE_STATUS;
139 std::map<CMD4Hash, PARTFILE_STATUS> m_dirty_status;
140 public:
141 ECPartFileMsgSource();
143 void SetDirty(const CPartFile *file);
144 void SetNew(const CPartFile *file);
145 void SetCompleted(const CPartFile *file);
146 void SetRemoved(const CPartFile *file);
148 virtual CECPacket *GetNextPacket();
152 class ECKnownFileMsgSource : public ECUpdateMsgSource {
153 typedef struct {
154 bool m_new;
155 bool m_comment_changed;
156 bool m_removed;
157 bool m_dirty;
158 const CKnownFile *m_file;
159 } KNOWNFILE_STATUS;
160 std::map<CMD4Hash, KNOWNFILE_STATUS> m_dirty_status;
161 public:
162 ECKnownFileMsgSource();
164 void SetDirty(const CKnownFile *file);
165 void SetNew(const CKnownFile *file);
166 void SetRemoved(const CKnownFile *file);
168 virtual CECPacket *GetNextPacket();
171 class ECClientMsgSource : public ECUpdateMsgSource {
172 public:
173 virtual CECPacket *GetNextPacket();
176 class ECStatusMsgSource : public ECUpdateMsgSource {
177 uint32 m_last_ed2k_status_sent;
178 uint32 m_last_kad_status_sent;
179 void *m_server;
181 uint32 GetEd2kStatus();
182 uint32 GetKadStatus();
183 public:
184 ECStatusMsgSource();
186 virtual CECPacket *GetNextPacket();
189 class ECSearchMsgSource : public ECUpdateMsgSource {
190 typedef struct {
191 bool m_new;
192 bool m_child_dirty;
193 bool m_dirty;
194 const CSearchFile *m_file;
195 } SEARCHFILE_STATUS;
196 std::map<CMD4Hash, SEARCHFILE_STATUS> m_dirty_status;
197 public:
198 ECSearchMsgSource();
200 void SetDirty(const CSearchFile *file);
201 void SetChildDirty(const CSearchFile *file);
203 void FlushStatus();
205 virtual CECPacket *GetNextPacket();
208 class ECNotifier {
210 // designated priority for each type of update
212 enum EC_SOURCE_PRIO {
213 EC_PARTFILE = 0,
214 EC_SEARCH,
215 EC_CLIENT,
216 EC_STATUS,
217 EC_KNOWN,
219 EC_STATUS_LAST_PRIO
222 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
223 std::map<CECServerSocket *, ECUpdateMsgSource **> m_msg_source;
225 void NextPacketToSocket();
227 CECPacket *GetNextPacket(ECUpdateMsgSource *msg_source_array[]);
228 // Make class non assignable
229 void operator=(const ECNotifier&);
230 ECNotifier(const ECNotifier&);
231 public:
232 ECNotifier();
233 ~ECNotifier();
235 void Add_EC_Client(CECServerSocket *sock);
236 void Remove_EC_Client(CECServerSocket *sock);
238 CECPacket *GetNextPacket(CECServerSocket *sock);
241 // Interface to notification macros
243 void DownloadFile_SetDirty(const CPartFile *file);
244 void DownloadFile_RemoveFile(const CPartFile *file);
245 void DownloadFile_RemoveSource(const CPartFile *file);
246 void DownloadFile_AddFile(const CPartFile *file);
247 void DownloadFile_AddSource(const CPartFile *file);
249 void SharedFile_AddFile(const CKnownFile *file);
250 void SharedFile_RemoveFile(const CKnownFile *file);
251 void SharedFile_RemoveAllFiles();
256 #endif // EXTERNALCONN_H
257 // File_checked_for_headers