KVIrc  4.9.2
DeveloperAPIs
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 "KviPointerList.h"
36 #include "KviQString.h"
37 
38 class KviModule;
40 
42 {
43 protected:
45 
46 public:
48  KviKvsRunTimeContext * pContext,
49  KviKvsVariantList * pParams)
50  : KviKvsRunTimeCall(pContext, pParams), m_pModule(pModule) {}
52 
53 public:
54  KviModule * module() { return m_pModule; };
55 };
56 
58 {
59 public:
61  KviKvsRunTimeContext * pContext,
62  KviKvsVariantList * pParams)
63  : KviKvsModuleRunTimeCall(pModule, pContext, pParams){};
65 };
66 
68 {
69 protected:
71 
72 public:
74  KviKvsRunTimeContext * pContext,
75  KviKvsVariantList * pParams,
76  KviKvsSwitchList * pSwitches)
77  : KviKvsModuleRunTimeCall(pModule, pContext, pParams), m_pSwitchList(pSwitches){};
79 
80 public:
81  KviKvsSwitchList * switches() { return m_pSwitchList; };
82  KviKvsSwitchList * switchList() { return m_pSwitchList; };
83 
84  // forwarders for the switch list
85  bool hasSwitch(unsigned short u, const QString & szSwitch) { return (m_pSwitchList->find(u, szSwitch) != 0); };
86  KviKvsVariant * getSwitch(unsigned short u, const QString & szSwitch) { return m_pSwitchList->find(u, szSwitch); };
87 };
88 
90 {
91 protected:
93  KviKvsTreeNodeDataList * m_pParameterDataList; // core subtree that rappresents the parameter list
94 public:
96  KviKvsRunTimeContext * pContext,
97  KviKvsVariantList * pParams,
98  KviKvsSwitchList * pSwitches,
99  const KviKvsScript * pCallback,
100  KviKvsTreeNodeDataList * pDataList)
101  : KviKvsModuleCommandCall(pModule, pContext, pParams, pSwitches), m_pCallback(pCallback), m_pParameterDataList(pDataList){};
103 
104 public:
105  // Never NULL, but may have empty code
106  const KviKvsScript * callback() { return m_pCallback; };
107  virtual bool getParameterCode(unsigned int uParamIdx, QString & szParamBuffer);
108 };
109 
111 {
113 
114 protected:
116 
117 public:
119  KviKvsRunTimeContext * pContext,
120  KviKvsVariantList * pParams,
121  KviKvsVariant * pResult)
122  : KviKvsModuleRunTimeCall(pModule, pContext, pParams), m_pResult(pResult){};
124 
125 public:
126  KviKvsVariant * returnValue() { return m_pResult; };
127 };
128 
133 
135 {
136  friend class KviKvsModuleManager;
137 
138 public:
141 
142 protected:
146 
147 public:
148  void kvsRegisterSimpleCommand(const QString & szCommand, KviKvsModuleSimpleCommandExecRoutine r);
149  void kvsRegisterCallbackCommand(const QString & szCommand, KviKvsModuleCallbackCommandExecRoutine r);
150  void kvsRegisterFunction(const QString & szFunction, KviKvsModuleFunctionExecRoutine r);
151  bool kvsRegisterAppEventHandler(unsigned int iEventIdx, KviKvsModuleEventHandlerRoutine r);
152  bool kvsRegisterRawEventHandler(unsigned int iRawIdx, KviKvsModuleEventHandlerRoutine r);
153 
154  void kvsUnregisterSimpleCommand(const QString & szCommand)
155  {
156  m_pModuleSimpleCommandExecRoutineDict->remove(szCommand);
157  };
158  void kvsUnregisterCallbackCommand(const QString & szCommand)
159  {
160  m_pModuleCallbackCommandExecRoutineDict->remove(szCommand);
161  };
162  void kvsUnregisterFunction(const QString & szFunction)
163  {
164  m_pModuleFunctionExecRoutineDict->remove(szFunction);
165  };
166  void kvsUnregisterAppEventHandler(unsigned int iEventIdx);
167  void kvsUnregisterRawEventHandler(unsigned int iRawIdx);
168 
170  {
171  m_pModuleSimpleCommandExecRoutineDict->clear();
172  };
174  {
175  m_pModuleCallbackCommandExecRoutineDict->clear();
176  };
178  {
179  m_pModuleFunctionExecRoutineDict->clear();
180  };
181  void kvsUnregisterAllAppEventHandlers();
182  void kvsUnregisterAllRawEventHandlers();
183  void kvsUnregisterAllEventHandlers();
184 
186  {
187  return m_pModuleSimpleCommandExecRoutineDict->find(szCommand);
188  };
190  {
191  return m_pModuleCallbackCommandExecRoutineDict->find(szCommand);
192  };
193  KviKvsModuleFunctionExecRoutine * kvsFindFunction(const QString & szFunction)
194  {
195  return m_pModuleFunctionExecRoutineDict->find(szFunction);
196  };
197 
198  void completeCommand(const QString & cmd, KviPointerList<QString> * matches);
199  void completeFunction(const QString & cmd, KviPointerList<QString> * matches);
200  void getAllFunctionsCommandsModule(QStringList * list, QString & szModuleName);
201 
202 protected:
203  void registerDefaultCommands();
204 };
205 
206 #define KVSM_REGISTER_SIMPLE_COMMAND(_pModule, _szCmd, _procname) \
207  _pModule->kvsRegisterSimpleCommand(_szCmd, _procname);
208 
209 #define KVSM_UNREGISTER_SIMPLE_COMMAND(_pModule, _szCmd) \
210  _pModule->kvsUnregisterSimpleCommand(_szCmd);
211 
212 #define KVSM_REGISTER_CALLBACK_COMMAND(_pModule, _szCmd, _procname) \
213  _pModule->kvsRegisterCallbackCommand(_szCmd, _procname);
214 
215 #define KVSM_UNREGISTER_CALLBACK_COMMAND(_pModule, _szCmd) \
216  _pModule->kvsUnregisterCallbackCommand(_szCmd);
217 
218 #define KVSM_REGISTER_FUNCTION(_pModule, _szFnc, _procname) \
219  _pModule->kvsRegisterFunction(_szFnc, _procname);
220 
221 #define KVSM_UNREGISTER_FUNCTION(_pModule, _szFnc) \
222  _pModule->kvsUnregisterFunction(_szFnc);
223 
224 #define KVSM_UNREGISTER_ALL_SIMPLE_COMMANDS(_pModule) \
225  _pModule->kvsUnregisterAllSimpleCommands();
226 
227 #define KVSM_UNREGISTER_ALL_CALLBACK_COMMANDS(_pModule) \
228  _pModule->kvsUnregisterAllCallbackCommands();
229 
230 #define KVSM_UNREGISTER_ALL_FUNCTIONS(_pModule) \
231  _pModule->kvsUnregisterAllFunctions();
232 
233 #define KVSM_PARAMETER(a, b, c, d) KVS_PARAMETER(a, b, c, d)
234 #define KVSM_PARAMETER_IGNORED(a) KVS_PARAMETER_IGNORED(a)
235 
236 #define KVSM_PARAMETERS_BEGIN(pCall) \
237  KVS_PARAMETERS_BEGIN(parameter_format_list)
238 
239 #define KVSM_PARAMETERS_END(pCall) \
240  KVS_PARAMETERS_END \
241  if(!KviKvsParameterProcessor::process(pCall->params(), pCall->context(), parameter_format_list)) \
242  return false;
243 
244 #define KVSM_REQUIRE_CONNECTION(pCall) \
245  if(!pCall->window()->context()) \
246  return c->context()->errorNoIrcContext(); \
247  if(!pCall->window()->connection()) \
248  return c->context()->warningNoIrcConnection();
249 
250 #endif
KviKvsModuleEventCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams)
Definition: KviKvsModuleInterface.h:60
KviKvsVariant * getSwitch(unsigned short u, const QString &szSwitch)
Definition: KviKvsModuleInterface.h:86
~KviKvsModuleRunTimeCall()
Definition: KviKvsModuleInterface.h:51
KviKvsModuleCallbackCommandCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsSwitchList *pSwitches, const KviKvsScript *pCallback, KviKvsTreeNodeDataList *pDataList)
Definition: KviKvsModuleInterface.h:95
This class defines a new data type which contains variant data.
Definition: KviKvsVariant.h:351
bool(* KviKvsModuleEventHandlerRoutine)(KviKvsModuleEventCall *c)
Definition: KviKvsModuleInterface.h:132
KviModule * module()
Definition: KviKvsModuleInterface.h:54
#define KVIRC_API
Definition: kvi_settings.h:128
char s char s char s s s s s char char c s *s c s s s d c s *s d c d d d d c
Definition: KviIrcNumericCodes.h:391
KviModule * m_pModule
Definition: KviKvsModuleInterface.h:44
bool(* KviKvsModuleSimpleCommandExecRoutine)(KviKvsModuleCommandCall *c)
Definition: KviKvsModuleInterface.h:129
Definition: KviKvsModuleInterface.h:41
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
The KVIrc Script class.
Definition: KviKvsScript.h:59
KviKvsModuleFunctionCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsVariant *pResult)
Definition: KviKvsModuleInterface.h:118
void kvsUnregisterAllSimpleCommands()
Definition: KviKvsModuleInterface.h:169
KVIrc Script manager.
~KviKvsModuleEventCall()
Definition: KviKvsModuleInterface.h:64
void kvsUnregisterFunction(const QString &szFunction)
Definition: KviKvsModuleInterface.h:162
KviKvsVariant * m_pResult
Definition: KviKvsModuleInterface.h:115
const KviKvsScript * callback()
Definition: KviKvsModuleInterface.h:106
void kvsUnregisterAllFunctions()
Definition: KviKvsModuleInterface.h:177
Definition: KviKvsSwitchList.h:33
~KviKvsModuleCommandCall()
Definition: KviKvsModuleInterface.h:78
Pointer Hash Table.
void kvsUnregisterSimpleCommand(const QString &szCommand)
Definition: KviKvsModuleInterface.h:154
KviPointerHashTable< QString, KviKvsModuleSimpleCommandExecRoutine > * m_pModuleSimpleCommandExecRoutineDict
Definition: KviKvsModuleInterface.h:143
KviKvsSwitchList * m_pSwitchList
Definition: KviKvsModuleInterface.h:70
void kvsUnregisterAllCallbackCommands()
Definition: KviKvsModuleInterface.h:173
Definition: KviKvsModuleInterface.h:89
Definition: KviKvsModuleInterface.h:67
bool(* KviKvsModuleCallbackCommandExecRoutine)(KviKvsModuleCallbackCommandCall *c)
Definition: KviKvsModuleInterface.h:131
Definition: KviKvsModuleInterface.h:110
KviKvsModuleSimpleCommandExecRoutine * kvsFindSimpleCommand(const QString &szCommand)
Definition: KviKvsModuleInterface.h:185
bool(* KviKvsModuleFunctionExecRoutine)(KviKvsModuleFunctionCall *c)
Definition: KviKvsModuleInterface.h:130
KviKvsModuleFunctionExecRoutine * kvsFindFunction(const QString &szFunction)
Definition: KviKvsModuleInterface.h:193
Definition: KviKvsTreeNodeDataList.h:35
KviPointerHashTable< QString, KviKvsModuleFunctionExecRoutine > * m_pModuleFunctionExecRoutineDict
Definition: KviKvsModuleInterface.h:144
Definition: KviKvsModuleInterface.h:57
~KviKvsModuleCallbackCommandCall()
Definition: KviKvsModuleInterface.h:102
#define r
Definition: detector.cpp:82
C++ Template based double linked pointer list class.
Definition: KviKvsTreeNodeModuleFunctionCall.h:35
Definition: KviKvsRunTimeContext.h:103
Definition: KviModule.h:131
KviPointerHashTable< QString, KviKvsModuleCallbackCommandExecRoutine > * m_pModuleCallbackCommandExecRoutineDict
Definition: KviKvsModuleInterface.h:145
KviKvsModuleRunTimeCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams)
Definition: KviKvsModuleInterface.h:47
#define u
Definition: detector.cpp:85
~KviKvsModuleFunctionCall()
Definition: KviKvsModuleInterface.h:123
KviKvsModuleCallbackCommandExecRoutine * kvsFindCallbackCommand(const QString &szCommand)
Definition: KviKvsModuleInterface.h:189
KviKvsModuleCommandCall(KviModule *pModule, KviKvsRunTimeContext *pContext, KviKvsVariantList *pParams, KviKvsSwitchList *pSwitches)
Definition: KviKvsModuleInterface.h:73
This file contains compile time settings.
Definition: KviKvsModuleInterface.h:134
KviKvsSwitchList * switches()
Definition: KviKvsModuleInterface.h:81
KviKvsTreeNodeDataList * m_pParameterDataList
Definition: KviKvsModuleInterface.h:93
Definition: KviKvsRunTimeCall.h:33
KviKvsSwitchList * switchList()
Definition: KviKvsModuleInterface.h:82
const KviKvsScript * m_pCallback
Definition: KviKvsModuleInterface.h:92
Helper functions for the QString class.
KviKvsVariant * returnValue()
Definition: KviKvsModuleInterface.h:126
virtual bool getParameterCode(unsigned int uParamIdx, QString &szParamBuffer)
Definition: KviKvsRunTimeCall.cpp:44
void kvsUnregisterCallbackCommand(const QString &szCommand)
Definition: KviKvsModuleInterface.h:158
bool hasSwitch(unsigned short u, const QString &szSwitch)
Definition: KviKvsModuleInterface.h:85