summaryrefslogtreecommitdiff
path: root/plugins/Boltun/src/Engine
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Boltun/src/Engine')
-rw-r--r--plugins/Boltun/src/Engine/CriticalSection.h54
-rw-r--r--plugins/Boltun/src/Engine/PerContactData.h36
-rw-r--r--plugins/Boltun/src/Engine/TalkEngine.cpp11
-rw-r--r--plugins/Boltun/src/Engine/TalkEngine.h2
-rw-r--r--plugins/Boltun/src/Engine/ValueChooser.h3
5 files changed, 20 insertions, 86 deletions
diff --git a/plugins/Boltun/src/Engine/CriticalSection.h b/plugins/Boltun/src/Engine/CriticalSection.h
deleted file mode 100644
index 550aa32696..0000000000
--- a/plugins/Boltun/src/Engine/CriticalSection.h
+++ /dev/null
@@ -1,54 +0,0 @@
-//***********************************************************
-// Copyright © 2008 Valentin Pavlyuchenko
-//
-// This file is part of Boltun.
-//
-// Boltun 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, either version 2 of the License, or
-// (at your option) any later version.
-//
-// Boltun 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 Boltun. If not, see <http://www.gnu.org/licenses/>.
-//
-//***********************************************************
-
-#ifndef CriticalSectionH
-#define CriticalSectionH
-
-class CriticalSection
-{
- CRITICAL_SECTION csQueue;
-public:
- inline CriticalSection()
- {
- InitializeCriticalSection(&csQueue);
- }
-
- inline ~CriticalSection()
- {
- DeleteCriticalSection(&csQueue);
- }
-
- inline void Enter()
- {
- EnterCriticalSection(&csQueue);
- }
-
- inline void Leave()
- {
- LeaveCriticalSection(&csQueue);
- }
-
- inline bool TryEnter()
- {
- return TryEnterCriticalSection(&csQueue) != 0;
- }
-};
-
-#endif /* CriticalSectionH */ \ No newline at end of file
diff --git a/plugins/Boltun/src/Engine/PerContactData.h b/plugins/Boltun/src/Engine/PerContactData.h
index e81192053f..75bc321b66 100644
--- a/plugins/Boltun/src/Engine/PerContactData.h
+++ b/plugins/Boltun/src/Engine/PerContactData.h
@@ -21,17 +21,16 @@
#ifndef PerContactDataH
#define PerContactDataH
-#include "CriticalSection.h"
-
static std::map<unsigned, void*> perContactDataObjects;
template <class Source, class Data, class ContactHandle>
class PerContactData
{
+ PerContactData& operator=(const PerContactData&);
+
template <class Source, class Data>
struct InternalData
{
- CriticalSection lock;
Data *data;
time_t time;
inline InternalData(const Source& src)
@@ -51,7 +50,7 @@ class PerContactData
delete data;
}
};
- CriticalSection mapLock;
+ mir_cs mapLock;
unsigned timerID;
std::map<ContactHandle, InternalData<Source, Data>* > datas;
typedef typename std::map<ContactHandle, InternalData<Source, Data>* >::iterator mapIt;
@@ -59,6 +58,7 @@ class PerContactData
void CleanupData();
template <class Source, class Data, class ContactHandle>
friend VOID CALLBACK RunTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
+
public:
PerContactData(const Source& src);
~PerContactData();
@@ -75,7 +75,7 @@ PerContactData<Source, Data, ContactHandle>::PerContactData(const Source& src)
template <class Source, class Data, class ContactHandle>
PerContactData<Source, Data, ContactHandle>::~PerContactData()
{
- mapLock.Enter();
+ mir_cslock mlck(mapLock);
if (timerID)
{
KillTimer(NULL, timerID);
@@ -83,40 +83,26 @@ PerContactData<Source, Data, ContactHandle>::~PerContactData()
}
while (!datas.empty())
{
- while (!(*datas.begin()).second->lock.TryEnter())
- {
- mapLock.Leave();
- Sleep(10);
- mapLock.Enter();
- }
- //Now we know exactly that no-one onws a contact lock
- InternalData<Source, Data>* data = (*datas.begin()).second;
- data->lock.Leave();
- delete data;
+ delete (*datas.begin()).second;
datas.erase(datas.begin());
}
- mapLock.Leave();
}
template <class Source, class Data, class ContactHandle>
Data* PerContactData<Source, Data, ContactHandle>::GetData(ContactHandle Contact)
{
- mapLock.Enter();
+ mir_cslock mlck(mapLock);
mapIt it;
if ((it = datas.find(Contact)) == datas.end())
it = datas.insert(make_pair(Contact, new InternalData<Source, Data>(source))).first;
- (*it).second->lock.Enter();
(*it).second->time = 0;
- Data* data = (*it).second->data;
- mapLock.Leave();
- return data;
+ return (*it).second->data;
}
template <class Source, class Data, class ContactHandle>
void PerContactData<Source, Data, ContactHandle>::PutData(ContactHandle Contact)
{
- mapLock.Enter();
- datas[Contact]->lock.Leave();
+ mir_cslock mlck(mapLock);
::time(&(datas[Contact]->time));
if (!timerID)
{
@@ -124,13 +110,12 @@ void PerContactData<Source, Data, ContactHandle>::PutData(ContactHandle Contact)
assert(timerID);
perContactDataObjects[timerID] = this;
}
- mapLock.Leave();
}
template <class Source, class Data, class ContactHandle>
void PerContactData<Source, Data, ContactHandle>::CleanupData()
{
- mapLock.Enter();
+ mir_cslock mlck(mapLock);
time_t now;
time(&now);
for (mapIt it = datas.begin(); it != datas.end();)
@@ -156,7 +141,6 @@ void PerContactData<Source, Data, ContactHandle>::CleanupData()
KillTimer(NULL, timerID);
perContactDataObjects.erase(timerID);
}
- mapLock.Leave();
}
template <class Source, class Data, class ContactHandle>
diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp
index 0391c11112..8d4efbf476 100644
--- a/plugins/Boltun/src/Engine/TalkEngine.cpp
+++ b/plugins/Boltun/src/Engine/TalkEngine.cpp
@@ -97,8 +97,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
const TCHAR dividers[] = _T(" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—\1");
tstring sentence = message;
tstring result;
- int len = (int)sentence.length();
- map<int, tstring> sm;
+ map<size_t, tstring> sm;
//Find smiles
for (size_t i = 0; i < sentence.length() - 1; i++)
{
@@ -116,7 +115,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
}
}
}
- len = (int)sentence.length();
+ int len = (int)sentence.length();
bool hadQuestionSigns = false;
int it = 0;
while (it != len)
@@ -125,7 +124,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message)
{
if (sentence[it] == _T('?'))
hadQuestionSigns = true;
- map<int, tstring>::iterator smit;
+ map<size_t, tstring>::iterator smit;
if (sentence[it] == '\1')
{
smit = sm.find(it);
@@ -515,7 +514,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords,
const TCHAR dividers[] = _T(" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—");
int len = (int)sentence.length();
vector<tstring> words;
- map<int, tstring> sm;
+ map<size_t, tstring> sm;
//Find smiles
for (size_t i = 0; i < sentence.length() - 1; i++)
{
@@ -543,7 +542,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector<tstring>& keywords,
{
if (sentence[it] == _T('?'))
hadQuestionSigns = true;
- map<int, tstring>::iterator smit;
+ map<size_t, tstring>::iterator smit;
if (_istspace(sentence[it]) && (smit = sm.find(it)) != sm.end())
words.push_back((*smit).second);
it++;
diff --git a/plugins/Boltun/src/Engine/TalkEngine.h b/plugins/Boltun/src/Engine/TalkEngine.h
index 6f95541941..c18f3df1c1 100644
--- a/plugins/Boltun/src/Engine/TalkEngine.h
+++ b/plugins/Boltun/src/Engine/TalkEngine.h
@@ -28,6 +28,8 @@
class TalkBot
{
+ TalkBot& operator=(const TalkBot&);
+
public:
struct MessageInfo
{
diff --git a/plugins/Boltun/src/Engine/ValueChooser.h b/plugins/Boltun/src/Engine/ValueChooser.h
index 10256a5b70..0018ac8ff2 100644
--- a/plugins/Boltun/src/Engine/ValueChooser.h
+++ b/plugins/Boltun/src/Engine/ValueChooser.h
@@ -29,6 +29,9 @@ private:
bool *numbers;
const container data;
bool notifyOnReset;
+
+ ValueChooser& operator=(const ValueChooser&);
+
public:
ValueChooser(const container& vec, bool NotifyOnReset = false)
:data(vec), notifyOnReset(NotifyOnReset)