Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / camera / CameraPreferences.h
blob3d260a3f31afa29952df3997ff1d372376561252
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef DOM_CAMERA_CAMERAPREFERENCES_H
7 #define DOM_CAMERA_CAMERAPREFERENCES_H
9 #include "nsString.h"
10 #include "nsIObserver.h"
11 #ifdef MOZ_WIDGET_GONK
12 #include "mozilla/StaticPtr.h"
13 #endif
15 #if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) || defined(MOZ_HAVE_CXX11_ENUM_TYPE)
16 // Older compilers that don't support strongly-typed enums
17 // just typedef uint32_t to nsresult, which results in conflicting
18 // overloaded members in CameraPreferences.
19 #define CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
20 #endif
22 namespace mozilla {
24 template<class T> class StaticAutoPtr;
26 class CameraPreferences
27 #ifdef MOZ_WIDGET_GONK
28 : public nsIObserver
29 #endif
31 public:
32 #ifdef MOZ_WIDGET_GONK
33 NS_DECL_ISUPPORTS
34 NS_DECL_NSIOBSERVER
35 #endif
37 static bool Initialize();
38 static void Shutdown();
40 static bool GetPref(const char* aPref, nsACString& aVal);
41 #ifdef CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
42 static bool GetPref(const char* aPref, nsresult& aVal);
43 #endif
44 static bool GetPref(const char* aPref, uint32_t& aVal);
45 static bool GetPref(const char* aPref, bool& aVal);
47 protected:
48 static const uint32_t kPrefNotFound = UINT32_MAX;
49 static uint32_t PrefToIndex(const char* aPref);
51 static void PreferenceChanged(const char* aPref, void* aClosure);
52 #ifdef CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
53 static nsresult UpdatePref(const char* aPref, nsresult& aVar);
54 #endif
55 static nsresult UpdatePref(const char* aPref, uint32_t& aVar);
56 static nsresult UpdatePref(const char* aPref, nsACString& aVar);
57 static nsresult UpdatePref(const char* aPref, bool& aVar);
59 enum PrefValueType {
60 kPrefValueIsNsResult,
61 kPrefValueIsUint32,
62 kPrefValueIsCString,
63 kPrefValueIsBoolean
65 struct Pref {
66 const char* const mPref;
67 PrefValueType mValueType;
68 union {
69 // The 'mAsVoid' member must be first and is required to allow 'mValue'
70 // to be initialized with any pointer type, as not all of our platforms
71 // support the use of designated initializers; in their absence, only
72 // the first element of a union can be statically initialized, and
73 // 'void*' lets us stuff any pointer type into it.
74 void* mAsVoid;
75 StaticAutoPtr<nsCString>* mAsCString;
76 nsresult* mAsNsResult;
77 uint32_t* mAsUint32;
78 bool* mAsBoolean;
79 } mValue;
81 static Pref sPrefs[];
83 static StaticAutoPtr<nsCString> sPrefTestEnabled;
84 static StaticAutoPtr<nsCString> sPrefHardwareTest;
85 static StaticAutoPtr<nsCString> sPrefGonkParameters;
87 static nsresult sPrefCameraControlMethodErrorOverride;
88 static nsresult sPrefCameraControlAsyncErrorOverride;
90 static uint32_t sPrefCameraControlLowMemoryThresholdMB;
92 static bool sPrefCameraParametersIsLowMemory;
94 #ifdef MOZ_WIDGET_GONK
95 static StaticRefPtr<CameraPreferences> sObserver;
97 nsresult PreinitCameraHardware();
99 protected:
100 // Objects may be instantiated for use as observers.
101 CameraPreferences() { }
102 virtual ~CameraPreferences() { }
103 #else
104 private:
105 // Static class only.
106 CameraPreferences();
107 ~CameraPreferences();
108 #endif
111 } // namespace mozilla
113 #endif // DOM_CAMERA_CAMERAPREFERENCES_H