Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef GNASH_PLUGIN_SCRIPT_OBJECT_H
00036 #define GNASH_PLUGIN_SCRIPT_OBJECT_H
00037
00038 #include <map>
00039 #include <string>
00040
00041 #include <glib.h>
00042 #include "npapi.h"
00043 #include "npruntime.h"
00044 #include "GnashNPVariant.h"
00045
00046 #define READFD 0
00047 #define WRITEFD 1
00048
00049 namespace gnash {
00050
00054 void
00055 CopyVariantValue(const NPVariant& from, NPVariant& to);
00056
00057 class GnashPluginScriptObject : public NPObject
00058 {
00059 public:
00060
00061 GnashPluginScriptObject();
00062 GnashPluginScriptObject(NPP npp);
00063 ~GnashPluginScriptObject();
00064
00065 static NPClass *marshalGetNPClass();
00066
00067
00068
00069 static NPObject *marshalAllocate (NPP npp, NPClass *aClass);
00070 static void marshalDeallocate (NPObject *npobj);
00071 static void marshalInvalidate (NPObject *npobj);
00072 static bool marshalHasMethod (NPObject *npobj, NPIdentifier name);
00073 static bool marshalInvoke (NPObject *npobj, NPIdentifier name,
00074 const NPVariant *args, uint32_t argCount,
00075 NPVariant *result);
00076 static bool marshalInvokeDefault (NPObject *npobj, const NPVariant *args,
00077 uint32_t argCount, NPVariant *result);
00078 static bool marshalHasProperty (NPObject *npobj, NPIdentifier name);
00079 static bool marshalGetProperty (NPObject *npobj, NPIdentifier name,
00080 NPVariant *result);
00081 static bool marshalSetProperty (NPObject *npobj, NPIdentifier name,
00082 const NPVariant *value);
00083 static bool marshalRemoveProperty (NPObject *npobj, NPIdentifier name);
00084 static bool marshalEnumerate (NPObject *npobj, void***identifier,
00085 uint32_t *count);
00086 static bool marshalConstruct (NPObject *npobj, const NPVariant *data,
00087 uint32_t count, NPVariant *result);
00088
00089 static NPClass _npclass;
00090
00093
00097 void setControlFD(int x);
00098 int getControlFD();
00099
00103 void setHostFD(int x);
00104 int getHostFD();
00105
00113 bool SetVariable(const std::string &name, const NPVariant& value);
00114
00120 GnashNPVariant GetVariable(const std::string &name);
00121
00122
00123 bool createPipe();
00124
00125
00126 bool closePipe();
00127 bool closePipe(int fd);
00128
00129
00130 bool checkPipe();
00131 bool checkPipe(int fd);
00132
00133 int getReadFD() { return _sockfds[READFD]; };
00134 GIOChannel *getReadChannel() { return _iochan[READFD]; };
00135 int getWriteFD() { return _sockfds[WRITEFD]; };
00136 GIOChannel *getWriteChannel() { return _iochan[WRITEFD]; };
00137
00138
00139 int writePlayer(const std::string &data);
00140 int writePlayer(int fd, const std::string &data);
00141
00142
00143 std::string readPlayer();
00144 std::string readPlayer(int fd);
00145
00146 bool Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args,
00147 uint32_t argCount, NPVariant *result);
00148 bool AddMethod(NPIdentifier name, NPInvokeFunctionPtr func);
00149 void AddProperty(const std::string &name, const std::string &str);
00150 void AddProperty(const std::string &name, double num);
00151 void AddProperty(const std::string &name, int num);
00152
00153 protected:
00154
00155 void Deallocate();
00156 void Invalidate();
00157 bool HasMethod(NPIdentifier name);
00158
00159 bool InvokeDefault(const NPVariant *args, uint32_t argCount,
00160 NPVariant *result);
00161 bool HasProperty(NPIdentifier name);
00162 bool GetProperty(NPIdentifier name, NPVariant *result);
00163 bool SetProperty(NPIdentifier name, const NPVariant& value);
00164 bool RemoveProperty(NPIdentifier name);
00165 bool Enumerate(NPIdentifier **identifier, uint32_t *count);
00166 bool Construct(const NPVariant *data, uint32_t argCount, NPVariant *result);
00167
00168 bool handleInvoke(GIOChannel *iochan, GIOCondition cond);
00169
00171
00182 bool processPlayerRequest(gchar* buf, gsize len);
00183 private:
00184 static bool handleInvokeWrapper(GIOChannel* iochan, GIOCondition cond,
00185 GnashPluginScriptObject* plugin);
00186
00187 void initializeIdentifiers();
00188 void setInstance(NPP inst) { _nppinstance = inst; };
00189
00190
00191 NPP _nppinstance;
00192
00193 std::map<NPIdentifier, GnashNPVariant> _properties;
00194 std::map<NPIdentifier, NPInvokeFunctionPtr> _methods;
00195
00196 int _sockfds[2];
00197 GIOChannel *_iochan[2];
00198
00199 int _watchid;
00200 };
00201
00202 }
00203
00204 #endif // GNASH_PLUGIN_SCRIPT_OBJECT_H
00205
00206
00207
00208
00209