2016-09-09 18:23:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MediaResult_h_
|
|
|
|
#define MediaResult_h_
|
|
|
|
|
2017-02-21 08:30:44 +03:00
|
|
|
#include "nsString.h" // Required before 'mozilla/ErrorNames.h'!?
|
|
|
|
#include "mozilla/ErrorNames.h"
|
2017-08-31 12:21:28 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2016-09-09 18:23:31 +03:00
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
// MediaResult can be used interchangeably with nsresult.
|
|
|
|
// It allows to store extra information such as where the error occurred.
|
|
|
|
// While nsresult is typically passed by value; due to its potential size, using
|
|
|
|
// MediaResult const references is recommended.
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class MediaResult {
|
|
|
|
public:
|
2019-09-26 17:51:56 +03:00
|
|
|
MediaResult() : mCode(NS_OK) {}
|
2016-09-09 18:23:31 +03:00
|
|
|
MOZ_IMPLICIT MediaResult(nsresult aResult) : mCode(aResult) {}
|
|
|
|
MediaResult(nsresult aResult, const nsACString& aMessage)
|
|
|
|
: mCode(aResult), mMessage(aMessage) {}
|
|
|
|
MediaResult(nsresult aResult, const char* aMessage)
|
|
|
|
: mCode(aResult), mMessage(aMessage) {}
|
|
|
|
MediaResult(const MediaResult& aOther) = default;
|
|
|
|
MediaResult(MediaResult&& aOther) = default;
|
|
|
|
MediaResult& operator=(const MediaResult& aOther) = default;
|
|
|
|
MediaResult& operator=(MediaResult&& aOther) = default;
|
|
|
|
|
|
|
|
nsresult Code() const { return mCode; }
|
2017-09-22 11:23:08 +03:00
|
|
|
nsCString ErrorName() const {
|
|
|
|
nsCString name;
|
|
|
|
GetErrorName(mCode, name);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-09-09 18:23:31 +03:00
|
|
|
const nsCString& Message() const { return mMessage; }
|
|
|
|
|
|
|
|
// Interoperations with nsresult.
|
|
|
|
bool operator==(nsresult aResult) const { return aResult == mCode; }
|
|
|
|
bool operator!=(nsresult aResult) const { return aResult != mCode; }
|
|
|
|
operator nsresult() const { return mCode; }
|
|
|
|
|
|
|
|
nsCString Description() const {
|
2016-09-14 09:49:56 +03:00
|
|
|
if (NS_SUCCEEDED(mCode)) {
|
|
|
|
return nsCString();
|
|
|
|
}
|
2017-02-21 08:30:44 +03:00
|
|
|
return nsPrintfCString("%s (0x%08" PRIx32 ")%s%s", ErrorName().get(),
|
|
|
|
static_cast<uint32_t>(mCode),
|
|
|
|
mMessage.IsEmpty() ? "" : " - ", mMessage.get());
|
2016-09-09 18:23:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult mCode;
|
|
|
|
nsCString mMessage;
|
|
|
|
};
|
|
|
|
|
2017-02-21 06:44:40 +03:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define RESULT_DETAIL(arg, ...) \
|
|
|
|
nsPrintfCString("%s: " arg, __FUNCSIG__, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define RESULT_DETAIL(arg, ...) \
|
|
|
|
nsPrintfCString("%s: " arg, __PRETTY_FUNCTION__, ##__VA_ARGS__)
|
|
|
|
#endif
|
2016-09-20 08:50:31 +03:00
|
|
|
|
2016-09-09 18:23:31 +03:00
|
|
|
} // namespace mozilla
|
2016-12-14 19:32:21 +03:00
|
|
|
#endif // MediaResult_h_
|