From 8bd2456f654ef5eea44fcf4ad6ce5f7107f7d829 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 16 Apr 2015 14:03:24 +0000 Subject: IsStatusConnecting() - useful macro git-svn-id: http://svn.miranda-ng.org/main/trunk@12860 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/statusmodes.h | 9 +++++++++ plugins/Clist_modern/src/modern_clisttray.cpp | 11 +++++------ plugins/Clist_modern/src/modern_clui.cpp | 2 +- plugins/SimpleStatusMsg/src/main.cpp | 2 +- plugins/StatusPlugins/KeepStatus/keepstatus.cpp | 6 +++--- plugins/StatusPlugins/commonstatus.cpp | 3 ++- plugins/StopSpamPlus/src/services.cpp | 2 +- protocols/AimOscar/src/links.cpp | 2 +- protocols/JabberG/src/jabber_proto.cpp | 2 +- protocols/VKontakte/src/vk_queue.cpp | 2 +- protocols/VKontakte/src/vk_status.cpp | 4 ++-- protocols/WhatsApp/src/proto.cpp | 2 +- src/modules/clist/clistmod.cpp | 6 +++--- src/modules/clist/clui.cpp | 2 +- src/modules/skin/skinicons.cpp | 2 +- 15 files changed, 33 insertions(+), 24 deletions(-) diff --git a/include/statusmodes.h b/include/statusmodes.h index 432292959f..f34892d1f7 100644 --- a/include/statusmodes.h +++ b/include/statusmodes.h @@ -34,6 +34,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //and/or should do. #define MAX_CONNECT_RETRIES 10000 +#if defined __cplusplus +__forceinline bool IsStatusConnecting(int iStatus) +{ + return iStatus >= ID_STATUS_CONNECTING && iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES; +} +#else + #define IsStatusConnecting(X) (X >= ID_STATUS_CONNECTING && X < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) +#endif + #define ID_STATUS_OFFLINE 40071 #define ID_STATUS_ONLINE 40072 #define ID_STATUS_AWAY 40073 diff --git a/plugins/Clist_modern/src/modern_clisttray.cpp b/plugins/Clist_modern/src/modern_clisttray.cpp index a6c0126ec2..4357e06315 100644 --- a/plugins/Clist_modern/src/modern_clisttray.cpp +++ b/plugins/Clist_modern/src/modern_clisttray.cpp @@ -98,7 +98,7 @@ INT_PTR CListTray_GetGlobalStatus(WPARAM, LPARAM) if (!pcli->pfnGetProtocolVisibility(p.szProto)) continue; - if (p.dwStatus >= ID_STATUS_CONNECTING && p.dwStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) { + if (IsStatusConnecting(p.dwStatus)) { connectingCount++; if (connectingCount == 1) g_szConnectingProto = p.szProto; @@ -472,8 +472,7 @@ int GetGoodAccNum(bool *bDiffers, bool *bConn) d = 2; if (bConn) - if ( acc[i]->ppro->m_iStatus >= ID_STATUS_CONNECTING - && acc[i]->ppro->m_iStatus <= (ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) + if (IsStatusConnecting(acc[i]->ppro->m_iStatus)) *bConn = TRUE; } } @@ -606,7 +605,7 @@ int cliTrayCalcChanged(const char *szChangedProto, int, int) break; iStatus = ProtoCallService(szProto, PS_GETSTATUS, 0, 0); - if (g_StatusBarData.bConnectingIcon && (iStatus >= ID_STATUS_CONNECTING) && (iStatus <= (ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES))) + if (g_StatusBarData.bConnectingIcon && IsStatusConnecting(iStatus)) hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)szProto, 0); else hIcon = pcli->pfnGetIconFromStatusMode(NULL, szProto, ProtoCallService(szProto, PS_GETSTATUS, 0, 0)); @@ -616,7 +615,7 @@ int cliTrayCalcChanged(const char *szChangedProto, int, int) case TRAY_ICON_MODE_CYCLE: iStatus = ProtoCallService(szChangedProto, PS_GETSTATUS, 0, 0); - if (g_StatusBarData.bConnectingIcon && (iStatus >= ID_STATUS_CONNECTING) && (iStatus <= (ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES))) + if (g_StatusBarData.bConnectingIcon && IsStatusConnecting(iStatus)) hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)szChangedProto, 0); else if (!bConn) hIcon = pcli->pfnGetIconFromStatusMode(NULL, szChangedProto, ProtoCallService(szChangedProto, PS_GETSTATUS, 0, 0)); @@ -630,7 +629,7 @@ int cliTrayCalcChanged(const char *szChangedProto, int, int) break; iStatus = ProtoCallService(szChangedProto, PS_GETSTATUS, 0, 0); - if (g_StatusBarData.bConnectingIcon && (iStatus >= ID_STATUS_CONNECTING) && (iStatus <= (ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES))) + if (g_StatusBarData.bConnectingIcon && IsStatusConnecting(iStatus)) hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)szChangedProto, 0); else hIcon = pcli->pfnGetIconFromStatusMode(NULL, szChangedProto, ProtoCallService(szChangedProto, PS_GETSTATUS, 0, 0)); diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp index 82f1250257..f4957bd96a 100644 --- a/plugins/Clist_modern/src/modern_clui.cpp +++ b/plugins/Clist_modern/src/modern_clui.cpp @@ -2012,7 +2012,7 @@ LRESULT CLUI::OnStatusBarUpdateTimer(UINT msg, WPARAM wParam, LPARAM lParam) else status = CallProtoService(pt->szProto, PS_GETSTATUS, 0, 0); - if (!(status >= ID_STATUS_CONNECTING && status <= ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + if (!IsStatusConnecting(status)) { pt->nCycleStartTick = 0; ImageList_Destroy(pt->himlIconList); pt->himlIconList = NULL; diff --git a/plugins/SimpleStatusMsg/src/main.cpp b/plugins/SimpleStatusMsg/src/main.cpp index 6925b4f189..dba1c45e3a 100644 --- a/plugins/SimpleStatusMsg/src/main.cpp +++ b/plugins/SimpleStatusMsg/src/main.cpp @@ -1192,7 +1192,7 @@ static int ProcessProtoAck(WPARAM wParam,LPARAM lParam) if (ack->type != ACKTYPE_STATUS || ack->result != ACKRESULT_SUCCESS || ack->hContact != NULL) return 0; - if (ack->lParam >= ID_STATUS_CONNECTING && ack->lParam < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) + if (IsStatusConnecting(ack->lParam)) ack->lParam = ID_STATUS_OFFLINE; SaveStatusAsCurrent(ack->szModule, (int)ack->lParam); diff --git a/plugins/StatusPlugins/KeepStatus/keepstatus.cpp b/plugins/StatusPlugins/KeepStatus/keepstatus.cpp index 81461cba9b..bb4ff2f96c 100644 --- a/plugins/StatusPlugins/KeepStatus/keepstatus.cpp +++ b/plugins/StatusPlugins/KeepStatus/keepstatus.cpp @@ -605,7 +605,7 @@ static VOID CALLBACK CheckConnectingTimer(HWND, UINT, UINT_PTR, DWORD) TConnectionSettings& cs = connectionSettings[i]; int curStatus = GetStatus(cs); - if (curStatus < MAX_CONNECT_RETRIES) { // connecting + if (IsStatusConnecting(curStatus)) { // connecting maxConnectingTime = db_get_dw(NULL, MODULENAME, SETTING_MAXCONNECTINGTIME, 0); if (maxConnectingTime > 0) { if ((unsigned int)maxConnectingTime <= ((GetTickCount() - cs.lastStatusAckTime) / 1000)) { @@ -633,7 +633,7 @@ static VOID CALLBACK CheckAckStatusTimer(HWND, UINT, UINT_PTR, DWORD) if (curStatus == ID_STATUS_CURRENT || curStatus == ID_STATUS_DISABLED || curStatus == newStatus || newStatus > MAX_STATUS) continue; - if (newStatus < MAX_CONNECT_RETRIES) { // connecting + if (IsStatusConnecting(newStatus)) { // connecting maxConnectingTime = db_get_dw(NULL, MODULENAME, SETTING_MAXCONNECTINGTIME, 0); if (maxConnectingTime > 0) StartTimer(IDT_CHECKCONNECTING, (maxConnectingTime * 1000 - (GetTickCount() - cs.lastStatusAckTime)), FALSE); @@ -850,7 +850,7 @@ static void CheckContinueslyFunction(void *) if (!IsSuitableProto(protos[i])) continue; - if (CallProtoService(protos[i]->szModuleName, PS_GETSTATUS, 0, 0) < MAX_CONNECT_RETRIES) { + if (IsStatusConnecting(CallProtoService(protos[i]->szModuleName, PS_GETSTATUS, 0, 0))) { log_debugA("CheckContinueslyFunction: %s is connecting", protos[i]->szModuleName); continue; // connecting, leave alone } diff --git a/plugins/StatusPlugins/commonstatus.cpp b/plugins/StatusPlugins/commonstatus.cpp index 573ae414ae..1ff0f978de 100644 --- a/plugins/StatusPlugins/commonstatus.cpp +++ b/plugins/StatusPlugins/commonstatus.cpp @@ -233,7 +233,8 @@ INT_PTR SetStatusEx(WPARAM wParam, LPARAM) int oldstatus = CallProtoService(szProto, PS_GETSTATUS, 0, 0); // set last status protoSettings[i]->lastStatus = oldstatus; - if (oldstatus <= MAX_CONNECT_RETRIES) {// ignore if connecting, but it didn't came this far if it did + if (IsStatusConnecting(oldstatus)) { + // ignore if connecting, but it didn't came this far if it did log_debugA("CommonStatus: %s is already connecting", szProto); continue; } diff --git a/plugins/StopSpamPlus/src/services.cpp b/plugins/StopSpamPlus/src/services.cpp index 2ff1a25d8b..9e9145f2b6 100644 --- a/plugins/StopSpamPlus/src/services.cpp +++ b/plugins/StopSpamPlus/src/services.cpp @@ -34,7 +34,7 @@ INT_PTR RemoveTempContacts(WPARAM wParam,LPARAM lParam) DWORD caps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0); if (caps & PF1_SERVERCLIST) { int status = CallProtoService(szProto, PS_GETSTATUS, 0, 0); - if (status == ID_STATUS_OFFLINE || (status >= ID_STATUS_CONNECTING && status < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) + if (status == ID_STATUS_OFFLINE || IsStatusConnecting(status)) // Set a flag so we remember to delete the contact when the protocol goes online the next time db_set_b( hContact, "CList", "Delete", 1 ); else diff --git a/protocols/AimOscar/src/links.cpp b/protocols/AimOscar/src/links.cpp index b1c954d413..12f69bd9fc 100644 --- a/protocols/AimOscar/src/links.cpp +++ b/protocols/AimOscar/src/links.cpp @@ -77,7 +77,7 @@ static INT_PTR ServiceParseAimLink(WPARAM,LPARAM lParam) CAimProto *proto = &g_Instances[0]; for (int i = 0; i < g_Instances.getCount(); ++i) { - if (g_Instances[i].m_iStatus != ID_STATUS_OFFLINE && g_Instances[i].m_iStatus != ID_STATUS_CONNECTING) + if (g_Instances[i].m_iStatus != ID_STATUS_OFFLINE && !IsStatusConnecting(g_Instances[i].m_iStatus)) { proto = &g_Instances[i]; break; diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index b93b55c489..fc6e0612b7 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -1117,7 +1117,7 @@ int __cdecl CJabberProto::SetStatus(int iNewStatus) m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } - else if (!m_ThreadInfo && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + else if (!m_ThreadInfo && !IsStatusConnecting(m_iStatus)) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); ForkThread((MyThreadFunc)&CJabberProto::ServerThread, NULL); diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index aed8f64e50..c01442fa26 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -56,7 +56,7 @@ void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } else if (pReq->bIsMainConn) { - if (m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) + if (IsStatusConnecting(m_iStatus)) ConnectionFailed(LOGINERR_NONETWORK); else if (pReq->m_iRetry && !m_bTerminated) { pReq->bNeedsRestart = true; diff --git a/protocols/VKontakte/src/vk_status.cpp b/protocols/VKontakte/src/vk_status.cpp index 6e9670e13d..e7d6ee7cc6 100644 --- a/protocols/VKontakte/src/vk_status.cpp +++ b/protocols/VKontakte/src/vk_status.cpp @@ -37,7 +37,7 @@ int CVkProto::SetStatus(int iNewStatus) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); debugLogA("CVkProto::SetStatus (1) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus); } - else if (m_hWorkerThread == NULL && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + else if (m_hWorkerThread == NULL && !IsStatusConnecting(m_iStatus)) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); debugLogA("CVkProto::SetStatus (2) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus); @@ -50,7 +50,7 @@ int CVkProto::SetStatus(int iNewStatus) else { debugLogA("CVkProto::SetStatus (4) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus); ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - if (!(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) + if (!IsStatusConnecting(m_iStatus)) m_iDesiredStatus = m_iStatus; debugLogA("CVkProto::SetStatus (5) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus); } diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index c91b72dcc5..2b5c275981 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -137,7 +137,7 @@ int WhatsAppProto::SetStatus(int new_status) m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } - else if (m_pSocket == NULL && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + else if (m_pSocket == NULL && !IsStatusConnecting(m_iStatus)) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); diff --git a/src/modules/clist/clistmod.cpp b/src/modules/clist/clistmod.cpp index 74d4a38aa8..8c5ef09b82 100644 --- a/src/modules/clist/clistmod.cpp +++ b/src/modules/clist/clistmod.cpp @@ -101,9 +101,9 @@ TCHAR* fnGetStatusModeDescription(int mode, int flags) descr = LPGENT("Idle"); break; default: - if (mode > ID_STATUS_CONNECTING && mode < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) { + if (IsStatusConnecting(mode)) { const TCHAR* connFmt = LPGENT("Connecting (attempt %d)"); - mir_sntprintf(szMode, SIZEOF(szMode), (flags&GSMDF_UNTRANSLATED)?connFmt:TranslateTS(connFmt), mode - ID_STATUS_CONNECTING + 1); + mir_sntprintf(szMode, SIZEOF(szMode), (flags & GSMDF_UNTRANSLATED) ? connFmt : TranslateTS(connFmt), mode - ID_STATUS_CONNECTING + 1); return szMode; } return NULL; @@ -114,7 +114,7 @@ TCHAR* fnGetStatusModeDescription(int mode, int flags) static INT_PTR GetStatusModeDescription(WPARAM wParam, LPARAM lParam) { - TCHAR* buf1 = cli.pfnGetStatusModeDescription(wParam, lParam); + TCHAR *buf1 = cli.pfnGetStatusModeDescription(wParam, lParam); if (!(lParam & GSMDF_TCHAR)) { static char szMode[64]; diff --git a/src/modules/clist/clui.cpp b/src/modules/clist/clui.cpp index 74afdda313..c330fdc95f 100644 --- a/src/modules/clist/clui.cpp +++ b/src/modules/clist/clui.cpp @@ -182,7 +182,7 @@ static INT_PTR MenuItem_DeleteContact(WPARAM wParam, LPARAM lParam) DWORD caps = CallProtoServiceInt(NULL, szProto, PS_GETCAPS, PFLAGNUM_1, 0); if (caps & PF1_SERVERCLIST) { int status = CallProtoServiceInt(NULL, szProto, PS_GETSTATUS, 0, 0); - if (status == ID_STATUS_OFFLINE || (status >= ID_STATUS_CONNECTING && status < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + if (status == ID_STATUS_OFFLINE || IsStatusConnecting(status)) { // Set a flag so we remember to delete the contact when the protocol goes online the next time db_set_b(wParam, "CList", "Delete", 1); MessageBox(NULL, diff --git a/src/modules/skin/skinicons.cpp b/src/modules/skin/skinicons.cpp index 048322bc49..d7c2884f14 100644 --- a/src/modules/skin/skinicons.cpp +++ b/src/modules/skin/skinicons.cpp @@ -233,7 +233,7 @@ HICON LoadSkinProtoIcon(const char *szProto, int status, bool big) else if ((caps2 = CallProtoServiceInt(NULL,szProto, PS_GETCAPS, PFLAGNUM_2, 0)) == CALLSERVICE_NOTFOUND) caps2 = 0; - if (status >= ID_STATUS_CONNECTING && status < ID_STATUS_CONNECTING+MAX_CONNECT_RETRIES) { + if (IsStatusConnecting(status)) { mir_snprintf(iconName, SIZEOF(iconName), "%s%d", mainIconsFmt, 7); return IcoLib_GetIcon(iconName, big); } -- cgit v1.2.3