summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2015-09-23 19:23:39 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2015-09-23 19:23:39 +0000
commit037511a364629d200c22cd08e0fa4922f2429bfc (patch)
tree510680699b0e8eb046b771b9de350b20fd0e7fa8 /protocols/SkypeWeb
parenta8dfca9c4a079c6d9706fa819b8993a2df5d7270 (diff)
SkypeWeb: code optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@15429 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb')
-rw-r--r--protocols/SkypeWeb/src/request_queue.cpp8
-rw-r--r--protocols/SkypeWeb/src/request_queue.h3
-rw-r--r--protocols/SkypeWeb/src/skype_login.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_polling.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp10
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h6
-rw-r--r--protocols/SkypeWeb/src/skype_trouter.cpp8
-rw-r--r--protocols/SkypeWeb/src/skype_utils.h30
8 files changed, 45 insertions, 24 deletions
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp
index 1e8113cfdb..5d6cb2893a 100644
--- a/protocols/SkypeWeb/src/request_queue.cpp
+++ b/protocols/SkypeWeb/src/request_queue.cpp
@@ -22,13 +22,11 @@ hConnection(hConnection), requests(1)
{
isTerminated = true;
hRequestQueueThread = NULL;
- hRequestQueueEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
RequestQueue::~RequestQueue()
{
requests.destroy();
- CloseHandle(hRequestQueueEvent);
}
void RequestQueue::Start()
@@ -47,7 +45,7 @@ void RequestQueue::Stop()
return;
isTerminated = true;
- SetEvent(hRequestQueueEvent);
+ hRequestQueueEvent.Set();
}
void RequestQueue::Push(HttpRequest *request, HttpResponseCallback response, void *arg)
@@ -61,7 +59,7 @@ void RequestQueue::Push(HttpRequest *request, HttpResponseCallback response, voi
requests.insert(item);
}
- SetEvent(hRequestQueueEvent);
+ hRequestQueueEvent.Set();
}
void RequestQueue::Send(HttpRequest *request, HttpResponseCallback response, void *arg)
@@ -96,7 +94,7 @@ unsigned int RequestQueue::WorkerThread(void *arg)
while (!queue->isTerminated)
{
- WaitForSingleObject(queue->hRequestQueueEvent, INFINITE);
+ queue->hRequestQueueEvent.Wait();
while (true)
{
RequestQueueItem *item = NULL;
diff --git a/protocols/SkypeWeb/src/request_queue.h b/protocols/SkypeWeb/src/request_queue.h
index c8e1948819..962a03aef5 100644
--- a/protocols/SkypeWeb/src/request_queue.h
+++ b/protocols/SkypeWeb/src/request_queue.h
@@ -47,7 +47,8 @@ private:
HANDLE hConnection;
mir_cs requestQueueLock;
LIST<RequestQueueItem> requests;
- HANDLE hRequestQueueEvent, hRequestQueueThread;
+ EventHandle hRequestQueueEvent;
+ HANDLE hRequestQueueThread;
void Execute(RequestQueueItem *item);
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp
index 13b6e605fe..467396baae 100644
--- a/protocols/SkypeWeb/src/skype_login.cpp
+++ b/protocols/SkypeWeb/src/skype_login.cpp
@@ -263,7 +263,7 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response)
FreeList(skypenames);
skypenames.destroy();
- SetEvent(m_hPollingEvent);
+ m_hPollingEvent.Set();
SendRequest(new LoadChatsRequest(li), &CSkypeProto::OnLoadChats);
SendRequest(new CreateTrouterRequest(), &CSkypeProto::OnCreateTrouter);
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp
index 423fb399a9..59c167b9cc 100644
--- a/protocols/SkypeWeb/src/skype_polling.cpp
+++ b/protocols/SkypeWeb/src/skype_polling.cpp
@@ -24,7 +24,7 @@ void CSkypeProto::PollingThread(void*)
int nErrors = 0;
while (!m_bThreadsTerminated)
{
- WaitForSingleObject(m_hPollingEvent, INFINITE);
+ m_hPollingEvent.Wait();
nErrors = 0;
while ((nErrors < POLLING_ERRORS_LIMIT) && m_iStatus != ID_STATUS_OFFLINE)
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp
index d8b5c823b4..54d443256e 100644
--- a/protocols/SkypeWeb/src/skype_proto.cpp
+++ b/protocols/SkypeWeb/src/skype_proto.cpp
@@ -46,10 +46,6 @@ CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) :
SkinAddNewSoundEx("skype_inc_call", "SkypeWeb", LPGEN("Incoming call sound"));
SkinAddNewSoundEx("skype_call_canceled", "SkypeWeb", LPGEN("Incoming call canceled sound"));
- m_hTrouterEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hPollingEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hTrouterHealthEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-
SkypeSetTimer();
m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, NULL, NULL);
@@ -69,16 +65,12 @@ CSkypeProto::~CSkypeProto()
TerminateThread(m_hPollingThread, NULL);
m_hPollingThread = NULL;
}
- CloseHandle(m_hPollingEvent); m_hPollingEvent = NULL;
if (m_hTrouterThread)
{
TerminateThread(m_hTrouterThread, NULL);
m_hTrouterThread = NULL;
}
- CloseHandle(m_hTrouterEvent); m_hTrouterEvent = NULL;
-
- CloseHandle(m_hTrouterHealthEvent);
SkypeUnsetTimer();
}
@@ -93,7 +85,7 @@ int CSkypeProto::OnPreShutdown(WPARAM, LPARAM)
ShutdownConnections();
- SetEvent(m_hPollingEvent);
+ m_hPollingEvent.Set();
return 0;
}
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 2edf1a3ac4..cb53e1690f 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -126,10 +126,10 @@ private:
bool m_bThreadsTerminated;
- HANDLE m_hPollingEvent;
- HANDLE m_hTrouterEvent;
+ EventHandle m_hPollingEvent;
+ EventHandle m_hTrouterEvent;
- HANDLE m_hTrouterHealthEvent;
+ EventHandle m_hTrouterHealthEvent;
static CSkypeProto* GetContactAccount(MCONTACT hContact);
int __cdecl OnAccountLoaded(WPARAM, LPARAM);
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp
index d53ce95b0f..68ec568c24 100644
--- a/protocols/SkypeWeb/src/skype_trouter.cpp
+++ b/protocols/SkypeWeb/src/skype_trouter.cpp
@@ -104,8 +104,8 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response)
CMStringA szToken = data.Tokenize(":", iStart).Trim();
TRouter.sessId = szToken.GetString();
- SetEvent(m_hTrouterEvent);
- SetEvent(m_hTrouterHealthEvent);
+ m_hTrouterEvent.Set();
+ m_hTrouterHealthEvent.Set();
if ((time(NULL) - TRouter.lastRegistrationTime) >= 3600)
{
@@ -136,7 +136,7 @@ void CSkypeProto::TRouterThread(void*)
while (!m_bThreadsTerminated)
{
- WaitForSingleObject(m_hTrouterEvent, INFINITE);
+ m_hTrouterEvent.Wait();
errors = 0;
while (errors < POLLING_ERRORS_LIMIT && m_iStatus > ID_STATUS_OFFLINE)
@@ -169,7 +169,7 @@ void CSkypeProto::TRouterThread(void*)
else
{
SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth);
- WaitForSingleObject(m_hTrouterHealthEvent, INFINITE);
+ m_hTrouterHealthEvent.Wait();
}
m_TrouterConnection = response->nlc;
}
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h
index b50b65546a..1a608bce47 100644
--- a/protocols/SkypeWeb/src/skype_utils.h
+++ b/protocols/SkypeWeb/src/skype_utils.h
@@ -76,5 +76,35 @@ public:
__inline char *get_reason() { return mir_strdup(szReason); }
};
+class EventHandle
+{
+ HANDLE _hEvent;
+public:
+ inline EventHandle()
+ {
+ _hEvent = CreateEvent(NULL, 0, 0, NULL);
+ }
+ inline ~EventHandle()
+ {
+ CloseHandle(_hEvent);
+ }
+ inline void Set()
+ {
+ SetEvent(_hEvent);
+ }
+ inline void Wait()
+ {
+ WaitForSingleObject(_hEvent, INFINITE);
+ }
+ inline void Wait(DWORD dwMilliseconds)
+ {
+ WaitForSingleObject(_hEvent, dwMilliseconds);
+ }
+ inline operator HANDLE()
+ {
+ return _hEvent;
+ }
+};
+
#endif //_UTILS_H_ \ No newline at end of file