KVIrc  4.9.2
DeveloperAPIs
KviKvsRunTimeContext.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_RUNTIMECONTEXT_H_
2 #define _KVI_KVS_RUNTIMECONTEXT_H_
3 //=============================================================================
4 //
5 // File : KviKvsRunTimeContext.h
6 // Creation date : Tue 07 Oct 2003 01:49:40 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 #include "KviWindow.h"
29 
30 #include "KviKvsVariant.h"
31 #include "KviKvsHash.h"
32 #include "KviKvsVariantList.h"
33 #include "KviKvsSwitchList.h"
34 
35 class KviKvsScript;
36 class KviConsoleWindow;
37 class KviIrcContext;
38 class KviIrcConnection;
39 class KviKvsTreeNode;
40 class KviKvsObject;
41 class KviKvsReportHandler;
42 
44 {
45  friend class KviKvsRunTimeContext;
46 
47 protected:
48  KviKvsHash * m_pExtendedScopeVariables; // extended scope vars, shallow, may be 0
49  KviKvsSwitchList * m_pAliasSwitchList; // switches for the aliases, shallow, may be 0
50  KviKvsObject * m_pThisObject; // the current object for object function calls
51  QString * m_pScriptFilePath; // the current script file path, shallow, may be 0
53  QString * m_pPopupId;
54 
55 public:
56  // all shallow data, all may be 0
58  : m_pExtendedScopeVariables(0),
59  m_pAliasSwitchList(0),
60  m_pThisObject(0),
61  m_pScriptFilePath(0),
62  m_bAutoDelete(false),
63  m_pPopupId(0){};
64  KviKvsExtendedRunTimeData(KviKvsHash * pExtScopeVariables, bool autoDelete = false)
65  : m_pExtendedScopeVariables(pExtScopeVariables),
66  m_pAliasSwitchList(0),
67  m_pThisObject(0),
68  m_pScriptFilePath(0),
69  m_bAutoDelete(autoDelete),
70  m_pPopupId(0){};
71  KviKvsExtendedRunTimeData(KviKvsSwitchList * pAliasSwitchList, bool autoDelete = false)
72  : m_pExtendedScopeVariables(0),
73  m_pAliasSwitchList(pAliasSwitchList),
74  m_pThisObject(0),
75  m_pScriptFilePath(0),
76  m_bAutoDelete(autoDelete),
77  m_pPopupId(0){};
78  KviKvsExtendedRunTimeData(KviKvsObject * pThisObject, bool autoDelete = false)
79  : m_pExtendedScopeVariables(0),
80  m_pAliasSwitchList(0),
81  m_pThisObject(pThisObject),
82  m_pScriptFilePath(0),
83  m_bAutoDelete(autoDelete),
84  m_pPopupId(0){};
85  KviKvsExtendedRunTimeData(QString * pScriptFilePath, bool autoDelete = false)
86  : m_pExtendedScopeVariables(0),
87  m_pAliasSwitchList(0),
88  m_pThisObject(0),
89  m_pScriptFilePath(pScriptFilePath),
90  m_bAutoDelete(autoDelete),
91  m_pPopupId(0){};
93 
94 public:
95  KviKvsHash * extendedScopeVariables() { return m_pExtendedScopeVariables; };
96  KviKvsSwitchList * aliasSwitchList() { return m_pAliasSwitchList; };
97  KviKvsObject * thisObject() { return m_pThisObject; };
98  QString * scriptFilePath() { return m_pScriptFilePath; };
99  QString * popupId() { return m_pPopupId; };
100  void setPopupId(QString * pPopupId);
101 };
102 
104 {
105  friend class KviKvsScript;
106  friend class KviKvsObject;
107  friend class KviKvsRunTimeCall;
108  friend class KviKvsEventManager;
109 
110 protected:
111  // only KviKvsScript, KviKvsEventManager and KviKvsObject can instantiate this class
113  KviWindow * pWnd,
114  KviKvsVariantList * pParams,
115  KviKvsVariant * pRetVal,
116  KviKvsExtendedRunTimeData * pExtData = 0);
117 
118 public:
120 
121 protected:
122  // stuff that is fixed in the whole script context
123  KviKvsScript * m_pScript; // shallow, may be 0!
124  KviKvsHash * m_pLocalVariables; // owned, never 0
125  KviKvsVariantList * m_pParameterList; // shallow, never 0
126  KviKvsVariant * m_pReturnValue; // shallow, never 0
127 
128  // stuff that is generally global but sometimes may change
129  // during the execution of the script
130  KviWindow * m_pWindow; // shallow, never 0
131 
133  {
134  BreakPending = 1,
135  ContinuePending = 2,
136  HaltCalled = 4,
137  DisableReporting = 8
138  };
139  unsigned int m_uRunTimeFlags; // a combination of RunTimeFlags
140 
142 
143  // error handling
144  bool m_bError; // was error() ever called ?
145  KviKvsTreeNode * m_pDefaultReportLocation; // default report location for error()
146 public:
147  // the window that this script is bound to (it MAY change during the script parsing)
149  {
150  return m_pWindow;
151  };
152  // quick access to the irc context (it MAY be zero!)
154  {
155  return m_pWindow->context();
156  };
157  // quick access to the console that this script is bound to (it MAY be zero, if there is no console)
159  {
160  return m_pWindow->console();
161  };
162  // quick access to the connection: it MAY be zero!
164  {
165  return m_pWindow->connection();
166  };
167 
168  // the local variables of this script
170  {
171  return m_pLocalVariables;
172  };
173  // the global application-wide variables
174  KviKvsHash * globalVariables();
175  // the parameters passed to this script
177  {
178  return m_pParameterList;
179  };
180 
181  // parent script, may be 0!
183  {
184  return m_pScript;
185  };
186 
188  {
189  return m_pReturnValue;
190  };
191 
192  // this is the default error reporting location
193  // it is also used by rfc2812wrapper to find out the current command name!
195  {
196  return m_pDefaultReportLocation;
197  };
198 
199  // the extended stuff
201  {
202  return m_pExtendedData ? m_pExtendedData->extendedScopeVariables() : 0;
203  };
205  {
206  return m_pExtendedData ? m_pExtendedData->aliasSwitchList() : 0;
207  };
209  {
210  return m_pExtendedData ? m_pExtendedData->thisObject() : 0;
211  };
212  QString * scriptFilePath()
213  {
214  return m_pExtendedData ? m_pExtendedData->scriptFilePath() : 0;
215  };
216  QString * popupId()
217  {
218  return m_pExtendedData ? m_pExtendedData->popupId() : 0;
219  };
220 
221  // this MUST be called before any blocking call that might return to the main event loop
222  // and eventually quit kvirc or close the window that this command is associated to
223  // Actually this is a NO-OP but later may really do something that avoids kvirc to crash
224  void enterBlockingSection();
225  // this MUST be called after exiting the blocking section above
226  // if this function returns false your parsing code MUST "return false" immediately:
227  // it means that something rather critical happened and the script
228  // execution cannot continue
229  bool leaveBlockingSection();
230 
231  // Error handling
232 
233  // was error(...) ever called ?
234  bool error() const { return m_bError; };
235 
236  void error(KviKvsTreeNode * pNode, QString szMsgFmt, ...);
237  void warning(KviKvsTreeNode * pNode, QString szMsgFmt, ...);
238  void error(QString szMsgFmt, ...);
239  void warning(QString szMsgFmt, ...);
240  void setDefaultReportLocation(KviKvsTreeNode * pNode);
241  bool errorNoIrcContext();
242  bool warningNoIrcConnection();
243  bool warningMissingParameter();
244 
245  //PRIVATE:
246  // tricky
247  // don't use it: it's only for the parser
248  void setWindow(KviWindow * pWnd)
249  {
250  m_pWindow = pWnd;
251  };
252 
253  // returns the old pointer
254  KviKvsVariant * swapReturnValuePointer(KviKvsVariant * pNewPointer);
255  // the old pointer MUST be reset!
256 
257  // this is called by the parser when a break is encountered
258  // the parser calls setBreakPending() and returns false
259  // the contexts that can handle a break should check breakPending()
260  // after an internal evaluation returned false.
261  // if breakPending() they should handle it with handleBreak() and
262  // return true instead.
264  {
265  m_uRunTimeFlags |= BreakPending;
266  };
267  // this tells if a break command has been called
268  // it may return true if an execution() command has returned false
269  // (if breakPending() there should be no error()
271  {
272  return (m_uRunTimeFlags & BreakPending);
273  };
274  // this is called by the commands that can handle a break
275  void handleBreak()
276  {
277  m_uRunTimeFlags &= ~BreakPending;
278  };
279 
280  // this is called by the parser when a continue is encountered
282  {
283  m_uRunTimeFlags |= ContinuePending;
284  };
285  // this tells if a continue command has been called
287  {
288  return (m_uRunTimeFlags & ContinuePending);
289  };
290  // this is called by the commands that can handle a continue
292  {
293  m_uRunTimeFlags &= ~ContinuePending;
294  };
295 
296  // this is called by the parser when a halt is encountered
297  // the parser then returns false and all the stack frames
298  // above should do the same
300  {
301  m_uRunTimeFlags |= HaltCalled;
302  };
303  bool haltCalled()
304  {
305  return (m_uRunTimeFlags & HaltCalled);
306  };
307 
308  // this is used by KviKvsScript to disable reporting when the Quiet flag is used
310  {
311  m_uRunTimeFlags |= DisableReporting;
312  };
314  {
315  return (m_uRunTimeFlags & DisableReporting);
316  };
318  {
319  m_uRunTimeFlags &= ~DisableReporting;
320  };
321 
322  // clears the error status on this context
323  // this is useful to continue execution after an error
324  // and probably used only in /eval
325  void clearError()
326  {
327  m_bError = false;
328  };
329 
330 protected:
331  void report(bool bError, KviKvsTreeNode * pNode, const QString & szMsgFmt, kvi_va_list va);
332 };
333 
334 #endif
KviKvsSwitchList * m_pAliasSwitchList
Definition: KviKvsRunTimeContext.h:49
RunTimeFlags
Definition: KviKvsRunTimeContext.h:132
bool error() const
Definition: KviKvsRunTimeContext.h:234
KviWindow * window()
Definition: KviKvsRunTimeContext.h:148
Treenode class.
Definition: KviKvsTreeNodeBase.h:40
KviKvsTreeNode * m_pDefaultReportLocation
Definition: KviKvsRunTimeContext.h:145
This class defines a new data type which contains variant data.
Definition: KviKvsVariant.h:351
Definition: KviConsoleWindow.h:75
#define KVIRC_API
Definition: kvi_settings.h:128
void enableReporting()
Definition: KviKvsRunTimeContext.h:317
KviKvsExtendedRunTimeData()
Definition: KviKvsRunTimeContext.h:57
KviKvsExtendedRunTimeData * m_pExtendedData
Definition: KviKvsRunTimeContext.h:141
void setBreakPending()
Definition: KviKvsRunTimeContext.h:263
bool m_bAutoDelete
Definition: KviKvsRunTimeContext.h:52
QString * m_pPopupId
Definition: KviKvsRunTimeContext.h:53
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
KviKvsExtendedRunTimeData(KviKvsObject *pThisObject, bool autoDelete=false)
Definition: KviKvsRunTimeContext.h:78
KviKvsScript * script()
Definition: KviKvsRunTimeContext.h:182
KviKvsVariantList * m_pParameterList
Definition: KviKvsRunTimeContext.h:125
void disableReporting()
Definition: KviKvsRunTimeContext.h:309
The KVIrc Script class.
Definition: KviKvsScript.h:59
An abstraction of a connection to an IRC server.
Definition: KviIrcConnection.h:95
Definition: KviKvsObject.h:50
void setContinuePending()
Definition: KviKvsRunTimeContext.h:281
KviKvsTreeNode * defaultReportLocation()
Definition: KviKvsRunTimeContext.h:194
KviKvsSwitchList * aliasSwitchList()
Definition: KviKvsRunTimeContext.h:204
void handleContinue()
Definition: KviKvsRunTimeContext.h:291
KviKvsExtendedRunTimeData(KviKvsSwitchList *pAliasSwitchList, bool autoDelete=false)
Definition: KviKvsRunTimeContext.h:71
#define kvi_va_list
Definition: kvi_stdarg.h:31
QString * popupId()
Definition: KviKvsRunTimeContext.h:216
bool reportingDisabled()
Definition: KviKvsRunTimeContext.h:313
KviKvsHash * extendedScopeVariables()
Definition: KviKvsRunTimeContext.h:95
Definition: KviKvsRunTimeContext.h:43
QString * scriptFilePath()
Definition: KviKvsRunTimeContext.h:212
void setHaltCalled()
Definition: KviKvsRunTimeContext.h:299
This class defines a new data type which contains hash data.
Definition: KviKvsHash.h:47
KviConsoleWindow * console()
Definition: KviKvsRunTimeContext.h:158
KviIrcConnection * connection()
Definition: KviKvsRunTimeContext.h:163
Definition: KviKvsSwitchList.h:33
KviKvsVariant * m_pReturnValue
Definition: KviKvsRunTimeContext.h:126
bool continuePending()
Definition: KviKvsRunTimeContext.h:286
void clearError()
Definition: KviKvsRunTimeContext.h:325
KviKvsObject * m_pThisObject
Definition: KviKvsRunTimeContext.h:50
KviKvsObject * thisObject()
Definition: KviKvsRunTimeContext.h:97
bool breakPending()
Definition: KviKvsRunTimeContext.h:270
QString * scriptFilePath()
Definition: KviKvsRunTimeContext.h:98
KviKvsScript * m_pScript
Definition: KviKvsRunTimeContext.h:123
bool haltCalled()
Definition: KviKvsRunTimeContext.h:303
void warning(QString fmt,...)
Definition: KviMessageBox.cpp:41
Base class for all windows in KVIrc.
Definition: KviWindow.h:74
KviKvsExtendedRunTimeData(QString *pScriptFilePath, bool autoDelete=false)
Definition: KviKvsRunTimeContext.h:85
KviIrcContext * context()
Definition: KviKvsRunTimeContext.h:153
Definition: KviKvsRunTimeContext.h:103
KviKvsVariantList * parameterList()
Definition: KviKvsRunTimeContext.h:176
KviKvsSwitchList * aliasSwitchList()
Definition: KviKvsRunTimeContext.h:96
Parser class to handle variant variables lists.
bool m_bError
Definition: KviKvsRunTimeContext.h:144
KviKvsObject * thisObject()
Definition: KviKvsRunTimeContext.h:208
Contains the KviWindow class.
Handling of variant data type in KVS.
QString * m_pScriptFilePath
Definition: KviKvsRunTimeContext.h:51
void handleBreak()
Definition: KviKvsRunTimeContext.h:275
KviKvsHash * localVariables()
Definition: KviKvsRunTimeContext.h:169
KviKvsVariant * returnValue()
Definition: KviKvsRunTimeContext.h:187
void setWindow(KviWindow *pWnd)
Definition: KviKvsRunTimeContext.h:248
Handling of hash data type in KVS.
KviKvsExtendedRunTimeData(KviKvsHash *pExtScopeVariables, bool autoDelete=false)
Definition: KviKvsRunTimeContext.h:64
This file contains compile time settings.
KviKvsHash * m_pLocalVariables
Definition: KviKvsRunTimeContext.h:124
Definition: KviKvsRunTimeCall.h:33
KviKvsHash * m_pExtendedScopeVariables
Definition: KviKvsRunTimeContext.h:48
QString * popupId()
Definition: KviKvsRunTimeContext.h:99
Definition: KviIrcContext.h:58
KviConsoleWindow * console()
Returns the console that this window belongs to.
Definition: KviWindow.h:290
KviKvsHash * extendedScopeVariables()
Definition: KviKvsRunTimeContext.h:200
KviWindow * m_pWindow
Definition: KviKvsRunTimeContext.h:130
unsigned int m_uRunTimeFlags
Definition: KviKvsRunTimeContext.h:139
Definition: KviKvsEventManager.h:39