00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _FLASH_UTILS_H
00021 #define _FLASH_UTILS_H
00022
00023 #include "compat.h"
00024 #include "swftypes.h"
00025 #include "flashevents.h"
00026 #include "thread_pool.h"
00027 #include "timer.h"
00028
00029 #include <map>
00030
00031 namespace lightspark
00032 {
00033 const tiny_string flash_proxy="http://www.adobe.com/2006/actionscript/flash/proxy";
00034
00035 class ByteArray: public ASObject
00036 {
00037 friend class Loader;
00038 friend class URLLoader;
00039 protected:
00040 uint8_t* bytes;
00041 unsigned int len;
00042 unsigned int position;
00043 ByteArray(const ByteArray& b);
00044 public:
00045 ByteArray();
00046 ~ByteArray();
00047 ASFUNCTION(_getBytesAvailable);
00048 ASFUNCTION(_getLength);
00049 ASFUNCTION(_getPosition);
00050 ASFUNCTION(_setPosition);
00051 ASFUNCTION(readBytes);
00052
00053 void acquireBuffer(uint8_t* buf, int bufLen);
00054 uint8_t* getBuffer(unsigned int size);
00055
00056 static void sinit(Class_base* c);
00057 static void buildTraits(ASObject* o);
00058 ASObject* getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
00059 {
00060 assert_and_throw(implEnable);
00061 throw UnsupportedException("getVariableByName not supported for ByteArray");
00062 return NULL;
00063 }
00064 ASObject* getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true, ASObject* base=NULL);
00065 intptr_t getVariableByMultiname_i(const multiname& name);
00066 void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool skip_impl=false);
00067 void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true, ASObject* base=NULL);
00068 void setVariableByMultiname_i(const multiname& name, intptr_t value);
00069 bool isEqual(ASObject* r);
00070 };
00071
00072 class Timer: public EventDispatcher, public ITickJob
00073 {
00074 private:
00075 void tick();
00076 protected:
00077 uint32_t delay;
00078 uint32_t repeatCount;
00079 bool running;
00080 public:
00081 Timer():delay(0),repeatCount(0),running(false){};
00082 static void sinit(Class_base* c);
00083 ASFUNCTION(_constructor);
00084 ASFUNCTION(start);
00085 ASFUNCTION(reset);
00086 };
00087
00088 class Dictionary: public ASObject
00089 {
00090 friend class ABCVm;
00091 private:
00092 std::map<ASObject*,ASObject*> data;
00093 public:
00094 Dictionary(){}
00095 virtual ~Dictionary();
00096 static void sinit(Class_base*);
00097 static void buildTraits(ASObject* o);
00098 ASFUNCTION(_constructor);
00099 ASObject* getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
00100 {
00101 assert_and_throw(implEnable);
00102 throw UnsupportedException("getVariableByQName not supported for Dictionary");
00103 return NULL;
00104 }
00105 ASObject* getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true, ASObject* base=NULL);
00106 intptr_t getVariableByMultiname_i(const multiname& name)
00107 {
00108 assert_and_throw(implEnable);
00109 throw UnsupportedException("getVariableByMultiName_i not supported for Dictionary");
00110 }
00111 void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool skip_impl=false)
00112 {
00113 assert_and_throw(implEnable);
00114 throw UnsupportedException("setVariableByQName not supported for Dictionary");
00115 }
00116 void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true, ASObject* base=NULL);
00117 void setVariableByMultiname_i(const multiname& name, intptr_t value);
00118 void deleteVariableByMultiname(const multiname& name);
00119 tiny_string toString(bool debugMsg=false);
00120 bool isEqual(ASObject* r)
00121 {
00122 assert_and_throw(implEnable);
00123 throw UnsupportedException("isEqual not supported for Dictionary");
00124 }
00125 bool hasNext(unsigned int& index, bool& out);
00126 bool nextName(unsigned int index, ASObject*& out);
00127 bool nextValue(unsigned int index, ASObject*& out);
00128 };
00129
00130 class Proxy: public ASObject
00131 {
00132 friend class ABCVm;
00133 public:
00134 static void sinit(Class_base*);
00135
00136
00137 ASObject* getVariableByQName(const tiny_string& name, const tiny_string& ns, bool skip_impl=false)
00138 {
00139 if(!implEnable || skip_impl)
00140 return ASObject::getVariableByQName(name,ns,skip_impl);
00141 throw RunTimeException("Proxy::getVariableByQName");
00142 return NULL;
00143 }
00144 ASObject* getVariableByMultiname(const multiname& name, bool skip_impl=false, bool enableOverride=true, ASObject* base=NULL);
00145 intptr_t getVariableByMultiname_i(const multiname& name)
00146 {
00147 assert_and_throw(implEnable);
00148 throw UnsupportedException("getVariableByMultiName_i not supported for Proxy");
00149 }
00150 void setVariableByQName(const tiny_string& name, const tiny_string& ns, ASObject* o, bool skip_impl=false)
00151 {
00152 if(!implEnable || skip_impl)
00153 ASObject::setVariableByQName(name,ns,o,skip_impl);
00154 else
00155 throw RunTimeException("Proxy::setVariableByQName");
00156 }
00157 void setVariableByMultiname(const multiname& name, ASObject* o, bool enableOverride=true, ASObject* base=NULL);
00158 void setVariableByMultiname_i(const multiname& name, intptr_t value)
00159 {
00160 assert_and_throw(implEnable);
00161 throw UnsupportedException("setVariableByMultiName_i not supported for Proxy");
00162 }
00163 void deleteVariableByMultiname(const multiname& name)
00164 {
00165 assert_and_throw(implEnable);
00166 throw UnsupportedException("deleteVariableByMultiName not supported for Proxy");
00167 }
00168 tiny_string toString(bool debugMsg=false)
00169 {
00170 if(debugMsg)
00171 return ASObject::toString(debugMsg);
00172 else
00173 throw UnsupportedException("Proxy is missing some stuff");
00174 }
00175 bool isEqual(ASObject* r)
00176 {
00177 assert_and_throw(implEnable);
00178 throw UnsupportedException("Proxy is missing some stuff");
00179 }
00180 bool hasNext(unsigned int& index, bool& out);
00181 bool nextName(unsigned int index, ASObject*& out);
00182 bool nextValue(unsigned int index, ASObject*& out)
00183 {
00184 assert_and_throw(implEnable);
00185 throw UnsupportedException("Proxy is missing some stuff");
00186 }
00187 };
00188
00189 ASObject* getQualifiedClassName(ASObject*, ASObject* const* args, const unsigned int len);
00190 ASObject* getQualifiedSuperclassName(ASObject*, ASObject* const* args, const unsigned int len);
00191 ASObject* getDefinitionByName(ASObject*, ASObject* const* args, const unsigned int len);
00192 ASObject* getTimer(ASObject* obj,ASObject* const* args, const unsigned int argslen);
00193
00194 };
00195
00196 #endif