diff options
author | George Hazan <george.hazan@gmail.com> | 2013-07-08 22:10:14 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-07-08 22:10:14 +0000 |
commit | bb952e431866d131bae95c08e579ec8a00f00343 (patch) | |
tree | 60881668cf328b50906346c5f66ce47da2d9ad88 /protocols/IRCG | |
parent | c181af64bab27eb50e684c64c0a3caa49f8bbe39 (diff) |
core protocol helpers for creating protocol evengs, services & threads
git-svn-id: http://svn.miranda-ng.org/main/trunk@5286 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IRCG')
-rw-r--r-- | protocols/IRCG/src/commandmonitor.cpp | 4 | ||||
-rw-r--r-- | protocols/IRCG/src/irc.h | 17 | ||||
-rw-r--r-- | protocols/IRCG/src/irclib.cpp | 2 | ||||
-rw-r--r-- | protocols/IRCG/src/ircproto.cpp | 65 | ||||
-rw-r--r-- | protocols/IRCG/src/options.cpp | 2 | ||||
-rw-r--r-- | protocols/IRCG/src/services.cpp | 8 | ||||
-rw-r--r-- | protocols/IRCG/src/tools.cpp | 24 |
7 files changed, 42 insertions, 80 deletions
diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index f5d73cfe71..345a0ff0e8 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -276,7 +276,7 @@ bool CIrcProto::OnIrc_WELCOME(const CIrcMessage* pmsg) lstrcpyn( host, word.c_str(), SIZEOF(host));
TCHAR* p1 = _tcschr( host, '@' );
if ( p1 )
- ircFork( &CIrcProto::ResolveIPThread, new IPRESOLVE( _T2A(p1+1), IP_AUTO ));
+ ForkThread( &CIrcProto::ResolveIPThread, new IPRESOLVE( _T2A(p1+1), IP_AUTO ));
}
word = GetWord(pmsg->parameters[1].c_str(), ++i);
@@ -2039,7 +2039,7 @@ bool CIrcProto::OnIrc_WHO_REPLY(const CIrcMessage* pmsg) if ( lstrcmpi( pmsg->parameters[5].c_str(), m_info.sNick.c_str()) == 0 ) {
TCHAR host[1024];
lstrcpyn( host, pmsg->parameters[3].c_str(), 1024 );
- ircFork( &CIrcProto::ResolveIPThread, new IPRESOLVE( _T2A(host), IP_AUTO ));
+ ForkThread( &CIrcProto::ResolveIPThread, new IPRESOLVE( _T2A(host), IP_AUTO ));
} }
if ( command[0] == 'U' )
diff --git a/protocols/IRCG/src/irc.h b/protocols/IRCG/src/irc.h index d82b394a70..a7ba4ab3bf 100644 --- a/protocols/IRCG/src/irc.h +++ b/protocols/IRCG/src/irc.h @@ -195,12 +195,6 @@ using namespace irc; /////////////////////////////////////////////////////////////////////////////////////////
-struct CIrcProto;
-typedef void ( __cdecl CIrcProto::*IrcThreadFunc )( void* param );
-typedef int ( __cdecl CIrcProto::*IrcEventFunc )( WPARAM, LPARAM );
-typedef INT_PTR ( __cdecl CIrcProto::*IrcServiceFunc )( WPARAM, LPARAM );
-typedef INT_PTR ( __cdecl CIrcProto::*IrcServiceFuncParam )( WPARAM, LPARAM, LPARAM );
-
typedef bool (CIrcProto::*PfnIrcMessageHandler)(const CIrcMessage* pmsg);
struct CIrcHandler
@@ -214,9 +208,9 @@ struct CIrcHandler PfnIrcMessageHandler m_handler;
};
-struct CIrcProto : public PROTO_INTERFACE
+struct CIrcProto : public PROTO<CIrcProto>
{
- CIrcProto( const char*, const TCHAR* );
+ CIrcProto(const char*, const TCHAR*);
~CIrcProto();
// Protocol interface
@@ -483,12 +477,8 @@ struct CIrcProto : public PROTO_INTERFACE void ConnectToServer(void);
void DisconnectFromServer(void);
void DoNetlibLog( const char* fmt, ... );
- void IrcHookEvent( const char*, IrcEventFunc );
void InitMainMenus(void);
- void ircFork( IrcThreadFunc, void* arg );
- HANDLE ircForkEx( IrcThreadFunc, void* arg );
-
UINT_PTR RetryTimer;
void __cdecl ConnectServerThread( void* );
@@ -498,11 +488,10 @@ struct CIrcProto : public PROTO_INTERFACE void AddToJTemp(TCHAR op, CMString& sCommand);
bool AddWindowItemData(CMString window, const TCHAR* pszLimit, const TCHAR* pszMode, const TCHAR* pszPassword, const TCHAR* pszTopic);
INT_PTR CallChatEvent(WPARAM wParam, LPARAM lParam);
- void CreateProtoService( const char* serviceName, IrcServiceFunc pFunc );
INT_PTR DoEvent(int iEvent, const TCHAR* pszWindow, const TCHAR* pszNick, const TCHAR* pszText, const TCHAR* pszStatus, const TCHAR* pszUserInfo, DWORD_PTR dwItemData, bool bAddToLog, bool bIsMe,time_t timestamp = 1);
void FindLocalIP(HANDLE con);
bool FreeWindowItemData(CMString window, CHANNELINFO* wis);
- bool IsChannel(const char* sName);
+ bool IsChannel(const char* sName);
bool IsChannel(const TCHAR* sName);
void KillChatTimer(UINT_PTR &nIDEvent);
CMString MakeWndID(const TCHAR* sWindow);
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 7314d726cf..78f30e729c 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -221,7 +221,7 @@ bool CIrcProto::Connect(const CIrcSessionInfo& info) m_info = info;
// start receiving messages from host
- ircFork( &CIrcProto::ThreadProc, NULL );
+ ForkThread( &CIrcProto::ThreadProc, NULL );
Sleep( 100 );
if ( info.sPassword.GetLength())
NLSend( "PASS %s\r\n", info.sPassword.c_str());
diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp index de23f16b83..24028adc45 100644 --- a/protocols/IRCG/src/ircproto.cpp +++ b/protocols/IRCG/src/ircproto.cpp @@ -32,40 +32,39 @@ static int CompareSessions( const CDccSession* p1, const CDccSession* p2 ) }
CIrcProto::CIrcProto(const char* szModuleName, const TCHAR* tszUserName) :
+ PROTO<CIrcProto>(szModuleName, tszUserName),
m_dcc_chats( 10, CompareSessions ),
m_dcc_xfers( 10, CompareSessions ),
m_ignoreItems( 10 ),
vUserhostReasons( 10 ),
vWhoInProgress( 10 )
{
- ProtoConstructor(this, szModuleName, tszUserName);
-
InitializeCriticalSection(&cs);
InitializeCriticalSection(&m_gchook);
m_evWndCreate = ::CreateEvent( NULL, FALSE, FALSE, NULL );
- CreateProtoService( PS_GETMYAWAYMSG, &CIrcProto::GetMyAwayMsg );
-
- CreateProtoService( PS_CREATEACCMGRUI, &CIrcProto::SvcCreateAccMgrUI );
- CreateProtoService( PS_JOINCHAT, &CIrcProto::OnJoinChat );
- CreateProtoService( PS_LEAVECHAT, &CIrcProto::OnLeaveChat );
-
- CreateProtoService( IRC_JOINCHANNEL, &CIrcProto::OnJoinMenuCommand );
- CreateProtoService( IRC_QUICKCONNECT, &CIrcProto::OnQuickConnectMenuCommand);
- CreateProtoService( IRC_CHANGENICK, &CIrcProto::OnChangeNickMenuCommand );
- CreateProtoService( IRC_SHOWLIST, &CIrcProto::OnShowListMenuCommand );
- CreateProtoService( IRC_SHOWSERVER, &CIrcProto::OnShowServerMenuCommand );
- CreateProtoService( IRC_UM_CHANSETTINGS, &CIrcProto::OnMenuChanSettings );
- CreateProtoService( IRC_UM_WHOIS, &CIrcProto::OnMenuWhois );
- CreateProtoService( IRC_UM_DISCONNECT, &CIrcProto::OnMenuDisconnect );
- CreateProtoService( IRC_UM_IGNORE, &CIrcProto::OnMenuIgnore );
-
- CreateProtoService( "/DblClickEvent", &CIrcProto::OnDoubleclicked );
- CreateProtoService( "/InsertRawIn", &CIrcProto::Scripting_InsertRawIn );
- CreateProtoService( "/InsertRawOut", &CIrcProto::Scripting_InsertRawOut );
- CreateProtoService( "/InsertGuiIn", &CIrcProto::Scripting_InsertGuiIn );
- CreateProtoService( "/InsertGuiOut", &CIrcProto::Scripting_InsertGuiOut);
- CreateProtoService( "/GetIrcData", &CIrcProto::Scripting_GetIrcData);
+ CreateService( PS_GETMYAWAYMSG, &CIrcProto::GetMyAwayMsg );
+
+ CreateService( PS_CREATEACCMGRUI, &CIrcProto::SvcCreateAccMgrUI );
+ CreateService( PS_JOINCHAT, &CIrcProto::OnJoinChat );
+ CreateService( PS_LEAVECHAT, &CIrcProto::OnLeaveChat );
+
+ CreateService( IRC_JOINCHANNEL, &CIrcProto::OnJoinMenuCommand );
+ CreateService( IRC_QUICKCONNECT, &CIrcProto::OnQuickConnectMenuCommand);
+ CreateService( IRC_CHANGENICK, &CIrcProto::OnChangeNickMenuCommand );
+ CreateService( IRC_SHOWLIST, &CIrcProto::OnShowListMenuCommand );
+ CreateService( IRC_SHOWSERVER, &CIrcProto::OnShowServerMenuCommand );
+ CreateService( IRC_UM_CHANSETTINGS, &CIrcProto::OnMenuChanSettings );
+ CreateService( IRC_UM_WHOIS, &CIrcProto::OnMenuWhois );
+ CreateService( IRC_UM_DISCONNECT, &CIrcProto::OnMenuDisconnect );
+ CreateService( IRC_UM_IGNORE, &CIrcProto::OnMenuIgnore );
+
+ CreateService( "/DblClickEvent", &CIrcProto::OnDoubleclicked );
+ CreateService( "/InsertRawIn", &CIrcProto::Scripting_InsertRawIn );
+ CreateService( "/InsertRawOut", &CIrcProto::Scripting_InsertRawOut );
+ CreateService( "/InsertGuiIn", &CIrcProto::Scripting_InsertGuiIn );
+ CreateService( "/InsertGuiOut", &CIrcProto::Scripting_InsertGuiOut);
+ CreateService( "/GetIrcData", &CIrcProto::Scripting_GetIrcData);
codepage = CP_ACP;
InitializeCriticalSection(&m_resolve);
@@ -169,8 +168,6 @@ CIrcProto::~CIrcProto() DeleteCriticalSection(&m_dcc);
KillChatTimer(OnlineNotifTimer);
KillChatTimer(OnlineNotifTimer3);
-
- ProtoDestructor(this);
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -232,8 +229,8 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM ) gcr.ptszModuleDispName = m_tszUserName;
gcr.pszModule = m_szModuleName;
CallServiceSync( MS_GC_REGISTER, NULL, (LPARAM)&gcr );
- IrcHookEvent( ME_GC_EVENT, &CIrcProto::GCEventHook );
- IrcHookEvent( ME_GC_BUILDMENU, &CIrcProto::GCMenuHook );
+ HookEvent( ME_GC_EVENT, &CIrcProto::GCEventHook );
+ HookEvent( ME_GC_BUILDMENU, &CIrcProto::GCMenuHook );
GCSESSION gcw = { sizeof(GCSESSION) };
gcw.dwFlags = GC_TCHAR;
@@ -312,8 +309,8 @@ int CIrcProto::OnModulesLoaded( WPARAM, LPARAM ) InitIgnore();
- IrcHookEvent( ME_USERINFO_INITIALISE, &CIrcProto::OnInitUserInfo );
- IrcHookEvent( ME_OPT_INITIALISE, &CIrcProto::OnInitOptionsPages );
+ HookEvent( ME_USERINFO_INITIALISE, &CIrcProto::OnInitUserInfo );
+ HookEvent( ME_OPT_INITIALISE, &CIrcProto::OnInitOptionsPages );
if (m_nick[0]) {
TCHAR szBuf[ 40 ];
@@ -579,7 +576,7 @@ HANDLE __cdecl CIrcProto::SearchBasic( const PROTOCHAR* szId ) szId && szId[0] && !IsChannel(szId)) {
AckBasicSearchParam* param = new AckBasicSearchParam;
lstrcpyn( param->buf, szId, 50 );
- ircFork( &CIrcProto::AckBasicSearch, param );
+ ForkThread( &CIrcProto::AckBasicSearch, param );
return ( HANDLE )1;
} }
@@ -825,11 +822,11 @@ int __cdecl CIrcProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc) BYTE bDcc = getByte(hContact, "DCC", 0);
WORD wStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE);
if (bDcc && wStatus != ID_STATUS_ONLINE) {
- ircFork(&CIrcProto::AckMessageFailDcc, hContact);
+ ForkThread(&CIrcProto::AckMessageFailDcc, hContact);
return 0;
}
if (!bDcc && (m_iStatus == ID_STATUS_OFFLINE || m_iStatus == ID_STATUS_CONNECTING)) {
- ircFork(&CIrcProto::AckMessageFail, hContact);
+ ForkThread(&CIrcProto::AckMessageFail, hContact);
return 0;
}
@@ -854,7 +851,7 @@ int __cdecl CIrcProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc) mir_free(result);
int seq = InterlockedIncrement(&g_msgid);
- ircFork(&CIrcProto::AckMessageSuccess, new TFakeAckParam(hContact, seq));
+ ForkThread(&CIrcProto::AckMessageSuccess, new TFakeAckParam(hContact, seq));
return seq;
}
diff --git a/protocols/IRCG/src/options.cpp b/protocols/IRCG/src/options.cpp index 3d200f4811..dc0f491e5e 100644 --- a/protocols/IRCG/src/options.cpp +++ b/protocols/IRCG/src/options.cpp @@ -955,7 +955,7 @@ void CCtcpPrefsDlg::OnApply() m_ip.GetTextA( szTemp, sizeof( szTemp ));
lstrcpynA(m_proto->m_mySpecifiedHost, GetWord(szTemp, 0).c_str(), 499);
if ( lstrlenA( m_proto->m_mySpecifiedHost ))
- m_proto->ircFork( &CIrcProto::ResolveIPThread, new IPRESOLVE( m_proto->m_mySpecifiedHost, IP_MANUAL ));
+ m_proto->ForkThread( &CIrcProto::ResolveIPThread, new IPRESOLVE( m_proto->m_mySpecifiedHost, IP_MANUAL ));
}
else m_proto->m_mySpecifiedHost[0] = 0;
diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index 3bf3f885b0..7755fa84fb 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -1091,7 +1091,7 @@ void __cdecl CIrcProto::ConnectServerThread( void* ) KillChatTimer( RetryTimer );
if ( m_mySpecifiedHost[0] )
- ircFork( &CIrcProto::ResolveIPThread, new IPRESOLVE( m_mySpecifiedHost, IP_MANUAL ));
+ ForkThread( &CIrcProto::ResolveIPThread, new IPRESOLVE( m_mySpecifiedHost, IP_MANUAL ));
DoEvent(GC_EVENT_CHANGESESSIONAME, SERVERWINDOW, NULL, m_info.sNetwork.c_str(), NULL, NULL, NULL, FALSE, TRUE);
}
@@ -1151,7 +1151,7 @@ void CIrcProto::ConnectToServer(void) sChannelModes = "btnimklps";
if (!m_bConnectThreadRunning)
- ircFork( &CIrcProto::ConnectServerThread, 0 );
+ ForkThread( &CIrcProto::ConnectServerThread, 0 );
else if (m_bConnectRequested < 1)
InterlockedIncrement((long *) &m_bConnectRequested);
@@ -1176,7 +1176,7 @@ void CIrcProto::DisconnectFromServer(void) gce.pDest = &gcd;
CallChatEvent( SESSION_TERMINATE, (LPARAM)&gce);
- ircFork( &CIrcProto::DisconnectServerThread, 0 );
+ ForkThread( &CIrcProto::DisconnectServerThread, 0 );
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1214,7 +1214,7 @@ VOID CALLBACK RetryTimerProc( HWND, UINT, UINT_PTR idEvent, DWORD ) ppro->DoEvent(GC_EVENT_INFORMATION, SERVERWINDOW, NULL, szTemp, NULL, NULL, NULL, true, false);
if ( !ppro->m_bConnectThreadRunning )
- ppro->ircFork( &CIrcProto::ConnectServerThread, 0 );
+ ppro->ForkThread( &CIrcProto::ConnectServerThread, 0 );
else
ppro->m_bConnectRequested = true;
diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp index b93d4ea498..0d12162854 100644 --- a/protocols/IRCG/src/tools.cpp +++ b/protocols/IRCG/src/tools.cpp @@ -132,23 +132,6 @@ void CIrcProto::AddToJTemp(TCHAR op, CMString& sCommand) setTString("JTemp", res.c_str());
}
-void CIrcProto::ircFork( IrcThreadFunc pFunc, void* arg )
-{
- unsigned threadID;
- CloseHandle(( HANDLE )::mir_forkthreadowner(( pThreadFuncOwner )( *( void** )&pFunc ), this, arg, &threadID ));
-}
-
-HANDLE CIrcProto::ircForkEx( IrcThreadFunc pFunc, void* arg )
-{
- unsigned threadID;
- return (HANDLE)::mir_forkthreadowner(( pThreadFuncOwner )( *( void** )&pFunc ), this, arg, &threadID );
-}
-
-void CIrcProto::IrcHookEvent( const char* szEvent, IrcEventFunc pFunc )
-{
- ::HookEventObj( szEvent, ( MIRANDAHOOKOBJ )*( void** )&pFunc, this );
-}
-
CMString __stdcall GetWord(const TCHAR* text, int index)
{
if ( text && *text ) {
@@ -791,13 +774,6 @@ bool CIrcProto::AddWindowItemData(CMString window, const TCHAR* pszLimit, const return false;
}
-void CIrcProto::CreateProtoService( const char* serviceName, IrcServiceFunc pFunc )
-{
- char temp[MAXMODULELABELLENGTH];
- mir_snprintf( temp, sizeof(temp), "%s%s", m_szModuleName, serviceName );
- CreateServiceFunctionObj( temp, ( MIRANDASERVICEOBJ )*( void** )&pFunc, this );
-}
-
void CIrcProto::FindLocalIP(HANDLE con) // inspiration from jabber
{
// Determine local IP
|