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
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->
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
) {
67 std::map
<uint32
, CValueMap
> m_obj_map
;
69 CValueMap
&GetValueMap(uint32 ECID
)
71 return m_obj_map
[ECID
];
76 return m_obj_map
.size();
81 class CECServerSocket
;
85 class CExternalConnListener
: public CLibSocketServer
88 CExternalConnListener(const amuleIPV4Address
& adr
, int flags
, ExternalConn
* conn
)
89 : CLibSocketServer(adr
, flags
), m_conn(conn
) {}
92 ExternalConn
* m_conn
;
96 class ExternalConn
: public wxEvtHandler
99 typedef std::set
<CECServerSocket
*> SocketSet
;
100 SocketSet socket_list
;
103 ExternalConn(amuleIPV4Address addr
, wxString
*msg
);
106 CExternalConnListener
*m_ECServer
;
107 ECNotifier
*m_ec_notifier
;
109 void AddSocket(CECServerSocket
*s
);
110 void RemoveSocket(CECServerSocket
*s
);
111 void KillAllSockets();
116 // event handlers (these functions should _not_ be virtual)
117 void OnServerEvent(wxSocketEvent
& event
);
118 DECLARE_EVENT_TABLE()
122 class ECUpdateMsgSource
{
124 virtual ~ECUpdateMsgSource()
127 virtual CECPacket
*GetNextPacket() = 0;
130 class ECPartFileMsgSource
: public ECUpdateMsgSource
{
133 bool m_comment_changed
;
137 const CPartFile
*m_file
;
139 std::map
<CMD4Hash
, PARTFILE_STATUS
> m_dirty_status
;
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
{
155 bool m_comment_changed
;
158 const CKnownFile
*m_file
;
160 std::map
<CMD4Hash
, KNOWNFILE_STATUS
> m_dirty_status
;
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
{
173 virtual CECPacket
*GetNextPacket();
176 class ECStatusMsgSource
: public ECUpdateMsgSource
{
177 uint32 m_last_ed2k_status_sent
;
178 uint32 m_last_kad_status_sent
;
181 uint32
GetEd2kStatus();
182 uint32
GetKadStatus();
186 virtual CECPacket
*GetNextPacket();
189 class ECSearchMsgSource
: public ECUpdateMsgSource
{
194 const CSearchFile
*m_file
;
196 std::map
<CMD4Hash
, SEARCHFILE_STATUS
> m_dirty_status
;
200 void SetDirty(const CSearchFile
*file
);
201 void SetChildDirty(const CSearchFile
*file
);
205 virtual CECPacket
*GetNextPacket();
210 // designated priority for each type of update
212 enum EC_SOURCE_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
&);
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