From ebc91d7be8f31d98822b896852e40c341b614a48 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 14 Aug 2015 11:04:04 +0000 Subject: SkypeWeb: Async polling processing, more optimizations git-svn-id: http://svn.miranda-ng.org/main/trunk@14951 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_polling.cpp | 31 +++++++++++++++---------------- protocols/SkypeWeb/src/skype_proto.h | 22 ++++++++++++---------- protocols/SkypeWeb/src/skype_utils.cpp | 5 ----- 3 files changed, 27 insertions(+), 31 deletions(-) (limited to 'protocols') diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 612547b1ee..b1b91a8d6f 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -17,39 +17,40 @@ along with this program. If not, see . #include "stdafx.h" -void CSkypeProto::ParsePollData(const JSONNode &data) +void CSkypeProto::ParsePollData(void *pData) { debugLogA("CSkypeProto::ParsePollData"); + JSONNode data = JSONNode::parse(ptrA((char*)pData)); + if (!data) return; + const JSONNode &node = data["eventMessages"]; - if (!node) - return; + if (!node) return; - const JSONNode &messages = node.as_array(); - for (size_t i = 0; i < messages.size(); i++) + for (auto it = node.begin(); it != node.end(); ++it) { - const JSONNode &message = messages.at(i); + const JSONNode &message = *it; const JSONNode &resType = message["resourceType"]; const JSONNode &resource = message["resource"]; std::string resourceType = resType.as_string(); - if (!mir_strcmpi(resourceType.c_str(), "NewMessage")) + if (resourceType == "NewMessage") { ProcessNewMessageRes(resource); } - else if (!mir_strcmpi(resourceType.c_str(), "UserPresence")) + else if (resourceType == "UserPresence") { ProcessUserPresenceRes(resource); } - else if (!mir_strcmpi(resourceType.c_str(), "EndpointPresence")) + else if (resourceType == "EndpointPresence") { ProcessEndpointPresenceRes(resource); } - else if (!mir_strcmpi(resourceType.c_str(), "ConversationUpdate")) + else if (resourceType == "ConversationUpdate") { ProcessConversationUpdateRes(resource); } - else if (!mir_strcmpi(resourceType.c_str(), "ThreadUpdate")) + else if (resourceType == "ThreadUpdate") { ProcessThreadUpdateRes(resource); } @@ -79,11 +80,9 @@ void CSkypeProto::PollingThread(void*) { if (response->pData) { - JSONNode root = JSONNode::parse(response->pData); - if (root["eventMessages"]) - { - ParsePollData(root); - } + void *pData = mir_alloc(response->dataLength); + memcpy(pData, response->pData, response->dataLength); + ForkThread(&CSkypeProto::ParsePollData, pData); } } else diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index ac07cb4eea..9e70268c7c 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -295,7 +295,7 @@ private: //polling void __cdecl PollingThread(void*); - void ParsePollData(const JSONNode &data); + void __cdecl ParsePollData(void *pData); void ProcessEndpointPresenceRes(const JSONNode &node); void ProcessUserPresenceRes(const JSONNode &node); void ProcessNewMessageRes(const JSONNode &node); @@ -309,15 +309,17 @@ private: { return (m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread); } - bool IsMe(const char *skypeName); + __forceinline bool IsMe(const char *szSkypename) + { return (!mir_strcmpi(szSkypename, m_szSelfSkypeName) || !mir_strcmp(szSkypename, ptrA(getStringA("SelfEndpointName")))); + } MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob); - time_t IsoToUnixTime(const char *stamp); - char *RemoveHtml(const char *text); - CMStringA GetStringChunk(const char *haystack, const char *start, const char *end); + static time_t IsoToUnixTime(const char *stamp); + static char *RemoveHtml(const char *text); + static CMStringA GetStringChunk(const char *haystack, const char *start, const char *end); - int SkypeToMirandaStatus(const char *status); - const char *MirandaToSkypeStatus(int status); + static int SkypeToMirandaStatus(const char *status); + static const char *MirandaToSkypeStatus(int status); void ShowNotification(const TCHAR *message, MCONTACT hContact = NULL); void ShowNotification(const TCHAR *caption, const TCHAR *message, MCONTACT hContact = NULL, int type = 0); @@ -325,12 +327,12 @@ private: static LRESULT CALLBACK PopupDlgProcCall(HWND hPopup, UINT uMsg, WPARAM wParam, LPARAM lParam); - CMStringA ParseUrl(const char *url, const char *token); + static CMStringA ParseUrl(const char *url, const char *token); void SetSrmmReadStatus(MCONTACT hContact); - CMStringA UrlToSkypename(const char *url); - CMStringA GetServerFromUrl(const char *url); + static CMStringA UrlToSkypename(const char *url); + static CMStringA GetServerFromUrl(const char *url); //---Timers void CALLBACK SkypeUnsetTimer(); diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 11e149adbc..756eba91d6 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -418,11 +418,6 @@ char *CSkypeProto::RemoveHtml(const char *text) return mir_strdup(new_string.c_str()); } -bool CSkypeProto::IsMe(const char *skypeName) -{ - return (!mir_strcmpi(skypeName, m_szSelfSkypeName) || !mir_strcmp(skypeName, ptrA(getStringA("SelfEndpointName")))); -} - const char *CSkypeProto::MirandaToSkypeStatus(int status) { switch (status) -- cgit v1.2.3