ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / pepper_interface.cc
blobad92a8f49117dc3e65949459248ec480584125ba
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"
6 #include <errno.h>
7 #include <ppapi/c/pp_errors.h>
9 namespace nacl_io {
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() {
28 if (resource_)
29 ppapi_->ReleaseResource(resource_);
32 void ScopedResource::Reset(PP_Resource resource) {
33 if (resource_)
34 ppapi_->ReleaseResource(resource_);
36 resource_ = resource;
39 PP_Resource ScopedResource::Release() {
40 PP_Resource result = resource_;
41 resource_ = 0;
42 return result;
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_);
57 var_ = var;
60 PP_Var ScopedVar::Release() {
61 PP_Var result = var_;
62 var_ = PP_MakeUndefined();
63 return result;
66 int PPErrorToErrno(int32_t err) {
67 // If not an error, then just return it.
68 if (err >= PP_OK)
69 return err;
71 switch (err) {
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;
103 return EINVAL;
106 } // namespace nacl_io