// 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 { namespace { template <> const char* interface_name() { return PPB_TRANSPORT_DEV_INTERFACE; } } // namespace Transport_Dev::Transport_Dev(Instance* instance, const char* name, const char* proto) { if (has_interface()) PassRefFromConstructor(get_interface()->CreateTransport( instance->pp_instance(), name, proto)); } bool Transport_Dev::IsWritable() { if (!has_interface()) return false; return PP_ToBool( get_interface()->IsWritable(pp_resource())); } int32_t Transport_Dev::SetProperty(PP_TransportProperty property, const Var& value) { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->SetProperty( pp_resource(), property, value.pp_var()); } int32_t Transport_Dev::Connect(const CompletionCallback& cc) { if (!has_interface()) return cc.MayForce(PP_ERROR_NOINTERFACE); return get_interface()->Connect( pp_resource(), cc.pp_completion_callback()); } int32_t Transport_Dev::GetNextAddress(Var* address, const CompletionCallback& cc) { if (!has_interface()) return cc.MayForce(PP_ERROR_NOINTERFACE); PP_Var temp_address = PP_MakeUndefined(); int32_t ret_val = get_interface()->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()) return PP_ERROR_NOINTERFACE; return get_interface()->ReceiveRemoteAddress( pp_resource(), address.pp_var()); } int32_t Transport_Dev::Recv(void* data, uint32_t len, const CompletionCallback& cc) { if (!has_interface()) return cc.MayForce(PP_ERROR_NOINTERFACE); return get_interface()->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()) return cc.MayForce(PP_ERROR_NOINTERFACE); return get_interface()->Send( pp_resource(), data, len, cc.pp_completion_callback()); } int32_t Transport_Dev::Close() { if (!has_interface()) return PP_ERROR_NOINTERFACE; return get_interface()->Close(pp_resource()); } } // namespace pp