Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / media / MediaResult.h
blob5504dcda4c011270ce6d43b3eb7fca9e550e36a3
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/. */
7 #ifndef MediaResult_h_
8 #define MediaResult_h_
10 #include "nsString.h" // Required before 'mozilla/ErrorNames.h'!?
11 #include "mozilla/ErrorNames.h"
12 #include "mozilla/TimeStamp.h"
13 #include "nsError.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.
20 namespace mozilla {
22 class CDMProxy;
24 class MediaResult {
25 public:
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 {
43 nsCString name;
44 GetErrorName(mCode, name);
45 return 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)) {
57 return nsCString();
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; }
66 private:
67 nsresult mCode;
68 nsCString mMessage;
69 // It's used when the error is NS_ERROR_DOM_MEDIA_CDM_PROXY_NOT_SUPPORTED_ERR.
70 CDMProxy* mCDMProxy;
73 #ifdef _MSC_VER
74 # define RESULT_DETAIL(arg, ...) \
75 nsPrintfCString("%s: " arg, __FUNCSIG__, ##__VA_ARGS__)
76 #else
77 # define RESULT_DETAIL(arg, ...) \
78 nsPrintfCString("%s: " arg, __PRETTY_FUNCTION__, ##__VA_ARGS__)
79 #endif
81 } // namespace mozilla
82 #endif // MediaResult_h_