dom/camera/CameraPreferences.h
author Dave Townsend <dtownsend@oxymoronical.com>
Fri, 26 Sep 2014 08:32:55 -0700
changeset 230683 8f7dd750e75fafc6460edd7f9fe6455029419f6c
parent 214458 88a2ebd864b079b08092a47ad7ddc9ef7882bea1
child 237851 506d33f3931e5d833e74e84340b7cb4c3331e27d
permissions -rw-r--r--
Bug 1068440: Uplift Add-on SDK to Firefox. https://github.com/mozilla/addon-sdk/compare/cc3242d1ca8c...cbf6cdd0d630

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 DOM_CAMERA_CAMERAPREFERENCES_H
#define DOM_CAMERA_CAMERAPREFERENCES_H

#include "nsString.h"

#if defined(MOZ_HAVE_CXX11_STRONG_ENUMS) || defined(MOZ_HAVE_CXX11_ENUM_TYPE)
// Older compilers that don't support strongly-typed enums
// just typedef uint32_t to nsresult, which results in conflicting
// overloaded members in CameraPreferences.
#define CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
#endif

namespace mozilla {

template<class T> class StaticAutoPtr;

class CameraPreferences
{
public:
  static bool Initialize();
  static void Shutdown();

  static bool GetPref(const char* aPref, nsACString& aVal);
#ifdef CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
  static bool GetPref(const char* aPref, nsresult& aVal);
#endif
  static bool GetPref(const char* aPref, uint32_t& aVal);
  static bool GetPref(const char* aPref, bool& aVal);

protected:
  static const uint32_t kPrefNotFound = UINT32_MAX;
  static uint32_t PrefToIndex(const char* aPref);

  static void PreferenceChanged(const char* aPref, void* aClosure);
#ifdef CAMERAPREFERENCES_HAVE_SEPARATE_UINT32_AND_NSRESULT
  static nsresult UpdatePref(const char* aPref, nsresult& aVar);
#endif
  static nsresult UpdatePref(const char* aPref, uint32_t& aVar);
  static nsresult UpdatePref(const char* aPref, nsACString& aVar);
  static nsresult UpdatePref(const char* aPref, bool& aVar);

  enum PrefValueType {
    kPrefValueIsNsResult,
    kPrefValueIsUint32,
    kPrefValueIsCString,
    kPrefValueIsBoolean
  };
  struct Pref {
    const char* const           mPref;
    PrefValueType               mValueType;
    union {
      // The 'mAsVoid' member must be first and is required to allow 'mValue'
      // to be initialized with any pointer type, as not all of our platforms
      // support the use of designated initializers; in their absence, only
      // the first element of a union can be statically initialized, and
      // 'void*' lets us stuff any pointer type into it.
      void*                     mAsVoid;
      StaticAutoPtr<nsCString>* mAsCString;
      nsresult*                 mAsNsResult;
      uint32_t*                 mAsUint32;
      bool*                     mAsBoolean;
    } mValue;
  };
  static Pref sPrefs[];

  static StaticAutoPtr<nsCString> sPrefTestEnabled;
  static StaticAutoPtr<nsCString> sPrefHardwareTest;
  static StaticAutoPtr<nsCString> sPrefGonkParameters;

  static nsresult sPrefCameraControlMethodErrorOverride;
  static nsresult sPrefCameraControlAsyncErrorOverride;

  static uint32_t sPrefCameraControlLowMemoryThresholdMB;

  static bool sPrefCameraParametersIsLowMemory;

private:
  // static class only
  CameraPreferences();
  ~CameraPreferences();
};

} // namespace mozilla

#endif // DOM_CAMERA_CAMERAPREFERENCES_H