VirtualBox

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

Last change on this file since 35105 was 32718, checked in by vboxsync, 14 years ago

com/string: Remove bool conversion operator and other convenience error operators. They are hiding programming errors (like incorrect empty string checks, and in one case a free of the wrong pointer).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: errorprint.cpp 32718 2010-09-23 12:57:52Z 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-2010 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
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/message.h>
27#include <iprt/path.h>
28
29namespace com
30{
31
32void GluePrintErrorInfo(com::ErrorInfo &info)
33{
34 Utf8Str str = Utf8StrFmt("%ls\n"
35 "Details: code %Rhrc (0x%RX32), component %ls, interface %ls, callee %ls\n"
36 ,
37 info.getText().raw(),
38 info.getResultCode(),
39 info.getResultCode(),
40 info.getComponent().raw(),
41 info.getInterfaceName().raw(),
42 info.getCalleeName().raw());
43 // print and log
44 RTMsgError("%s", str.c_str());
45 Log(("ERROR: %s", str.c_str()));
46}
47
48void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine)
49{
50 // pcszSourceFile comes from __FILE__ macro, which always contains the full path,
51 // which we don't want to see printed:
52 Utf8Str strFilename(RTPathFilename(pcszSourceFile));
53 Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n",
54 pcszContext,
55 ulLine,
56 strFilename.c_str());
57 // print and log
58 RTStrmPrintf(g_pStdErr, "%s", str.c_str());
59 Log(("%s", str.c_str()));
60}
61
62void GluePrintRCMessage(HRESULT rc)
63{
64 Utf8Str str = Utf8StrFmt("Code %Rhra (extended info not available)\n", rc);
65 // print and log
66 RTMsgError("%s", str.c_str());
67 Log(("ERROR: %s", str.c_str()));
68}
69
70void GlueHandleComError(ComPtr<IUnknown> iface,
71 const char *pcszContext,
72 HRESULT rc,
73 const char *pcszSourceFile,
74 uint32_t ulLine)
75{
76 // if we have full error info, print something nice, and start with the actual error message
77 com::ErrorInfo info(iface, COM_IIDOF(IUnknown));
78 if (info.isFullAvailable() || info.isBasicAvailable())
79 GluePrintErrorInfo(info);
80 else
81 GluePrintRCMessage(rc);
82 GluePrintErrorContext(pcszContext, pcszSourceFile, ulLine);
83}
84
85
86} /* namespace com */
87
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