KVIrc  4.9.2
DeveloperAPIs
KviKvsObject.h
Go to the documentation of this file.
1 #ifndef _KVI_KVS_OBJECT_H_
2 #define _KVI_KVS_OBJECT_H_
3 //=============================================================================
4 //
5 // File : KviKvsObject.h
6 // Creation date : Wed 08 Oct 2003 02:31:57 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 "KviQString.h"
29 #include "KviPointerList.h"
30 #include "KviKvsRunTimeCall.h"
33 #include "KviKvsTypes.h"
34 
35 #include <QObject>
36 
38 
40 {
41  KviKvsObject * pSourceObject; // source object (owner of the struct)
42  KviKvsObject * pTargetObject; // target object
43  QString szSignal; // source signal name
44  QString szSlot; // target slot function
46 
49 
50 class KVIRC_API KviKvsObject : public QObject
51 {
52  friend class KviKvsObjectController;
53  friend class KviKvsObjectClass;
54  Q_OBJECT
55 public:
56  KviKvsObject(KviKvsObjectClass * pClass, KviKvsObject * pParent, const QString & szName);
57  virtual ~KviKvsObject();
58 
59 protected:
60  // main data
61  QString m_szName; // object name
62  kvs_hobject_t m_hObject; // global object handle
63  KviKvsObjectClass * m_pClass; // the class definition
64 
65  KviKvsHash * m_pDataContainer; // member variables
66 
68 
70 
71  KviPointerHashTable<QString, KviKvsObjectConnectionList> * m_pSignalDict; // our signals connected to other object functions
72 
73  KviKvsObjectConnectionList * m_pConnectionList; // signals connected to this object functions
74 
75  // this is valid when processing one of our slots
77  QString m_szSignalName;
78 
79  // if this object wraps a qt one, it is here
80  QObject * m_pObject;
81  bool m_bObjectOwner; // do we have to destroy it ?
82 
83  // We're going to die soon after the control is given back to the event loop
85  // We're going to die BEFORE the control is given back to the event loop
87  // Did we already call the destructor ?
89 
90 public:
91  kvs_hobject_t handle() { return m_hObject; };
92 
93  // the wrapped Qt object (may be 0!)
94  QObject * object() const { return m_pObject; };
95  void setObject(QObject * o, bool bIsOwned = true);
96 
97  const QString & getName() { return m_szName; };
98 
99  KviKvsObject * parentObject() { return (KviKvsObject *)parent(); };
100  QWidget * parentScriptWidget();
101 
102  bool connectSignal(const QString & sigName, KviKvsObject * target, const QString & slotName);
103  bool disconnectSignal(const QString & sigName, KviKvsObjectConnection * con);
104  bool disconnectSignal(const QString & sigName, KviKvsObject * target, const QString & slotName);
105 
106  // Emits a signal by calling all the attacched slots in an unspecified order.
107  // Returns the number of slots called (may be 0, if no slot is connected)
108  // The parameters are preserved.
109  // this is intended to be called from other function calls (the parameters are copied from pOuterCall)
110  // since we should NEVER emit totally spontaneous signals: all of them
111  // should be generated inside object functions (either from scripting or by core calls)
112  int emitSignal(const QString & sigName, KviKvsObjectFunctionCall * pOuterCall, KviKvsVariantList * pParams = 0);
113 
114  void setSignalSender(kvs_hobject_t hObject) { m_hSignalSender = hObject; };
115  kvs_hobject_t signalSender() { return m_hSignalSender; };
116  void setSignalName(const QString & szSigName) { m_szSignalName = szSigName; };
117 
119 
120  KviKvsHash * dataContainer() { return m_pDataContainer; };
121 
122  bool die();
123  bool dieNow();
124 
125  KviKvsObjectClass * getExactClass() { return m_pClass; };
126  KviKvsObjectClass * getClass(const QString & classOverride = QString());
127  bool inheritsClass(KviKvsObjectClass * pClass);
128  bool inheritsClass(const QString & szClass);
129 
130  KviKvsObjectFunctionHandler * lookupFunctionHandler(const QString & funcName, const QString & classOverride = QString());
131 
132  // Registers a private implementation of a function
133  // The function may or may not be already registered in the class
134  // If szCode is empty the the private implementation is removed instead
135  void registerPrivateImplementation(const QString & szFunctionName, const QString & szCode);
136 
137  // ONLY pCaller can be zero here!
138  // please use one of the wrappers, if possible
139  bool callFunction(
140  KviKvsObject * pCaller, // calling object, can be zero (used for the "internal" access list verification)
141  const QString & fncName, // name of the function to call
142  const QString & classOverride, // eventual class override for the functon call, may be QString()
143  KviKvsRunTimeContext * pContext, // calling runtime context (you'll have problems with instantiating this... :P )
144  KviKvsVariant * pRetVal, // the return value
145  KviKvsVariantList * pParams); // the parameters for the call
146  // a nice and simple wrapper: it accepts a parameter list only (eventually 0)
147  bool callFunction(KviKvsObject * pCaller, const QString & fncName, KviKvsVariantList * pParams = 0);
148  // this one gets a non null ret val too
149  bool callFunction(KviKvsObject * pCaller, const QString & fncName, KviKvsVariant * pRetVal, KviKvsVariantList * pParams = 0);
150 
151  KviKvsObject * findChild(const QString & szClass, const QString & szName);
152  void killAllChildrenWithClass(KviKvsObjectClass * cl);
153 
154 protected:
155  void registerConnection(KviKvsObjectConnection * con);
156  bool unregisterConnection(KviKvsObjectConnection * con);
157 
158  virtual bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams);
159 
160  void registerChild(KviKvsObject * c);
161  void unregisterChild(KviKvsObject * c);
162 
163  virtual bool eventFilter(QObject * o, QEvent * e); //necessary ?
164  virtual void timerEvent(QTimerEvent * e);
165 
166 protected:
167  bool function_name(KviKvsObjectFunctionCall * c);
168  bool function_startTimer(KviKvsObjectFunctionCall * c);
169  bool function_killTimer(KviKvsObjectFunctionCall * c);
170  bool function_className(KviKvsObjectFunctionCall * c);
171  bool function_findChild(KviKvsObjectFunctionCall * c);
172  bool function_childCount(KviKvsObjectFunctionCall * c);
173  bool function_emit(KviKvsObjectFunctionCall * c);
174  bool function_children(KviKvsObjectFunctionCall * c);
175  bool function_signalSender(KviKvsObjectFunctionCall * c);
176  bool function_signalName(KviKvsObjectFunctionCall * c);
177  bool function_destructor(KviKvsObjectFunctionCall * c);
178  bool function_parent(KviKvsObjectFunctionCall * c);
179  bool function_property(KviKvsObjectFunctionCall * c);
180  bool function_setProperty(KviKvsObjectFunctionCall * c);
181  bool function_listProperties(KviKvsObjectFunctionCall * c);
182 protected slots:
183  void delayedDie();
184  void objectDestroyed();
185 
186 private:
187  void callDestructor();
188 };
189 
190 #define KVSO_PARAMETER(a, b, c, d) KVS_PARAMETER(a, b, c, d)
191 
192 #define KVSO_PARAMETERS_BEGIN(pCall) \
193  KVS_PARAMETERS_BEGIN(parameter_format_list)
194 
195 #define KVSO_PARAMETERS_END(pCall) \
196  KVS_PARAMETERS_END \
197  if(!KviKvsParameterProcessor::process(pCall->params(), pCall->context(), parameter_format_list)) \
198  return false;
199 
200 #endif
KviKvsObjectClass * m_pClass
Definition: KviKvsObject.h:63
void setSignalSender(kvs_hobject_t hObject)
Definition: KviKvsObject.h:114
QString szSlot
Definition: KviKvsObject.h:44
kvs_hobject_t handle()
Definition: KviKvsObject.h:91
KviPointerHashTable< QString, KviKvsObjectConnectionList > * m_pSignalDict
Definition: KviKvsObject.h:71
QString m_szSignalName
Definition: KviKvsObject.h:77
This class defines a new data type which contains variant data.
Definition: KviKvsVariant.h:351
#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
KviKvsHash * m_pDataContainer
Definition: KviKvsObject.h:65
KviPointerHashTable< QString, KviKvsObjectFunctionHandler > * m_pFunctionHandlers
Definition: KviKvsObject.h:69
KviKvsObject * parentObject()
Definition: KviKvsObject.h:99
kvs_hobject_t m_hSignalSender
Definition: KviKvsObject.h:76
Class to handle variant variables lists.
Definition: KviKvsVariantList.h:41
bool m_bDestructorCalled
Definition: KviKvsObject.h:88
Definition: KviKvsObjectController.h:37
Definition: KviKvsObjectFunctionCall.h:33
Definition: KviKvsObject.h:50
QString m_szName
Definition: KviKvsObjectClass.h:65
KviKvsObjectFunctionHandler * lookupFunctionHandler(const QString &szFunc)
Definition: KviKvsObjectClass.h:103
KviKvsObjectClass * getExactClass()
Definition: KviKvsObject.h:125
Definition: KviKvsObjectClass.h:49
KviPointerList< KviKvsObject > * m_pChildList
Definition: KviKvsObject.h:67
KviKvsObject * pTargetObject
Definition: KviKvsObject.h:42
const QString & getName()
Definition: KviKvsObject.h:97
#define e
Definition: detector.cpp:69
This class defines a new data type which contains hash data.
Definition: KviKvsHash.h:47
QString szSignal
Definition: KviKvsObject.h:43
KviKvsObjectConnectionList * m_pConnectionList
Definition: KviKvsObject.h:73
friend class KviKvsObject
Definition: KviKvsObjectClass.h:51
bool m_bAboutToDie
Definition: KviKvsObject.h:86
KviPointerHashTable< QString, KviKvsObjectFunctionHandler > * m_pFunctionHandlers
Definition: KviKvsObjectClass.h:67
QObject * m_pObject
Definition: KviKvsObject.h:80
void setSignalName(const QString &szSigName)
Definition: KviKvsObject.h:116
KviPointerList< KviKvsObjectConnection > KviKvsObjectConnectionList
Definition: KviKvsObject.h:47
C++ Template based double linked pointer list class.
QObject * object() const
Definition: KviKvsObject.h:94
A template double linked list of pointers.
Definition: KviPointerList.h:55
KviPointerListIterator< KviKvsObjectConnection > KviKvsObjectConnectionListIterator
Definition: KviKvsObject.h:48
struct _KviKvsObjectConnection KviKvsObjectConnection
Definition: KviKvsRunTimeContext.h:103
#define o
Definition: detector.cpp:79
bool m_bInDelayedDeath
Definition: KviKvsObject.h:84
bool m_bObjectOwner
Definition: KviKvsObject.h:81
KviKvsHash * dataContainer()
Definition: KviKvsObject.h:120
KviKvsObject * pSourceObject
Definition: KviKvsObject.h:41
kvs_hobject_t m_hObject
Definition: KviKvsObject.h:62
void * kvs_hobject_t
Definition: KviKvsTypes.h:32
Definition: KviKvsObject.h:39
int init()
Definition: winamp.cpp:118
kvs_hobject_t signalSender()
Definition: KviKvsObject.h:115
This file contains compile time settings.
KviPointerHashTable< QString, KviKvsObjectFunctionHandler > * functionHandlers()
Definition: KviKvsObject.h:118
A fast KviPointerList iterator.
Definition: KviPointerList.h:57
Helper functions for the QString class.
QString m_szName
Definition: KviKvsObject.h:61
Definition: KviKvsObjectFunctionHandler.h:34