gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12147: fix handling of returning do


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12147: fix handling of returning doubles and strings.
Date: Tue, 13 Apr 2010 21:24:40 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12147
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Tue 2010-04-13 21:24:40 -0600
message:
  fix handling of returning doubles and strings.
modified:
  plugin/npapi/plugin.cpp
  plugin/npapi/pluginScriptObject.cpp
  plugin/npapi/pluginScriptObject.h
=== modified file 'plugin/npapi/plugin.cpp'
--- a/plugin/npapi/plugin.cpp   2010-04-13 22:11:42 +0000
+++ b/plugin/npapi/plugin.cpp   2010-04-14 03:24:40 +0000
@@ -66,7 +66,7 @@
 //  1: fatal errors (errors preventing the plugin from working as it should)
 //  2: informational messages
 //
-#define GNASH_PLUGIN_DEBUG 2
+#define GNASH_PLUGIN_DEBUG 1
 //#define WRITE_FILE
 
 // Defining this flag disables the pipe to the standalone player, as well
@@ -118,7 +118,6 @@
 void GnashLogDebug(const std::string& msg);
 void GnashLogError(const std::string& msg);
 
-
 /// \brief Return the MIME Type description for this plugin.
 char*
 NPP_GetMIMEDescription(void)
@@ -391,12 +390,12 @@
                             reinterpret_cast<struct sockaddr *>(&sock_in),
                             sizeof(sock_in));
         if (ret == 0) {
-            GnashLogDebug("Connected to debug server");
+            printf("Connected to debug server on fd #%d\n", sockfd);
             _controlfd = sockfd;
             GnashPluginScriptObject *gpso = (GnashPluginScriptObject 
*)_scriptObject;
             gpso->setControlFD(_controlfd);
         } else {
-            GnashLogError("Couldn't connect to debug server");
+            printf("Couldn't connect to debug server: %s\n", strerror(errno));
         }
     }
 #endif
@@ -542,19 +541,12 @@
 
     _window = reinterpret_cast<Window> (aWindow->window);
 
-#ifdef ENABLE_SCRIPTABLE
-    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)_scriptObject;
-//    printf("FIXME: the control FD is #%d\n", _controlfd);
-    gpso->setControlFD(_controlfd);
-#endif
-
     // When testing the interface to the plugin, don't start the player
     // as a debug client "nc -l 1111" is used instead.
-#ifndef NETTEST
     if (!_childpid && !_swf_url.empty()) {
         startProc();
     }
-#endif
+
     return NPERR_NO_ERROR;
 }
 
@@ -1093,6 +1085,11 @@
 
     _controlfd = p2c_controlpipe[1];
     
+#ifdef ENABLE_SCRIPTABLE
+    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)_scriptObject;
+    gpso->setControlFD(_controlfd);
+#endif
+    
     /*
     Setup the command line for starting Gnash
     */

=== modified file 'plugin/npapi/pluginScriptObject.cpp'
--- a/plugin/npapi/pluginScriptObject.cpp       2010-04-13 22:11:42 +0000
+++ b/plugin/npapi/pluginScriptObject.cpp       2010-04-14 03:24:40 +0000
@@ -122,6 +122,30 @@
     return true;
 }
 
+void
+printNPVariant(NPVariant *value)
+{
+    if (NPVARIANT_IS_DOUBLE(*value)) {
+        double num = NPVARIANT_TO_DOUBLE(*value);
+        printf("is double, value %g\n", num);
+    } else if (NPVARIANT_IS_STRING(*value)) {
+        std::string str(NPVARIANT_TO_STRING(*value).UTF8Characters);
+        printf("is string, value %s\n", str.c_str());
+    } else if (NPVARIANT_IS_BOOLEAN(*value)) {
+        bool flag = NPVARIANT_TO_BOOLEAN(*value);
+        printf("is boolean, value %d\n", flag);
+    } else if (NPVARIANT_IS_INT32(*value)) {
+        int num = NPVARIANT_TO_INT32(*value);
+        printf("is int, value %d\n", num);
+    } else if (NPVARIANT_IS_NULL(*value)) {
+        printf("value is null\n");
+    } else if (NPVARIANT_IS_VOID(*value)) {
+        printf("value is void\n");
+    } else if (NPVARIANT_IS_OBJECT(*value)) {
+        printf("value is object\n");
+    }    
+}
+
 // Callbacks for the default methods
 
 // As these callbacks use a generalized typedef for the signature, often some
@@ -202,6 +226,7 @@
         }
     }
     
+    NPN_MemFree(value);
     NPVARIANT_IS_NULL(*result);
     return false;
 }
@@ -270,7 +295,7 @@
         }        
         const char *data = 0;
         char *ptr = 0;
-        ret = gpso->readPlayer(controlfd, &data, 0);
+        ret = gpso->readPlayer(gpso->getControlFD(), &data, 0);
         if (ret == 0) {
             BOOLEAN_TO_NPVARIANT(false, *result);
             return false;
@@ -420,7 +445,7 @@
         }        
         const char *data = 0;
         char *ptr = 0;
-        ret = gpso->readPlayer(controlfd, &data, 0);
+        ret = gpso->readPlayer(gpso->getControlFD(), &data, 0);
         if (ret == 0) {
             BOOLEAN_TO_NPVARIANT(false, *result);
             return false;
@@ -656,7 +681,7 @@
         }        
         const char *data = 0;
         char *ptr = 0;
-        ret = gpso->readPlayer(controlfd, &data, 0);
+        ret = gpso->readPlayer(gpso->getControlFD(), &data, 0);
         if (ret == 0) {
             BOOLEAN_TO_NPVARIANT(false, *result);
             return false;
@@ -1239,7 +1264,6 @@
     GnashLogDebug(__PRETTY_FUNCTION__);
 
     // Build the command message
-    printf("Set Variable \"%s\" to ", name.c_str());
     std::stringstream ss;
     ss << "SetVariable " << name;
     if (NPVARIANT_IS_DOUBLE(*value)) {
@@ -1248,28 +1272,27 @@
         std::string varname = NPVARIANT_TO_STRING(*value).UTF8Characters;
         ss << " string " << varname;
     } else if (NPVARIANT_IS_BOOLEAN(*value)) {
-        ss << " boolean " << NPVARIANT_TO_BOOLEAN(*value);
+        ss << " boolean\n" << NPVARIANT_TO_BOOLEAN(*value);
     } else if (NPVARIANT_IS_INT32(*value)) {
-        ss << " int32 " << NPVARIANT_TO_INT32(*value);
+        ss << " int32\n" << NPVARIANT_TO_INT32(*value);
     } else if (NPVARIANT_IS_NULL(*value)) {
         ss << " null";
     } else if (NPVARIANT_IS_VOID(*value)) {
         ss << " void";
     } else if (NPVARIANT_IS_OBJECT(*value)) {
-        ss << " object";         // FIXME: add the object data
+        ss << " object\n";         // FIXME: add the object data
     }
 
-    if (controlfd > 0) {
-        // Add the CR, so we know where the message ends when parsing.
-        ss << std::endl;
-        // Write the message to the Control FD.
-        size_t ret = writePlayer(controlfd, ss.str());
-        // Unless we wrote the same amount of data as the message contained,
-        // something went wrong.
-        if (ret != ss.str().size()) {
-            GnashLogError("Couldn't set the variable, network problems.");
-            return false;
-        }
+    // Add the CR, so we know where the message ends when parsing.
+    ss << std::endl;
+
+    // Write the message to the Control FD.
+    size_t ret = writePlayer(controlfd, ss.str());
+    // Unless we wrote the same amount of data as the message contained,
+    // something went wrong.
+    if (ret != ss.str().size()) {
+        GnashLogError("Couldn't set the variable, network problems.");
+        return false;
     }
 
     return true;
@@ -1282,25 +1305,24 @@
 GnashPluginScriptObject::GetVariable(const std::string &name)
 {
     GnashLogDebug(__PRETTY_FUNCTION__);
-    printf("Get Variable \"%s\" is ", name.c_str());
 
     NPVariant *value =  (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
     NULL_TO_NPVARIANT(*value);
 
     std::stringstream ss;
     
-    if (controlfd <= 0) {
-        return value;
-    }
-
     ss << "GetVariable " << name << std::endl;
-    writePlayer(controlfd, ss.str());
+    size_t ret = writePlayer(controlfd, ss.str());
+    if (ret != ss.str().size()) {
+        GnashLogError("Couldn't send GetVariable request, network problems.");
+        return false;
+    }
 
     // Have the read function allocate the memory
     const char *data = 0;
     char *ptr = 0;
     ptr = const_cast<char *>(data);
-    int ret = readPlayer(controlfd, &data, 0);
+    ret = readPlayer(controlfd, &data, 0);
     if (ret == 0) {
         return value;
     }
@@ -1327,33 +1349,34 @@
     }
 #endif
     ptr += name.size() + 1;     // don't forget to skip the space
-    
+
     if (strncmp(ptr, "double ", 7) == 0) {
+        ptr += 7;
         double num = strtod(ptr, NULL);
-        ptr += 7;
-        printf("\tdouble %s = %g\n", name.c_str(), num);
         DOUBLE_TO_NPVARIANT(num, *value);
     } else if (strncmp(ptr, "string ", 7) == 0) {
         ptr += 7;
         std::string str(ptr);
-        printf("\tstring %s = %s\n", name.c_str(), str.c_str());
+        int length = str.size();;
+        char *bar = (char *)NPN_MemAlloc(length+1);
+        std::copy(str.begin(), str.end(), bar);
+        bar[length] = 0;  // terminate the new string or bad things happen
+        // When an NPVariant becomes a string object, it *does not* make a 
copy.
+        // Instead it stores the pointer (and length) we just allocated.
+        STRINGN_TO_NPVARIANT(bar, length, *value);
     } else if (strncmp(ptr, "boolean ", 8) == 0) {
         ptr += 8;
         bool flag = strtol(ptr, NULL, 0);
-        printf("\tboolean %s = %d\n", name.c_str(), flag);
         BOOLEAN_TO_NPVARIANT(flag, *value);
     } else if (strncmp(ptr, "int32 ", 6) == 0) {
         ptr += 6;
         int num = strtol(ptr, NULL, 0);
-        printf("\tint32 %s = %d\n", name.c_str(), num);
         INT32_TO_NPVARIANT(num, *value);
     } else if (strncmp(ptr, "null ", 5) == 0) {
         ptr += 5;
-        printf("\t%s = null\n", name.c_str());
         NULL_TO_NPVARIANT(*value);
     } else if (strncmp(ptr, "void ", 5) == 0) {
         ptr += 5;
-        printf("\t%s = void\n", name.c_str());
         VOID_TO_NPVARIANT(*value);
     } else if (strncmp(ptr, "object ", 7) == 0) {
         ptr += 7;
@@ -1361,26 +1384,27 @@
         // OBJECT_TO_NPVARIANT(num, *value);
     }
 
-    ss << std::endl;
-
     // free the memory used for the data, as it was allocated in readPlayer().
     NPN_MemFree(reinterpret_cast<void *>(const_cast<char *>(data)));
     
+    printNPVariant(value);
+    
     return value;
 }
 
 void
 GnashPluginScriptObject::setControlFD(int x)
 {
-    GnashLogDebug(__PRETTY_FUNCTION__);
+//    printf("%s: %d\n", __FUNCTION__, x);
+    
     controlfd = x;
 }
 
 int
 GnashPluginScriptObject::getControlFD()
 {
-//    GnashLogDebug(__PRETTY_FUNCTION__);
-
+    printf("%s: %d\n", __FUNCTION__, controlfd);
+    
     return controlfd;
 };
 
@@ -1390,15 +1414,24 @@
 GnashPluginScriptObject::writePlayer(int fd, const std::string &data)
 {
     GnashLogDebug(__PRETTY_FUNCTION__);
-    return writePlayer(fd, data.c_str(), data.size());
+
+    printf("Writing to fd #%d: %s\n", fd, data.c_str());
+
+    if (fd > 2) {
+        return writePlayer(fd, data.c_str(), data.size());
+    }
+    
+    return 0;
 }
 
 int
 GnashPluginScriptObject::writePlayer(int fd, const char *data, size_t length)
 {
-//    GnashLogDebug(__PRETTY_FUNCTION__);
+    GnashLogDebug(__PRETTY_FUNCTION__);
     
-    if (controlfd > 0) {
+    printf("Writing to fd #%d: %s\n", fd, data);
+
+    if (fd > 2) {
         return ::write(fd, data, length);
     }
     

=== modified file 'plugin/npapi/pluginScriptObject.h'
--- a/plugin/npapi/pluginScriptObject.h 2010-04-13 22:11:42 +0000
+++ b/plugin/npapi/pluginScriptObject.h 2010-04-14 03:24:40 +0000
@@ -120,6 +120,7 @@
     bool Enumerate(NPIdentifier **identifier, uint32_t *count);
     bool Construct(const NPVariant *data, uint32_t argCount, NPVariant 
*result);
 
+    
 private:
     void initializeIdentifiers();
     void setInstance(NPP inst) { _nppinstance = inst; };
@@ -129,6 +130,7 @@
     
     std::map<NPIdentifier, NPVariant *> _properties;
     std::map<NPIdentifier,  NPInvokeFunctionPtr> _methods;
+    // int _control;
 };
 
 #endif /* GNASH_PLUGIN_SCRIPT_OBJECT_H */


reply via email to

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