VirtualBox

source: vbox/trunk/src/VBox/Main/glue/errorprint2.cpp@ 16554

Last change on this file since 16554 was 16554, checked in by vboxsync, 16 years ago

export

File size: 2.8 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer:
3 * Error info print helpers. This implements the shared code from the macros from errorprint2.h.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23#include <VBox/com/ErrorInfo.h>
24#include <VBox/com/errorprint2.h>
25#include <VBox/log.h>
26
27#include <iprt/stream.h>
28#include <iprt/path.h>
29
30namespace com
31{
32
33
34void GluePrintErrorInfo(com::ErrorInfo &info)
35{
36 Utf8Str str = Utf8StrFmt("ERROR: %ls\n"
37 "Details: code %Rhrc (0x%RX32), component %ls, interface %ls, callee %ls\n"
38 ,
39 info.getText().raw(),
40 info.getResultCode(),
41 info.getResultCode(),
42 info.getComponent().raw(),
43 info.getInterfaceName().raw(),
44 info.getCalleeName().raw());
45 // print and log
46 RTPrintf("%s", str.c_str());
47 Log(("%s", str.c_str()));
48}
49
50void GluePrintRCMessage(HRESULT rc)
51{
52 Utf8Str str = Utf8StrFmt("ERROR: code %Rhra (extended info not available)\n", rc);
53 // print and log
54 RTPrintf("%s", str.c_str());
55 Log(("%s", str.c_str()));
56}
57
58void GlueHandleComError(ComPtr<IUnknown> iface,
59 const char *pcszContext,
60 HRESULT rc,
61 const char *pcszSourceFile,
62 uint32_t ulLine)
63{
64 // if we have full error info, print something nice, and start with the actual error message
65 com::ErrorInfo info(iface);
66 if (info.isFullAvailable() || info.isBasicAvailable())
67 {
68 GluePrintErrorInfo(info);
69
70 // pcszSourceFile comes from __FILE__ macro, which always contains the full path,
71 // which we don't want to see printed:
72 Utf8Str strFilename(RTPathFilename(pcszSourceFile));
73 Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n",
74 pcszContext,
75 ulLine,
76 strFilename.c_str());
77 // print and log
78 RTPrintf("%s", str.c_str());
79 Log(("%s", str.c_str()));
80 }
81}
82
83
84} /* namespace com */
85
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