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 (CECPacket::const_iterator it
= request
->begin(); it
!= request
->end(); it
++) {
56 const CECTag
*tag
= & *it
;
57 if ( tag
->GetTagName() == OP
) {
58 this->InSet(tag
, T());
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();
101 // event handlers (these functions should _not_ be virtual)
102 void OnServerEvent(wxSocketEvent
& event
);
103 DECLARE_EVENT_TABLE()
106 class ECUpdateMsgSource
{
108 virtual ~ECUpdateMsgSource()
111 virtual CECPacket
*GetNextPacket() = 0;
114 class ECPartFileMsgSource
: public ECUpdateMsgSource
{
117 bool m_comment_changed
;
123 std::map
<CMD4Hash
, PARTFILE_STATUS
> m_dirty_status
;
125 ECPartFileMsgSource();
127 void SetDirty(CPartFile
*file
);
128 void SetNew(CPartFile
*file
);
129 void SetCompleted(CPartFile
*file
);
130 void SetRemoved(CPartFile
*file
);
132 virtual CECPacket
*GetNextPacket();
136 class ECKnownFileMsgSource
: public ECUpdateMsgSource
{
139 bool m_comment_changed
;
144 std::map
<CMD4Hash
, KNOWNFILE_STATUS
> m_dirty_status
;
146 ECKnownFileMsgSource();
148 void SetDirty(CKnownFile
*file
);
149 void SetNew(CKnownFile
*file
);
150 void SetRemoved(CKnownFile
*file
);
152 virtual CECPacket
*GetNextPacket();
155 class ECClientMsgSource
: public ECUpdateMsgSource
{
157 virtual CECPacket
*GetNextPacket();
160 class ECStatusMsgSource
: public ECUpdateMsgSource
{
161 uint32 m_last_ed2k_status_sent
;
162 uint32 m_last_kad_status_sent
;
165 uint32
GetEd2kStatus();
166 uint32
GetKadStatus();
170 virtual CECPacket
*GetNextPacket();
173 class ECSearchMsgSource
: public ECUpdateMsgSource
{
180 std::map
<CMD4Hash
, SEARCHFILE_STATUS
> m_dirty_status
;
184 void SetDirty(CSearchFile
*file
);
185 void SetChildDirty(CSearchFile
*file
);
189 virtual CECPacket
*GetNextPacket();
194 // designated priority for each type of update
196 enum EC_SOURCE_PRIO
{
206 //ECUpdateMsgSource *m_msg_source[EC_STATUS_LAST_PRIO];
207 std::map
<CECServerSocket
*, ECUpdateMsgSource
**> m_msg_source
;
209 void NextPacketToSocket();
211 CECPacket
*GetNextPacket(ECUpdateMsgSource
*msg_source_array
[]);
212 // Make class non assignable
213 void operator=(const ECNotifier
&);
214 ECNotifier(const ECNotifier
&);
219 void Add_EC_Client(CECServerSocket
*sock
);
220 void Remove_EC_Client(CECServerSocket
*sock
);
222 CECPacket
*GetNextPacket(CECServerSocket
*sock
);
225 // Interface to notification macros
227 void DownloadFile_SetDirty(CPartFile
*file
);
228 void DownloadFile_RemoveFile(CPartFile
*file
);
229 void DownloadFile_RemoveSource(CPartFile
*file
);
230 void DownloadFile_AddFile(CPartFile
*file
);
231 void DownloadFile_AddSource(CPartFile
*file
);
233 void Status_ConnectionState();
234 void Status_QueueCount();
235 void Status_UserCount();
237 void SharedFile_AddFile(CKnownFile
*file
);
238 void SharedFile_RemoveFile(CKnownFile
*file
);
239 void SharedFile_RemoveAllFiles();
244 #endif // EXTERNALCONN_H
245 // File_checked_for_headers