[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10383: More NetConnection event imp
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10383: More NetConnection event implementation. Stub unimplemented events from |
Date: |
Wed, 03 Dec 2008 20:41:19 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10383
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2008-12-03 20:41:19 +0100
message:
More NetConnection event implementation. Stub unimplemented events from
documentation (not easy to test without a server). Tests.
modified:
libcore/asobj/NetConnection.cpp
libcore/asobj/NetConnection.h
testsuite/actionscript.all/NetConnection.as
------------------------------------------------------------
revno: 10379.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-12-03 17:51:40 +0100
message:
Make NetConnection.close() and NetConnection.call() AS-correct (the
effects
of NetConnection.close() have yet to be established).
Test NetConnection properties and function returns.
modified:
libcore/asobj/NetConnection.cpp
libcore/asobj/NetConnection.h
testsuite/actionscript.all/NetConnection.as
------------------------------------------------------------
revno: 10379.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Wed 2008-12-03 19:51:57 +0100
message:
More testing for NetConnection events, correct and clean up
implementation.
modified:
libcore/asobj/NetConnection.cpp
libcore/asobj/NetConnection.h
testsuite/actionscript.all/NetConnection.as
=== modified file 'libcore/asobj/NetConnection.cpp'
--- a/libcore/asobj/NetConnection.cpp 2008-12-03 11:25:33 +0000
+++ b/libcore/asobj/NetConnection.cpp 2008-12-03 19:41:19 +0000
@@ -46,7 +46,6 @@
// for NetConnection.call()
#include "VM.h"
-//#include "array.h"
#include "amf.h"
#include "SimpleBuffer.h"
#include "timers.h"
@@ -190,14 +189,11 @@
reply_start = 0;
reply_end = 0;
// reset connection before calling the callback
- _connection.reset();
-
- // FIXME: should only call NetConnection's onStatus
- // if the IOChannel is in error condition.
- // (tipically 404).
- // When the response is empty, just nothing happens.
- _nc.callMethod(NSV::PROP_ON_STATUS, as_value());
-
+ _connection.reset();
+
+ // This is just a guess, but is better than sending
+ // 'undefined'
+ _nc.notifyStatus(NetConnection::CALL_FAILED);
}
else if(_connection->eof() )
{
@@ -472,7 +468,8 @@
:
as_object(getNetConnectionInterface()),
_callQueue(0),
- _isConnected(false)
+ _isConnected(false),
+ _inError(false)
{
attachProperties(*this);
}
@@ -589,19 +586,74 @@
info.second = "error";
return;
+ case CONNECT_APPSHUTDOWN:
+ info.first = "NetConnection.Connect.AppShutdown";
+ info.second = "error";
+ return;
+
+ case CONNECT_REJECTED:
+ info.first = "NetConnection.Connect.Rejected";
+ info.second = "error";
+ return;
+
case CALL_FAILED:
info.first = "NetConnection.Call.Failed";
info.second = "error";
return;
- case CALL_SUCCESS:
- info.first = "NetConnection.Call.Success";
+ case CALL_BADVERSION:
+ info.first = "NetConnection.Call.BadVersion";
info.second = "status";
return;
+
+ case CONNECT_CLOSED:
+ info.first = "NetConnection.Connect.Closed";
+ info.second = "status";
}
}
+
+void
+NetConnection::connect()
+{
+ _isConnected = true;
+ _inError = false;
+ notifyStatus(CONNECT_SUCCESS);
+}
+
+
+void
+NetConnection::connect(const std::string& uri)
+{
+
+ // FIXME: RTMP URLs should attempt a connection (warning: this seems
+ // to be different for SWF8). Would probably return true on success and
+ // set isConnected.
+ //
+ // For URLs starting with anything other than "rtmp://" no connection is
+ // initiated, but the uri is still set.
+ addToURL(uri);
+
+ _isConnected = false;
+ _inError = true;
+ notifyStatus(CONNECT_FAILED);
+}
+
+
+void
+NetConnection::close()
+{
+ /// TODO: what should actually happen here? Should an attached
+ /// NetStream object be interrupted?
+ _isConnected = false;
+
+ // If a previous connect() attempt failed, close() will not send
+ // an onStatus event.
+ if (!_inError) notifyStatus(CONNECT_CLOSED);
+}
+
+
void
NetConnection::call(as_object* asCallback, const std::string& callNumber,
const SimpleBuffer& buf)
@@ -666,6 +718,11 @@
namespace {
+
+/// NetConnection.call()
+//
+/// Documented to return void, and current tests suggest this might be
+/// correct, though they don't test with any calls that might succeed.
as_value
netconnection_call(const fn_call& fn)
{
@@ -675,9 +732,9 @@
if (fn.nargs < 1)
{
IF_VERBOSE_ASCODING_ERRORS(
- log_aserror(_("NetConnection.call(): needs at least one argument"));
+ log_aserror(_("NetConnection.call(): needs at least one
argument"));
);
- return as_value(false); // FIXME should we return true anyway?
+ return as_value();
}
const as_value& methodName_as = fn.arg(0);
@@ -687,7 +744,7 @@
log_aserror(_("NetConnection.call(%s): first argument "
"(methodName) must be a string"), ss.str());
);
- return as_value(false); // FIXME should we return true anyway?
+ return as_value();
}
std::stringstream ss; fn.dump_args(ss);
@@ -714,7 +771,7 @@
static int call_number = 0;
- boost::scoped_ptr<SimpleBuffer> buf ( new SimpleBuffer(32) );
+ boost::scoped_ptr<SimpleBuffer> buf (new SimpleBuffer(32));
// method name
buf->appendNetworkShort(methodName.size());
@@ -761,7 +818,6 @@
ptr->call(asCallback.get(), callNumberString, *buf);
- // Why return undefined here?
return as_value();
}
@@ -770,9 +826,9 @@
{
boost::intrusive_ptr<NetConnection> ptr =
ensureType<NetConnection>(fn.this_ptr);
- UNUSED(ptr);
-
- log_unimpl("NetConnection.close()");
+
+ ptr->close();
+
return as_value();
}
@@ -884,42 +940,25 @@
const VM& vm = ptr->getVM();
- bool success = false;
-
// Check first arg for validity
if (uri.is_null() || (vm.getSWFVersion() > 6 && uri.is_undefined()))
{
// Null URL was passed. This is expected. Of course, it also makes this
// function (and, this class) rather useless. We return true,
// even though returning true has no meaning.
-
- success = true;
-
+ ptr->connect();
}
- else if (uri.is_string()) {
-
- // FIXME: RTMP URLs should attempt a connection (warning: this seems
- // to be different for SWF8). Would probably return true on success.
- //
- // URLs starting with "http://" are invalid, and no connection is
- // initiated.
- ptr->addToURL(uri.to_string());
-
+ else {
if ( fn.nargs > 1 )
{
std::stringstream ss; fn.dump_args(ss);
log_unimpl("NetConnection.connect(%s): args after the first are "
"not supported", ss.str());
}
-
- success = false;
+ ptr->connect(uri.to_string());
}
- ptr->notifyStatus(success ? NetConnection::CONNECT_SUCCESS :
- NetConnection::CONNECT_FAILED);
-
- ptr->setConnected(success);
- return as_value(success);
+ return as_value(ptr->isConnected());
}
=== modified file 'libcore/asobj/NetConnection.h'
--- a/libcore/asobj/NetConnection.h 2008-12-03 11:25:33 +0000
+++ b/libcore/asobj/NetConnection.h 2008-12-03 19:41:19 +0000
@@ -44,8 +44,11 @@
{
CONNECT_FAILED,
CONNECT_SUCCESS,
+ CONNECT_CLOSED,
+ CONNECT_REJECTED,
+ CONNECT_APPSHUTDOWN,
CALL_FAILED,
- CALL_SUCCESS
+ CALL_BADVERSION
};
NetConnection();
@@ -73,17 +76,19 @@
void call(as_object* asCallback, const std::string& callNumber,
const SimpleBuffer& buf);
- void setConnected(bool b) {
- _isConnected = b;
- }
+ /// Process the close() method.
+ void close();
+
+ /// Process the connect(uri) method.
+ void connect(const std::string& uri);
+
+ /// Carry out the connect(null) method.
+ void connect();
bool isConnected() const {
return _isConnected;
}
- /// Extend the URL to be used for playing
- void addToURL(const std::string& url);
-
/// Notify the NetConnection onStatus handler of a change.
void notifyStatus(StatusCode code);
@@ -91,9 +96,18 @@
/// Mark responders associated with remoting calls
void markReachableResources() const;
+
private:
+
friend class AMFQueue;
+ typedef std::pair<std::string, std::string> NetConnectionStatus;
+
+ void getStatusCodeInfo(StatusCode code, NetConnectionStatus& info);
+
+ /// Extend the URL to be used for playing
+ void addToURL(const std::string& url);
+
std::auto_ptr<AMFQueue> _callQueue;
/// the url prefix optionally passed to connect()
@@ -104,9 +118,8 @@
bool _isConnected;
- typedef std::pair<std::string, std::string> NetConnectionStatus;
+ bool _inError;
- void getStatusCodeInfo(StatusCode code, NetConnectionStatus& info);
};
=== modified file 'testsuite/actionscript.all/NetConnection.as'
--- a/testsuite/actionscript.all/NetConnection.as 2008-12-03 11:25:33
+0000
+++ b/testsuite/actionscript.all/NetConnection.as 2008-12-03 18:51:57
+0000
@@ -29,13 +29,20 @@
check_equals(NetConnection, undefined);
check_totals(1);
-#else // OUTPUT_VERSION >= 7
+#else // OUTPUT_VERSION >= 6
+
+check(NetConnection.prototype.hasOwnProperty("call"));
+check(NetConnection.prototype.hasOwnProperty("connect"));
+check(NetConnection.prototype.hasOwnProperty("addHeader"));
+check(NetConnection.prototype.hasOwnProperty("close"));
+
+check(!NetConnection.prototype.hasOwnProperty("isConnected"));
+check(!NetConnection.prototype.hasOwnProperty("uri"));
check_equals(typeof(NetConnection), 'function');
check_equals(typeof(NetConnection.prototype), 'object');
check_equals(typeof(NetConnection.prototype.isConnected), 'undefined');
check_equals(typeof(NetConnection.prototype.connect), 'function');
-// TODO: add tests for all interfaces
var tmp = new NetConnection;
check_equals(typeof(tmp), 'object');
@@ -112,6 +119,7 @@
ret = tmp.connect(null);
check_equals(ret, true);
check_equals(tmp.isConnected, true);
+check_equals(result, "NetConnection.Connect.Success");
check_equals(level, "status");
ret = tmp.connect("http://someserver");
@@ -139,8 +147,68 @@
nc.connect(null);
check_equals(infoObj.code, "NetConnection.Connect.Failed");
-
-check_totals(43);
+/// Check call
+
+result = "";
+level = "";
+
+nc.onStatus = function(info) {
+ result = info.code;
+ level = info.level;
+};
+
+// Sanity check
+check(nc.isConnected);
+
+ret = nc.call();
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "");
+check_equals(level, "");
+
+ret = nc.call(1);
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "");
+check_equals(level, "");
+
+ret = nc.call("string");
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "");
+check_equals(level, "");
+
+// NetConnection close
+
+check(nc.isConnected);
+ret = nc.close();
+check_equals(nc.isConnected, false);
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "NetConnection.Connect.Closed");
+check_equals(level, "status");
+
+ret = nc.close();
+check_equals(nc.isConnected, false);
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "NetConnection.Connect.Closed");
+check_equals(level, "status");
+
+nc.connect(1);
+check_equals(nc.isConnected, false);
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "NetConnection.Connect.Failed");
+check_equals(level, "error");
+ret = nc.close();
+check_equals(nc.isConnected, false);
+check_equals(typeof(ret), "undefined");
+check_equals(ret, undefined);
+check_equals(result, "NetConnection.Connect.Failed");
+check_equals(level, "error");
+
+check_totals(84);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10383: More NetConnection event implementation. Stub unimplemented events from,
Benjamin Wolsey <=