1 /*************************************************************************** 2 csearchsocket.h - description 3 ------------------- 4 begin : Thu May 27 2004 5 copyright : (C) 2004 by Mathias Küster 6 email : mathen@users.berlios.de 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef CSEARCHSOCKET_H 19 #define CSEARCHSOCKET_H 20 21 /** 22 *@author Mathias Küster 23 * 24 * This class receives UDP packets and parses them into search results. 25 * Because originally dclib did not terminate it's search results with a |, 26 * the parser adds one. I think only 1 result is allowed per packet, 27 * but like with most of the NMDC protocol it's probably undefined. 28 */ 29 30 #include <dclib/dcos.h> 31 #include <dclib/core/csocket.h> 32 #include <dclib/core/ccallback.h> 33 #include <dclib/core/cmutex.h> 34 #include <dclib/core/cbytearray.h> 35 36 class CMessageSearchResult; 37 38 class CSearchSocket : private CSocket { 39 public: 40 /** */ 41 CSearchSocket(); 42 /** */ 43 virtual ~CSearchSocket(); 44 45 /** */ 46 void SetCallBackFunction( _CCallback1<CMessageSearchResult*> * callback ); 47 48 /** CSocket function made public and protected by mutex */ 49 eConnectState Connect( CString Host, int Port, bool iAsync ); 50 /** CSocket function made public and protected by mutex */ 51 int Disconnect(); 52 53 /** 54 * Receives up to maxpackets UDP packets, 55 * returning earlier if no more data available from the socket. 56 * Parses the data and sends the results over the callback. 57 */ 58 void Receive( int maxpackets = 25 ); 59 60 private: 61 /** callback function */ 62 _CCallback1<CMessageSearchResult*> * m_pCallback; 63 /** */ 64 CMutex m_SearchSocketMutex; 65 /** */ 66 CByteArray m_Buffer; 67 }; 68 69 /** */ SetCallBackFunction(_CCallback1<CMessageSearchResult * > * callback)70inline void CSearchSocket::SetCallBackFunction( _CCallback1<CMessageSearchResult*> * callback ) 71 { m_SearchSocketMutex.Lock(); delete m_pCallback; m_pCallback = callback; m_SearchSocketMutex.UnLock(); } 72 73 #endif 74