From bb952e431866d131bae95c08e579ec8a00f00343 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 8 Jul 2013 22:10:14 +0000 Subject: 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 --- protocols/Omegle/src/chat.cpp | 18 +++++++++--------- protocols/Omegle/src/communication.cpp | 5 ++--- protocols/Omegle/src/proto.cpp | 19 +++++++++---------- protocols/Omegle/src/proto.h | 12 ++++++------ protocols/Omegle/src/utils.h | 29 ----------------------------- 5 files changed, 26 insertions(+), 57 deletions(-) (limited to 'protocols/Omegle') diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 62a00d5174..c6681c051f 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -85,12 +85,12 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) facy.spy_mode_ = false; facy.question_ = ""; - ForkThread(&OmegleProto::NewChatWorker, this, NULL); + ForkThread(&OmegleProto::NewChatWorker, NULL); break; } else if (!stricmp(command.c_str(), "quit")) { - ForkThread(&OmegleProto::StopChatWorker, this, NULL); + ForkThread(&OmegleProto::StopChatWorker, NULL); break; } else if (!stricmp(command.c_str(), "spy")) @@ -98,7 +98,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) facy.spy_mode_ = true; facy.question_ = ""; - ForkThread(&OmegleProto::NewChatWorker, this, NULL); + ForkThread(&OmegleProto::NewChatWorker, NULL); break; } else if (!stricmp(command.c_str(), "ask")) @@ -131,7 +131,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) facy.spy_mode_ = true; facy.question_ = params; - ForkThread(&OmegleProto::NewChatWorker, this, NULL); + ForkThread(&OmegleProto::NewChatWorker, NULL); break; } else if (!stricmp(command.c_str(), "asl")) @@ -177,7 +177,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) case STATE_ACTIVE: LOG("**Chat - Outgoing message: %s", text.c_str()); - ForkThread(&OmegleProto::SendMsgWorker, this, (void*)new std::string(text)); + ForkThread(&OmegleProto::SendMsgWorker, new std::string(text)); break; case STATE_INACTIVE: @@ -199,13 +199,13 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) case GC_USER_TYPNOTIFY: if ( facy.state_ == STATE_ACTIVE ) - ForkThread(&OmegleProto::SendTypingWorker, this, (void*)mir_tstrdup(hook->ptszText)); + ForkThread(&OmegleProto::SendTypingWorker, mir_tstrdup(hook->ptszText)); break; case GC_USER_LEAVE: case GC_SESSION_TERMINATE: mir_free( facy.nick_ ); - ForkThread(&OmegleProto::StopChatWorker, this, NULL); + ForkThread(&OmegleProto::StopChatWorker, NULL); break; } @@ -271,7 +271,7 @@ void OmegleProto::DeleteChatContact(const TCHAR *name) CallServiceSync(MS_GC_EVENT,0,reinterpret_cast(&gce)); } -int OmegleProto::OnJoinChat(WPARAM,LPARAM suppress) +INT_PTR OmegleProto::OnJoinChat(WPARAM,LPARAM suppress) { GCSESSION gcw = {sizeof(gcw)}; @@ -330,7 +330,7 @@ void OmegleProto::SetTopic(const TCHAR *topic) CallServiceSync(MS_GC_EVENT,0, reinterpret_cast(&gce)); } -int OmegleProto::OnLeaveChat(WPARAM,LPARAM) +INT_PTR OmegleProto::OnLeaveChat(WPARAM,LPARAM) { GCDEST gcd = { m_szModuleName }; gcd.ptszID = const_cast(m_tszUserName); diff --git a/protocols/Omegle/src/communication.cpp b/protocols/Omegle/src/communication.cpp index d06a260966..bfad43d05d 100644 --- a/protocols/Omegle/src/communication.cpp +++ b/protocols/Omegle/src/communication.cpp @@ -701,10 +701,9 @@ bool Omegle_client::events( ) db_free(&dbv); parent->Log("**Chat - saying Hi! message"); - ForkThread(&OmegleProto::SendMsgWorker, parent, (void*)message); - } else { - parent->Log("**Chat - Hi message is enabled but not used"); + parent->ForkThread(&OmegleProto::SendMsgWorker, message); } + else parent->Log("**Chat - Hi message is enabled but not used"); } } diff --git a/protocols/Omegle/src/proto.cpp b/protocols/Omegle/src/proto.cpp index 09f330a111..e3c1fd6d1b 100644 --- a/protocols/Omegle/src/proto.cpp +++ b/protocols/Omegle/src/proto.cpp @@ -22,10 +22,9 @@ along with this program. If not, see . #include "common.h" -OmegleProto::OmegleProto(const char* proto_name, const TCHAR* username) +OmegleProto::OmegleProto(const char* proto_name, const TCHAR* username) : + PROTO(proto_name, username) { - ProtoConstructor(this, proto_name, username); - this->facy.parent = this; this->signon_lock_ = CreateMutex( NULL, FALSE, NULL ); @@ -34,13 +33,13 @@ OmegleProto::OmegleProto(const char* proto_name, const TCHAR* username) this->facy.connection_lock_ = CreateMutex( NULL, FALSE, NULL ); // Group chats - CreateProtoService(m_szModuleName, PS_JOINCHAT, &OmegleProto::OnJoinChat, this); - CreateProtoService(m_szModuleName, PS_LEAVECHAT, &OmegleProto::OnLeaveChat, this); + CreateService(PS_JOINCHAT, &OmegleProto::OnJoinChat); + CreateService(PS_LEAVECHAT, &OmegleProto::OnLeaveChat); - CreateProtoService(m_szModuleName, PS_CREATEACCMGRUI, &OmegleProto::SvcCreateAccMgrUI, this); + CreateService(PS_CREATEACCMGRUI, &OmegleProto::SvcCreateAccMgrUI); - HookProtoEvent(ME_OPT_INITIALISE, &OmegleProto::OnOptionsInit, this); - HookProtoEvent(ME_GC_EVENT, &OmegleProto::OnChatEvent, this); + HookEvent(ME_OPT_INITIALISE, &OmegleProto::OnOptionsInit); + HookEvent(ME_GC_EVENT, &OmegleProto::OnChatEvent); // Create standard network connection TCHAR descr[512]; @@ -169,9 +168,9 @@ int OmegleProto::OnEvent(PROTOEVENTTYPE event,WPARAM wParam,LPARAM lParam) ////////////////////////////////////////////////////////////////////////////// // EVENTS -int OmegleProto::SvcCreateAccMgrUI(WPARAM wParam,LPARAM lParam) +INT_PTR OmegleProto::SvcCreateAccMgrUI(WPARAM wParam,LPARAM lParam) { - return (int)CreateDialogParam(g_hInstance,MAKEINTRESOURCE(IDD_OmegleACCOUNT), + return (INT_PTR)CreateDialogParam(g_hInstance,MAKEINTRESOURCE(IDD_OmegleACCOUNT), (HWND)lParam, OmegleAccountProc, (LPARAM)this ); } diff --git a/protocols/Omegle/src/proto.h b/protocols/Omegle/src/proto.h index 6af449a453..0d37301648 100644 --- a/protocols/Omegle/src/proto.h +++ b/protocols/Omegle/src/proto.h @@ -22,7 +22,7 @@ along with this program. If not, see . #pragma once -class OmegleProto : public PROTO_INTERFACE +class OmegleProto : public PROTO { public: OmegleProto( const char *proto_name, const TCHAR *username ); @@ -91,7 +91,7 @@ public: virtual int __cdecl OnEvent( PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam ); // Services - int __cdecl SvcCreateAccMgrUI( WPARAM, LPARAM ); + INT_PTR __cdecl SvcCreateAccMgrUI( WPARAM, LPARAM ); // Events int __cdecl OnModulesLoaded(WPARAM, LPARAM); @@ -101,10 +101,10 @@ public: int __cdecl OnPrebuildContactMenu(WPARAM,LPARAM); // Chat handling - int __cdecl OnChatEvent(WPARAM,LPARAM); - int __cdecl OnJoinChat(WPARAM,LPARAM); - int __cdecl OnLeaveChat(WPARAM,LPARAM); - + int __cdecl OnChatEvent(WPARAM,LPARAM); + INT_PTR __cdecl OnJoinChat(WPARAM,LPARAM); + INT_PTR __cdecl OnLeaveChat(WPARAM,LPARAM); + // Loops void __cdecl EventsLoop(void*); diff --git a/protocols/Omegle/src/utils.h b/protocols/Omegle/src/utils.h index d6b8e560eb..67a071d00c 100644 --- a/protocols/Omegle/src/utils.h +++ b/protocols/Omegle/src/utils.h @@ -22,35 +22,6 @@ along with this program. If not, see . #pragma once -template -void CreateProtoService(const char *module,const char *service, - int (__cdecl T::*serviceProc)(WPARAM,LPARAM),T *self) -{ - char temp[MAX_PATH*2]; - - mir_snprintf(temp,sizeof(temp),"%s%s",module,service); - CreateServiceFunctionObj(temp,( MIRANDASERVICEOBJ )*(void**)&serviceProc, self ); -} - -template -void HookProtoEvent(const char* evt, int (__cdecl T::*eventProc)(WPARAM,LPARAM), T *self) -{ - ::HookEventObj(evt,(MIRANDAHOOKOBJ)*(void**)&eventProc,self); -} - -template -HANDLE ForkThreadEx(void (__cdecl T::*thread)(void*),T *self,void *data = 0) -{ - return reinterpret_cast( mir_forkthreadowner( - (pThreadFuncOwner)*(void**)&thread,self,data,0)); -} - -template -void ForkThread(void (__cdecl T::*thread)(void*),T *self,void *data = 0) -{ - CloseHandle(ForkThreadEx(thread,self,data)); -} - namespace utils { namespace url -- cgit v1.2.3