diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-05 21:46:05 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-05 21:46:05 +0000 |
commit | b8283f989e1d0a5d623f7f57c89c1499618158c4 (patch) | |
tree | f096e09089027b5e1f85669359c8117865f3a570 /protocols/VKontakte | |
parent | 3a686f86c91cb428e6c8f4534f7d2b72054ecf38 (diff) |
VK:
- SetStatus implementation;
- worker thread
git-svn-id: http://svn.miranda-ng.org/main/trunk@6360 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 5 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 60 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 12 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 37 | ||||
-rw-r--r-- | protocols/VKontakte/vk_10.vcxproj | 1 | ||||
-rw-r--r-- | protocols/VKontakte/vk_10.vcxproj.filters | 3 | ||||
-rw-r--r-- | protocols/VKontakte/vk_11.vcxproj | 1 | ||||
-rw-r--r-- | protocols/VKontakte/vk_11.vcxproj.filters | 3 |
8 files changed, 103 insertions, 19 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index dba3de5535..0802d73405 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -26,3 +26,8 @@ TCHAR* CVkProto::GetUserStoredPassword() }
return NULL;
}
+
+int CVkProto::SetServerStatus(int iStatus)
+{
+ return 0;
+}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index ebc47f8516..fe308aff71 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -71,11 +71,51 @@ DWORD_PTR CVkProto::GetCaps(int type, HANDLE hContact) //////////////////////////////////////////////////////////////////////////////
-int CVkProto::SetStatus(int new_status)
+int CVkProto::SetStatus(int iNewStatus)
{
+ if (m_iDesiredStatus == iNewStatus)
+ return 0;
+
+ int oldStatus = m_iStatus;
+ 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)) {
+ m_iStatus = ID_STATUS_CONNECTING;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ ForkThread(&CVkProto::WorkerThread, 0);
+ }
+ else if ( IsOnline())
+ SetServerStatus(iNewStatus);
+ else
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
return 0;
}
+//////////////////////////////////////////////////////////////////////////////
+
+int CVkProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam)
+{
+ switch(event) {
+ case EV_PROTO_ONLOAD:
+ return OnModulesLoaded(wParam,lParam);
+
+ case EV_PROTO_ONEXIT:
+ return OnPreShutdown(wParam,lParam);
+
+ case EV_PROTO_ONOPTIONS:
+ return OnOptionsInit(wParam,lParam);
+ }
+
+ return 1;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
HANDLE CVkProto::SearchBasic(const PROTOCHAR* id)
{
return 0;
@@ -229,21 +269,3 @@ int CVkProto::SetAwayMsg(int status, const PROTOCHAR *msg) {
return 0; // Status messages are disabled
}
-
-//////////////////////////////////////////////////////////////////////////////
-
-int CVkProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam)
-{
- switch(event) {
- case EV_PROTO_ONLOAD:
- return OnModulesLoaded(wParam,lParam);
-
- case EV_PROTO_ONEXIT:
- return OnPreShutdown(wParam,lParam);
-
- case EV_PROTO_ONOPTIONS:
- return OnOptionsInit(wParam,lParam);
- }
-
- return 1;
-}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 9000017dee..cc1d82884c 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -82,4 +82,16 @@ struct CVkProto : public PROTO<CVkProto> //==== Misc ==========================================================================
TCHAR* GetUserStoredPassword(void);
+
+ __forceinline bool IsOnline() const { return m_bOnline; }
+
+ void ShutdownSession();
+ void OnLoggedOut();
+ void __cdecl WorkerThread(void*);
+
+private:
+ int SetServerStatus(int);
+
+ bool m_bOnline;
+ UINT m_hWorkerThread;
};
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp new file mode 100644 index 0000000000..dea822ec83 --- /dev/null +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -0,0 +1,37 @@ +/*
+Copyright (C) 2013 Miranda NG Project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+void CVkProto::ShutdownSession()
+{
+ OnLoggedOut();
+}
+
+void CVkProto::OnLoggedOut()
+{
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, ID_STATUS_OFFLINE);
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+}
+
+void CVkProto::WorkerThread(void*)
+{
+ m_hWorkerThread = GetCurrentThreadId();
+
+ OnLoggedOut();
+ m_hWorkerThread = 0;
+}
diff --git a/protocols/VKontakte/vk_10.vcxproj b/protocols/VKontakte/vk_10.vcxproj index 731d00cb26..721069ae12 100644 --- a/protocols/VKontakte/vk_10.vcxproj +++ b/protocols/VKontakte/vk_10.vcxproj @@ -176,6 +176,7 @@ </ClCompile>
<ClCompile Include="src\vk_options.cpp" />
<ClCompile Include="src\vk_proto.cpp" />
+ <ClCompile Include="src\vk_thread.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\resource.h" />
diff --git a/protocols/VKontakte/vk_10.vcxproj.filters b/protocols/VKontakte/vk_10.vcxproj.filters index 91b996d16d..eaf30d69b3 100644 --- a/protocols/VKontakte/vk_10.vcxproj.filters +++ b/protocols/VKontakte/vk_10.vcxproj.filters @@ -30,6 +30,9 @@ <ClCompile Include="src\misc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\vk_thread.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\resource.h">
diff --git a/protocols/VKontakte/vk_11.vcxproj b/protocols/VKontakte/vk_11.vcxproj index 1e4eccda74..b4ec687c4c 100644 --- a/protocols/VKontakte/vk_11.vcxproj +++ b/protocols/VKontakte/vk_11.vcxproj @@ -179,6 +179,7 @@ </ClCompile>
<ClCompile Include="src\vk_options.cpp" />
<ClCompile Include="src\vk_proto.cpp" />
+ <ClCompile Include="src\vk_thread.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\stdafx.h" />
diff --git a/protocols/VKontakte/vk_11.vcxproj.filters b/protocols/VKontakte/vk_11.vcxproj.filters index 1e2a6fa2c9..de21e62729 100644 --- a/protocols/VKontakte/vk_11.vcxproj.filters +++ b/protocols/VKontakte/vk_11.vcxproj.filters @@ -30,6 +30,9 @@ <ClCompile Include="src\misc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\vk_thread.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\version.h">
|