KVIrc 5.2.0
Developer APIs
KviKvsModuleInterface.h
Go to the documentation of this file.
1#ifndef _KVI_KVS_MODULEINTERFACE_H_
2#define _KVI_KVS_MODULEINTERFACE_H_
3//=============================================================================
4//
5// File : KviKvsModuleInterface.h
6// Creation date : Tue 16 Dec 2003 00:27:54 by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 2003-2010 Szymon Stefanek <pragma at kvirc dot net>
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
27#include "kvi_settings.h"
28
29#include "KviPointerHashTable.h"
30
31#include "KviKvsRunTimeCall.h"
33#include "KviKvsSwitchList.h"
34#include "KviKvsScript.h"
35#include "KviQString.h"
36
37#include <vector>
38
39class KviModule;
41
43{
44protected:
46
47public:
49 KviKvsRunTimeContext * pContext,
50 KviKvsVariantList * pParams)
51 : KviKvsRunTimeCall(pContext, pParams), m_pModule(pModule) {}
53
54public:
55 KviModule * module() { return m_pModule; };
56};
57
59{
60public:
62 KviKvsRunTimeContext * pContext,
63 KviKvsVariantList * pParams)
64 : KviKvsModuleRunTimeCall(pModule, pContext, pParams){};
66};
67
69{
70protected:
72
73public:
75 KviKvsRunTimeContext * pContext,
76 KviKvsVariantList * pParams,
77 KviKvsSwitchList * pSwitches)
78 : KviKvsModuleRunTimeCall(pModule, pContext, pParams), m_pSwitchList(pSwitches){};
80
81public:
82 KviKvsSwitchList * switches() { return m_pSwitchList; };
83 KviKvsSwitchList * switchList() { return m_pSwitchList; };
84
85 // forwarders for the switch list
86 bool hasSwitch(unsigned short u, const QString & szSwitch) { return (m_pSwitchList->find(u, szSwitch) != 0); };
87 KviKvsVariant * getSwitch(unsigned short u, const QString & szSwitch) { return m_pSwitchList->find(u, szSwitch); };
88};
89
91{
92protected:
94 KviKvsTreeNodeDataList * m_pParameterDataList; // core subtree that rappresents the parameter list
95public:
97 KviKvsRunTimeContext * pContext,
98 KviKvsVariantList * pParams,
99 KviKvsSwitchList * pSwitches,
100 const KviKvsScript * pCallback,
101 KviKvsTreeNodeDataList * pDataList)
102 : KviKvsModuleCommandCall(pModule, pContext, pParams, pSwitches), m_pCallback(pCallback), m_pParameterDataList(pDataList){};
104
105public:
106 // Never nullptr, but may have empty code
107 const KviKvsScript * callback() { return m_pCallback; };
108 virtual bool getParameterCode(unsigned int uParamIdx, QString & szParamBuffer);
109};
110
112{
114
115protected:
117
118public:
120 KviKvsRunTimeContext * pContext,
121 KviKvsVariantList * pParams,
122 KviKvsVariant * pResult)
123 : KviKvsModuleRunTimeCall(pModule, pContext, pParams), m_pResult(pResult){};
125
126public:
127 KviKvsVariant * returnValue() { return m_pResult; };
128};
129
134
136{
137 friend class KviKvsModuleManager;
138
139public:
142
143protected:
147
148public:
149 void kvsRegisterSimpleCommand(const QString & szCommand, KviKvsModuleSimpleCommandExecRoutine r);
150 void kvsRegisterCallbackCommand(const QString & szCommand, KviKvsModuleCallbackCommandExecRoutine r);
151 void kvsRegisterFunction(const QString & szFunction, KviKvsModuleFunctionExecRoutine r);
152 bool kvsRegisterAppEventHandler(unsigned int iEventIdx, KviKvsModuleEventHandlerRoutine r);
153 bool kvsRegisterRawEventHandler(unsigned int iRawIdx, KviKvsModuleEventHandlerRoutine r);
154
155 void kvsUnregisterSimpleCommand(const QString & szCommand)
156 {
157 m_pModuleSimpleCommandExecRoutineDict->remove(szCommand);
158 };
159 void kvsUnregisterCallbackCommand(const QString & szCommand)
160 {
161 m_pModuleCallbackCommandExecRoutineDict->remove(szCommand);
162 };
163 void kvsUnregisterFunction(const QString & szFunction)
164 {
165 m_pModuleFunctionExecRoutineDict->remove(szFunction);
166 };
167 void kvsUnregisterAppEventHandler(unsigned int iEventIdx);
168 void kvsUnregisterRawEventHandler(unsigned int iRawIdx);
169
171 {
172 m_pModuleSimpleCommandExecRoutineDict->clear();
173 };
175 {
176 m_pModuleCallbackCommandExecRoutineDict->clear();
177 };
179 {
180 m_pModuleFunctionExecRoutineDict->clear();
181 };
182 void kvsUnregisterAllAppEventHandlers();
183 void kvsUnregisterAllRawEventHandlers();
184 void kvsUnregisterAllEventHandlers();
185
187 {
188 return m_pModuleSimpleCommandExecRoutineDict->find(szCommand);
189 };
191 {
192 return m_pModuleCallbackCommandExecRoutineDict->find(szCommand);
193 };
195 {
196 return m_pModuleFunctionExecRoutineDict->find(szFunction);
197 };
198
199 void completeCommand(const QString & cmd, std::vector<QString> & matches);
200 void completeFunction(const QString & cmd, std::vector<QString> & matches);
201 void getAllFunctionsCommandsModule(QStringList * list, QString & szModuleName);
202
203protected:
204 void registerDefaultCommands();
205};
206
207#define KVSM_REGISTER_SIMPLE_COMMAND(_pModule, _szCmd, _procname) \
208 _pModule->kvsRegisterSimpleCommand(_szCmd, _procname);
209
210#define KVSM_UNREGISTER_SIMPLE_COMMAND(_pModule, _szCmd) \
211 _pModule->kvsUnregisterSimpleCommand(_szCmd);
212
213#define KVSM_REGISTER_CALLBACK_COMMAND(_pModule, _szCmd, _procname) \
214 _pModule->kvsRegisterCallbackCommand(_szCmd, _procname);
215
216#define KVSM_UNREGISTER_CALLBACK_COMMAND(_pModule, _szCmd) \
217 _pModule->kvsUnregisterCallbackCommand(_szCmd);
218
219#define KVSM_REGISTER_FUNCTION(_pModule, _szFnc, _procname) \
220 _pModule->kvsRegisterFunction(_szFnc, _procname);
221
222#define KVSM_UNREGISTER_FUNCTION(_pModule, _szFnc) \
223 _pModule->kvsUnregisterFunction(_szFnc);
224
225#define KVSM_UNREGISTER_ALL_SIMPLE_COMMANDS(_pModule) \
226 _pModule->kvsUnregisterAllSimpleCommands();
227
228#define KVSM_UNREGISTER_ALL_CALLBACK_COMMANDS(_pModule) \
229 _pModule->kvsUnregisterAllCallbackCommands();
230
231#define KVSM_UNREGISTER_ALL_FUNCTIONS(_pModule) \
232 _pModule->kvsUnregisterAllFunctions();
233
234#define KVSM_PARAMETER(a, b, c, d) KVS_PARAMETER(a, b, c, d)
235#define KVSM_PARAMETER_IGNORED(a) KVS_PARAMETER_IGNORED(a)
236
237#define KVSM_PARAMETERS_BEGIN(pCall) \
238 KVS_PARAMETERS_BEGIN(parameter_format_list)
239
240#define KVSM_PARAMETERS_END(pCall) \
241 KVS_PARAMETERS_END \
242 if(!KviKvsParameterProcessor::process(pCall->params(), pCall->context(), parameter_format_list)) \
243 return false;
244
245#define KVSM_REQUIRE_CONNECTION(pCall) \
246 if(!pCall->window()->context()) \
247 return c->context()->errorNoIrcContext(); \
248 if(!pCall->window()->connection()) \
249 return c->context()->warningNoIrcConnection();
250
251#endif
bool(* KviKvsModuleEventHandlerRoutine)(KviKvsModuleEventCall *c)
Definition KviKvsModuleInterface.h:133
bool(* KviKvsModuleCallbackCommandExecRoutine)(KviKvsModuleCallbackCommandCall *c)
Definition KviKvsModuleInterface.h:132
bool(* KviKvsModuleSimpleCommandExecRoutine)(KviKvsModuleCommandCall *c)
Definition KviKvsModuleInterface.h:130
bool(* KviKvsModuleFunctionExecRoutine)(KviKvsModuleFunctionCall *c)
Definition KviKvsModuleInterface.h:131
KVIrc Script manager.
Pointer Hash Table.
Helper functions for the QString class.
Definition KviKvsModuleInterface.h:91
KviKvsModuleCallbackCommandCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsSwitchList *pSwitches, const KviKvsScript *pCallback, KviKvsTreeNodeDataList *pDataList)
Definition KviKvsModuleInterface.h:96
~KviKvsModuleCallbackCommandCall()
Definition KviKvsModuleInterface.h:103
const KviKvsScript * m_pCallback
Definition KviKvsModuleInterface.h:93
KviKvsTreeNodeDataList * m_pParameterDataList
Definition KviKvsModuleInterface.h:94
const KviKvsScript * callback()
Definition KviKvsModuleInterface.h:107
Definition KviKvsModuleInterface.h:69
KviKvsVariant * getSwitch(unsigned short u, const QString &szSwitch)
Definition KviKvsModuleInterface.h:87
KviKvsSwitchList * m_pSwitchList
Definition KviKvsModuleInterface.h:71
KviKvsSwitchList * switches()
Definition KviKvsModuleInterface.h:82
KviKvsModuleCommandCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsSwitchList *pSwitches)
Definition KviKvsModuleInterface.h:74
bool hasSwitch(unsigned short u, const QString &szSwitch)
Definition KviKvsModuleInterface.h:86
~KviKvsModuleCommandCall()
Definition KviKvsModuleInterface.h:79
KviKvsSwitchList * switchList()
Definition KviKvsModuleInterface.h:83
Definition KviKvsModuleInterface.h:59
KviKvsModuleEventCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams)
Definition KviKvsModuleInterface.h:61
~KviKvsModuleEventCall()
Definition KviKvsModuleInterface.h:65
Definition KviKvsModuleInterface.h:112
KviKvsVariant * m_pResult
Definition KviKvsModuleInterface.h:116
KviKvsModuleFunctionCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsVariant *pResult)
Definition KviKvsModuleInterface.h:119
KviKvsVariant * returnValue()
Definition KviKvsModuleInterface.h:127
~KviKvsModuleFunctionCall()
Definition KviKvsModuleInterface.h:124
Definition KviKvsModuleInterface.h:136
void kvsUnregisterSimpleCommand(const QString &szCommand)
Definition KviKvsModuleInterface.h:155
void kvsUnregisterFunction(const QString &szFunction)
Definition KviKvsModuleInterface.h:163
KviKvsModuleSimpleCommandExecRoutine * kvsFindSimpleCommand(const QString &szCommand)
Definition KviKvsModuleInterface.h:186
KviPointerHashTable< QString, KviKvsModuleSimpleCommandExecRoutine > * m_pModuleSimpleCommandExecRoutineDict
Definition KviKvsModuleInterface.h:144
KviPointerHashTable< QString, KviKvsModuleCallbackCommandExecRoutine > * m_pModuleCallbackCommandExecRoutineDict
Definition KviKvsModuleInterface.h:146
void kvsUnregisterCallbackCommand(const QString &szCommand)
Definition KviKvsModuleInterface.h:159
KviKvsModuleFunctionExecRoutine * kvsFindFunction(const QString &szFunction)
Definition KviKvsModuleInterface.h:194
KviPointerHashTable< QString, KviKvsModuleFunctionExecRoutine > * m_pModuleFunctionExecRoutineDict
Definition KviKvsModuleInterface.h:145
void kvsUnregisterAllFunctions()
Definition KviKvsModuleInterface.h:178
void kvsUnregisterAllCallbackCommands()
Definition KviKvsModuleInterface.h:174
KviKvsModuleCallbackCommandExecRoutine * kvsFindCallbackCommand(const QString &szCommand)
Definition KviKvsModuleInterface.h:190
void kvsUnregisterAllSimpleCommands()
Definition KviKvsModuleInterface.h:170
Definition KviKvsModuleInterface.h:43
KviKvsModuleRunTimeCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams)
Definition KviKvsModuleInterface.h:48
~KviKvsModuleRunTimeCall()
Definition KviKvsModuleInterface.h:52
KviModule * module()
Definition KviKvsModuleInterface.h:55
KviModule * m_pModule
Definition KviKvsModuleInterface.h:45
Definition KviKvsRunTimeCall.h:34
virtual bool getParameterCode(unsigned int uParamIdx, QString &szParamBuffer)
Definition KviKvsRunTimeCall.cpp:44
Definition KviKvsRunTimeContext.h:104
The KVIrc Script class.
Definition KviKvsScript.h:60
Definition KviKvsSwitchList.h:34
KviKvsVariant * find(const QChar &c)
Definition KviKvsSwitchList.h:50
Definition KviKvsTreeNodeDataList.h:36
Definition KviKvsTreeNodeModuleFunctionCall.h:36
Class to handle variant variables lists.
Definition KviKvsVariantList.h:42
This class defines a new data type which contains variant data.
Definition KviKvsVariant.h:352
Definition KviModule.h:131
A fast pointer hash table implementation.
Definition KviPointerHashTable.h:450
void clear()
Removes all the items from the hash table.
Definition KviPointerHashTable.h:650
bool remove(const Key &hKey)
Removes the item pointer associated to the key hKey, if such an item exists in the hash table.
Definition KviPointerHashTable.h:581
T * find(const Key &hKey)
Returns the item associated to the key.
Definition KviPointerHashTable.h:471
#define u
Definition detector.cpp:86
#define r
Definition detector.cpp:83
This file contains compile time settings.
#define KVIRC_API
Definition kvi_settings.h:127