-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandDB.cpp
More file actions
112 lines (88 loc) · 3.18 KB
/
CommandDB.cpp
File metadata and controls
112 lines (88 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (C) 2003, 2004 Amit Schreiber <gnobal@yahoo.com>
*
* This file is part of Relay plugin for Miranda IM.
*
* Relay plugin for Miranda IM 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.
*
* Relay plugin for Miranda IM 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 Relay plugin for Miranda IM ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "CommandDB.h"
#include <utility>
using std::make_pair;
CommandDB& CommandDB::Instance()
{
static CommandDB theDB;
return theDB;
}
HANDLE CommandDB::AddCommandHandler(const string& strCommandName,
const HANDLE hHookableEvent,
const HANDLE hHookHandle,
const COMMAND_STATE eState)
{
CommandInfo info;
info.eCommandState = eState;
info.nNumHandlers = 1;
info.hHookableEvent = hHookableEvent;
std::pair<CommandMap::iterator, bool> insertPair = commandMap.insert(make_pair(strCommandName, info));
HandleToCommandMapping mapping;
mapping.hHookHandle = hHookHandle;
mapping.itCommand = insertPair.first;
mappingVector.push_back(mapping);
const HANDLE hRet = reinterpret_cast<HANDLE>(mappingVector.size()-1);
if (insertPair.second) // New command
return hRet;
insertPair.first->second.nNumHandlers++;
return hRet;
}
HANDLE CommandDB::RemoveCommandHandler(const HANDLE hHandler)
{
MappingVector::size_type nMappingId = reinterpret_cast<MappingVector::size_type>(hHandler);
if (nMappingId < 0 || nMappingId >= mappingVector.size())
return NULL;
CommandMap::iterator it = mappingVector[nMappingId].itCommand;
if (--it->second.nNumHandlers == 0)
commandMap.erase(it);
return mappingVector[nMappingId].hHookHandle;
}
int CommandDB::SetCommandState(const string& strCommandName, COMMAND_STATE eNewState)
{
CommandMap::iterator it = commandMap.find(strCommandName);
if (it == commandMap.end())
return -1;
it->second.eCommandState = eNewState;
return 0;
}
bool CommandDB::CommandExists(const string& strCommandName) const
{
Iterator it = commandMap.find(strCommandName);
if (it == commandMap.end())
return false;
return true;
}
int CommandDB::GetCommandInfo(const string& strCommandName, COMMAND_STATE& eState, HANDLE& hHookableEvent) const
{
Iterator it = commandMap.find(strCommandName);
if (it == commandMap.end())
return -1;
eState = it->second.eCommandState;
hHookableEvent = it->second.hHookableEvent;
return 0;
}
int CommandDB::GetCommandInfo(Iterator it, string& strCommandName, COMMAND_STATE& eState, HANDLE& hHookableEvent) const
{
eState = it->second.eCommandState;
hHookableEvent = it->second.hHookableEvent;
strCommandName = it->first;
return 0;
}