ASHandlers.h

Go to the documentation of this file.
00001 //   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
00002 // 
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 3 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00016 
00017 #ifndef __ASHANDLERS_H__
00018 #define __ASHANDLERS_H__
00019 
00020 #include <string>
00021 #include <map>
00022 #include <vector>
00023 #include "action.h" // we should get rid of this probably
00024 #include "swf.h"
00025 
00026 
00027 // Forward declarations
00028 namespace gnash {
00029         class ActionExec;
00030 }
00031 
00032 namespace gnash {
00033 
00034 namespace SWF { // gnash::SWF
00035 
00036 typedef enum {
00037     ARG_NONE = 0,
00038     ARG_STR,
00039     // default hex dump, in case the format is unknown or unsupported
00040     ARG_HEX,
00041     ARG_U8,
00042     ARG_U16,
00043     ARG_S16,
00044     ARG_PUSH_DATA,
00045     ARG_DECL_DICT,
00046     ARG_FUNCTION2
00047 } as_arg_t;
00048 
00049 typedef enum {
00050     ENCGUESS_UNICODE = 0,
00051     ENCGUESS_JIS = 1,
00052     ENCGUESS_OTHER = 2
00053 } as_encoding_guess_t;
00054 
00055 // @@strk@@ should we move this to .cpp file ? it's only
00056 // use is within SWFHandlers, anyway...
00057 typedef void (*action_callback_t)(ActionExec& thread);
00058 //as_environment &env, action_buffer& code, size_t& PC);
00059 class ActionHandler
00060 {
00061 public:
00062     ActionHandler();
00063     ActionHandler(action_type type, action_callback_t func);
00064     ActionHandler(action_type type, std::string name, 
00065                   action_callback_t func);
00066     ActionHandler(action_type type, std::string name, 
00067                   action_callback_t func, as_arg_t format);
00068     ActionHandler(action_type type, std::string name, 
00069                   action_callback_t func, as_arg_t format, int nargs);
00070     ~ActionHandler();
00071 
00073     void execute(ActionExec& thread) const;
00074 
00075     void toggleDebug(bool state) const { _debug = state; }
00076     action_type getType()   const { return _type; }
00077     std::string getName()   const { return _name; }
00078     int getNumArgs()        const { return _stack_args; }
00079     as_arg_t getArgFormat() const { return _arg_format; }
00080 private:
00081     action_type       _type;
00082     std::string       _name;
00083     action_callback_t _callback;
00084     mutable bool      _debug;
00085     int               _stack_args; // the number of args to pop from the stack
00086     as_arg_t          _arg_format;
00087 };
00088 
00090 class SWFHandlers
00091 {
00092 public:
00093 
00097         //typedef std::map<action_type, ActionHandler> container_type;
00098 
00099         // Indexed by action id
00100         typedef std::vector<ActionHandler> container_type;
00101 
00103         static const SWFHandlers& instance();
00104 
00106         void execute(action_type type, ActionExec& thread) const;
00107 
00108         void toggleDebug(bool state) { _debug = state; }
00109 
00110         size_t size() const { return get_handlers().size(); }
00111 
00112         action_type lastType() const
00113         {
00114                 return ACTION_GOTOEXPRESSION;
00115                 //return _handlers[ACTION_GOTOEXPRESSION].getType();
00116         }
00117 
00118         const ActionHandler &operator[] (action_type x) const
00119         {
00120                 //return const_cast<ActionHandler>(_handlers[x]);
00121                 return get_handlers()[x];
00122         }
00123 
00124         const char* action_name(action_type x) const;
00125 
00126 private:
00127 
00128         static container_type & get_handlers();
00129         static std::vector<std::string> & get_property_names();
00130 
00132         //
00142         static void CommonGetUrl(as_environment& env, 
00143                         as_value target, const char* url,
00144                         boost::uint8_t method);
00145 
00147         //
00157         static void CommonSetTarget(ActionExec& thread, 
00158                         const std::string& target_name);
00159 
00161         // Shift-Jis, UTF8, and other. Puts the character count in length,
00162         // and the offsets to the characters in offsets, if offsets is not NULL.
00163         // If not NULL, offsets should be at least s.length().
00164         // offsets are not accurate if the return value is GUESSENC_OTHER
00165         static as_encoding_guess_t GuessEncoding(std::string& s, int& length,
00166             std::vector<int>& offsets);
00167 
00168         static void ActionEnd(ActionExec& thread);
00169         static void ActionNextFrame(ActionExec& thread);
00170         static void ActionPrevFrame(ActionExec& thread);
00171         static void ActionPlay(ActionExec& thread);
00172         static void ActionStop(ActionExec& thread);
00173         static void ActionToggleQuality(ActionExec& thread);
00174         static void ActionStopSounds(ActionExec& thread);
00175         static void ActionGotoFrame(ActionExec& thread);
00176         static void ActionGetUrl(ActionExec& thread);
00177         static void ActionWaitForFrame(ActionExec& thread);
00178         static void ActionSetTarget(ActionExec& thread);
00179         static void ActionGotoLabel(ActionExec& thread);
00180         static void ActionAdd(ActionExec& thread);
00181         static void ActionSubtract(ActionExec& thread);
00182         static void ActionMultiply(ActionExec& thread);
00183         static void ActionDivide(ActionExec& thread);
00184         static void ActionEqual(ActionExec& thread);
00185         static void ActionLessThan(ActionExec& thread);
00186         static void ActionLogicalAnd(ActionExec& thread);
00187         static void ActionLogicalOr(ActionExec& thread);
00188         static void ActionLogicalNot(ActionExec& thread);
00189         static void ActionStringEq(ActionExec& thread);
00190         static void ActionStringLength(ActionExec& thread);
00191         static void ActionSubString(ActionExec& thread);
00192         static void ActionPop(ActionExec& thread);
00193         static void ActionInt(ActionExec& thread);
00194         static void ActionGetVariable(ActionExec& thread);
00195         static void ActionSetVariable(ActionExec& thread);
00196         static void ActionSetTargetExpression(ActionExec& thread);
00197         static void ActionStringConcat(ActionExec& thread);
00198         static void ActionGetProperty(ActionExec& thread);
00199         static void ActionSetProperty(ActionExec& thread);
00200         static void ActionDuplicateClip(ActionExec& thread);
00201         static void ActionRemoveClip(ActionExec& thread);
00202         static void ActionTrace(ActionExec& thread);
00203         static void ActionStartDragMovie(ActionExec& thread);
00204         static void ActionStopDragMovie(ActionExec& thread);
00205         static void ActionStringCompare(ActionExec& thread);
00206         static void ActionThrow(ActionExec& thread);
00207         static void ActionCastOp(ActionExec& thread);
00208         static void ActionImplementsOp(ActionExec& thread);
00209         static void ActionFscommand2(ActionExec& thread);
00210         static void ActionRandom(ActionExec& thread);
00211         static void ActionMbLength(ActionExec& thread);
00212         static void ActionOrd(ActionExec& thread);
00213         static void ActionChr(ActionExec& thread);
00214         static void ActionGetTimer(ActionExec& thread);
00215         static void ActionMbSubString(ActionExec& thread);
00216         static void ActionMbOrd(ActionExec& thread);
00217         static void ActionMbChr(ActionExec& thread);
00218         static void ActionWaitForFrameExpression(ActionExec& thread);
00219         static void ActionPushData(ActionExec& thread);
00220         static void ActionBranchAlways(ActionExec& thread);
00221         static void ActionGetUrl2(ActionExec& thread);
00222         static void ActionBranchIfTrue(ActionExec& thread);
00223         static void ActionCallFrame(ActionExec& thread);
00224         static void ActionGotoExpression(ActionExec& thread);
00225         static void ActionDelete(ActionExec& thread);
00226         static void ActionDelete2(ActionExec& thread);
00227         static void ActionVarEquals(ActionExec& thread);
00228         static void ActionCallFunction(ActionExec& thread);
00229         static void ActionReturn(ActionExec& thread);
00230         static void ActionModulo(ActionExec& thread);
00231         static void ActionNew(ActionExec& thread);
00232         static void ActionVar(ActionExec& thread);
00233         static void ActionInitArray(ActionExec& thread);
00234         static void ActionInitObject(ActionExec& thread);
00235         static void ActionTypeOf(ActionExec& thread);
00236         static void ActionTargetPath(ActionExec& thread);
00237         static void ActionEnumerate(ActionExec& thread);
00238         static void ActionNewAdd(ActionExec& thread);
00239         static void ActionNewLessThan(ActionExec& thread);
00240         static void ActionNewEquals(ActionExec& thread);
00241         static void ActionToNumber(ActionExec& thread);
00242         static void ActionToString(ActionExec& thread);
00243         static void ActionDup(ActionExec& thread);
00244         static void ActionSwap(ActionExec& thread);
00245         static void ActionGetMember(ActionExec& thread);
00246         static void ActionSetMember(ActionExec& thread);
00247         static void ActionIncrement(ActionExec& thread);
00248         static void ActionDecrement(ActionExec& thread);
00249         static void ActionCallMethod(ActionExec& thread);
00250         static void ActionNewMethod(ActionExec& thread);
00251         static void ActionInstanceOf(ActionExec& thread);
00252         static void ActionEnum2(ActionExec& thread);
00253         static void ActionBitwiseAnd(ActionExec& thread);
00254         static void ActionBitwiseOr(ActionExec& thread);
00255         static void ActionBitwiseXor(ActionExec& thread);
00256         static void ActionShiftLeft(ActionExec& thread);
00257         static void ActionShiftRight(ActionExec& thread);
00258         static void ActionShiftRight2(ActionExec& thread);
00259         static void ActionStrictEq(ActionExec& thread);
00260         static void ActionGreater(ActionExec& thread);
00261         static void ActionStringGreater(ActionExec& thread);
00262         static void ActionExtends(ActionExec& thread);
00263         static void ActionConstantPool(ActionExec& thread);
00264         static void ActionDefineFunction2(ActionExec& thread);
00265         static void ActionTry(ActionExec& thread);
00266         static void ActionWith(ActionExec& thread);
00267         static void ActionDefineFunction(ActionExec& thread);
00268         static void ActionSetRegister(ActionExec& thread);
00269 
00270         bool _debug;
00271 
00272         // Use the ::instance() method to get a reference
00273         SWFHandlers();
00274 
00275         // You won't destroy a singleton
00276         ~SWFHandlers();
00277 
00278 };
00279 
00280 
00281 } // namespace gnash::SWF
00282 
00283 } // namespace gnash
00284 
00285 #endif // end of __ASHANDLERS_H__

Generated on Thu Mar 6 18:25:06 2008 for Gnash by  doxygen 1.5.4