gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash libamf/sol.h server/asobj/SharedObject.cp...


From: Rob Savoye
Subject: [Gnash-commit] gnash libamf/sol.h server/asobj/SharedObject.cp...
Date: Wed, 19 Dec 2007 05:18:47 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Rob Savoye <rsavoye>    07/12/19 05:18:47

Modified files:
        libamf         : sol.h 
        server/asobj   : SharedObject.cpp 
        .              : ChangeLog 

Log message:
                * libamf/sol.h: Add overloaded writeFile with no args that uses
                only private data. Add accessors for filespec and the object
                name. 
                * server/asobj/SharedObject.{cpp,h}: Add support for
                PropertyLists. Implement flush, getLocal, and getSize().

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.h?cvsroot=gnash&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/SharedObject.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5215&r2=1.5216

Patches:
Index: libamf/sol.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- libamf/sol.h        18 Dec 2007 01:55:18 -0000      1.2
+++ libamf/sol.h        19 Dec 2007 05:18:46 -0000      1.3
@@ -40,7 +40,7 @@
 // After this is a series of AMF objects
 namespace amf
 {
-  class SOL {
+class SOL {
 public:
     SOL();
     ~SOL();
@@ -56,6 +56,7 @@
     bool formatHeader(std::string &name, int filesize);
 
     // write the data to disk as a .sol file
+    bool writeFile();
     bool writeFile(std::string &filespec, std::string &objname);
     bool writeFile(std::string &filespec, const char *objname);
     bool writeFile(const char *filespec, const char *objname);
@@ -63,7 +64,6 @@
     // read the .sol file from disk
     bool readFile(std::string &filespec);
 
-    
     std::vector<uint8_t> getHeader() { return _header; };
 
     // Add the AMF objects that are the data of the file
@@ -72,6 +72,13 @@
     AMF::amf_element_t getElement(int x) { return _amfobjs[x]; };
 
     void dump();
+//protected:
+    void setFilespec(std::string &x) { _filespec = x; };
+    std::string &getFilespec() { return _filespec; };
+
+    void setObjectName(std::string &x) { _objname = x; };
+    std::string &getObjectName() { return _objname; };
+        
  private:
     std::vector<uint8_t> _header;
     std::vector<uint8_t> _data;

Index: server/asobj/SharedObject.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/SharedObject.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/asobj/SharedObject.cpp       31 Aug 2007 21:53:32 -0000      1.12
+++ server/asobj/SharedObject.cpp       19 Dec 2007 05:18:46 -0000      1.13
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include "amf.h"
+#include "sol.h"
 #include "SharedObject.h"
 #include "as_object.h" // for inheritance
 #include "log.h"
@@ -28,6 +30,12 @@
 #include "smart_ptr.h" // for boost intrusive_ptr
 #include "builtin_function.h" // need builtin_function
 #include "Object.h" // for getObjectInterface
+#include "VM.h"
+#include "PropertyList.h"
+#include "Property.h"
+#include "string_table.h"
+
+using namespace amf;
 
 namespace gnash {
 
@@ -37,53 +45,93 @@
 as_value sharedobject_getsize(const fn_call& fn);
 as_value sharedobject_ctor(const fn_call& fn);
 
+void sharedobject_iter(string_table::key key, const as_value &reference);
+
+static SOL sol;
+
+static void
+attachProperties(as_object& o)
+{
+    GNASH_REPORT_FUNCTION;
+     as_object *proto = new as_object();
+     o.init_member("data", proto);
+}
+
 static void
 attachSharedObjectInterface(as_object& o)
 {
+    GNASH_REPORT_FUNCTION;
        // TODO: clear, flush and getSize not in SWF<6 , it seems
        o.init_member("clear", new builtin_function(sharedobject_clear));
        o.init_member("flush", new builtin_function(sharedobject_flush));
        //o.init_member("getLocal", new 
builtin_function(sharedobject_getlocal));
        o.init_member("getSize", new builtin_function(sharedobject_getsize));
+    attachProperties(o);
 }
 
 static void
 attachSharedObjectStaticInterface(as_object& o)
 {
+    GNASH_REPORT_FUNCTION;
        o.init_member("getLocal", new builtin_function(sharedobject_getlocal));
+    attachProperties(o);
 }
 
 static as_object*
 getSharedObjectInterface()
 {
+    GNASH_REPORT_FUNCTION;
        static boost::intrusive_ptr<as_object> o;
-       if ( ! o )
-       {
+    if ( ! o ) {
                o = new as_object(getObjectInterface());
                attachSharedObjectInterface(*o);
        }
        return o.get();
 }
 
-class SharedObject: public as_object
-{
 
+class SharedObject: public as_object, public amf::SOL
+{
 public:
-
        SharedObject()
                :
                as_object(getSharedObjectInterface())
-       {}
+        { 
+        }
+};
 
-       // override from as_object ?
-       //std::string get_text_value() const { return "SharedObject"; }
+// Turn each property into an AMF element
+void
+sharedobject_iter(string_table::key key, const as_value &reference)
+{
+//    GNASH_REPORT_FUNCTION;
 
-       // override from as_object ?
-       //double get_numeric_value() const { return 0; }
-};
+    AMF amf;
+    AMF::amf_element_t el;
+    string_table& st = VM::get().getStringTable();
+    string str = st.string_table::value(key);
+//    cerr << "FIXME: yes!!!!! " << str << ": "<< reference.to_string() << 
endl;
 
-as_value sharedobject_clear(const fn_call& fn)
+    if (reference.is_string()) {
+        string str = reference.to_string();
+        amf.createElement(&el, str, str);
+    }
+    if (reference.is_bool()) {
+        bool b;
+        amf.createElement(&el, str, b);
+    }
+    if (reference.is_number()) {
+        double dub = reference.to_number();
+        amf.createElement(&el, str, dub);
+    }
+    
+    sol.addObj(el);
+}
+
+as_value
+sharedobject_clear(const fn_call& fn)
 {
+    GNASH_REPORT_FUNCTION;
        boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
        UNUSED(obj);
 
@@ -95,51 +143,56 @@
        return as_value();
 }
 
-as_value sharedobject_flush(const fn_call& fn)
+as_value
+sharedobject_flush(const fn_call& fn)
 {
+    GNASH_REPORT_FUNCTION;
+
        boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
-       UNUSED(obj);
 
-       static bool warned=false;
-       if ( ! warned ) {
-               log_unimpl (__FUNCTION__);
-               warned=true;
-       }
-       return as_value();
+     log_msg("Flushing to file %s", obj->getFilespec().c_str());
+
+     string_table::key dataKey = VM::get().getStringTable().find("data");
+     as_value as = obj->getMember(dataKey);
+     boost::intrusive_ptr<as_object> ptr = as.to_object();
+     ptr->visitPropertyValues(sharedobject_iter);
+     sol.writeFile(obj->getFilespec(), "settings");
+    return as_value(true);
 }
 
-as_value sharedobject_getlocal(const fn_call& /*fn*/)
+as_value
+sharedobject_getlocal(const fn_call& fn)
 {
+    GNASH_REPORT_FUNCTION;
        // This should return a SharedObject, and it's a static function
 
-       //boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
-       //UNUSED(obj);
+//    static boost::intrusive_ptr<as_object> obj = new 
as_object(getSharedObjectInterface());
+    static boost::intrusive_ptr<SharedObject> obj = new SharedObject();
 
-       static bool warned=false;
-       if ( ! warned ) {
-               log_unimpl (__FUNCTION__);
-               warned=true;
+    if (fn.nargs > 0) {
+        std::string filespec = fn.arg(0).to_string();
+        obj->setFilespec(filespec);
+        obj->setObjectName(filespec);
+        log_msg("Opening SharedObject file: %s", filespec.c_str());
        }
-       return as_value();
+    
+    return as_value(obj.get()); // will keep alive
 }
 
-as_value sharedobject_getsize(const fn_call& fn)
+as_value
+sharedobject_getsize(const fn_call& fn)
 {
+    GNASH_REPORT_FUNCTION;
        boost::intrusive_ptr<SharedObject> obj = 
ensureType<SharedObject>(fn.this_ptr);
-       UNUSED(obj);
-
-       static bool warned=false;
-       if ( ! warned ) {
-               log_unimpl (__FUNCTION__);
-               warned=true;
-       }
-       return as_value();
+    return as_value(obj->size());
 }
 
 as_value
 sharedobject_ctor(const fn_call& /* fn */)
 {
-       boost::intrusive_ptr<as_object> obj = new SharedObject;
+    GNASH_REPORT_FUNCTION;
+//    boost::intrusive_ptr<as_object> obj = new SharedObject;
+    static boost::intrusive_ptr<as_object> obj = new 
as_object(getSharedObjectInterface());
        
        return as_value(obj.get()); // will keep alive
 }
@@ -147,21 +200,19 @@
 // extern (used by Global.cpp)
 void sharedobject_class_init(as_object& global)
 {
+    GNASH_REPORT_FUNCTION;
        // This is going to be the global SharedObject "class"/"function"
        static boost::intrusive_ptr<builtin_function> cl;
 
-       if ( cl == NULL )
-       {
+    if (cl == NULL) {
                cl=new builtin_function(&sharedobject_ctor, 
getSharedObjectInterface());
                // replicate all interface to class, to be able to access
                // all methods as static functions
                attachSharedObjectStaticInterface(*cl);
-                    
        }
 
        // Register _global.SharedObject
        global.init_member("SharedObject", cl.get());
-
 }
 
 } // end of gnash namespace

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5215
retrieving revision 1.5216
diff -u -b -r1.5215 -r1.5216
--- ChangeLog   19 Dec 2007 01:57:08 -0000      1.5215
+++ ChangeLog   19 Dec 2007 05:18:46 -0000      1.5216
@@ -1,3 +1,11 @@
+2007-12-18  Rob Savoye  <address@hidden>
+
+       * libamf/sol.h: Add overloaded writeFile with no args that uses
+       only private data. Add accessors for filespec and the object
+       name. 
+       * server/asobj/SharedObject.{cpp,h}: Add support for
+       PropertyLists. Implement flush, getLocal, and getSize().
+
 2007-12-18 Sandro Santilli <address@hidden>
 
        * server/array.cpp (array_new): drop an absurdly complex and unneeded
@@ -66,7 +74,7 @@
 
        * cygnal/testsuite/cygnal.all/Makefile.am: Add server to include
        paths.
-       * libamf/amf.{cpp,h}: Include as_objecth Don't make swapBytes
+       * libamf/amf.{cpp,h}: Include as_object.h. Don't make swapBytes()
        static, we want to use it elsewhere. Add methods for creating
        elements, and encoding elements.
        * libamf/sol.cpp: Store elements in a vactor as they get




reply via email to

[Prev in Thread] Current Thread [Next in Thread]