2 // This file is part of the aMule Project.
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)
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
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->
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
) {
66 std::map
<uint32
, CValueMap
> m_obj_map
;
68 CValueMap
&GetValueMap(uint32 ECID
)
70 return m_obj_map
[ECID
];
75 return m_obj_map
.size();
80 class CECServerSocket
;
84 class CExternalConnListener
: public CLibSocketServer
87 CExternalConnListener(const amuleIPV4Address
& adr
, int flags
, ExternalConn
* conn
)
88 : CLibSocketServer(adr
, flags
), m_conn(conn
) {}
91 ExternalConn
* m_conn
;
95 class ExternalConn
: public wxEvtHandler
98 typedef std::set
<CECServerSocket
*> SocketSet
;
99 SocketSet socket_list
;
102 ExternalConn(amuleIPV4Address addr
, wxString
*msg
);
105 CExternalConnListener
*m_ECServer
;
106 ECNotifier
*m_ec_notifier
;
108 void AddSocket(CECServerSocket
*s
);
109 void RemoveSocket(CECServerSocket
*s
);
110 void KillAllSockets();
114 // event handlers (these functions should _not_ be virtual)
115 void OnServerEvent(wxSocketEvent
& event
);
116 DECLARE_EVENT_TABLE()
119 class ECUpdateMsgSource
{
121 virtual ~ECUpdateMsgSource()
124 virtual CECPacket
*GetNextPacket() = 0;
127 class ECPartFileMsgSource
: public ECUpdateMsgSource
{
130 bool m_comment_changed
;
134 const CPartFile
*m_file
;
136 std::map
<CMD4Hash
, PARTFILE_STATUS
> m_dirty_status
;
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
{
152 bool m_comment_changed
;
155 const CKnownFile
*m_file
;
157 std::map
<CMD4Hash
, KNOWNFILE_STATUS
> m_dirty_status
;
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
{
170 virtual CECPacket
*GetNextPacket();
173 class ECStatusMsgSource
: public ECUpdateMsgSource
{
174 uint32 m_last_ed2k_status_sent
;
175 uint32 m_last_kad_status_sent
;
178 uint32
GetEd2kStatus();
179 uint32
GetKadStatus();
183 virtual CECPacket
*GetNextPacket();
186 class ECSearchMsgSource
: public ECUpdateMsgSource
{
191 const CSearchFile
*m_file
;
193 std::map
<CMD4Hash
, SEARCHFILE_STATUS
> m_dirty_status
;
197 void SetDirty(const CSearchFile
*file
);
198 void SetChildDirty(const CSearchFile
*file
);
202 virtual CECPacket
*GetNextPacket();
207 // designated priority for each type of update
209 enum EC_SOURCE_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
&);
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