From 74bbe14fb8a018a65f89d28386eb3e88edfd0516 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 6 Oct 2013 13:17:00 +0000 Subject: VK: async http requests git-svn-id: http://svn.miranda-ng.org/main/trunk@6373 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/vk_proto.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'protocols/VKontakte/src/vk_proto.cpp') diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index fe308aff71..d2e213e998 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -18,13 +18,33 @@ along with this program. If not, see . #include "stdafx.h" CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : - PROTO(szModuleName, ptszUserName) + PROTO(szModuleName, ptszUserName), + m_arRequestsQueue(10) { + InitQueue(); + CreateProtoService(PS_CREATEACCMGRUI, &CVkProto::SvcCreateAccMgrUI); + + TCHAR descr[512]; + mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s server connection"), m_tszUserName); + + NETLIBUSER nlu = {sizeof(nlu)}; + nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; + nlu.szSettingsModule = m_szModuleName; + nlu.szSettingsModule = m_szModuleName; + nlu.ptszDescriptiveName = descr; + m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + + mir_sntprintf(descr, SIZEOF(descr), _T("%%miranda_avatarcache%%\\%s"), m_tszUserName); + hAvatarFolder = FoldersRegisterCustomPathT(LPGEN("Avatars"), m_szModuleName, descr, m_tszUserName); + + // Set all contacts offline -- in case we crashed + SetAllContactStatuses(ID_STATUS_OFFLINE); } CVkProto::~CVkProto() { + UninitQueue(); } int CVkProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam) @@ -34,6 +54,8 @@ int CVkProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam) int CVkProto::OnPreShutdown(WPARAM wParam, LPARAM lParam) { + m_bTerminated = true; + SetEvent(m_evRequestsQueue); return 0; } @@ -77,17 +99,19 @@ int CVkProto::SetStatus(int iNewStatus) return 0; int oldStatus = m_iStatus; - if (iNewStatus == ID_STATUS_OFFLINE) { + m_iDesiredStatus = iNewStatus; + + if (iNewStatus == ID_STATUS_OFFLINE) { if ( IsOnline()) ShutdownSession(); m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); } - else if (!m_hWorkerThread && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { + else if ( !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); - ForkThread(&CVkProto::WorkerThread, 0); + m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL); } else if ( IsOnline()) SetServerStatus(iNewStatus); -- cgit v1.2.3