1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "nsString.h" // Required before 'mozilla/ErrorNames.h'!?
11 #include "mozilla/ErrorNames.h"
12 #include "mozilla/TimeStamp.h"
14 #include "nsPrintfCString.h"
16 // MediaResult can be used interchangeably with nsresult.
17 // It allows to store extra information such as where the error occurred.
18 // While nsresult is typically passed by value; due to its potential size, using
19 // MediaResult const references is recommended.
26 MediaResult() : mCode(NS_OK
) {}
27 MOZ_IMPLICIT
MediaResult(nsresult aResult
) : mCode(aResult
) {}
28 MediaResult(nsresult aResult
, const nsACString
& aMessage
)
29 : mCode(aResult
), mMessage(aMessage
) {}
30 MediaResult(nsresult aResult
, const char* aMessage
)
31 : mCode(aResult
), mMessage(aMessage
) {}
32 MediaResult(nsresult aResult
, CDMProxy
* aCDMProxy
)
33 : mCode(aResult
), mCDMProxy(aCDMProxy
) {
34 MOZ_ASSERT(aResult
== NS_ERROR_DOM_MEDIA_CDM_PROXY_NOT_SUPPORTED_ERR
);
36 MediaResult(const MediaResult
& aOther
) = default;
37 MediaResult(MediaResult
&& aOther
) = default;
38 MediaResult
& operator=(const MediaResult
& aOther
) = default;
39 MediaResult
& operator=(MediaResult
&& aOther
) = default;
41 nsresult
Code() const { return mCode
; }
42 nsCString
ErrorName() const {
44 GetErrorName(mCode
, name
);
48 const nsCString
& Message() const { return mMessage
; }
50 // Interoperations with nsresult.
51 bool operator==(nsresult aResult
) const { return aResult
== mCode
; }
52 bool operator!=(nsresult aResult
) const { return aResult
!= mCode
; }
53 operator nsresult() const { return mCode
; }
55 nsCString
Description() const {
56 if (NS_SUCCEEDED(mCode
)) {
59 return nsPrintfCString("%s (0x%08" PRIx32
")%s%s", ErrorName().get(),
60 static_cast<uint32_t>(mCode
),
61 mMessage
.IsEmpty() ? "" : " - ", mMessage
.get());
64 CDMProxy
* GetCDMProxy() const { return mCDMProxy
; }
69 // It's used when the error is NS_ERROR_DOM_MEDIA_CDM_PROXY_NOT_SUPPORTED_ERR.
74 # define RESULT_DETAIL(arg, ...) \
75 nsPrintfCString("%s: " arg, __FUNCSIG__, ##__VA_ARGS__)
77 # define RESULT_DETAIL(arg, ...) \
78 nsPrintfCString("%s: " arg, __PRETTY_FUNCTION__, ##__VA_ARGS__)
81 } // namespace mozilla
82 #endif // MediaResult_h_