• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

plugin.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 /* Xlib/Xt stuff */
00042 #include <X11/Xlib.h>
00043 //#include <X11/Intrinsic.h>
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     // We are required to implement these three methods.
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; }; // FIXME: debug only!!!
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     // EMBED or OBJECT attributes / parameters
00113     // @@ this should likely replace the _options element below
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 // Define the following to make the plugin verbose
00138 // WARNING: will write to .xsession_errors !
00139 // Values:
00140 //  0: no messages at all
00141 //  1: fatal errors (errors preventing the plugin from working as it should)
00142 //  2: informational messages
00143 #define GNASH_PLUGIN_DEBUG 1
00144 
00145 // This following logging code is copied from libbase/log.h, but
00146 // duplicated here because the plugin only needs a more trimmed down
00147 // version that doesn't require any Gnash libraires to keep the
00148 // memory footprint down.
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 // end of __PLUGIN_H__
00198 #endif
00199 
00200 } // end of gnash namespace
00201 
00202 // local Variables:
00203 // mode: C++
00204 // indent-tabs-mode: nil
00205 // End:

Generated on Fri Mar 16 2012 15:46:11 for Gnash by  doxygen 1.7.1