VirtualBox

source: vbox/trunk/src/VBox/Main/src-all/GlobalStatusConversion.cpp@ 100709

Last change on this file since 100709 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: GlobalStatusConversion.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox COM global definitions - status code conversion.
4 *
5 * NOTE: This file is part of both VBoxC.dll and VBoxSVC.exe.
6 */
7
8/*
9 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * SPDX-License-Identifier: GPL-3.0-only
28 */
29
30#include "Global.h"
31
32#include <iprt/assert.h>
33#include <VBox/err.h>
34
35
36/*static*/ int
37Global::vboxStatusCodeFromCOM(HRESULT aComStatus)
38{
39 switch (aComStatus)
40 {
41 case S_OK: return VINF_SUCCESS;
42
43 /* Standard COM status codes. See also RTErrConvertFromDarwinCOM */
44 case E_UNEXPECTED: return VERR_COM_UNEXPECTED;
45 case E_NOTIMPL: return VERR_NOT_IMPLEMENTED;
46 case E_OUTOFMEMORY: return VERR_NO_MEMORY;
47 case E_INVALIDARG: return VERR_INVALID_PARAMETER;
48 case E_NOINTERFACE: return VERR_NOT_SUPPORTED;
49 case E_POINTER: return VERR_INVALID_POINTER;
50#ifdef E_HANDLE
51 case E_HANDLE: return VERR_INVALID_HANDLE;
52#endif
53 case E_ABORT: return VERR_CANCELLED;
54 case E_FAIL: return VERR_GENERAL_FAILURE;
55 case E_ACCESSDENIED: return VERR_ACCESS_DENIED;
56
57 /* VirtualBox status codes */
58 case VBOX_E_OBJECT_NOT_FOUND: return VERR_COM_OBJECT_NOT_FOUND;
59 case VBOX_E_INVALID_VM_STATE: return VERR_COM_INVALID_VM_STATE;
60 case VBOX_E_VM_ERROR: return VERR_COM_VM_ERROR;
61 case VBOX_E_FILE_ERROR: return VERR_COM_FILE_ERROR;
62 case VBOX_E_IPRT_ERROR: return VERR_COM_IPRT_ERROR;
63 case VBOX_E_PDM_ERROR: return VERR_COM_PDM_ERROR;
64 case VBOX_E_INVALID_OBJECT_STATE: return VERR_COM_INVALID_OBJECT_STATE;
65 case VBOX_E_HOST_ERROR: return VERR_COM_HOST_ERROR;
66 case VBOX_E_NOT_SUPPORTED: return VERR_COM_NOT_SUPPORTED;
67 case VBOX_E_XML_ERROR: return VERR_COM_XML_ERROR;
68 case VBOX_E_INVALID_SESSION_STATE: return VERR_COM_INVALID_SESSION_STATE;
69 case VBOX_E_OBJECT_IN_USE: return VERR_COM_OBJECT_IN_USE;
70
71 default:
72 if (SUCCEEDED(aComStatus))
73 return VINF_SUCCESS;
74 /** @todo Check for the win32 facility and use the
75 * RTErrConvertFromWin32 function on windows. */
76 return VERR_UNRESOLVED_ERROR;
77 }
78}
79
80
81/*static*/ HRESULT
82Global::vboxStatusCodeToCOM(int aVBoxStatus)
83{
84 switch (aVBoxStatus)
85 {
86 case VINF_SUCCESS: return S_OK;
87
88 /* Standard COM status codes. */
89 case VERR_COM_UNEXPECTED: return E_UNEXPECTED;
90 case VERR_NOT_IMPLEMENTED: return E_NOTIMPL;
91 case VERR_NO_MEMORY: return E_OUTOFMEMORY;
92 case VERR_INVALID_PARAMETER: return E_INVALIDARG;
93 case VERR_NOT_SUPPORTED: return E_NOINTERFACE;
94 case VERR_INVALID_POINTER: return E_POINTER;
95#ifdef E_HANDLE
96 case VERR_INVALID_HANDLE: return E_HANDLE;
97#endif
98 case VERR_CANCELLED: return E_ABORT;
99 case VERR_GENERAL_FAILURE: return E_FAIL;
100 case VERR_ACCESS_DENIED: return E_ACCESSDENIED;
101
102 /* VirtualBox COM status codes. */
103 case VERR_COM_OBJECT_NOT_FOUND: return VBOX_E_OBJECT_NOT_FOUND;
104 case VERR_COM_INVALID_VM_STATE: return VBOX_E_INVALID_VM_STATE;
105 case VERR_COM_VM_ERROR: return VBOX_E_VM_ERROR;
106 case VERR_COM_FILE_ERROR: return VBOX_E_FILE_ERROR;
107 case VERR_COM_IPRT_ERROR: return VBOX_E_IPRT_ERROR;
108 case VERR_COM_PDM_ERROR: return VBOX_E_PDM_ERROR;
109 case VERR_COM_INVALID_OBJECT_STATE: return VBOX_E_INVALID_OBJECT_STATE;
110 case VERR_COM_HOST_ERROR: return VBOX_E_HOST_ERROR;
111 case VERR_COM_NOT_SUPPORTED: return VBOX_E_NOT_SUPPORTED;
112 case VERR_COM_XML_ERROR: return VBOX_E_XML_ERROR;
113 case VERR_COM_INVALID_SESSION_STATE: return VBOX_E_INVALID_SESSION_STATE;
114 case VERR_COM_OBJECT_IN_USE: return VBOX_E_OBJECT_IN_USE;
115
116 /* Other errors. */
117 case VERR_UNRESOLVED_ERROR: return E_FAIL;
118 case VERR_NOT_EQUAL: return VBOX_E_FILE_ERROR;
119 case VERR_FILE_NOT_FOUND: return VBOX_E_OBJECT_NOT_FOUND;
120 case VERR_IO_NOT_READY: return VBOX_E_INVALID_OBJECT_STATE;
121
122 /* Guest Control errors. */
123 case VERR_GSTCTL_MAX_CID_OBJECTS_REACHED: return VBOX_E_MAXIMUM_REACHED;
124 case VERR_GSTCTL_GUEST_ERROR: return VBOX_E_GSTCTL_GUEST_ERROR;
125
126 default:
127 if (RT_SUCCESS(aVBoxStatus))
128 return S_OK;
129
130 /* try categorize it */
131 if ( aVBoxStatus < 0
132 && ( aVBoxStatus > -1000
133 || (aVBoxStatus < -22000 && aVBoxStatus > -32766) )
134 )
135 return VBOX_E_IPRT_ERROR;
136 if ( aVBoxStatus < VERR_PDM_NO_SUCH_LUN / 100 * 10
137 && aVBoxStatus > VERR_PDM_NO_SUCH_LUN / 100 * 10 - 100)
138 return VBOX_E_PDM_ERROR;
139 if ( aVBoxStatus <= -1000
140 && aVBoxStatus > -5000 /* wrong, but so what... */)
141 return VBOX_E_VM_ERROR;
142
143 AssertMsgFailed(("%Rrc\n", aVBoxStatus));
144 return E_FAIL;
145 }
146}
147
148/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette