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 "nacl_io/pepper_interface.h"
7 #include <ppapi/c/pp_errors.h>
11 void PepperInterface::AddRefResource(PP_Resource resource
) {
12 GetCoreInterface()->AddRefResource(resource
);
15 void PepperInterface::ReleaseResource(PP_Resource resource
) {
16 GetCoreInterface()->ReleaseResource(resource
);
19 ScopedResource::ScopedResource(PepperInterface
* ppapi
)
20 : ppapi_(ppapi
), resource_(0) {
23 ScopedResource::ScopedResource(PepperInterface
* ppapi
, PP_Resource resource
)
24 : ppapi_(ppapi
), resource_(resource
) {
27 ScopedResource::~ScopedResource() {
29 ppapi_
->ReleaseResource(resource_
);
32 void ScopedResource::Reset(PP_Resource resource
) {
34 ppapi_
->ReleaseResource(resource_
);
39 PP_Resource
ScopedResource::Release() {
40 PP_Resource result
= resource_
;
45 ScopedVar::ScopedVar(PepperInterface
* ppapi
)
46 : ppapi_(ppapi
), var_(PP_MakeUndefined()) {}
48 ScopedVar::ScopedVar(PepperInterface
* ppapi
, PP_Var var
)
49 : ppapi_(ppapi
), var_(var
) {}
51 ScopedVar::~ScopedVar() {
52 ppapi_
->GetVarInterface()->Release(var_
);
55 void ScopedVar::Reset(PP_Var var
) {
56 ppapi_
->GetVarInterface()->Release(var_
);
60 PP_Var
ScopedVar::Release() {
62 var_
= PP_MakeUndefined();
66 int PPErrorToErrno(int32_t err
) {
67 // If not an error, then just return it.
72 case PP_OK_COMPLETIONPENDING
: return 0;
73 case PP_ERROR_FAILED
: return EPERM
;
74 case PP_ERROR_ABORTED
: return EPERM
;
75 case PP_ERROR_BADARGUMENT
: return EINVAL
;
76 case PP_ERROR_BADRESOURCE
: return EBADF
;
77 case PP_ERROR_NOINTERFACE
: return ENOSYS
;
78 case PP_ERROR_NOACCESS
: return EACCES
;
79 case PP_ERROR_NOMEMORY
: return ENOMEM
;
80 case PP_ERROR_NOSPACE
: return ENOSPC
;
81 case PP_ERROR_NOQUOTA
: return ENOSPC
;
82 case PP_ERROR_INPROGRESS
: return EBUSY
;
83 case PP_ERROR_NOTSUPPORTED
: return ENOSYS
;
84 case PP_ERROR_BLOCKS_MAIN_THREAD
: return EPERM
;
85 case PP_ERROR_FILENOTFOUND
: return ENOENT
;
86 case PP_ERROR_FILEEXISTS
: return EEXIST
;
87 case PP_ERROR_FILETOOBIG
: return EFBIG
;
88 case PP_ERROR_FILECHANGED
: return EINVAL
;
89 case PP_ERROR_TIMEDOUT
: return EBUSY
;
90 case PP_ERROR_USERCANCEL
: return EPERM
;
91 case PP_ERROR_NO_USER_GESTURE
: return EPERM
;
92 case PP_ERROR_CONTEXT_LOST
: return EPERM
;
93 case PP_ERROR_NO_MESSAGE_LOOP
: return EPERM
;
94 case PP_ERROR_WRONG_THREAD
: return EPERM
;
95 case PP_ERROR_CONNECTION_ABORTED
: return ECONNABORTED
;
96 case PP_ERROR_CONNECTION_REFUSED
: return ECONNREFUSED
;
97 case PP_ERROR_CONNECTION_FAILED
: return ECONNREFUSED
;
98 case PP_ERROR_CONNECTION_TIMEDOUT
: return ETIMEDOUT
;
99 case PP_ERROR_ADDRESS_UNREACHABLE
: return ENETUNREACH
;
100 case PP_ERROR_ADDRESS_IN_USE
: return EADDRINUSE
;
106 } // namespace nacl_io