summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 21:04:38 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 21:04:38 +0000
commit6cc251f2ed23cec3a2bb138f633cad6a2266d220 (patch)
tree39ab816c808f60056bd7f557b113f6bb86461b2d /ppapi
parent649d44cd6f0f5d8070fd89d1013ce8f525969007 (diff)
downloadchromium_src-6cc251f2ed23cec3a2bb138f633cad6a2266d220.zip
chromium_src-6cc251f2ed23cec3a2bb138f633cad6a2266d220.tar.gz
chromium_src-6cc251f2ed23cec3a2bb138f633cad6a2266d220.tar.bz2
Basic implementation of Pepper Transport API.
BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/6478018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/dev/ppb_transport_dev.h34
-rw-r--r--ppapi/cpp/dev/transport_dev.cc59
-rw-r--r--ppapi/cpp/dev/transport_dev.h16
-rw-r--r--ppapi/tests/test_transport.cc41
-rw-r--r--ppapi/tests/test_transport.h10
5 files changed, 129 insertions, 31 deletions
diff --git a/ppapi/c/dev/ppb_transport_dev.h b/ppapi/c/dev/ppb_transport_dev.h
index 7dc9ad3..72ebb67 100644
--- a/ppapi/c/dev/ppb_transport_dev.h
+++ b/ppapi/c/dev/ppb_transport_dev.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010 The Chromium Authors. All rights reserved.
+/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -16,8 +16,8 @@
#define PPB_TRANSPORT_DEV_INTERFACE "PPB_Transport;0.4"
struct PPB_Transport_Dev {
- // Creates a new transport object with the specified name
- // using the specified protocol.
+ // Creates a new transport object with the specified name using the
+ // specified protocol.
PP_Resource (*CreateTransport)(PP_Instance instance,
const char* name,
const char* proto);
@@ -25,23 +25,24 @@ struct PPB_Transport_Dev {
// Returns PP_TRUE if resource is a Transport, PP_FALSE otherwise.
PP_Bool (*IsTransport)(PP_Resource resource);
- // Returns PP_TRUE if the transport is currently writable
- // (i.e. can send data to the remote peer), PP_FALSE otherwise.
+ // Returns PP_TRUE if the transport is currently writable (i.e. can
+ // send data to the remote peer), PP_FALSE otherwise.
PP_Bool (*IsWritable)(PP_Resource transport);
// TODO(juberti): other getters/setters
// connect state
// connect type, protocol
// RTT
- // Establishes a connection to the remote peer.
- // Returns PP_ERROR_WOULDBLOCK and notifies on |cb|
- // when connectivity is established (or timeout occurs).
+ // Establishes a connection to the remote peer. Returns
+ // PP_ERROR_WOULDBLOCK and notifies on |cb| when connectivity is
+ // established (or timeout occurs).
int32_t (*Connect)(PP_Resource transport,
struct PP_CompletionCallback cb);
- // Obtains another ICE candidate address to be provided
- // to the remote peer. Returns PP_ERROR_WOULDBLOCK
- // if there are no more addresses to be sent.
+ // Obtains another ICE candidate address to be provided to the
+ // remote peer. Returns PP_ERROR_WOULDBLOCK if there are no more
+ // addresses to be sent. After the callback is called
+ // GetNextAddress() must be called again to get the address.
int32_t (*GetNextAddress)(PP_Resource transport,
struct PP_Var* address,
struct PP_CompletionCallback cb);
@@ -50,14 +51,16 @@ struct PPB_Transport_Dev {
int32_t (*ReceiveRemoteAddress)(PP_Resource transport,
struct PP_Var address);
- // Like recv(), receives data. Returns PP_ERROR_WOULDBLOCK
- // if there is currently no data to receive.
+ // Like recv(), receives data. Returns PP_ERROR_WOULDBLOCK if there
+ // is currently no data to receive. In that case, the |data| pointer
+ // should remain valid until the callback is called.
int32_t (*Recv)(PP_Resource transport,
void* data,
uint32_t len,
struct PP_CompletionCallback cb);
- // Like send(), sends data. Returns PP_ERROR_WOULDBLOCK
- // if the socket is currently flow-controlled.
+ // Like send(), sends data. Returns PP_ERROR_WOULDBLOCK if the
+ // socket is currently flow-controlled. In that case, the |data|
+ // pointer should remain valid until the callback is called.
int32_t (*Send)(PP_Resource transport,
const void* data,
uint32_t len,
@@ -68,4 +71,3 @@ struct PPB_Transport_Dev {
};
#endif /* PPAPI_C_PPB_TRANSPORT_DEV_H_ */
-
diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc
index 241c3bd..0b62829 100644
--- a/ppapi/cpp/dev/transport_dev.cc
+++ b/ppapi/cpp/dev/transport_dev.cc
@@ -1,13 +1,15 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/cpp/dev/transport_dev.h"
+#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+#include "ppapi/cpp/var.h"
namespace pp {
@@ -27,5 +29,58 @@ Transport_Dev::Transport_Dev(Instance* instance,
instance->pp_instance(), name, proto));
}
-} // namespace pp
+bool Transport_Dev::IsWritable() {
+ if (!has_interface<PPB_Transport_Dev>())
+ return false;
+ return PPBoolToBool(
+ get_interface<PPB_Transport_Dev>()->IsWritable(pp_resource()));
+}
+
+int32_t Transport_Dev::Connect(const CompletionCallback& cc) {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Transport_Dev>()->Connect(
+ pp_resource(), cc.pp_completion_callback());
+}
+
+int32_t Transport_Dev::GetNextAddress(Var* address,
+ const CompletionCallback& cc) {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ PP_Var temp_address = PP_MakeUndefined();
+ int32_t ret_val = get_interface<PPB_Transport_Dev>()->GetNextAddress(
+ pp_resource(), &temp_address, cc.pp_completion_callback());
+ *address = Var(Var::PassRef(), temp_address);
+ return ret_val;
+}
+
+int32_t Transport_Dev::ReceiveRemoteAddress(const pp::Var& address) {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Transport_Dev>()->ReceiveRemoteAddress(
+ pp_resource(), address.pp_var());
+}
+int32_t Transport_Dev::Recv(void* data, uint32_t len,
+ const CompletionCallback& cc) {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Transport_Dev>()->Recv(
+ pp_resource(), data, len, cc.pp_completion_callback());
+}
+
+int32_t Transport_Dev::Send(const void* data, uint32_t len,
+ const CompletionCallback& cc) {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Transport_Dev>()->Send(
+ pp_resource(), data, len, cc.pp_completion_callback());
+}
+
+int32_t Transport_Dev::Close() {
+ if (!has_interface<PPB_Transport_Dev>())
+ return PP_ERROR_NOINTERFACE;
+ return get_interface<PPB_Transport_Dev>()->Close(pp_resource());
+}
+
+} // namespace pp
diff --git a/ppapi/cpp/dev/transport_dev.h b/ppapi/cpp/dev/transport_dev.h
index a03b232..d6ad56d 100644
--- a/ppapi/cpp/dev/transport_dev.h
+++ b/ppapi/cpp/dev/transport_dev.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,19 +6,29 @@
#define PPAPI_CPP_DEV_TRANSPORT_DEV_H_
#include "ppapi/c/dev/ppb_transport_dev.h"
+#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/resource.h"
namespace pp {
class Instance;
+class Var;
class Transport_Dev : public Resource {
public:
- Transport_Dev() {}
Transport_Dev(Instance* instance, const char* name, const char* proto);
+
+ bool IsWritable();
+ int32_t Connect(const CompletionCallback& cc);
+ int32_t GetNextAddress(pp::Var* address, const CompletionCallback& cc);
+ int32_t ReceiveRemoteAddress(const pp::Var& address);
+ int32_t Recv(void* data, uint32_t len,
+ const CompletionCallback& cc);
+ int32_t Send(const void* data, uint32_t len,
+ const CompletionCallback& cb);
+ int32_t Close();
};
} // namespace pp
#endif // PPAPI_CPP_DEV_TRANSPORT_DEV_H_
-
diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc
index bcb7552..f394a7d 100644
--- a/ppapi/tests/test_transport.cc
+++ b/ppapi/tests/test_transport.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,11 +9,11 @@
#include <string>
#include "ppapi/c/dev/ppb_testing_dev.h"
-#include "ppapi/c/dev/ppb_transport_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/dev/transport_dev.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
@@ -26,11 +26,42 @@ bool TestTransport::Init() {
}
void TestTransport::RunTest() {
- RUN_TEST(FirstTransport);
+ RUN_TEST(Basics);
// TODO(juberti): more Transport tests here...
}
-std::string TestTransport::TestFirstTransport() {
- // TODO(juberti): actual test
+std::string TestTransport::TestBasics() {
+ pp::Transport_Dev transport1(instance_, "test", "");
+ pp::Transport_Dev transport2(instance_, "test", "");
+
+ TestCompletionCallback connect_cb1;
+ TestCompletionCallback connect_cb2;
+ ASSERT_EQ(transport1.Connect(connect_cb1), PP_ERROR_WOULDBLOCK);
+ ASSERT_EQ(transport2.Connect(connect_cb2), PP_ERROR_WOULDBLOCK);
+
+ pp::Var address1;
+ pp::Var address2;
+ TestCompletionCallback next_address_cb1;
+ TestCompletionCallback next_address_cb2;
+ ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1),
+ PP_ERROR_WOULDBLOCK);
+ ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2),
+ PP_ERROR_WOULDBLOCK);
+ ASSERT_EQ(next_address_cb1.WaitForResult(), 0);
+ ASSERT_EQ(next_address_cb2.WaitForResult(), 0);
+ ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1), PP_OK);
+ ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2), PP_OK);
+
+ ASSERT_EQ(transport1.ReceiveRemoteAddress(address2), 0);
+ ASSERT_EQ(transport2.ReceiveRemoteAddress(address1), 0);
+
+ ASSERT_EQ(connect_cb1.WaitForResult(), 0);
+ ASSERT_EQ(connect_cb2.WaitForResult(), 0);
+
+ ASSERT_TRUE(transport1.IsWritable());
+ ASSERT_TRUE(transport2.IsWritable());
+
+ // TODO(sergeyu): Verify that data can be sent/received.
+
PASS();
}
diff --git a/ppapi/tests/test_transport.h b/ppapi/tests/test_transport.h
index e52983a..43e4306 100644
--- a/ppapi/tests/test_transport.h
+++ b/ppapi/tests/test_transport.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PAPPI_TESTS_TEST_TRANSPORT_H_
-#define PAPPI_TESTS_TEST_TRANSPORT_H_
+#ifndef PPAPI_TESTS_TEST_TRANSPORT_H_
+#define PPAPI_TESTS_TEST_TRANSPORT_H_
#include <string>
@@ -24,10 +24,10 @@ class TestTransport : public TestCase {
virtual void RunTest();
private:
- std::string TestFirstTransport();
+ std::string TestBasics();
// Used by the tests that access the C API directly.
const PPB_Transport_Dev* transport_interface_;
};
-#endif // PAPPI_TESTS_TEST_TRANSPORT_H_
+#endif // PPAPI_TESTS_TEST_TRANSPORT_H_