michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkHRESULT_DEFINED michael@0: #define SkHRESULT_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: void SkTraceHR(const char* file, unsigned long line, michael@0: HRESULT hr, const char* msg); michael@0: michael@0: #ifdef SK_DEBUG michael@0: #define SK_TRACEHR(_hr, _msg) SkTraceHR(__FILE__, __LINE__, _hr, _msg) michael@0: #else michael@0: #define SK_TRACEHR(_hr, _msg) _hr michael@0: #endif michael@0: michael@0: #define HR_GENERAL(_ex, _msg, _ret) {\ michael@0: HRESULT _hr = _ex;\ michael@0: if (FAILED(_hr)) {\ michael@0: SK_TRACEHR(_hr, _msg);\ michael@0: return _ret;\ michael@0: }\ michael@0: } michael@0: michael@0: //@{ michael@0: /** michael@0: These macros are for reporting HRESULT errors. michael@0: The expression will be evaluated. michael@0: If the resulting HRESULT SUCCEEDED then execution will continue normally. michael@0: If the HRESULT FAILED then the macro will return from the current function. michael@0: In variants ending with 'M' the given message will be traced when FAILED. michael@0: The HR variants will return the HRESULT when FAILED. michael@0: The HRB variants will return false when FAILED. michael@0: The HRN variants will return NULL when FAILED. michael@0: The HRV variants will simply return when FAILED. michael@0: The HRZ variants will return 0 when FAILED. michael@0: */ michael@0: #define HR(ex) HR_GENERAL(ex, NULL, _hr) michael@0: #define HRM(ex, msg) HR_GENERAL(ex, msg, _hr) michael@0: michael@0: #define HRB(ex) HR_GENERAL(ex, NULL, false) michael@0: #define HRBM(ex, msg) HR_GENERAL(ex, msg, false) michael@0: michael@0: #define HRN(ex) HR_GENERAL(ex, NULL, NULL) michael@0: #define HRNM(ex, msg) HR_GENERAL(ex, msg, NULL) michael@0: michael@0: #define HRV(ex) HR_GENERAL(ex, NULL, ) michael@0: #define HRVM(ex, msg) HR_GENERAL(ex, msg, ) michael@0: michael@0: #define HRZ(ex) HR_GENERAL(ex, NULL, 0) michael@0: #define HRZM(ex, msg) HR_GENERAL(ex, msg, 0) michael@0: //@} michael@0: #endif