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());
48 void InSet(const CECTag
*tag
, CMD4Hash
)
50 this->insert(tag
->GetMD4Data());
53 CTagSet(const CECPacket
*request
) : std::set
<T
>()
55 for (unsigned int i
= 0;i
< request
->GetTagCount();i
++) {
56 const CECTag
*tag
= request
->GetTagByIndex(i
);
57 if ( tag
->GetTagName() == OP
) {
58 this->InSet(tag
, T());
66 std::map
<const void *, CValueMap
> m_obj_map
;
68 CValueMap
&GetValueMap(const void *object
)
70 return m_obj_map
[object
];
75 return m_obj_map
.size();
78 void RemoveDeleted(std::set
<void *>& WXUNUSED(current_set
))
80 for(std::map<void *, CValueMap>::iterator i = m_obj_map.begin(); i != m_obj_map.end(); i++) {
81 if ( !current_set.count(i->first) ) {
82 m_obj_map.erase(i->first);
90 class CECServerSocket
;
93 class ExternalConn
: public wxEvtHandler
96 typedef std::set
<CECServerSocket
*> SocketSet
;
97 SocketSet socket_list
;
100 ExternalConn(amuleIPV4Address addr
, wxString
*msg
);
103 wxSocketServer
*m_ECServer
;
104 ECNotifier
*m_ec_notifier
;
106 void AddSocket(CECServerSocket
*s
);
107 void RemoveSocket(CECServerSocket
*s
);
108 void KillAllSockets();
111 // event handlers (these functions should _not_ be virtual)
112 void OnServerEvent(wxSocketEvent
& event
);
113 DECLARE_EVENT_TABLE()
116 class ECUpdateMsgSource
{
118 virtual ~ECUpdateMsgSource()
121 virtual CECPacket
*GetNextPacket() = 0;
124 class ECPartFileMsgSource
: public ECUpdateMsgSource
{
127 bool m_comment_changed
;
133 std::map
<CMD4Hash
, PARTFILE_STATUS
> m_dirty_status
;
135 ECPartFileMsgSource();
137 void SetDirty(CPartFile
*file
);
138 void SetNew(CPartFile
*file
);
139 void SetCompleted(CPartFile
*file
);
140 void SetRemoved(CPartFile
*file
);
142 virtual CECPacket
*GetNextPacket();
146 class ECKnownFileMsgSource
: public ECUpdateMsgSource
{
149 bool m_comment_changed
;
154 std::map
<CMD4Hash
, KNOWNFILE_STATUS
> m_dirty_status
;
156 ECKnownFileMsgSource();
158 void SetDirty(CKnownFile
*file
);
159 void SetNew(CKnownFile
*file
);
160 void SetRemoved(CKnownFile
*file
);
162 virtual CECPacket
*GetNextPacket();
165 class ECClientMsgSource
: public ECUpdateMsgSource
{
167 virtual CECPacket
*GetNextPacket();
170 class ECStatusMsgSource
: public ECUpdateMsgSource
{
171 uint32 m_last_ed2k_status_sent
;
172 uint32 m_last_kad_status_sent
;
175 uint32
GetEd2kStatus();
176 uint32
GetKadStatus();
180 virtual CECPacket
*GetNextPacket();
183 class ECSearchMsgSource
: public ECUpdateMsgSource
{
190 std::map
<CMD4Hash
, SEARCHFILE_STATUS
> m_dirty_status
;
194 void SetDirty(CSearchFile
*file
);
195 void SetChildDirty(CSearchFile
*file
);
199 virtual CECPacket
*GetNextPacket();
204 // designated priority for each type of update
206 enum EC_SOURCE_PRIO
{
216 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
217 std::map
<CECServerSocket
*, ECUpdateMsgSource
**> m_msg_source
;
219 void NextPacketToSocket();
221 CECPacket
*GetNextPacket(ECUpdateMsgSource
*msg_source_array
[]);
222 // Make class non assignable
223 void operator=(const ECNotifier
&);
224 ECNotifier(const ECNotifier
&);
229 void Add_EC_Client(CECServerSocket
*sock
);
230 void Remove_EC_Client(CECServerSocket
*sock
);
232 CECPacket
*GetNextPacket(CECServerSocket
*sock
);
235 // Interface to notification macros
237 void DownloadFile_SetDirty(CPartFile
*file
);
238 void DownloadFile_RemoveFile(CPartFile
*file
);
239 void DownloadFile_RemoveSource(CPartFile
*file
);
240 void DownloadFile_AddFile(CPartFile
*file
);
241 void DownloadFile_AddSource(CPartFile
*file
);
243 void Status_ConnectionState();
244 void Status_QueueCount();
245 void Status_UserCount();
247 void SharedFile_AddFile(CKnownFile
*file
);
248 void SharedFile_RemoveFile(CKnownFile
*file
);
249 void SharedFile_RemoveAllFiles();
254 #endif // EXTERNALCONN_H
255 // File_checked_for_headers