1
#ifndef _KVI_KVS_MODULEINTERFACE_H_
2
#define _KVI_KVS_MODULEINTERFACE_H_
3
//=============================================================================
5
// File : kvi_kvs_moduleinterface.h
6
// Creation date : Tue 16 Dec 2003 00:27:54 by Szymon Stefanek
8
// This file is part of the KVIrc IRC client distribution
9
// Copyright (C) 2003-2008 Szymon Stefanek <pragma at kvirc dot net>
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 opinion) any later version.
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.
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.
25
//=============================================================================
28
#include "kvi_settings.h"
30
#include "kvi_pointerhashtable.h"
32
#include "kvi_kvs_runtimecall.h"
33
#include "kvi_kvs_parameterprocessor.h"
34
#include "kvi_kvs_switchlist.h"
35
#include "kvi_kvs_script.h"
36
#include "kvi_pointerlist.h"
37
#include "kvi_qstring.h"
40
class KviKvsTreeNodeDataList;
42
class KVIRC_API KviKvsModuleRunTimeCall : public KviKvsRunTimeCall
45
KviModule * m_pModule;
47
KviKvsModuleRunTimeCall(KviModule * pModule,
48
KviKvsRunTimeContext * pContext,
49
KviKvsVariantList * pParams)
50
: KviKvsRunTimeCall(pContext,pParams), m_pModule(pModule) {}
51
~KviKvsModuleRunTimeCall(){};
53
KviModule * module(){ return m_pModule; };
56
class KVIRC_API KviKvsModuleEventCall : public KviKvsModuleRunTimeCall
59
KviKvsModuleEventCall(KviModule * pModule,
60
KviKvsRunTimeContext * pContext,
61
KviKvsVariantList * pParams)
62
: KviKvsModuleRunTimeCall(pModule,pContext,pParams){};
63
~KviKvsModuleEventCall(){};
66
class KVIRC_API KviKvsModuleCommandCall : public KviKvsModuleRunTimeCall
69
KviKvsSwitchList * m_pSwitchList;
71
KviKvsModuleCommandCall(KviModule * pModule,
72
KviKvsRunTimeContext * pContext,
73
KviKvsVariantList * pParams,
74
KviKvsSwitchList * pSwitches)
75
: KviKvsModuleRunTimeCall(pModule,pContext,pParams), m_pSwitchList(pSwitches){};
76
~KviKvsModuleCommandCall(){};
78
KviKvsSwitchList * switches(){ return m_pSwitchList; };
79
KviKvsSwitchList * switchList(){ return m_pSwitchList; };
81
// forwarders for the switch list
82
bool hasSwitch(unsigned short u,const QString &szSwitch){ return (m_pSwitchList->find(u,szSwitch) != 0); };
83
KviKvsVariant * getSwitch(unsigned short u,const QString &szSwitch){ return m_pSwitchList->find(u,szSwitch); };
86
class KVIRC_API KviKvsModuleCallbackCommandCall : public KviKvsModuleCommandCall
89
const KviKvsScript * m_pCallback;
90
KviKvsTreeNodeDataList * m_pParameterDataList; // core subtree that rappresents the parameter list
92
KviKvsModuleCallbackCommandCall(KviModule * pModule,
93
KviKvsRunTimeContext * pContext,
94
KviKvsVariantList * pParams,
95
KviKvsSwitchList * pSwitches,
96
const KviKvsScript * pCallback,
97
KviKvsTreeNodeDataList * pDataList)
98
: KviKvsModuleCommandCall(pModule,pContext,pParams,pSwitches), m_pCallback(pCallback), m_pParameterDataList(pDataList) {};
99
~KviKvsModuleCallbackCommandCall(){};
101
// Never NULL, but may have empty code
102
const KviKvsScript * callback(){ return m_pCallback; };
103
virtual bool getParameterCode(unsigned int uParamIdx,QString &szParamBuffer);
107
class KVIRC_API KviKvsModuleFunctionCall : public KviKvsModuleRunTimeCall
109
friend class KviKvsTreeNodeModuleFunctionCall;
111
KviKvsVariant * m_pResult;
113
KviKvsModuleFunctionCall(KviModule * pModule,
114
KviKvsRunTimeContext * pContext,
115
KviKvsVariantList * pParams,
116
KviKvsVariant * pResult)
117
: KviKvsModuleRunTimeCall(pModule,pContext,pParams), m_pResult(pResult)
119
~KviKvsModuleFunctionCall(){};
121
KviKvsVariant * returnValue(){ return m_pResult; };
126
typedef bool (*KviKvsModuleSimpleCommandExecRoutine)(KviKvsModuleCommandCall * c);
127
typedef bool (*KviKvsModuleFunctionExecRoutine)(KviKvsModuleFunctionCall * c);
128
typedef bool (*KviKvsModuleCallbackCommandExecRoutine)(KviKvsModuleCallbackCommandCall * c);
129
typedef bool (*KviKvsModuleEventHandlerRoutine)(KviKvsModuleEventCall * c);
133
class KVIRC_API KviKvsModuleInterface
135
friend class KviKvsModuleManager;
137
KviKvsModuleInterface();
138
~KviKvsModuleInterface();
140
KviPointerHashTable<QString,KviKvsModuleSimpleCommandExecRoutine> * m_pModuleSimpleCommandExecRoutineDict;
141
KviPointerHashTable<QString,KviKvsModuleFunctionExecRoutine> * m_pModuleFunctionExecRoutineDict;
142
KviPointerHashTable<QString,KviKvsModuleCallbackCommandExecRoutine> * m_pModuleCallbackCommandExecRoutineDict;
144
void kvsRegisterSimpleCommand(const QString &szCommand,KviKvsModuleSimpleCommandExecRoutine r);
145
void kvsRegisterCallbackCommand(const QString &szCommand,KviKvsModuleCallbackCommandExecRoutine r);
146
void kvsRegisterFunction(const QString &szFunction,KviKvsModuleFunctionExecRoutine r);
147
bool kvsRegisterAppEventHandler(unsigned int iEventIdx,KviKvsModuleEventHandlerRoutine r);
148
bool kvsRegisterRawEventHandler(unsigned int iRawIdx,KviKvsModuleEventHandlerRoutine r);
150
void kvsUnregisterSimpleCommand(const QString &szCommand)
151
{ m_pModuleSimpleCommandExecRoutineDict->remove(szCommand); };
152
void kvsUnregisterCallbackCommand(const QString &szCommand)
153
{ m_pModuleCallbackCommandExecRoutineDict->remove(szCommand); };
154
void kvsUnregisterFunction(const QString &szFunction)
155
{ m_pModuleFunctionExecRoutineDict->remove(szFunction); };
156
void kvsUnregisterAppEventHandler(unsigned int iEventIdx);
157
void kvsUnregisterRawEventHandler(unsigned int iRawIdx);
159
void kvsUnregisterAllSimpleCommands()
160
{ m_pModuleSimpleCommandExecRoutineDict->clear(); };
161
void kvsUnregisterAllCallbackCommands()
162
{ m_pModuleCallbackCommandExecRoutineDict->clear(); };
163
void kvsUnregisterAllFunctions()
164
{ m_pModuleFunctionExecRoutineDict->clear(); };
165
void kvsUnregisterAllAppEventHandlers();
166
void kvsUnregisterAllRawEventHandlers();
167
void kvsUnregisterAllEventHandlers();
169
KviKvsModuleSimpleCommandExecRoutine * kvsFindSimpleCommand(const QString &szCommand)
170
{ return m_pModuleSimpleCommandExecRoutineDict->find(szCommand); };
171
KviKvsModuleCallbackCommandExecRoutine * kvsFindCallbackCommand(const QString &szCommand)
172
{ return m_pModuleCallbackCommandExecRoutineDict->find(szCommand); };
173
KviKvsModuleFunctionExecRoutine * kvsFindFunction(const QString &szFunction)
174
{ return m_pModuleFunctionExecRoutineDict->find(szFunction); };
176
void completeCommand(const QString &cmd,KviPointerList<QString> * matches);
177
void completeFunction(const QString &cmd,KviPointerList<QString> * matches);
178
void getAllFunctionsCommandsModule(QStringList *list,QString &szModuleName);
180
void registerDefaultCommands();
185
#define KVSM_REGISTER_SIMPLE_COMMAND(_pModule,_szCmd,_procname) \
186
_pModule->kvsRegisterSimpleCommand(_szCmd,_procname);
188
#define KVSM_UNREGISTER_SIMPLE_COMMAND(_pModule,_szCmd) \
189
_pModule->kvsUnregisterSimpleCommand(_szCmd);
191
#define KVSM_REGISTER_CALLBACK_COMMAND(_pModule,_szCmd,_procname) \
192
_pModule->kvsRegisterCallbackCommand(_szCmd,_procname);
194
#define KVSM_UNREGISTER_CALLBACK_COMMAND(_pModule,_szCmd) \
195
_pModule->kvsUnregisterCallbackCommand(_szCmd);
197
#define KVSM_REGISTER_FUNCTION(_pModule,_szFnc,_procname) \
198
_pModule->kvsRegisterFunction(_szFnc,_procname); \
200
#define KVSM_UNREGISTER_FUNCTION(_pModule,_szFnc) \
201
_pModule->kvsUnregisterFunction(_szFnc);
203
#define KVSM_UNREGISTER_ALL_SIMPLE_COMMANDS(_pModule) \
204
_pModule->kvsUnregisterAllSimpleCommands();
206
#define KVSM_UNREGISTER_ALL_CALLBACK_COMMANDS(_pModule) \
207
_pModule->kvsUnregisterAllCallbackCommands();
209
#define KVSM_UNREGISTER_ALL_FUNCTIONS(_pModule) \
210
_pModule->kvsUnregisterAllFunctions();
213
#define KVSM_PARAMETER(a,b,c,d) KVS_PARAMETER(a,b,c,d)
214
#define KVSM_PARAMETER_IGNORED(a) KVS_PARAMETER_IGNORED(a)
216
#define KVSM_PARAMETERS_BEGIN(pCall) \
217
KVS_PARAMETERS_BEGIN(parameter_format_list)
219
#define KVSM_PARAMETERS_END(pCall) \
221
if(!KviKvsParameterProcessor::process(pCall->params(),pCall->context(),parameter_format_list))return false;
223
#define KVSM_REQUIRE_CONNECTION(pCall) \
224
if(!pCall->window()->context())return c->context()->errorNoIrcContext(); \
225
if(!pCall->window()->connection())return c->context()->warningNoIrcConnection();
229
#endif //!_KVI_KVS_MODULEINTERFACE_H_