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 #ifndef GNASH_PLUGIN_H
00021 #define GNASH_PLUGIN_H
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include "gnashconfig.h"
00025 #endif
00026
00027 #ifndef HAVE_FUNCTION
00028 # ifndef HAVE_func
00029 # define dummystr(x) # x
00030 # define dummyestr(x) dummystr(x)
00031 # define __FUNCTION__ __FILE__":"dummyestr(__LINE__)
00032 # else
00033 # define __FUNCTION__ __func__
00034 # endif
00035 #endif
00036
00037 #ifndef HAVE_PRETTY_FUNCTION
00038 # define __PRETTY_FUNCTION__ __FUNCTION__
00039 #endif
00040
00041
00042 #include <X11/Xlib.h>
00043
00044 #include <X11/cursorfont.h>
00045 #include <glib.h>
00046 #include <string>
00047 #include <map>
00048 #include <vector>
00049 #include <boost/format.hpp>
00050 #include <boost/preprocessor/arithmetic/inc.hpp>
00051 #include <boost/preprocessor/repetition/enum_params.hpp>
00052 #include <boost/preprocessor/repetition/repeat.hpp>
00053 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
00054 #include <boost/preprocessor/seq/for_each.hpp>
00055
00056 #include "pluginbase.h"
00057 #include "pluginScriptObject.h"
00058
00059 namespace gnash {
00060
00061 extern NPBool plugInitialized;
00062
00063 class nsPluginInstance : public nsPluginInstanceBase
00064 {
00065 public:
00066 nsPluginInstance(nsPluginCreateData* );
00067 virtual ~nsPluginInstance();
00068
00069
00070 NPBool init(NPWindow *aWindow);
00071 NPBool isInitialized() { return plugInitialized; }
00072 void shut();
00073
00074 NPError GetValue(NPPVariable variable, void *value);
00075 NPError SetWindow(NPWindow *aWindow);
00076
00078 NPError NewStream(NPMIMEType type, NPStream *stream, NPBool seekable,
00079 uint16_t *stype);
00081 NPError DestroyStream(NPStream * stream, NPError reason);
00082
00084 int32_t WriteReady(NPStream *stream);
00085 int32_t Write(NPStream *stream, int32_t offset, int32_t len, void *buffer);
00086 NPObject *getScriptableObject();
00087 const char *getEmbedURL() const;
00088
00089 GnashPluginScriptObject *getScriptObject() { return _scriptObject; };
00090
00091 private:
00092 void startProc();
00093 std::vector<std::string> getCmdLine(int hostfd, int controlfd);
00094 static bool handlePlayerRequestsWrapper(GIOChannel* iochan, GIOCondition cond, nsPluginInstance* plugin);
00095
00096 bool handlePlayerRequests(GIOChannel* iochan, GIOCondition cond);
00097
00099
00110 bool processPlayerRequest(gchar* buf, gsize len);
00111
00112
00113
00114 std::map<std::string, std::string> _params;
00115
00116 NPP _instance;
00117 Window _window;
00118 std::string _swf_url;
00119 std::string _swf_file;
00120 unsigned int _width;
00121 unsigned int _height;
00122 std::map<std::string, std::string> _options;
00123 int _streamfd;
00124 GIOChannel* _ichan;
00125 int _ichanWatchId;
00126 int _controlfd;
00127 pid_t _childpid;
00128 int _filefd;
00129
00131 std::string _name;
00132 GnashPluginScriptObject *_scriptObject;
00133
00134 std::string getCurrentPageURL() const;
00135 };
00136
00137
00138
00139
00140
00141
00142
00143 #define GNASH_PLUGIN_DEBUG 1
00144
00145
00146
00147
00148
00149 DSOEXPORT void processLog_error(const boost::format& fmt);
00150 DSOEXPORT void processLog_debug(const boost::format& fmt);
00151 DSOEXPORT void processLog_trace(const boost::format& fmt);
00152
00155
00158 #define TOKENIZE_FORMAT(z, n, t) % t##n
00159
00163 #define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n
00164
00168 #define LOG_TYPES (error) (debug) (trace)
00169
00170
00171 #define ARG_NUMBER 4
00172 #define LOG_TEMPLATES(z, n, data)\
00173 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\
00174 inline void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \
00175 {\
00176 if (GNASH_PLUGIN_DEBUG < 1) return; \
00177 boost::format f(t0); \
00178 using namespace boost::io; \
00179 f.exceptions(all_error_bits ^ (too_many_args_bit | \
00180 too_few_args_bit | \
00181 bad_format_string_bit)); \
00182 processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
00183 BOOST_PP_INC(n), \
00184 TOKENIZE_FORMAT, t));\
00185 }
00186
00190 #define GENERATE_LOG_TYPES(r, _, t) \
00191 BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t)
00192
00195 BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES, _, LOG_TYPES)
00196
00197
00198 #endif
00199
00200 }
00201
00202
00203
00204
00205