VirtualBox

source: vbox/trunk/src/VBox/Main/glue/errorprint.cpp@ 30760

Last change on this file since 30760 was 30760, checked in by vboxsync, 15 years ago

Main: separate internal machine data structs into MachineImplPrivate.h to significantly speed up compilation and for better interface separation; remove obsolete ConsoleEvents.h file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: errorprint.cpp 30760 2010-07-09 13:12:04Z vboxsync $ */
2
3/** @file
4 * MS COM / XPCOM Abstraction Layer:
5 * Error info print helpers. This implements the shared code from the macros from errorprint.h.
6 */
7
8/*
9 * Copyright (C) 2009 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. 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
21#include <VBox/com/ErrorInfo.h>
22#include <VBox/com/errorprint.h>
23#include <VBox/log.h>
24
25#include <iprt/stream.h>
26#include <iprt/path.h>
27
28#ifndef DEBUG
29// string used by ComAssert macro (VirtualBoxBase.h)
30const char *g_pcszComAssertFailedString
31 = "Assertion failed: [%s] at '%s' (%d) in %s.\nPlease contact the product vendor!";
32const char *g_pcszComAssertMsgFailedString
33 = "Assertion failed: [%s] at '%s' (%d) in %s.\n%s\nPlease contact the product vendor!";
34#endif
35
36namespace com
37{
38
39void GluePrintErrorInfo(com::ErrorInfo &info)
40{
41 Utf8Str str = Utf8StrFmt("ERROR: %ls\n"
42 "Details: code %Rhrc (0x%RX32), component %ls, interface %ls, callee %ls\n"
43 ,
44 info.getText().raw(),
45 info.getResultCode(),
46 info.getResultCode(),
47 info.getComponent().raw(),
48 info.getInterfaceName().raw(),
49 info.getCalleeName().raw());
50 // print and log
51 RTPrintf("%s", str.c_str());
52 Log(("%s", str.c_str()));
53}
54
55void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine)
56{
57 // pcszSourceFile comes from __FILE__ macro, which always contains the full path,
58 // which we don't want to see printed:
59 Utf8Str strFilename(RTPathFilename(pcszSourceFile));
60 Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n",
61 pcszContext,
62 ulLine,
63 strFilename.c_str());
64 // print and log
65 RTPrintf("%s", str.c_str());
66 Log(("%s", str.c_str()));
67}
68
69void GluePrintRCMessage(HRESULT rc)
70{
71 Utf8Str str = Utf8StrFmt("ERROR: code %Rhra (extended info not available)\n", rc);
72 // print and log
73 RTPrintf("%s", str.c_str());
74 Log(("%s", str.c_str()));
75}
76
77void GlueHandleComError(ComPtr<IUnknown> iface,
78 const char *pcszContext,
79 HRESULT rc,
80 const char *pcszSourceFile,
81 uint32_t ulLine)
82{
83 // if we have full error info, print something nice, and start with the actual error message
84 com::ErrorInfo info(iface, COM_IIDOF(IUnknown));
85 if (info.isFullAvailable() || info.isBasicAvailable())
86 GluePrintErrorInfo(info);
87 else
88 GluePrintRCMessage(rc);
89 GluePrintErrorContext(pcszContext, pcszSourceFile, ulLine);
90}
91
92
93} /* namespace com */
94
Note: See TracBrowser for help on using the repository browser.

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