gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12158: more invoke methods tests an


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12158: more invoke methods tests and support
Date: Thu, 15 Apr 2010 14:19:54 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12158
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Thu 2010-04-15 14:19:54 -0600
message:
  more invoke methods tests and support
modified:
  plugin/npapi/external.cpp
  plugin/npapi/external.h
  plugin/npapi/plugin.cpp
  plugin/npapi/plugin.h
  plugin/npapi/pluginScriptObject.cpp
  plugin/npapi/pluginScriptObject.h
  plugin/npapi/scriptable-test.html
  plugin/npapi/test.cpp
=== modified file 'plugin/npapi/external.cpp'
--- a/plugin/npapi/external.cpp 2010-04-15 16:07:35 +0000
+++ b/plugin/npapi/external.cpp 2010-04-15 20:19:54 +0000
@@ -55,7 +55,11 @@
     }
     
     ss << "</arguments>";
-    ss << "<invoke>";
+    ss << "</invoke>";
+
+    // Add a CR on the end so the output is more readable on the other
+    // end. XL should be ignoring the CR anyway.
+    ss << std::endl;
     
     return ss.str();
 }
@@ -273,7 +277,7 @@
 }
 
 std::string
-ExternalInterface::convertNPVariant (NPVariant *value)
+ExternalInterface::convertNPVariant (const NPVariant *value)
 {
     std::stringstream ss;
     

=== modified file 'plugin/npapi/external.h'
--- a/plugin/npapi/external.h   2010-04-15 16:07:35 +0000
+++ b/plugin/npapi/external.h   2010-04-15 20:19:54 +0000
@@ -56,7 +56,7 @@
     NPVariant *parseXML(const std::string &xml);
     std::map<std::string, NPVariant *> parseProperties(const std::string &xml);
     std::vector<NPVariant *> parseArguments(const std::string &xml);
-    std::string convertNPVariant (NPVariant *npv);
+    std::string convertNPVariant (const NPVariant *npv);
 };
 
 #endif // GNASH_PLUGIN_EXTERNAL_H

=== modified file 'plugin/npapi/plugin.cpp'
--- a/plugin/npapi/plugin.cpp   2010-04-14 19:28:49 +0000
+++ b/plugin/npapi/plugin.cpp   2010-04-15 20:19:54 +0000
@@ -68,6 +68,7 @@
 // as prevents the standalone Gnash player from being exec'd. Instead it
 // makes a network connection to localhost:1111 so the developer can use
 // Netcat (nc) to send and receive messages to test the interface.
+// #define NETTEST 1
 #undef NETTEST
 
 #include "plugin.h" 

=== modified file 'plugin/npapi/plugin.h'
--- a/plugin/npapi/plugin.h     2010-04-14 19:28:49 +0000
+++ b/plugin/npapi/plugin.h     2010-04-15 20:19:54 +0000
@@ -137,7 +137,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
 
 // This following logging code is copied from libbase/log.h, but
 // duplicated here because the plugin only needs a more trimmed down

=== modified file 'plugin/npapi/pluginScriptObject.cpp'
--- a/plugin/npapi/pluginScriptObject.cpp       2010-04-14 19:48:12 +0000
+++ b/plugin/npapi/pluginScriptObject.cpp       2010-04-15 20:19:54 +0000
@@ -43,6 +43,7 @@
 #include "npruntime.h"
 #include "plugin.h" 
 #include "callbacks.h" 
+#include "external.h" 
 #include "pluginScriptObject.h"
 
 extern NPNetscapeFuncs NPNFuncs;
@@ -66,48 +67,6 @@
 
 static int controlfd = -1;
 
-#if 0
-
-// 
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_04.html
-// Tell Target Methods. Use TGetProperty, TGetPropertyAsNumber, TSetProperty
-TCallLabel
-TCurrentFrame
-TCurrentLabel
-TGetProperty
-TGetPropertyAsNumber
-TGotoFrame
-TGotoLabel
-TPlay
-TSetProperty
-TStopPlay
-
-// Target Properties
-X_POS
-Y_POS
-X_SCALE
-Y_SCALE
-CURRENT_FRAME                   // read-only
-TOTAL_FRAMES                    // read-only
-ALPHA
-VISIBLE
-WIDTH                           // read-only
-HEIGHT                          // read-only
-ROTATE
-TARGET                          // read-only
-FRAMES_LOADED                   // read-only
-NAME
-DROP_TARGET                     // read-only
-URL                             // read-only
-HIGH_QUALITY
-FOCUS_RECT
-SOUND_BUF_TIME
-
-// Standard Events
-OnProgress
-OnReadyStateChange
-FSCommand
-#endif
-
 bool
 testfunc (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
           uint32_t /* argCount */, NPVariant *result)
@@ -120,7 +79,7 @@
 }
 
 void
-printNPVariant(NPVariant *value)
+printNPVariant(const NPVariant *value)
 {
     if (NPVARIANT_IS_DOUBLE(*value)) {
         double num = NPVARIANT_TO_DOUBLE(*value);
@@ -510,22 +469,21 @@
         // log_debug(" FOUND");
         return true;
     }
-    
+
     return false;
 };
 
 bool
 GnashPluginScriptObject::GetProperty(NPIdentifier name, NPVariant *result)
 {
-//    log_debug(__PRETTY_FUNCTION__);
+    // log_debug(__PRETTY_FUNCTION__);
 
-    log_debug("Getting Property \"");
     if (NPN_IdentifierIsString(name)) {
-        log_debug("%s\"...", NPN_UTF8FromIdentifier(name));
+        log_debug("Getting Property %s\"...", NPN_UTF8FromIdentifier(name));
     } else {
-        log_debug("%d\"...", NPN_IntFromIdentifier(name));
+        log_debug("Getting Property %d\"...", NPN_IntFromIdentifier(name));
     }
-    
+
     std::map<NPIdentifier, NPVariant *>::iterator it;
     it = _properties.find(name);
     if (it != _properties.end()) {
@@ -699,38 +657,24 @@
 {
     log_debug(__PRETTY_FUNCTION__);
 
-    // Build the command message
-    std::stringstream ss;
-    ss << "SetVariable " << name;
-    if (NPVARIANT_IS_DOUBLE(*value)) {
-        ss << " double " << NPVARIANT_TO_DOUBLE(*value);
-    } else if (NPVARIANT_IS_STRING(*value)) {
-        std::string varname = NPVARIANT_TO_STRING(*value).UTF8Characters;
-        ss << " string " << varname;
-    } else if (NPVARIANT_IS_BOOLEAN(*value)) {
-        ss << " boolean\n" << NPVARIANT_TO_BOOLEAN(*value);
-    } else if (NPVARIANT_IS_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\n";         // FIXME: add the object data
-    }
-
-    // Add the CR, so we know where the message ends when parsing.
-    ss << std::endl;
-
+    ExternalInterface ei;
+    
+    std::vector<std::string> iargs;
+    std::string str = ei.makeString(name);
+    iargs.push_back(str);
+    str = ei.convertNPVariant(value);
+    iargs.push_back(str);
+    str = ei.makeInvoke("SetVariable", iargs);
+    
     // Write the message to the Control FD.
-    size_t ret = writePlayer(controlfd, ss.str());
+    size_t ret = writePlayer(controlfd, str);
     // Unless we wrote the same amount of data as the message contained,
     // something went wrong.
-    if (ret != ss.str().size()) {
+    if (ret != str.size()) {
         log_error("Couldn't set the variable, network problems.");
         return false;
     }
-
+    
     return true;
 }
 
@@ -742,84 +686,32 @@
 {
     log_debug(__PRETTY_FUNCTION__);
 
-    NPVariant *value =  (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
-    NULL_TO_NPVARIANT(*value);
+    ExternalInterface ei;
+    std::vector<std::string> iargs;
+    std::string str = ei.makeString(name);
+    iargs.push_back(str);
+    str = ei.makeInvoke("GetVariable", iargs);
 
-    std::stringstream ss;
-    
-    ss << "GetVariable " << name << std::endl;
-    size_t ret = writePlayer(controlfd, ss.str());
-    if (ret != ss.str().size()) {
+    size_t ret = writePlayer(controlfd, str);
+    if (ret != str.size()) {
         log_error("Couldn't send GetVariable request, network problems.");
         return false;
     }
 
     // Have the read function allocate the memory
+    NPVariant *value = 0;
     const char *data = 0;
     char *ptr = 0;
     ptr = const_cast<char *>(data);
     ret = readPlayer(controlfd, &data, 0);
     if (ret == 0) {
-        return value;
-    }
-    // We need a non const pointer to walk through the data.
-    ptr = const_cast<char *>(data);
-
-    // Make sure this mesasge is our response, whnich it should be,
-    // but you never know...
-    if (strncmp(ptr, "GetVariable ", 12) != 0) {
-        log_debug("Illegal response! %s", ptr);
-        return value;
-    } else {
-        // A legit response has CR on the end already
-        log_debug("Legit response: %s", ptr);
-    }    
-    ptr += 12;
-
-#if 0
-    if (strncmp(ptr, name.c_str(), name.size()) == 0) {
-        log_debug("Mismatched variable name! %s", ptr);
-        return value;
-    } else {
-        log_debug("Variable names matched: %s", ptr);
-    }
-#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);
-        DOUBLE_TO_NPVARIANT(num, *value);
-    } else if (strncmp(ptr, "string ", 7) == 0) {
-        ptr += 7;
-        std::string str(ptr);
-        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);
-        BOOLEAN_TO_NPVARIANT(flag, *value);
-    } else if (strncmp(ptr, "int32 ", 6) == 0) {
-        ptr += 6;
-        int num = strtol(ptr, NULL, 0);
-        INT32_TO_NPVARIANT(num, *value);
-    } else if (strncmp(ptr, "null ", 5) == 0) {
-        ptr += 5;
+        value =  (NPVariant *)NPN_MemAlloc(sizeof(NPVariant));
         NULL_TO_NPVARIANT(*value);
-    } else if (strncmp(ptr, "void ", 5) == 0) {
-        ptr += 5;
-        VOID_TO_NPVARIANT(*value);
-    } else if (strncmp(ptr, "object ", 7) == 0) {
-        ptr += 7;
-        log_debug("\tFIXME: %s = object", name);
-        // OBJECT_TO_NPVARIANT(num, *value);
+        return value;
     }
 
+    value = ei.parseXML(data);
+
     // free the memory used for the data, as it was allocated in readPlayer().
     NPN_MemFree(reinterpret_cast<void *>(const_cast<char *>(data)));
     
@@ -908,7 +800,7 @@
             ioctlSocket(fd, FIONREAD, &bytes);
 #endif
         // } else {
-        //     log_debug("There is no data in thhe network");
+        //     log_debug("There is no data in the network");
         }
         
 

=== modified file 'plugin/npapi/pluginScriptObject.h'
--- a/plugin/npapi/pluginScriptObject.h 2010-04-14 03:24:40 +0000
+++ b/plugin/npapi/pluginScriptObject.h 2010-04-15 20:19:54 +0000
@@ -87,9 +87,19 @@
     int getControlFD();
 
     /// Set a variable in the standalone player
+    ///
+    /// @param name the name of the variable to set
+    ///
+    /// @param value the value to set the variable to
+    ///
+    /// @return true or false based on the status of the invoke call
     bool SetVariable(const std::string &name, NPVariant *value);
     
     /// Get the value of a variable from the standalone player
+    ///
+    /// @param name the name of the variable to set
+    ///
+    /// @return the value as returned by the standalone player
     NPVariant *GetVariable(const std::string &name);
 
     // Write to the standalone player over the control socket

=== modified file 'plugin/npapi/scriptable-test.html'
--- a/plugin/npapi/scriptable-test.html 2010-04-10 18:33:53 +0000
+++ b/plugin/npapi/scriptable-test.html 2010-04-15 20:19:54 +0000
@@ -130,16 +130,16 @@
 
 function FlashPlay()
 {
-//          embed.Play();
+          embed.Play();
 //          document.write("Play()<br>");
-        alert("FlashPlay");
+//        alert("FlashPlay");
 }
 
 function FlashRewind()
 {
-//          embed.Rewind();
+          embed.Rewind();
 //          document.write("Rewind()<br>");
-        alert("FlashRewind");
+//        alert("FlashRewind");
 }
 
 function FlashSetZoomRect(left, top, right, bottom)

=== modified file 'plugin/npapi/test.cpp'
--- a/plugin/npapi/test.cpp     2010-04-15 16:07:35 +0000
+++ b/plugin/npapi/test.cpp     2010-04-15 20:19:54 +0000
@@ -243,8 +243,8 @@
     str = ei.makeNumber(135.78);
     iargs.push_back(str);
     
-    str = ei.makeInvoke("barfoo", iargs);
-    xml = "<invoke name=\"barfoo\" 
returntype=\"xml\"><arguments><string>barfoo</string><number>135.78</number></arguments><invoke>";
+    str = ei.makeInvoke("barbyfoo", iargs);
+    xml = "<invoke name=\"barbyfoo\" 
returntype=\"xml\"><arguments><string>barfoo</string><number>135.78</number></arguments></invoke>";
 //    std::cout << str << std::endl;
     regcomp (&regex_pat, xml.c_str(), REG_NOSUB|REG_NEWLINE);
     if (regexec (&regex_pat, reinterpret_cast<const char*>(str.c_str()), 0, 
(regmatch_t *)0, 0) == 0) {
@@ -267,6 +267,8 @@
     }
 }
 
+// We have to implement these two memory allocation functions as
+// they're used in the code we're testing.
 void* NPN_MemAlloc(uint32_t size)
 {
   void * rv = NULL;
@@ -284,28 +286,6 @@
 {
 }
 
-bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier name,
-                     const NPVariant *value)
-{
-    _properties[name] = const_cast<NPVariant *>(value);
-}
-
-bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier name,
-                     const NPVariant *value)
-{
-    return _properties[name];
-}
-
-bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier name,
-                     const NPVariant *value)
-{
-    std::map<NPIdentifier, NPVariant *>::iterator it;
-    it = _properties.find(name);
-    if (it != _properties.end()) {
-        return true;
-    }
-}
-
 nsPluginInstanceBase *
 NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
 {
@@ -337,3 +317,31 @@
 NS_DestroyPluginInstance(nsPluginInstanceBase *aPlugin)
 {
 }
+
+// Implement minimal properties handling
+bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier name,
+                     const NPVariant *value)
+{
+    _properties[name] = const_cast<NPVariant *>(value);
+}
+
+bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier name,
+                     const NPVariant *value)
+{
+    return _properties[name];
+}
+
+bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier name,
+                     const NPVariant *value)
+{
+    std::map<NPIdentifier, NPVariant *>::iterator it;
+    it = _properties.find(name);
+    if (it != _properties.end()) {
+        return true;
+    }
+}
+
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: nil
+// End:


reply via email to

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