VirtualBox

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

Last change on this file since 31872 was 30764, checked in by vboxsync, 14 years ago

back out r63543, r63544 until windows build problems can be solved properly

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