2
* Copyright © 2008 Christian Persch
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
20
#ifndef __TOTEM_NPOBJECT_H__
21
#define __TOTEM_NPOBJECT_H__
26
#include "npruntime.h"
28
//FIXME force debug on
29
#define GNOME_ENABLE_DEBUG 1
35
class totemNPClass_base;
36
template<class T> class totemNPClass;
38
class totemNPObject : public NPObject {
42
virtual ~totemNPObject ();
44
void* operator new (size_t aSize) throw ();
47
friend class totemNPClass_base;
49
/* NPObject methods */
50
virtual void Invalidate ();
51
virtual bool HasMethod (NPIdentifier aName);
52
virtual bool Invoke (NPIdentifier aName, const NPVariant *argv, uint32_t argc, NPVariant *_result);
53
virtual bool InvokeDefault (const NPVariant *argv, uint32_t argc, NPVariant *_result);
54
virtual bool HasProperty (NPIdentifier aName);
55
virtual bool GetProperty (NPIdentifier aName, NPVariant *_result);
56
virtual bool SetProperty (NPIdentifier aName, const NPVariant *aValue);
57
virtual bool RemoveProperty (NPIdentifier aName);
58
virtual bool Enumerate (NPIdentifier **_result, uint32_t *_count);
59
virtual bool Construct (const NPVariant *argv, uint32_t argc, NPVariant *_result);
61
/* By Index methods */
62
virtual bool InvokeByIndex (int aIndex, const NPVariant *argv, uint32_t argc, NPVariant *_result);
63
virtual bool GetPropertyByIndex (int aIndex, NPVariant *_result);
64
virtual bool SetPropertyByIndex (int aIndex, const NPVariant *aValue);
65
virtual bool RemovePropertyByIndex (int aIndex);
74
bool IsValid () const { return mPlugin != 0; }
75
totemPlugin* Plugin () const { assert (IsValid ()); return mPlugin; }
77
bool Throw (const char*);
78
bool ThrowPropertyNotWritable ();
79
bool ThrowSecurityError ();
81
bool CheckArgc (uint32_t, uint32_t, uint32_t = uint32_t(-1), bool = true);
82
bool CheckArgType (NPVariantType, NPVariantType, uint32_t = 0);
83
bool CheckArg (const NPVariant*, uint32_t, uint32_t, NPVariantType);
84
bool CheckArgv (const NPVariant*, uint32_t, uint32_t, ...);
86
bool GetBoolFromArguments (const NPVariant*, uint32_t, uint32_t, bool&);
87
bool GetInt32FromArguments (const NPVariant*, uint32_t, uint32_t, int32_t&);
88
bool GetDoubleFromArguments (const NPVariant*, uint32_t, uint32_t, double&);
89
bool GetStringFromArguments (const NPVariant*, uint32_t, uint32_t, const char*&);
90
bool DupStringFromArguments (const NPVariant*, uint32_t, uint32_t, char*&);
91
bool GetObjectFromArguments (const NPVariant*, uint32_t, uint32_t, NPObject*&);
93
bool VoidVariant (NPVariant*);
94
bool NullVariant (NPVariant*);
95
bool BoolVariant (NPVariant*, bool);
96
bool Int32Variant (NPVariant*, int32_t);
97
bool DoubleVariant (NPVariant*, double);
98
bool StringVariant (NPVariant*, const char*, int32_t = -1);
99
bool ObjectVariant (NPVariant*, NPObject*);
103
totemNPClass_base* GetClass() const { return static_cast<totemNPClass_base*>(_class); }
108
#ifdef GNOME_ENABLE_DEBUG
110
#define TOTEM_LOG_CTOR() D ("%s [%p]", __func__, (void*) this)
111
#define TOTEM_LOG_DTOR() D ("%s [%p]", __func__, (void*) this)
113
#define TOTEM_LOG_INVOKE(i, T) \
115
static bool logAccess[G_N_ELEMENTS (methodNames)];\
116
if (!logAccess[i]) {\
117
D ("NOTE: site calls function %s::%s", #T, methodNames[i]);\
118
logAccess[i] = true;\
122
#define TOTEM_LOG_GETTER(i, T) \
124
static bool logAccess[G_N_ELEMENTS (propertyNames)];\
125
if (!logAccess[i]) {\
126
D ("NOTE: site gets property %s::%s", #T, propertyNames[i]);\
127
logAccess[i] = true;\
131
#define TOTEM_LOG_SETTER(i, T) \
133
static bool logAccess[G_N_ELEMENTS (propertyNames)];\
134
if (!logAccess[i]) {\
135
D ("NOTE: site sets property %s::%s", #T, propertyNames[i]);\
136
logAccess[i] = true;\
142
#define TOTEM_LOG_CTOR()
143
#define TOTEM_LOG_DTOR()
144
#define TOTEM_LOG_INVOKE(i, T)
145
#define TOTEM_LOG_GETTER(i, T)
146
#define TOTEM_LOG_SETTER(i, T)
148
#endif /* GNOME_ENABLE_DEBUG */
150
#define TOTEM_WARN_INVOKE_UNIMPLEMENTED(i, T) \
152
static bool logWarning[G_N_ELEMENTS (methodNames)];\
153
if (!logWarning[i]) {\
154
D ("WARNING: function %s::%s is unimplemented", #T, methodNames[i]);\
155
logWarning[i] = true;\
159
#define TOTEM_WARN_1_INVOKE_UNIMPLEMENTED(i, T) \
161
static bool logWarning;\
163
D ("WARNING: function %s::%s is unimplemented", #T, methodNames[i]);\
168
#define TOTEM_WARN_GETTER_UNIMPLEMENTED(i, T) \
170
static bool logWarning[G_N_ELEMENTS (propertyNames)];\
171
if (!logWarning[i]) {\
172
D ("WARNING: getter for property %s::%s is unimplemented", #T, propertyNames[i]);\
173
logWarning[i] = true;\
177
#define TOTEM_WARN_1_GETTER_UNIMPLEMENTED(i, T) \
179
static bool logWarning;\
181
D ("WARNING: getter for property %s::%s is unimplemented", #T, propertyNames[i]);\
186
#define TOTEM_WARN_SETTER_UNIMPLEMENTED(i, T) \
188
static bool logWarning[G_N_ELEMENTS (propertyNames)];\
189
if (!logWarning[i]) {\
190
D ("WARNING: setter for property %s::%s is unimplemented", #T, propertyNames[i]);\
191
logWarning[i] = true;\
195
#define TOTEM_WARN_1_SETTER_UNIMPLEMENTED(i, T) \
197
static bool logWarning;\
199
D ("WARNING: setter for property %s::%s is unimplemented", #T, propertyNames[i]);\
204
#endif /* __TOTEM_NPOBJECT_H__ */