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. 4 5 #include "nacl_io/pepper_interface.h" 6 #include <errno.h> 7 #include <ppapi/c/pp_errors.h> 8 9 namespace nacl_io { 10 11 void PepperInterface::AddRefResource(PP_Resource resource) { 12 GetCoreInterface()->AddRefResource(resource); 13 } 14 15 void PepperInterface::ReleaseResource(PP_Resource resource) { 16 GetCoreInterface()->ReleaseResource(resource); 17 } 18 19 ScopedResource::ScopedResource(PepperInterface* ppapi) 20 : ppapi_(ppapi), resource_(0) {} 21 22 ScopedResource::ScopedResource(PepperInterface* ppapi, PP_Resource resource) 23 : ppapi_(ppapi), resource_(resource) {} 24 25 ScopedResource::~ScopedResource() { 26 if (resource_) 27 ppapi_->ReleaseResource(resource_); 28 } 29 30 void ScopedResource::Reset(PP_Resource resource) { 31 if (resource_) 32 ppapi_->ReleaseResource(resource_); 33 34 resource_ = resource; 35 } 36 37 PP_Resource ScopedResource::Release() { 38 PP_Resource result = resource_; 39 resource_ = 0; 40 return result; 41 } 42 43 int PPErrorToErrno(int32_t err) { 44 // If not an error, then just return it. 45 if (err >= PP_OK) 46 return err; 47 48 switch (err) { 49 case PP_OK_COMPLETIONPENDING: return 0; 50 case PP_ERROR_FAILED: return EPERM; 51 case PP_ERROR_ABORTED: return EPERM; 52 case PP_ERROR_BADARGUMENT: return EINVAL; 53 case PP_ERROR_BADRESOURCE: return EBADF; 54 case PP_ERROR_NOINTERFACE: return ENOSYS; 55 case PP_ERROR_NOACCESS: return EACCES; 56 case PP_ERROR_NOMEMORY: return ENOMEM; 57 case PP_ERROR_NOSPACE: return ENOSPC; 58 case PP_ERROR_NOQUOTA: return ENOSPC; 59 case PP_ERROR_INPROGRESS: return EBUSY; 60 case PP_ERROR_NOTSUPPORTED: return ENOSYS; 61 case PP_ERROR_BLOCKS_MAIN_THREAD: return EPERM; 62 case PP_ERROR_FILENOTFOUND: return ENOENT; 63 case PP_ERROR_FILEEXISTS: return EEXIST; 64 case PP_ERROR_FILETOOBIG: return EFBIG; 65 case PP_ERROR_FILECHANGED: return EINVAL; 66 case PP_ERROR_TIMEDOUT: return EBUSY; 67 case PP_ERROR_USERCANCEL: return EPERM; 68 case PP_ERROR_NO_USER_GESTURE: return EPERM; 69 case PP_ERROR_CONTEXT_LOST: return EPERM; 70 case PP_ERROR_NO_MESSAGE_LOOP: return EPERM; 71 case PP_ERROR_WRONG_THREAD: return EPERM; 72 case PP_ERROR_CONNECTION_ABORTED: return ECONNABORTED; 73 case PP_ERROR_CONNECTION_REFUSED: return ECONNREFUSED; 74 case PP_ERROR_CONNECTION_FAILED: return ECONNREFUSED; 75 case PP_ERROR_CONNECTION_TIMEDOUT: return ETIMEDOUT; 76 case PP_ERROR_ADDRESS_UNREACHABLE: return ENETUNREACH; 77 case PP_ERROR_ADDRESS_IN_USE: return EADDRINUSE; 78 } 79 80 return EINVAL; 81 } 82 83 } // namespace nacl_io 84