VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: errorprint.cpp 28800 2010-04-27 08:22:32Z 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.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/path.h>
27
28namespace com
29{
30
31
32void GluePrintErrorInfo(com::ErrorInfo &info)
33{
34 Utf8Str str = Utf8StrFmt("ERROR: %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 RTPrintf("%s", str.c_str());
45 Log(("%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 RTPrintf("%s", str.c_str());
59 Log(("%s", str.c_str()));
60}
61
62void GluePrintRCMessage(HRESULT rc)
63{
64 Utf8Str str = Utf8StrFmt("ERROR: code %Rhra (extended info not available)\n", rc);
65 // print and log
66 RTPrintf("%s", str.c_str());
67 Log(("%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);
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