VirtualBox

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

Last change on this file since 92154 was 85929, checked in by vboxsync, 4 years ago

Main: bugref:9224: Main+VBoxManageDisk+doc part

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: GlobalStatusConversion.cpp 85929 2020-08-28 14:40:55Z 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-2020 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "Global.h"
21
22#include <iprt/assert.h>
23#include <VBox/err.h>
24
25
26/*static*/ int
27Global::vboxStatusCodeFromCOM(HRESULT aComStatus)
28{
29 switch (aComStatus)
30 {
31 case S_OK: return VINF_SUCCESS;
32
33 /* Standard COM status codes. See also RTErrConvertFromDarwinCOM */
34 case E_UNEXPECTED: return VERR_COM_UNEXPECTED;
35 case E_NOTIMPL: return VERR_NOT_IMPLEMENTED;
36 case E_OUTOFMEMORY: return VERR_NO_MEMORY;
37 case E_INVALIDARG: return VERR_INVALID_PARAMETER;
38 case E_NOINTERFACE: return VERR_NOT_SUPPORTED;
39 case E_POINTER: return VERR_INVALID_POINTER;
40#ifdef E_HANDLE
41 case E_HANDLE: return VERR_INVALID_HANDLE;
42#endif
43 case E_ABORT: return VERR_CANCELLED;
44 case E_FAIL: return VERR_GENERAL_FAILURE;
45 case E_ACCESSDENIED: return VERR_ACCESS_DENIED;
46
47 /* VirtualBox status codes */
48 case VBOX_E_OBJECT_NOT_FOUND: return VERR_COM_OBJECT_NOT_FOUND;
49 case VBOX_E_INVALID_VM_STATE: return VERR_COM_INVALID_VM_STATE;
50 case VBOX_E_VM_ERROR: return VERR_COM_VM_ERROR;
51 case VBOX_E_FILE_ERROR: return VERR_COM_FILE_ERROR;
52 case VBOX_E_IPRT_ERROR: return VERR_COM_IPRT_ERROR;
53 case VBOX_E_PDM_ERROR: return VERR_COM_PDM_ERROR;
54 case VBOX_E_INVALID_OBJECT_STATE: return VERR_COM_INVALID_OBJECT_STATE;
55 case VBOX_E_HOST_ERROR: return VERR_COM_HOST_ERROR;
56 case VBOX_E_NOT_SUPPORTED: return VERR_COM_NOT_SUPPORTED;
57 case VBOX_E_XML_ERROR: return VERR_COM_XML_ERROR;
58 case VBOX_E_INVALID_SESSION_STATE: return VERR_COM_INVALID_SESSION_STATE;
59 case VBOX_E_OBJECT_IN_USE: return VERR_COM_OBJECT_IN_USE;
60
61 default:
62 if (SUCCEEDED(aComStatus))
63 return VINF_SUCCESS;
64 /** @todo Check for the win32 facility and use the
65 * RTErrConvertFromWin32 function on windows. */
66 return VERR_UNRESOLVED_ERROR;
67 }
68}
69
70
71/*static*/ HRESULT
72Global::vboxStatusCodeToCOM(int aVBoxStatus)
73{
74 switch (aVBoxStatus)
75 {
76 case VINF_SUCCESS: return S_OK;
77
78 /* Standard COM status codes. */
79 case VERR_COM_UNEXPECTED: return E_UNEXPECTED;
80 case VERR_NOT_IMPLEMENTED: return E_NOTIMPL;
81 case VERR_NO_MEMORY: return E_OUTOFMEMORY;
82 case VERR_INVALID_PARAMETER: return E_INVALIDARG;
83 case VERR_NOT_SUPPORTED: return E_NOINTERFACE;
84 case VERR_INVALID_POINTER: return E_POINTER;
85#ifdef E_HANDLE
86 case VERR_INVALID_HANDLE: return E_HANDLE;
87#endif
88 case VERR_CANCELLED: return E_ABORT;
89 case VERR_GENERAL_FAILURE: return E_FAIL;
90 case VERR_ACCESS_DENIED: return E_ACCESSDENIED;
91
92 /* VirtualBox COM status codes. */
93 case VERR_COM_OBJECT_NOT_FOUND: return VBOX_E_OBJECT_NOT_FOUND;
94 case VERR_COM_INVALID_VM_STATE: return VBOX_E_INVALID_VM_STATE;
95 case VERR_COM_VM_ERROR: return VBOX_E_VM_ERROR;
96 case VERR_COM_FILE_ERROR: return VBOX_E_FILE_ERROR;
97 case VERR_COM_IPRT_ERROR: return VBOX_E_IPRT_ERROR;
98 case VERR_COM_PDM_ERROR: return VBOX_E_PDM_ERROR;
99 case VERR_COM_INVALID_OBJECT_STATE: return VBOX_E_INVALID_OBJECT_STATE;
100 case VERR_COM_HOST_ERROR: return VBOX_E_HOST_ERROR;
101 case VERR_COM_NOT_SUPPORTED: return VBOX_E_NOT_SUPPORTED;
102 case VERR_COM_XML_ERROR: return VBOX_E_XML_ERROR;
103 case VERR_COM_INVALID_SESSION_STATE: return VBOX_E_INVALID_SESSION_STATE;
104 case VERR_COM_OBJECT_IN_USE: return VBOX_E_OBJECT_IN_USE;
105
106 /* Other errors. */
107 case VERR_UNRESOLVED_ERROR: return E_FAIL;
108 case VERR_NOT_EQUAL: return VBOX_E_FILE_ERROR;
109 case VERR_FILE_NOT_FOUND: return VBOX_E_OBJECT_NOT_FOUND;
110 case VERR_IO_NOT_READY: return VBOX_E_INVALID_OBJECT_STATE;
111
112 /* Guest Control errors. */
113 case VERR_GSTCTL_MAX_CID_OBJECTS_REACHED: return VBOX_E_MAXIMUM_REACHED;
114 case VERR_GSTCTL_GUEST_ERROR: return VBOX_E_GSTCTL_GUEST_ERROR;
115
116 default:
117 AssertMsgFailed(("%Rrc\n", aVBoxStatus));
118 if (RT_SUCCESS(aVBoxStatus))
119 return S_OK;
120
121 /* try categorize it */
122 if ( aVBoxStatus < 0
123 && ( aVBoxStatus > -1000
124 || (aVBoxStatus < -22000 && aVBoxStatus > -32766) )
125 )
126 return VBOX_E_IPRT_ERROR;
127 if ( aVBoxStatus < VERR_PDM_NO_SUCH_LUN / 100 * 10
128 && aVBoxStatus > VERR_PDM_NO_SUCH_LUN / 100 * 10 - 100)
129 return VBOX_E_PDM_ERROR;
130 if ( aVBoxStatus <= -1000
131 && aVBoxStatus > -5000 /* wrong, but so what... */)
132 return VBOX_E_VM_ERROR;
133
134 return E_FAIL;
135 }
136}
137
138/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use