ClassOfService.h (2074B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef __ClassOfService_h__ 6 #define __ClassOfService_h__ 7 8 #include "nsIClassOfService.h" 9 #include "nsPrintfCString.h" 10 11 namespace IPC { 12 template <class P> 13 struct ParamTraits; 14 } // namespace IPC 15 16 namespace mozilla::net { 17 18 class ClassOfService { 19 public: 20 ClassOfService() = default; 21 ClassOfService(unsigned long flags, bool incremental) 22 : mClassFlags(flags), mIncremental(incremental) {} 23 24 // class flags (priority) 25 unsigned long Flags() const { return mClassFlags; } 26 void SetFlags(unsigned long flags) { mClassFlags = flags; } 27 28 // incremental flags 29 bool Incremental() const { return mIncremental; } 30 void SetIncremental(bool incremental) { mIncremental = incremental; } 31 32 nsIClassOfService::FetchPriority FetchPriority() { return mFetchPriority; } 33 void SetFetchPriority(nsIClassOfService::FetchPriority aPriority) { 34 mFetchPriority = aPriority; 35 } 36 37 static void ToString(const ClassOfService aCos, nsACString& aOut) { 38 return ToString(aCos.Flags(), aOut); 39 } 40 41 static void ToString(unsigned long aFlags, nsACString& aOut) { 42 aOut = nsPrintfCString("%lX", aFlags); 43 } 44 45 private: 46 unsigned long mClassFlags = 0; 47 bool mIncremental = false; 48 nsIClassOfService::FetchPriority mFetchPriority = 49 nsIClassOfService::FETCHPRIORITY_UNSET; 50 friend IPC::ParamTraits<mozilla::net::ClassOfService>; 51 friend bool operator==(const ClassOfService& lhs, const ClassOfService& rhs); 52 friend bool operator!=(const ClassOfService& lhs, const ClassOfService& rhs); 53 }; 54 55 inline bool operator==(const ClassOfService& lhs, const ClassOfService& rhs) { 56 return lhs.mClassFlags == rhs.mClassFlags && 57 lhs.mIncremental == rhs.mIncremental && 58 lhs.mFetchPriority == rhs.mFetchPriority; 59 } 60 61 inline bool operator!=(const ClassOfService& lhs, const ClassOfService& rhs) { 62 return !(lhs == rhs); 63 } 64 65 } // namespace mozilla::net 66 67 #endif