diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-04 21:02:56 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-04 21:02:56 +0300 |
commit | 1b89cbba1f3bc00ea24a8414b2e670c582ac5fc4 (patch) | |
tree | 76ac43351cbbdbece75774d6f7bbf1e89b6cdca8 | |
parent | 5b32a855e518f67589fd49837795a605a19badce (diff) |
Facebook: switch to mir_cs instead of custom lock
-rw-r--r-- | protocols/FacebookRM/src/avatars.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/client.h | 27 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 11 | ||||
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 11 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 29 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 8 | ||||
-rw-r--r-- | protocols/FacebookRM/src/stdafx.h | 22 |
9 files changed, 36 insertions, 84 deletions
diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index 91837ce2d8..25163a3797 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -112,7 +112,7 @@ void FacebookProto::UpdateAvatarWorker(void *) CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName);
}
- ScopedLock s(avatar_lock_);
+ mir_cslock s(avatar_lock_);
avatar_queue.erase(avatar_queue.begin());
if (avatar_queue.empty())
break;
@@ -185,7 +185,7 @@ INT_PTR FacebookProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam) if (needLoad) {
debugLogA("*** Starting avatar request thread for %s", _T2A(pai->filename));
- ScopedLock s(avatar_lock_);
+ mir_cslock s(avatar_lock_);
if (std::find(avatar_queue.begin(), avatar_queue.end(), pai->hContact) == avatar_queue.end()) {
bool is_empty = avatar_queue.empty();
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 3ece37c27e..2b3157617c 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -38,7 +38,6 @@ public: {
msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = chat_msgs_recv_ = chat_req_ = 0;
- send_message_lock_ = notifications_lock_ = cookies_lock_ = loading_history_lock_ = nullptr;
hChannelCon = nullptr;
hMessagesCon = nullptr;
hFcbCon = nullptr;
@@ -61,11 +60,11 @@ public: // Parent handle
- FacebookProto* parent;
+ FacebookProto *parent;
// User data
- facebook_user self_;
+ facebook_user self_;
std::string username_;
std::string password_;
@@ -100,7 +99,7 @@ public: ////////////////////////////////////////////////////////////
// Cookies, Data storage
- HANDLE cookies_lock_;
+ mir_cs cookies_lock_;
std::map<std::string, std::string> cookies;
std::map<std::string, std::string> pages;
@@ -165,24 +164,22 @@ public: ////////////////////////////////////////////////////////////
// Login handling
- bool login(const char *username, const char *password);
- bool logout();
- bool sms_code(const char *fb_dtsg);
-
- const std::string & get_username() const;
+ bool login(const char *username, const char *password);
+ bool logout();
+ bool sms_code(const char *fb_dtsg);
////////////////////////////////////////////////////////////
// Session handling
- bool home();
- bool reconnect();
- bool chat_state(bool online = true);
+ bool home();
+ bool reconnect();
+ bool chat_state(bool online = true);
////////////////////////////////////////////////////////////
// Updates handling
- HANDLE send_message_lock_;
- HANDLE notifications_lock_;
+ mir_cs send_message_lock_;
+ mir_cs notifications_lock_;
////////////////////////////////////////////////////////////
// Messages handling
@@ -191,7 +188,7 @@ public: std::map<int, time_t> messages_timestamp;
bool loading_history;
- HANDLE loading_history_lock_;
+ mir_cs loading_history_lock_;
bool channel();
bool activity_ping();
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index f07674b258..8b987063d9 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -215,7 +215,7 @@ std::string facebook_client::get_privacy_type() char* facebook_client::load_cookies() { - ScopedLock s(cookies_lock_); + mir_cslock s(cookies_lock_); std::string cookieString; @@ -232,7 +232,7 @@ char* facebook_client::load_cookies() void facebook_client::store_headers(http::response* resp, NETLIBHTTPHEADER* headers, int headersCount) { - ScopedLock c(cookies_lock_); + mir_cslock c(cookies_lock_); for (int i = 0; i < headersCount; i++) { std::string header_name = headers[i].szName; @@ -254,7 +254,7 @@ void facebook_client::store_headers(http::response* resp, NETLIBHTTPHEADER* head void facebook_client::clear_cookies() { - ScopedLock s(cookies_lock_); + mir_cslock s(cookies_lock_); if (!cookies.empty()) cookies.clear(); @@ -262,7 +262,7 @@ void facebook_client::clear_cookies() void facebook_client::clear_notifications() { - ScopedLock s(notifications_lock_); + mir_cslock s(notifications_lock_); for (auto &it : notifications) { if (it.second->hWndPopup != nullptr) @@ -989,7 +989,8 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin http::response resp; { HttpRequest *request = new SendMessageRequest(this, userId, threadId, messageId.c_str(), message_text.c_str(), isChatRoom, captcha.c_str(), captcha_persist_data.c_str()); - ScopedLock s(send_message_lock_); + + mir_cslock s(send_message_lock_); resp = sendRequest(request); *error_text = resp.error_text; diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 801e091a90..b99ab28544 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void FacebookProto::ChangeStatus(void*) { - ScopedLock s(signon_lock_); + mir_cslock s(signon_lock_); int new_status = m_iDesiredStatus; int old_status = m_iStatus; @@ -34,7 +34,7 @@ void FacebookProto::ChangeStatus(void*) debugLogA("### Beginning SignOff process"); m_signingOut = true; - SetEvent(update_loop_lock_); + SetEvent(update_loop_event); // Shutdown and close channel handle Netlib_Shutdown(facy.hChannelCon); @@ -84,7 +84,6 @@ void FacebookProto::ChangeStatus(void*) m_signingOut = false; debugLogA("### SignOff complete"); - return; } else if (old_status == ID_STATUS_OFFLINE) { @@ -100,7 +99,7 @@ void FacebookProto::ChangeStatus(void*) m_iStatus = facy.self_.status_id = ID_STATUS_CONNECTING; ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); - ResetEvent(update_loop_lock_); + ResetEvent(update_loop_event); // Workaround for not working "mbasic." for some users - reset this flag at every login facy.mbasicWorks = true; @@ -227,12 +226,12 @@ void FacebookProto::UpdateLoop(void *) ProcessFeeds(nullptr); debugLogA("*** FacebookProto::UpdateLoop[%d] going to sleep...", tim); - if (WaitForSingleObjectEx(update_loop_lock_, GetPollRate() * 1000, true) != WAIT_TIMEOUT) + if (WaitForSingleObjectEx(update_loop_event, GetPollRate() * 1000, true) != WAIT_TIMEOUT) break; debugLogA("*** FacebookProto::UpdateLoop[%d] waking up...", tim); } - ResetEvent(update_loop_lock_); + ResetEvent(update_loop_event); debugLogA("<<< Exiting FacebookProto::UpdateLoop[%d]", tim); } diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 5ce92f5441..8ed8d5f5b7 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -249,7 +249,7 @@ int FacebookProto::ParseNotifications(std::string *data, std::map< std::string, bool FacebookProto::IgnoreDuplicates(const std::string &mid) { - ScopedLock s(facy.send_message_lock_); + mir_cslock s(facy.send_message_lock_); std::map<std::string, int>::iterator it = facy.messages_ignore.find(mid); if (it != facy.messages_ignore.end()) { @@ -996,7 +996,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag NotifyEvent(m_tszUserName, ptrW(mir_utf8decodeW(text.c_str())), hContact, EVENT_TICKER, &url); } else if (t == "notifications_read" || t == "notifications_seen") { // revised 5.3.2017 - ScopedLock s(facy.notifications_lock_); + mir_cslock s(facy.notifications_lock_); const JSONNode &alerts = it["alert_ids"]; for (auto &itAlerts : alerts) { diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index cfbcdeec99..0aa29b9639 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -326,7 +326,7 @@ void FacebookProto::LoadHistory(void *pParam) MCONTACT hContact = *(MCONTACT*)pParam; delete (MCONTACT*)pParam; - ScopedLock s(facy.loading_history_lock_); + mir_cslock s(facy.loading_history_lock_); // Allow loading history only from one contact at a time if (!isOnline() || facy.loading_history) @@ -951,7 +951,7 @@ void FacebookProto::ProcessMessages(void* data) void FacebookProto::ShowNotifications() { - ScopedLock s(facy.notifications_lock_); + mir_cslock s(facy.notifications_lock_); // Show popups for unseen notifications and/or write them to chatroom for (auto &it : facy.notifications) { diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index f46b558c63..e2fde204d4 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -28,15 +28,7 @@ FacebookProto::FacebookProto(const char* proto_name, const wchar_t* username) : { facy.parent = this; - signon_lock_ = CreateMutex(nullptr, FALSE, nullptr); - avatar_lock_ = CreateMutex(nullptr, FALSE, nullptr); - log_lock_ = CreateMutex(nullptr, FALSE, nullptr); - update_loop_lock_ = CreateEvent(nullptr, FALSE, FALSE, nullptr); - facy.send_message_lock_ = CreateMutex(nullptr, FALSE, nullptr); - facy.fcb_conn_lock_ = CreateMutex(nullptr, FALSE, nullptr); - facy.notifications_lock_ = CreateMutex(nullptr, FALSE, nullptr); - facy.cookies_lock_ = CreateMutex(nullptr, FALSE, nullptr); - facy.loading_history_lock_ = CreateMutex(nullptr, FALSE, nullptr); + update_loop_event = CreateEvent(nullptr, FALSE, FALSE, nullptr); // Initialize random seed for this client facy.random_ = ::time(nullptr) + PtrToUint(&facy); @@ -122,23 +114,8 @@ FacebookProto::~FacebookProto() Netlib_CloseHandle(m_hNetlibUser); - WaitForSingleObject(signon_lock_, IGNORE); - WaitForSingleObject(avatar_lock_, IGNORE); - WaitForSingleObject(log_lock_, IGNORE); - WaitForSingleObject(facy.send_message_lock_, IGNORE); - WaitForSingleObject(facy.notifications_lock_, IGNORE); - WaitForSingleObject(facy.cookies_lock_, IGNORE); - WaitForSingleObject(facy.loading_history_lock_, IGNORE); - - CloseHandle(signon_lock_); - CloseHandle(avatar_lock_); - CloseHandle(log_lock_); - CloseHandle(update_loop_lock_); - CloseHandle(facy.send_message_lock_); - CloseHandle(facy.fcb_conn_lock_); - CloseHandle(facy.notifications_lock_); - CloseHandle(facy.cookies_lock_); - CloseHandle(facy.loading_history_lock_); + WaitForSingleObject(update_loop_event, INFINITE); + CloseHandle(update_loop_event); } ////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index db29bf6617..7a004640e8 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -264,10 +264,10 @@ public: HGENMENU m_hStatusMind; // Locks - HANDLE signon_lock_; - HANDLE avatar_lock_; - HANDLE log_lock_; - HANDLE update_loop_lock_; + mir_cs signon_lock_; + mir_cs avatar_lock_; + mir_cs log_lock_; + HANDLE update_loop_event; ptrW m_tszDefaultGroup; diff --git a/protocols/FacebookRM/src/stdafx.h b/protocols/FacebookRM/src/stdafx.h index 83f39e24e6..83efa47cf7 100644 --- a/protocols/FacebookRM/src/stdafx.h +++ b/protocols/FacebookRM/src/stdafx.h @@ -83,28 +83,6 @@ extern HINSTANCE g_hInstance; extern std::string g_strUserAgent;
extern DWORD g_mirandaVersion;
-class ScopedLock
-{
-public:
- ScopedLock(HANDLE h, int t = INFINITE) : handle_(h), timeout_(t)
- {
- WaitForSingleObject(handle_,timeout_);
- }
- ~ScopedLock()
- {
- if(handle_)
- ReleaseMutex(handle_);
- }
- void Unlock()
- {
- ReleaseMutex(handle_);
- handle_ = 0;
- }
-private:
- HANDLE handle_;
- int timeout_;
-};
-
template <typename T>
__inline static void FreeList(const LIST<T> &lst)
{
|