gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv...
Date: Fri, 30 Mar 2007 14:51:38 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/03/30 14:51:38

Modified files:
        .              : ChangeLog 
        server/asobj   : xmlsocket.cpp xmlsocket.h Global.cpp 
        testsuite/actionscript.all: Makefile.am 
Added files:
        testsuite/actionscript.all: XMLSocket.as 

Log message:
                * server/asobj/xmlsocket.{cpp,h}: first pass at cleanup,
                  fix XMLSocket.connect() to return the correct value.
                * server/asobj/Global.cpp: initialize XMLSocket with the
                  most current interface.
                * testsuite/actionscript.all/: Makefile.am, XMLSocket.as:
                  initial test for XMLSocket (methods availability).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2733&r2=1.2734
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.cpp?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.h?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Makefile.am?cvsroot=gnash&r1=1.70&r2=1.71
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/XMLSocket.as?cvsroot=gnash&rev=1.1

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2733
retrieving revision 1.2734
diff -u -b -r1.2733 -r1.2734
--- ChangeLog   30 Mar 2007 13:57:26 -0000      1.2733
+++ ChangeLog   30 Mar 2007 14:51:37 -0000      1.2734
@@ -1,3 +1,12 @@
+2007-03-30 Sandro Santilli <address@hidden>
+
+       * server/asobj/xmlsocket.{cpp,h}: first pass at cleanup,
+         fix XMLSocket.connect() to return the correct value.
+       * server/asobj/Global.cpp: initialize XMLSocket with the
+         most current interface.
+       * testsuite/actionscript.all/: Makefile.am, XMLSocket.as:
+         initial test for XMLSocket (methods availability).
+
 2007-03-30 Tomas Groth Christensen <address@hidden>
 
        * libbase/FLVParser.cpp: Fixed a few bugs.

Index: server/asobj/xmlsocket.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- server/asobj/xmlsocket.cpp  30 Mar 2007 09:01:29 -0000      1.14
+++ server/asobj/xmlsocket.cpp  30 Mar 2007 14:51:38 -0000      1.15
@@ -54,15 +54,43 @@
 #define MAXHOSTNAMELEN 256
 #endif
 
+#define GNASH_XMLSOCKET_DEBUG
+
 int xml_fd = 0;                 // FIXME: This file descriptor is used by
                                 // XML::checkSocket() when called from the main
                                 // processing loop. 
 
 namespace gnash {
+
+static as_value xmlsocket_connect(const fn_call& fn);
+static as_value xmlsocket_send(const fn_call& fn);
+static as_value xmlsocket_new(const fn_call& fn);
+static as_value xmlsocket_close(const fn_call& fn);
+
+// These are the event handlers called for this object
+static as_value xmlsocket_event_ondata(const fn_call& fn);
+
+static as_object* getXMLSocketInterface();
+static void attachXMLSocketInterface(as_object& o);
+
 const int SOCKET_DATA = 1;
   
 const int INBUF = 10000;
   
+class DSOLOCAL xmlsocket_as_object : public gnash::as_object
+{
+
+public:
+
+        xmlsocket_as_object()
+                :
+                as_object(getXMLSocketInterface())
+        {}
+
+        XMLSocket obj;
+};
+
+  
 XMLSocket::XMLSocket()
 {
 //    GNASH_REPORT_FUNCTION;
@@ -380,53 +408,50 @@
 as_value
 xmlsocket_connect(const fn_call& fn)
 {
-    GNASH_REPORT_FUNCTION;
+    //GNASH_REPORT_FUNCTION;
+
     as_value   method;
     as_value   val;
-    static bool first = true;     // This event handler should only be 
executed once.
     
-    if (!first) {
-        return as_value(true);
-    }
+#ifdef GNASH_XMLSOCKET_DEBUG
+    std::stringstream ss;
+    fn.dump_args(ss);
+    log_msg("XMLSocket.connect(%s) called", ss.str().c_str());
+#endif
     
-    log_msg("%s: nargs=%d\n", __FUNCTION__, fn.nargs);
     boost::intrusive_ptr<xmlsocket_as_object> ptr = 
ensureType<xmlsocket_as_object>(fn.this_ptr);
-    const std::string host = fn.arg(0).to_string();
-    std::string port_str = fn.arg(1).to_string();
-    double port = atof(port_str.c_str());
-    
-    ptr->obj.connect(host.c_str(), static_cast<int>(port));
-    
-#if 0 // use connect return as result
-    // Push result onto stack for onConnect
-    if (ret) {
-        fn.env().push(as_value(true));
-    }
-    else {
-        fn.env().push(as_value(false));
+    std::string host = fn.arg(0).to_std_string(&fn.env());
+    std::string port_str = fn.arg(1).to_std_string(&fn.env());
+    int port = atoi(port_str.c_str());
+    
+    bool success = ptr->obj.connect(host.c_str(), port);
+    
+    if ( success )
+    {
+        static bool first = true;     // This event handler should only be 
executed once.
+        if (!first)
+        {
+            log_warning("XMLSocket.onConnect() not being called the second 
time (dunno why: check %s:%d)", __FILE__, __LINE__);
     }
-#endif
-    fn.env().push(as_value(true));
-    if (fn.this_ptr->get_member("onConnect", &method)) {
+        else
+        {
+            first = false;  // dont call onConnect twice (is this correct??)
+
+            if (fn.this_ptr->get_member("onConnect", &method))
+            {
         //    log_msg("FIXME: Found onConnect!\n");
-        first = false; // what is this for ?
         val = call_method0(method, &fn.env(), fn.this_ptr.get());
-    } else {
-        //ptr->set_event_handler(event_id::SOCK_CONNECT, 
(as_c_function_ptr)&xmlsocket_event_connect);
     }
     
-#if 1
     // TODO: don't allocate on heap!
-    Timer *timer = new Timer;
-    boost::intrusive_ptr<builtin_function> ondata_handler = new 
builtin_function(
-        &xmlsocket_event_ondata, NULL);
-    timer->setInterval(*ondata_handler, 50, 
boost::dynamic_pointer_cast<as_object>(ptr), &fn.env());
-    VM::get().getRoot().add_interval_timer(*timer);
-#endif
-    
-    fn.env().pop();
+            Timer timer;
+            boost::intrusive_ptr<builtin_function> ondata_handler = new 
builtin_function(&xmlsocket_event_ondata, NULL);
+            timer.setInterval(*ondata_handler, 50, 
boost::dynamic_pointer_cast<as_object>(ptr), &fn.env());
+            VM::get().getRoot().add_interval_timer(timer);
+        }
+    }
     
-    return as_value(true);
+    return as_value(success);
 }
 
 
@@ -458,65 +483,19 @@
 }
 
 as_value
-xmlsocket_xml_new(const fn_call& fn)
-{
-    GNASH_REPORT_FUNCTION;
-    //log_msg("%s: nargs=%d\n", __FUNCTION__, nargs);
-    
-    xml_new(fn);
-    return as_value();
-}
-
-as_value
-xmlsocket_new(const fn_call& /* fn */)
+xmlsocket_new(const fn_call& fn)
 {
-    GNASH_REPORT_FUNCTION;
+    //GNASH_REPORT_FUNCTION;
     //log_msg("%s: nargs=%d\n", __FUNCTION__, nargs);
     
     as_object* xmlsock_obj = new xmlsocket_as_object;
-    //log_msg("\tCreated New XMLSocket object at 0x%X\n", (unsigned 
int)xmlsock_obj);
-    xmlsock_obj->init_member("connect",
-                             new builtin_function(xmlsocket_connect));
-    xmlsock_obj->init_member("send", new builtin_function(xmlsocket_send));
-    xmlsock_obj->init_member("close", new builtin_function(xmlsocket_close));
-    xmlsock_obj->init_member("Connected", true);
-    // swf_event*      ev = new swf_event;
-    // m_event_handlers.push_back(ev);
-    // Setup event handlers
-#if 0
-    xmlsock_obj->set_event_handler(event_id::SOCK_DATA,
-                                   (as_c_function_ptr)&xmlsocket_event_ondata);
-    xmlsock_obj->set_event_handler(event_id::SOCK_CLOSE,
-                                   (as_c_function_ptr)&xmlsocket_event_close);
-    //                                                         
xmlsock_obj->set_event_handler(event_id::SOCK_CONNECT,
-    //                                                                         
       (as_c_function_ptr)&xmlsocket_event_connect);
-    xmlsock_obj->set_event_handler(event_id::SOCK_XML,
-                                   (as_c_function_ptr)&xmlsocket_event_xml);
-#endif
-    //periodic_events.set_event_handler(xmlsock_obj);
-    
     
-#if 0 // TODO: setInterval and clearInterval shall be _global methods
-    //
-    //as_c_function_ptr int_handler = (as_c_function_ptr)&timer_setinterval;
-    //env->set_member("setInterval", int_handler);
-    fn.env().set_member("setInterval", timer_setinterval);
-    
-    //as_c_function_ptr clr_handler = timer_clearinterval;
-    // TODO:  check this, sounds suspicious
-    fn.env().set_member("clearInterval", timer_clearinterval);
-    
-    //env->set_variable("setInterval", int_handler, 0);
-    //xmlsock_obj->set_event_handler(event_id::TIMER,
-    //       (as_c_function_ptr)&timer_expire);
-#if 0
-    Timer *timer = new Timer;
-    as_c_function_ptr ondata_handler =
-        (as_c_function_ptr)&xmlsocket_event_ondata;
-    timer->setInterval(ondata_handler, 10);
-    timer->setObject(xmlsock_obj);
-    current_movie->add_interval_timer(timer);
-#endif
+#ifdef GNASH_XMLSOCKET_DEBUG
+    std::stringstream ss;
+    fn.dump_args(ss);
+    log_msg("new XMLSocket(%s) called - created object at %p", 
ss.str().c_str(), (void*)xmlsock_obj);
+#else
+    UNUSED(fn);
 #endif
     
     return as_value(xmlsock_obj);
@@ -595,75 +574,43 @@
   return as_value(true);
 }
 
-as_value
-xmlsocket_event_close(const fn_call& /* fn */)
+static as_object*
+getXMLSocketInterface()
 {
-#if 0
-  as_value* result = fn.result;
-  as_object* this_ptr = fn.this_ptr;
-  int nargs = fn.nargs;
-  int first_arg = fn.first_arg_bottom_index;
-#else
-  log_error("%s: unimplemented!\n", __FUNCTION__);
-#endif
-  return as_value();
-}
-
-as_value
-xmlsocket_event_connect(const fn_call& fn)
-{
-    GNASH_REPORT_FUNCTION;
-    as_value   method;
-    as_value   val;
-    static bool first = true;     // This event handler should only be 
executed once.
-    
-    if (!first) {
-        return as_value(true);
-    }
-    
-    boost::intrusive_ptr<xmlsocket_as_object> ptr = 
ensureType<xmlsocket_as_object>(fn.this_ptr);
-    
-    log_msg("%s: connected = %d\n", __FUNCTION__, ptr->obj.connected());
-    if ((ptr->obj.connected()) && (first)) {
-        first = false;
-        //env->set_variable("success", true, 0);
-        //env->bottom(0) = true;
-        
-        if (fn.this_ptr->get_member("onConnect", &method)) {
-           val = call_method0(method, &fn.env(), fn.this_ptr.get());
-        } else {
-            log_msg("FIXME: Couldn't find onConnect!");
-        }
+    static boost::intrusive_ptr<as_object> o;
+    if ( o == NULL )
+    {
+        o = new as_object();
+        attachXMLSocketInterface(*o);
     }
-    
-    return as_value(val.to_bool()); 
+    return o.get();
 }
-as_value
-xmlsocket_event_xml(const fn_call& /* fn */)
+
+static void
+attachXMLSocketInterface(as_object& o)
 {
-    GNASH_REPORT_FUNCTION;
-#if 0
-    as_value* result = fn.result;
-    as_object* this_ptr = fn.this_ptr;
-    int nargs = fn.nargs;
-    int first_arg = fn.first_arg_bottom_index;
-#else
-    log_error("%s: unimplemented!\n", __FUNCTION__);
-#endif  
-    return as_value();
+    o.init_member("connect", new builtin_function(xmlsocket_connect));
+    o.init_member("send", new builtin_function(xmlsocket_send));
+    o.init_member("close", new builtin_function(xmlsocket_close));
 }
 
-static XMLSocket xs;
-
-int
-check_sockets(int x)
+// extern (used by Global.cpp)
+void xmlsocket_class_init(as_object& global)
 {
-    GNASH_REPORT_FUNCTION;
-    if (xml_fd == 0) {
-        return -1;
+//    GNASH_REPORT_FUNCTION;
+    // This is going to be the global XMLSocket "class"/"function"
+    static boost::intrusive_ptr<builtin_function> cl;
+
+    if ( cl == NULL )
+    {
+        cl=new builtin_function(&xmlsocket_new, getXMLSocketInterface());
+        // Do not replicate all interface to class !
+        //attachXMLSocketInterface(*cl);
     }
     
-    return xs.checkSockets(x);
+    // Register _global.String
+    global.init_member("XMLSocket", cl.get());
+
 }
 
 } // end of gnash namespace

Index: server/asobj/xmlsocket.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- server/asobj/xmlsocket.h    19 Mar 2007 17:11:14 -0000      1.5
+++ server/asobj/xmlsocket.h    30 Mar 2007 14:51:38 -0000      1.6
@@ -82,26 +82,7 @@
     std::vector<as_object *>  _nodes;
 };
 
-
-class DSOLOCAL xmlsocket_as_object : public gnash::as_object
-{
-public:
-    XMLSocket obj;
-};
-
-DSOEXPORT as_value xmlsocket_connect(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_send(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_xml_new(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_new(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_close(const fn_call& fn);
-
-// These are the event handlers called for this object
-DSOEXPORT as_value xmlsocket_event_ondata(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_event_close(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_event_connect(const fn_call& fn);
-DSOEXPORT as_value xmlsocket_event_xml(const fn_call& fn);
-
-DSOEXPORT int check_sockets(int fd);
+void xmlsocket_class_init(as_object& global);
  
 } // end of gnash namespace
 

Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- server/asobj/Global.cpp     28 Mar 2007 20:01:04 -0000      1.56
+++ server/asobj/Global.cpp     30 Mar 2007 14:51:38 -0000      1.57
@@ -18,7 +18,7 @@
 
 // Implementation of the Global ActionScript Object
 
-/* $Id: Global.cpp,v 1.56 2007/03/28 20:01:04 strk Exp $ */
+/* $Id: Global.cpp,v 1.57 2007/03/30 14:51:38 strk Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -420,7 +420,7 @@
        color_class_init(*this);
        selection_class_init(*this); // Selection
        sound_class_init(*this);
-       init_member("XMLSocket", new builtin_function(xmlsocket_new));
+    xmlsocket_class_init(*this);
        date_class_init(*this);
        xml_class_init(*this);
        xmlnode_class_init(*this);

Index: testsuite/actionscript.all/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Makefile.am,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -b -r1.70 -r1.71
--- testsuite/actionscript.all/Makefile.am      30 Mar 2007 07:23:19 -0000      
1.70
+++ testsuite/actionscript.all/Makefile.am      30 Mar 2007 14:51:38 -0000      
1.71
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-# $Id: Makefile.am,v 1.70 2007/03/30 07:23:19 strk Exp $
+# $Id: Makefile.am,v 1.71 2007/03/30 14:51:38 strk Exp $
 
 AUTOMAKE_OPTIONS = dejagnu
 
@@ -103,6 +103,7 @@
        Function.as             \
        with.as                 \
        XML.as                  \
+       XMLSocket.as    \
        rtmp.as                 \
        XMLNode.as              \
        LocalConnection.as      \

Index: testsuite/actionscript.all/XMLSocket.as
===================================================================
RCS file: testsuite/actionscript.all/XMLSocket.as
diff -N testsuite/actionscript.all/XMLSocket.as
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ testsuite/actionscript.all/XMLSocket.as     30 Mar 2007 14:51:38 -0000      
1.1
@@ -0,0 +1,51 @@
+// 
+//   Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+// Test case for Function ActionScript class
+// compile this test case with Ming makeswf, and then
+// execute it like this gnash -1 -r 0 -v out.swf
+
+rcsid="$Id: XMLSocket.as,v 1.1 2007/03/30 14:51:38 strk Exp $";
+
+#include "check.as"
+
+check_equals(typeof(XMLSocket), 'function');
+check_equals(typeof(XMLSocket.connect), 'undefined');
+check_equals(typeof(XMLSocket.close), 'undefined');
+check_equals(typeof(XMLSocket.send), 'undefined');
+check_equals(typeof(XMLSocket.Connected), 'undefined');
+check_equals(typeof(XMLSocket.connected), 'undefined');
+
+check_equals(typeof(XMLSocket.prototype.connect), 'function');
+check_equals(typeof(XMLSocket.prototype.close), 'function');
+check_equals(typeof(XMLSocket.prototype.send), 'function');
+check_equals(typeof(XMLSocket.prototype.Connected), 'undefined');
+check_equals(typeof(XMLSocket.prototype.connected), 'undefined');
+#if OUTPUT_VERSION >= 6
+check(XMLSocket.prototype.hasOwnProperty('connect'));
+check(XMLSocket.prototype.hasOwnProperty('close'));
+check(XMLSocket.prototype.hasOwnProperty('send'));
+#endif
+
+socketObj = new XMLSocket;
+
+check_equals(typeof(socketObj), 'object');
+check_equals(socketObj.__proto__, XMLSocket.prototype);
+check( ! socketObj.hasOwnProperty('connect') );
+check( ! socketObj.hasOwnProperty('close') );
+check( ! socketObj.hasOwnProperty('send') );




reply via email to

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