[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10468: Add a getArgs method to fn_c
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10468: Add a getArgs method to fn_call, to expose the underlying args vector. |
Date: |
Thu, 18 Dec 2008 23:39:32 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10468
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Thu 2008-12-18 23:39:32 +0100
message:
Add a getArgs method to fn_call, to expose the underlying args vector.
Move rpc call serialization from AS code to NetConnection proper.
To be moved again later, this is just a first step.
modified:
libcore/asobj/NetConnection_as.cpp
libcore/asobj/NetConnection_as.h
libcore/vm/fn_call.h
=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp 2008-12-18 00:54:23 +0000
+++ b/libcore/asobj/NetConnection_as.cpp 2008-12-18 22:39:32 +0000
@@ -715,9 +715,54 @@
}
void
-NetConnection_as::call(as_object* asCallback, const std::string& callNumber,
- const SimpleBuffer& buf)
+NetConnection_as::call(as_object* asCallback, const std::string& methodName,
+ const std::vector<as_value>& args, size_t firstArg)
{
+ boost::scoped_ptr<SimpleBuffer> buf (new SimpleBuffer(32));
+
+ // method name
+ buf->appendNetworkShort(methodName.size());
+ buf->append(methodName.c_str(), methodName.size());
+
+ // client id (result number) as counted string
+ // the convention seems to be / followed by a unique (ascending) number
+ std::ostringstream os;
+ os << "/";
+ // Call number is not used if the callback is undefined
+ if ( asCallback )
+ {
+ os << nextCallNumber();
+ }
+ const std::string callNumberString = os.str();
+
+ buf->appendNetworkShort(callNumberString.size());
+ buf->append(callNumberString.c_str(), callNumberString.size());
+
+ size_t total_size_offset = buf->size();
+ buf->append("\000\000\000\000", 4); // total size to be filled in later
+
+ std::map<as_object*, size_t> offsetTable;
+
+ // encode array of arguments to remote method
+ buf->appendByte(amf::Element::STRICT_ARRAY_AMF0);
+ buf->appendNetworkLong(args.size()-firstArg);
+
+ VM& vm = getVM();
+
+ for (unsigned int i = firstArg; i < args.size(); ++i)
+ {
+ const as_value& arg = args[i];
+ // STRICT_ARRAY encoding is allowed for remoting
+ if ( ! arg.writeAMF0(*buf, offsetTable, vm, true) )
+ {
+ log_error("Could not serialize NetConnection.call argument %d",
+ i);
+ }
+ }
+
+ // Set the "total size" parameter.
+ *(reinterpret_cast<uint32_t*>(buf->data() + total_size_offset)) =
+ htonl(buf->size() - 4 - total_size_offset);
#ifdef GNASH_DEBUG_REMOTING
log_debug(_("NetConnection.call(): encoded args: %s"),
@@ -740,14 +785,14 @@
#ifdef GNASH_DEBUG_REMOTING
log_debug("calling enqueue with callback");
#endif
- _currentCallQueue->enqueue(buf, callNumber, asCallback);
+ _currentCallQueue->enqueue(*buf, callNumberString, asCallback);
}
else {
#ifdef GNASH_DEBUG_REMOTING
log_debug("calling enqueue without callback");
#endif
- _currentCallQueue->enqueue(buf);
+ _currentCallQueue->enqueue(*buf);
}
#ifdef GNASH_DEBUG_REMOTING
@@ -905,8 +950,8 @@
const as_value& methodName_as = fn.arg(0);
std::string methodName = methodName_as.to_string();
+#ifdef GNASH_DEBUG_REMOTING
std::stringstream ss; fn.dump_args(ss);
-#ifdef GNASH_DEBUG_REMOTING
log_debug("NetConnection.call(%s)", ss.str());
#endif
@@ -926,57 +971,8 @@
}
}
- boost::scoped_ptr<SimpleBuffer> buf (new SimpleBuffer(32));
-
- // method name
- buf->appendNetworkShort(methodName.size());
- buf->append(methodName.c_str(), methodName.size());
-
- // client id (result number) as counted string
- // the convention seems to be / followed by a unique (ascending) number
- std::ostringstream os;
- os << "/";
- // Call number is not used if the callback is undefined
- // TESTED manually by strk
- if ( asCallback )
- {
- os << ptr->nextCallNumber();
- }
- const std::string callNumberString = os.str();
-
- buf->appendNetworkShort(callNumberString.size());
- buf->append(callNumberString.c_str(), callNumberString.size());
-
- size_t total_size_offset = buf->size();
- buf->append("\000\000\000\000", 4); // total size to be filled in later
-
- std::map<as_object*, size_t> offsetTable;
-
- // encode array of arguments to remote method
- buf->appendByte(amf::Element::STRICT_ARRAY_AMF0);
- buf->appendNetworkLong(fn.nargs - 2);
-
- VM& vm = ptr->getVM();
-
- if (fn.nargs > 2)
- {
- for (unsigned int i = 2; i < fn.nargs; ++i)
- {
- const as_value& arg = fn.arg(i);
- // STRICT_ARRAY encoding is allowed for remoting
- if ( ! arg.writeAMF0(*buf, offsetTable, vm, true) )
- {
- log_error("Could not serialize NetConnection.call argument %d",
- i);
- }
- }
- }
-
- // Set the "total size" parameter.
- *(reinterpret_cast<uint32_t*>(buf->data() + total_size_offset)) =
- htonl(buf->size() - 4 - total_size_offset);
-
- ptr->call(asCallback.get(), callNumberString, *buf);
+ const std::vector<as_value>& args = fn.getArgs();
+ ptr->call(asCallback.get(), methodName, args, 2);
return as_value();
}
=== modified file 'libcore/asobj/NetConnection_as.h'
--- a/libcore/asobj/NetConnection_as.h 2008-12-17 20:55:37 +0000
+++ b/libcore/asobj/NetConnection_as.h 2008-12-18 22:39:32 +0000
@@ -63,8 +63,7 @@
/// Make the stored URI into a valid and checked URL.
std::string validateURL() const;
- void call(as_object* asCallback, const std::string& callNumber,
- const SimpleBuffer& buf);
+ void call(as_object* asCallback, const std::string& methodName, const
std::vector<as_value>& args, size_t firstArg);
/// Process the close() method.
void close();
=== modified file 'libcore/vm/fn_call.h'
--- a/libcore/vm/fn_call.h 2008-11-19 16:51:17 +0000
+++ b/libcore/vm/fn_call.h 2008-12-18 22:39:32 +0000
@@ -136,6 +136,10 @@
return (*_args)[n]; // _env->bottom(_stack_offset - n);
}
+ const std::vector<as_value>& getArgs() const {
+ return *_args;
+ }
+
void drop_bottom()
{
assert(_args.get() && !(*_args).empty());
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10468: Add a getArgs method to fn_call, to expose the underlying args vector.,
Sandro Santilli <=