From 3ad2582c4a4a6378f294f9256ecbcbdf0ae88e3a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 3 May 2018 16:02:14 +0200 Subject: mir_forkThread - stronger typizatioin for thread function parameter --- protocols/Sametime/src/conference.cpp | 6 +- protocols/Sametime/src/files.cpp | 21 +++---- protocols/Sametime/src/messaging.cpp | 2 +- protocols/Sametime/src/sametime.cpp | 12 ++-- protocols/Sametime/src/sametime.h | 15 +++-- protocols/Sametime/src/sametime_proto.cpp | 8 +-- protocols/Sametime/src/sametime_proto.h | 20 +++--- protocols/Sametime/src/sametime_session.cpp | 94 ++++++++++++++--------------- protocols/Sametime/src/userlist.cpp | 2 +- 9 files changed, 88 insertions(+), 92 deletions(-) (limited to 'protocols/Sametime') diff --git a/protocols/Sametime/src/conference.cpp b/protocols/Sametime/src/conference.cpp index d96ca4e66d..1df4c0570f 100644 --- a/protocols/Sametime/src/conference.cpp +++ b/protocols/Sametime/src/conference.cpp @@ -184,7 +184,7 @@ void mwServiceConf_on_peer_joined(mwConference* conf, mwLoginInfo *user) gce.ptszNick = tszUserName; gce.ptszUID = tszUserId; gce.ptszStatus = L"Normal"; - gce.time = (DWORD)time(nullptr); + gce.time = (DWORD)time(0); Chat_Event( &gce); @@ -209,7 +209,7 @@ void mwServiceConf_on_peer_parted(mwConference* conf, mwLoginInfo* user) gce.ptszNick = tszUserName; gce.ptszUID = tszUserId; gce.ptszStatus = L"Normal"; - gce.time = (DWORD)time(nullptr); + gce.time = (DWORD)time(0); Chat_Event(&gce); } @@ -229,7 +229,7 @@ void mwServiceConf_on_text(mwConference* conf, mwLoginInfo* user, const char* wh gce.ptszText = textT; gce.ptszNick = tszUserName; gce.ptszUID = tszUserId; - gce.time = (DWORD)time(nullptr); + gce.time = (DWORD)time(0); Chat_Event(&gce); } diff --git a/protocols/Sametime/src/files.cpp b/protocols/Sametime/src/files.cpp index e7d206c4fc..080e23fcc4 100644 --- a/protocols/Sametime/src/files.cpp +++ b/protocols/Sametime/src/files.cpp @@ -41,7 +41,7 @@ void mwFileTransfer_offered(mwFileTransfer* ft) PROTORECVFILE pre = {0}; pre.dwFlags = PRFF_UNICODE; pre.fileCount = 1; - pre.timestamp = time(nullptr); + pre.timestamp = time(0); pre.descr.w = descriptionT; pre.files.w = &filenameT; pre.lParam = (LPARAM)ft; @@ -52,12 +52,12 @@ void mwFileTransfer_offered(mwFileTransfer* ft) } //returns 0 if finished with current file -int SendFileChunk(CSametimeProto* proto, mwFileTransfer* ft, FileTransferClientData* ftcd) { - DWORD bytes_read; - +int SendFileChunk(CSametimeProto* proto, mwFileTransfer* ft, FileTransferClientData* ftcd) +{ if (!ftcd || !ftcd->buffer) return 0; + DWORD bytes_read; if (!ReadFile(ftcd->hFile, ftcd->buffer, FILE_BUFF_SIZE, &bytes_read, nullptr)) { proto->debugLogW(L"Sametime closing file transfer (SendFileChunk)"); mwFileTransfer_close(ft, mwFileTransfer_SUCCESS); @@ -72,9 +72,8 @@ int SendFileChunk(CSametimeProto* proto, mwFileTransfer* ft, FileTransferClientD return bytes_read; } -void __cdecl SendThread(LPVOID param) { - - mwFileTransfer* ft = (mwFileTransfer*)param; +void __cdecl SendThread(mwFileTransfer* ft) +{ if (!ft) return; CSametimeProto* proto = getProtoFromMwFileTransfer(ft); FileTransferClientData* ftcd = (FileTransferClientData*)mwFileTransfer_getClientData(ft); @@ -113,7 +112,6 @@ void __cdecl SendThread(LPVOID param) { delete ftcd; proto->debugLogW(L"SendThread() end"); - return; } /** a file transfer has been fully initiated */ @@ -124,10 +122,9 @@ void mwFileTransfer_opened(mwFileTransfer* ft) proto->debugLogW(L"Sametime mwFileTransfer_opened start"); - if (ftcd->sending) { - // create a thread to send chunks - since it seems not all clients send acks for each of our chunks! - mir_forkthread(SendThread, ft); - } + // create a thread to send chunks - since it seems not all clients send acks for each of our chunks! + if (ftcd->sending) + mir_forkThread(SendThread, ft); } /** a file transfer has been closed. Check the status of the file diff --git a/protocols/Sametime/src/messaging.cpp b/protocols/Sametime/src/messaging.cpp index 9b0fa0b9fb..cc79c8b9dc 100644 --- a/protocols/Sametime/src/messaging.cpp +++ b/protocols/Sametime/src/messaging.cpp @@ -82,7 +82,7 @@ void mwIm_conversation_recv(mwConversation* conv, mwImSendType type, gconstpoint return; PROTORECVEVENT pre = { 0 }; - time_t t = time(nullptr); + time_t t = time(0); pre.timestamp = t; pre.szMessage = (char*)msg; ProtoChainRecvMsg(hContact, &pre); diff --git a/protocols/Sametime/src/sametime.cpp b/protocols/Sametime/src/sametime.cpp index 3246dccc53..3c67736302 100644 --- a/protocols/Sametime/src/sametime.cpp +++ b/protocols/Sametime/src/sametime.cpp @@ -111,9 +111,8 @@ void ReleaseIconEx(const char* name, bool big) } // Copied from MSN plugin - sent acks need to be from different thread -void __cdecl sttFakeAckInfoSuccessThread(void *param) +void __cdecl sttFakeAckInfoSuccessThread(TFakeAckParams* tParam) { - TFakeAckParams* tParam = (TFakeAckParams*)param; CSametimeProto* proto = tParam->proto; proto->debugLogW(L"sttFakeAckInfoSuccessThread() start"); @@ -124,9 +123,8 @@ void __cdecl sttFakeAckInfoSuccessThread(void *param) mir_free(tParam); } -void __cdecl sttFakeAckMessageSuccessThread(void *param) +void __cdecl sttFakeAckMessageSuccessThread(TFakeAckParams* tParam) { - TFakeAckParams* tParam = (TFakeAckParams*)param; CSametimeProto* proto = tParam->proto; proto->debugLogW(L"sttFakeAckMessageSuccessThread() start"); @@ -137,9 +135,8 @@ void __cdecl sttFakeAckMessageSuccessThread(void *param) mir_free(tParam); } -void __cdecl sttFakeAckMessageFailedThread(void *param) +void __cdecl sttFakeAckMessageFailedThread(TFakeAckParams* tParam) { - TFakeAckParams* tParam = (TFakeAckParams*)param; CSametimeProto* proto = tParam->proto; proto->debugLogW(L"sttFakeAckMessageFailedThread() start"); @@ -150,9 +147,8 @@ void __cdecl sttFakeAckMessageFailedThread(void *param) mir_free(tParam); } -void __cdecl sttRecvAwayThread(void *param) +void __cdecl sttRecvAwayThread(TFakeAckParams* tParam) { - TFakeAckParams* tParam = (TFakeAckParams*)param; CSametimeProto* proto = tParam->proto; proto->debugLogW(L"sttRecvAwayThread() start"); diff --git a/protocols/Sametime/src/sametime.h b/protocols/Sametime/src/sametime.h index b0e807489b..ccf1c920e8 100644 --- a/protocols/Sametime/src/sametime.h +++ b/protocols/Sametime/src/sametime.h @@ -47,10 +47,17 @@ void ReleaseIconEx(const char* name, bool big); // services (async thread functions) -void __cdecl sttFakeAckInfoSuccessThread(void* param); -void __cdecl sttFakeAckMessageFailedThread(void* param); -void __cdecl sttFakeAckMessageSuccessThread(void* param); -void __cdecl sttRecvAwayThread(void* param); +struct TFakeAckParams +{ + struct CSametimeProto* proto; + MCONTACT hContact; + LPARAM lParam; +}; + +void __cdecl sttFakeAckInfoSuccessThread(TFakeAckParams* tParam); +void __cdecl sttFakeAckMessageFailedThread(TFakeAckParams* tParam); +void __cdecl sttFakeAckMessageSuccessThread(TFakeAckParams* tParam); +void __cdecl sttRecvAwayThread(TFakeAckParams* tParam); //sametime structs diff --git a/protocols/Sametime/src/sametime_proto.cpp b/protocols/Sametime/src/sametime_proto.cpp index 9b6abed685..f84ed684e3 100644 --- a/protocols/Sametime/src/sametime_proto.cpp +++ b/protocols/Sametime/src/sametime_proto.cpp @@ -147,7 +147,7 @@ int CSametimeProto::GetInfo(MCONTACT hContact, int infoType) tfap->proto = this; tfap->hContact = hContact; tfap->lParam = NULL; - mir_forkthread(sttFakeAckInfoSuccessThread, tfap); + mir_forkThread(sttFakeAckInfoSuccessThread, tfap); return 0; } @@ -219,7 +219,7 @@ int CSametimeProto::SendMsg(MCONTACT hContact, int, const char* msg) tfap->proto = this; tfap->hContact = hContact; tfap->lParam = 0; - mir_forkthread(sttFakeAckMessageFailedThread, tfap); + mir_forkThread(sttFakeAckMessageFailedThread, tfap); return 0; } @@ -232,7 +232,7 @@ int CSametimeProto::SendMsg(MCONTACT hContact, int, const char* msg) tfap->proto = this; tfap->hContact = hContact; tfap->lParam = (LPARAM)ret; - mir_forkthread(sttFakeAckMessageSuccessThread, tfap); + mir_forkThread(sttFakeAckMessageSuccessThread, tfap); return ret; } @@ -262,7 +262,7 @@ HANDLE CSametimeProto::GetAwayMsg(MCONTACT hContact) tfap = (TFakeAckParams*)malloc(sizeof(TFakeAckParams)); tfap->proto = this; tfap->hContact = hContact; - mir_forkthread(sttRecvAwayThread, tfap); + mir_forkThread(sttRecvAwayThread, tfap); return (HANDLE)1; } return nullptr; diff --git a/protocols/Sametime/src/sametime_proto.h b/protocols/Sametime/src/sametime_proto.h index 84407541de..242f68cf6c 100644 --- a/protocols/Sametime/src/sametime_proto.h +++ b/protocols/Sametime/src/sametime_proto.h @@ -14,7 +14,6 @@ struct CSametimeProto : public PROTO // PROTO_INTERFACE //==================================================================================== - MCONTACT AddToList(int flags, PROTOSEARCHRESULT* psr) override; HANDLE FileAllow(MCONTACT hContact, HANDLE hTransfer, const wchar_t* szPath) override; @@ -121,6 +120,9 @@ struct CSametimeProto : public PROTO void DeinitAwayMsg(); void InitMeanwhileServices(); void DeinitMeanwhileServices(); + + void __cdecl KeepAliveThread(void*); + void __cdecl SessionThread(void*); // options.cpp int __cdecl OptInit(WPARAM wParam, LPARAM lParam); @@ -198,14 +200,8 @@ struct CMPlugin : public ACCPROTOPLUGIN } }; -typedef struct tag_TFakeAckParams { - CSametimeProto* proto; - MCONTACT hContact; - LPARAM lParam; -} TFakeAckParams; - - -struct SendAnnouncementFunc_arg { +struct SendAnnouncementFunc_arg +{ CSametimeProto* proto; wchar_t msg[MAX_MESSAGE_SIZE]; GList* recipients; @@ -213,13 +209,15 @@ struct SendAnnouncementFunc_arg { typedef void (*SendAnnouncementFunc)(SendAnnouncementFunc_arg* ad); -struct SessionAnnounceDialogProc_arg { +struct SessionAnnounceDialogProc_arg +{ CSametimeProto* proto; SendAnnouncementFunc sendAnnouncementFunc; }; -struct PopupData { +struct PopupData +{ SametimePopupEnum flag; wchar_t* title; wchar_t* text; diff --git a/protocols/Sametime/src/sametime_session.cpp b/protocols/Sametime/src/sametime_session.cpp index fc029ee5ea..5cdf633385 100644 --- a/protocols/Sametime/src/sametime_session.cpp +++ b/protocols/Sametime/src/sametime_session.cpp @@ -245,7 +245,7 @@ int CSametimeProto::SetSessionStatus(int status) if (idle_timerid) KillTimer(nullptr, idle_timerid); - us.time = (DWORD)time(nullptr); + us.time = (DWORD)time(0); //us.time = 0; switch (status) { @@ -286,7 +286,7 @@ VOID CALLBACK IdleTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime if (proto->idle_status) { struct mwUserStatus us; - us.time = (DWORD)time(nullptr); + us.time = (DWORD)time(0); us.status = mwStatus_IDLE; us.desc = nullptr; mwSession_setUserStatus(proto->session, &us); @@ -341,19 +341,18 @@ void WakeThread(HANDLE hThread) QueueUserAPC(NullAPC, hThread, 0); } -void __cdecl KeepAliveThread(LPVOID param) +void __cdecl CSametimeProto::KeepAliveThread(void*) { - CSametimeProto* proto = (CSametimeProto*)param; int i = 120; - proto->debugLogW(L"KeepAliveThread() start"); + debugLogW(L"KeepAliveThread() start"); while (1) { if (i <= 0) { i = 120; // send keepalive every 120 * 250 = 30000[ms] - if (mwSession_isStarted(proto->session) && proto->session) { - mwSession_sendKeepalive(proto->session); + if (mwSession_isStarted(session) && session) { + mwSession_sendKeepalive(session); } } @@ -361,9 +360,9 @@ void __cdecl KeepAliveThread(LPVOID param) SleepEx(250, TRUE); - mir_cslock lck(proto->session_cs); - if (Miranda_IsTerminated() || !proto->session) { - proto->debugLogW(L"KeepAliveThread() end"); + mir_cslock lck(session_cs); + if (Miranda_IsTerminated() || !session) { + debugLogW(L"KeepAliveThread() end"); break; } } @@ -376,65 +375,64 @@ int waitcallback(unsigned int* timeout) return continue_connect ? 1 : 0; } -void __cdecl SessionThread(LPVOID param) +void __cdecl CSametimeProto::SessionThread(LPVOID) { - CSametimeProto* proto = (CSametimeProto*)param; - proto->debugLogW(L"SessionThread() start"); + debugLogW(L"SessionThread() start"); continue_connect = true; - proto->BroadcastNewStatus(ID_STATUS_CONNECTING); + BroadcastNewStatus(ID_STATUS_CONNECTING); // setup NETLIBOPENCONNECTION conn_data = { 0 }; conn_data.cbSize = sizeof(NETLIBOPENCONNECTION); conn_data.flags = NLOCF_V2; - conn_data.szHost = proto->options.server_name; - conn_data.wPort = proto->options.port; + conn_data.szHost = options.server_name; + conn_data.wPort = options.port; conn_data.timeout = 20; conn_data.waitcallback = waitcallback; - proto->server_connection = Netlib_OpenConnection(proto->m_hNetlibUser, &conn_data); + server_connection = Netlib_OpenConnection(m_hNetlibUser, &conn_data); - if (!proto->server_connection) { + if (!server_connection) { - proto->BroadcastNewStatus(ID_STATUS_OFFLINE); + BroadcastNewStatus(ID_STATUS_OFFLINE); if (continue_connect) { // real timeout - not user cancelled - proto->showPopup(TranslateT("No server connection!"), SAMETIME_POPUP_ERROR); + showPopup(TranslateT("No server connection!"), SAMETIME_POPUP_ERROR); } - proto->debugLogW(L"SessionThread() end, no server_connection, continue_connect=[%d]", continue_connect); + debugLogW(L"SessionThread() end, no server_connection, continue_connect=[%d]", continue_connect); return; } mwSessionHandler handler = {}; - handler.clear = SessionClear; - handler.io_write = SessionWrite; - handler.io_close = SessionClose; - handler.on_stateChange = SessionStateChange; - handler.on_admin = SessionAdmin; - handler.on_announce = SessionAnnounce; - handler.on_setPrivacyInfo = SessionSetPrivacyInfo; - handler.on_setUserStatus = SessionSetUserStatus; + handler.clear = ::SessionClear; + handler.io_write = ::SessionWrite; + handler.io_close = ::SessionClose; + handler.on_stateChange = ::SessionStateChange; + handler.on_admin = ::SessionAdmin; + handler.on_announce = ::SessionAnnounce; + handler.on_setPrivacyInfo = ::SessionSetPrivacyInfo; + handler.on_setUserStatus = ::SessionSetUserStatus; { - mir_cslock lck(proto->session_cs); - proto->session = mwSession_new(&handler); + mir_cslock lck(session_cs); + session = mwSession_new(&handler); - proto->InitMeanwhileServices(); + InitMeanwhileServices(); - mwSession_start(proto->session); + mwSession_start(session); } - mir_forkthread(KeepAliveThread, proto); + ForkThread(&CSametimeProto::KeepAliveThread); unsigned char* recv_buffer = (unsigned char*)mir_alloc(1024 * 32); int bytes; //while(session && server_connection && mwSession_getState(session) != mwSession_STOPPED) { - while (proto->server_connection) {// && session) {// && !mwSession_isStopped(session)) { // break on error - bytes = Netlib_Recv(proto->server_connection, (char *)recv_buffer, 1024 * 32, 0); - proto->debugLogW(L"SessionThread() Netlib_Recv'ed bytes=[%d]", bytes); + while (server_connection) {// && session) {// && !mwSession_isStopped(session)) { // break on error + bytes = Netlib_Recv(server_connection, (char *)recv_buffer, 1024 * 32, 0); + debugLogW(L"SessionThread() Netlib_Recv'ed bytes=[%d]", bytes); if (bytes == 0) { break; @@ -444,23 +442,23 @@ void __cdecl SessionThread(LPVOID param) break; } else { - mir_cslock lck(proto->session_cs); - mwSession_recv(proto->session, recv_buffer, bytes); + mir_cslock lck(session_cs); + mwSession_recv(session, recv_buffer, bytes); } } mir_free(recv_buffer); - mir_cslock lck2(proto->session_cs); - proto->DeinitMeanwhileServices(); - mwSession* old_session = proto->session; - proto->session = nullptr; // kills keepalive thread, if awake + mir_cslock lck2(session_cs); + DeinitMeanwhileServices(); + mwSession* old_session = session; + session = nullptr; // kills keepalive thread, if awake mwSession_free(old_session); - proto->BroadcastNewStatus(ID_STATUS_OFFLINE); - proto->SetAllOffline(); - proto->first_online = true; + BroadcastNewStatus(ID_STATUS_OFFLINE); + SetAllOffline(); + first_online = true; - proto->debugLogW(L"SessionThread() end"); + debugLogW(L"SessionThread() end"); return; } @@ -496,7 +494,7 @@ int CSametimeProto::LogIn(int ls, HANDLE hNetlibUser) login_status = ls; - mir_forkthread(SessionThread, this); + ForkThread(&CSametimeProto::SessionThread); return 0; } diff --git a/protocols/Sametime/src/userlist.cpp b/protocols/Sametime/src/userlist.cpp index f155fa6cb0..1d01d15e24 100644 --- a/protocols/Sametime/src/userlist.cpp +++ b/protocols/Sametime/src/userlist.cpp @@ -529,7 +529,7 @@ void mwAwareList_on_aware(mwAwareList* list, mwAwareSnapshot* aware) new_status = ID_STATUS_AWAY; db_set_w(hContact, proto->m_szModuleName, "Status", new_status); } - db_set_dw(hContact, proto->m_szModuleName, "IdleTS", (DWORD)time(nullptr)); + db_set_dw(hContact, proto->m_szModuleName, "IdleTS", (DWORD)time(0)); break; case mwStatus_BUSY: new_status = ID_STATUS_DND; -- cgit v1.2.3