cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / private / udp_socket_private.cc
blobc100924fc231d8f29e680da89102237c2852f417
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/private/udp_socket_private.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/module_impl.h"
13 #include "ppapi/cpp/var.h"
15 namespace pp {
17 namespace {
19 template <> const char* interface_name<PPB_UDPSocket_Private_0_4>() {
20 return PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4;
23 template <> const char* interface_name<PPB_UDPSocket_Private_0_3>() {
24 return PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3;
27 } // namespace
29 UDPSocketPrivate::UDPSocketPrivate(const InstanceHandle& instance) {
30 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
31 PassRefFromConstructor(get_interface<PPB_UDPSocket_Private_0_4>()->Create(
32 instance.pp_instance()));
33 } else if (has_interface<PPB_UDPSocket_Private_0_3>()) {
34 PassRefFromConstructor(get_interface<PPB_UDPSocket_Private_0_3>()->Create(
35 instance.pp_instance()));
39 // static
40 bool UDPSocketPrivate::IsAvailable() {
41 return has_interface<PPB_UDPSocket_Private_0_4>() ||
42 has_interface<PPB_UDPSocket_Private_0_3>();
45 int32_t UDPSocketPrivate::SetSocketFeature(PP_UDPSocketFeature_Private name,
46 const Var& value) {
47 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
48 return get_interface<PPB_UDPSocket_Private_0_4>()->SetSocketFeature(
49 pp_resource(), name, value.pp_var());
51 return PP_ERROR_NOINTERFACE;
54 int32_t UDPSocketPrivate::Bind(const PP_NetAddress_Private* addr,
55 const CompletionCallback& callback) {
56 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
57 return get_interface<PPB_UDPSocket_Private_0_4>()->Bind(
58 pp_resource(), addr, callback.pp_completion_callback());
60 if (has_interface<PPB_UDPSocket_Private_0_3>()) {
61 return get_interface<PPB_UDPSocket_Private_0_3>()->Bind(
62 pp_resource(), addr, callback.pp_completion_callback());
64 return callback.MayForce(PP_ERROR_NOINTERFACE);
67 bool UDPSocketPrivate::GetBoundAddress(PP_NetAddress_Private* addr) {
68 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
69 PP_Bool result =
70 get_interface<PPB_UDPSocket_Private_0_4>()->GetBoundAddress(
71 pp_resource(), addr);
72 return PP_ToBool(result);
74 if (has_interface<PPB_UDPSocket_Private_0_3>()) {
75 PP_Bool result =
76 get_interface<PPB_UDPSocket_Private_0_3>()->GetBoundAddress(
77 pp_resource(), addr);
78 return PP_ToBool(result);
80 return false;
83 int32_t UDPSocketPrivate::RecvFrom(char* buffer,
84 int32_t num_bytes,
85 const CompletionCallback& callback) {
86 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
87 return get_interface<PPB_UDPSocket_Private_0_4>()->RecvFrom(
88 pp_resource(), buffer, num_bytes, callback.pp_completion_callback());
90 if (has_interface<PPB_UDPSocket_Private_0_3>()) {
91 return get_interface<PPB_UDPSocket_Private_0_3>()->RecvFrom(
92 pp_resource(), buffer, num_bytes, callback.pp_completion_callback());
94 return callback.MayForce(PP_ERROR_NOINTERFACE);
97 bool UDPSocketPrivate::GetRecvFromAddress(PP_NetAddress_Private* addr) {
98 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
99 PP_Bool result =
100 get_interface<PPB_UDPSocket_Private_0_4>()->GetRecvFromAddress(
101 pp_resource(), addr);
102 return PP_ToBool(result);
104 if (has_interface<PPB_UDPSocket_Private_0_3>()) {
105 PP_Bool result =
106 get_interface<PPB_UDPSocket_Private_0_3>()->GetRecvFromAddress(
107 pp_resource(), addr);
108 return PP_ToBool(result);
110 return false;
113 int32_t UDPSocketPrivate::SendTo(const char* buffer,
114 int32_t num_bytes,
115 const PP_NetAddress_Private* addr,
116 const CompletionCallback& callback) {
117 if (has_interface<PPB_UDPSocket_Private_0_4>()) {
118 return get_interface<PPB_UDPSocket_Private_0_4>()->SendTo(
119 pp_resource(), buffer, num_bytes, addr,
120 callback.pp_completion_callback());
122 if (has_interface<PPB_UDPSocket_Private_0_3>()) {
123 return get_interface<PPB_UDPSocket_Private_0_3>()->SendTo(
124 pp_resource(), buffer, num_bytes, addr,
125 callback.pp_completion_callback());
127 return callback.MayForce(PP_ERROR_NOINTERFACE);
130 void UDPSocketPrivate::Close() {
131 if (has_interface<PPB_UDPSocket_Private_0_4>())
132 return get_interface<PPB_UDPSocket_Private_0_4>()->Close(pp_resource());
133 if (has_interface<PPB_UDPSocket_Private_0_3>())
134 return get_interface<PPB_UDPSocket_Private_0_3>()->Close(pp_resource());
137 } // namespace pp