2 // This file is part of the aMule Project.
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)
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
;
83 class ExternalConn
: public wxEvtHandler
86 typedef std::set
<CECServerSocket
*> SocketSet
;
87 SocketSet socket_list
;
90 ExternalConn(amuleIPV4Address addr
, wxString
*msg
);
93 wxSocketServer
*m_ECServer
;
94 ECNotifier
*m_ec_notifier
;
96 void AddSocket(CECServerSocket
*s
);
97 void RemoveSocket(CECServerSocket
*s
);
98 void KillAllSockets();
102 // event handlers (these functions should _not_ be virtual)
103 void OnServerEvent(wxSocketEvent
& event
);
104 DECLARE_EVENT_TABLE()
107 class ECUpdateMsgSource
{
109 virtual ~ECUpdateMsgSource()
112 virtual CECPacket
*GetNextPacket() = 0;
115 class ECPartFileMsgSource
: public ECUpdateMsgSource
{
118 bool m_comment_changed
;
124 std::map
<CMD4Hash
, PARTFILE_STATUS
> m_dirty_status
;
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
{
140 bool m_comment_changed
;
145 std::map
<CMD4Hash
, KNOWNFILE_STATUS
> m_dirty_status
;
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
{
158 virtual CECPacket
*GetNextPacket();
161 class ECStatusMsgSource
: public ECUpdateMsgSource
{
162 uint32 m_last_ed2k_status_sent
;
163 uint32 m_last_kad_status_sent
;
166 uint32
GetEd2kStatus();
167 uint32
GetKadStatus();
171 virtual CECPacket
*GetNextPacket();
174 class ECSearchMsgSource
: public ECUpdateMsgSource
{
181 std::map
<CMD4Hash
, SEARCHFILE_STATUS
> m_dirty_status
;
185 void SetDirty(CSearchFile
*file
);
186 void SetChildDirty(CSearchFile
*file
);
190 virtual CECPacket
*GetNextPacket();
195 // designated priority for each type of update
197 enum EC_SOURCE_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
&);
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