From 42dcdb26ad220c6d95c0b13d9b4c323511454bcf Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 31 Oct 2010 15:52:16 +0200 Subject: fixed cleanup threads --- utilities.cpp | 63 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'utilities.cpp') diff --git a/utilities.cpp b/utilities.cpp index 7b6657d..02ef0ba 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -379,16 +379,24 @@ void LogSpamToFile(HANDLE hContact, tstring message) boost::mutex clean_mutex; -void CleanProtocolTmpThread(char* proto) +void CleanProtocolTmpThread(std::string proto) { boost::this_thread::sleep(boost::posix_time::seconds(5)); std::list contacts; - for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact;) + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { - if(!strcmp(proto, (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0))) + if(!strcmp(proto.c_str(), (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0))) if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)|| (_T("Not In List")== DBGetContactSettingStringPAN(hContact,"CList","Group",_T("")))) contacts.push_back(hContact); } + while(true) + { + UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + if(status > ID_STATUS_OFFLINE) + break; + boost::this_thread::sleep(boost::posix_time::seconds(2)); + } + boost::this_thread::sleep(boost::posix_time::seconds(5)); clean_mutex.lock(); std::list::iterator end = contacts.end(); for(std::list::iterator i = contacts.begin(); i != end; ++i) @@ -400,16 +408,24 @@ void CleanProtocolTmpThread(char* proto) clean_mutex.unlock(); } -void CleanProtocolExclThread(char* proto) +void CleanProtocolExclThread(std::string proto) { boost::this_thread::sleep(boost::posix_time::seconds(5)); std::list contacts; - for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact;) + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { - if(!strcmp(proto, (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0))) + if(!strcmp(proto.c_str(), (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0))) if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) contacts.push_back(hContact); } + while(true) + { + UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + if(status > ID_STATUS_OFFLINE) + break; + boost::this_thread::sleep(boost::posix_time::seconds(2)); + } + boost::this_thread::sleep(boost::posix_time::seconds(5)); clean_mutex.lock(); std::list::iterator end = contacts.end(); for(std::list::iterator i = contacts.begin(); i != end; ++i) @@ -429,32 +445,17 @@ void CleanThread() PROTOACCOUNT **accounts; ProtoEnumAccounts(&count, &accounts); for(int i = 0; i < count; i++) - protocols.push_back(accounts[i]->szModuleName); - while(!protocols.empty()) { - std::list::iterator> elements_to_clean; - std::list::iterator end = protocols.end(); - for(std::list::iterator i = protocols.begin(); i != end; ++i) - { - UINT status = CallProtoService(i->c_str(), PS_GETSTATUS, 0, 0); - if(status>= ID_STATUS_CONNECTING && status <= ID_STATUS_OFFLINE) - ; - else - { - if(gbDelAllTempory) - boost::thread *thr = new boost::thread(boost::bind(CleanProtocolTmpThread, (char*)i->c_str())); - if(gbDelExcluded) - boost::thread *thr = new boost::thread(boost::bind(CleanProtocolExclThread, (char*)i->c_str())); - elements_to_clean.push_back(i); - } - } - if(!elements_to_clean.empty()) - { - std::list::iterator>::iterator end = elements_to_clean.end(); - for(std::list::iterator>::iterator i = elements_to_clean.begin(); i != end; ++i) - protocols.erase(*i); - } - boost::this_thread::sleep(boost::posix_time::seconds(1)); + if(!strstr(accounts[i]->szModuleName, "MetaContacts") && !strstr(accounts[i]->szModuleName, "Weather")) //not real protocols + protocols.push_back(accounts[i]->szModuleName); + } + std::list::iterator end = protocols.end(); + for(std::list::iterator i = protocols.begin(); i != end; ++i) + { + if(gbDelAllTempory) + boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolTmpThread, *i)); + if(gbDelExcluded) + boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolExclThread, *i)); } } void HistoryLog(HANDLE hContact, char *data, int event_type, int flags) -- cgit v1.2.3