mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
// Copyright 2020 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef PLATFORM_BASE_FEATURE_FLAGS_H_
|
|
#define PLATFORM_BASE_FEATURE_FLAGS_H_
|
|
|
|
#include "absl/synchronization/mutex.h"
|
|
|
|
namespace location {
|
|
namespace nearby {
|
|
|
|
// Global flags that control feature availability. This may be used to gating
|
|
// features in development, QA testing and releasing.
|
|
class FeatureFlags {
|
|
public:
|
|
// Holds for all the feature flags.
|
|
struct Flags {
|
|
bool enable_cancellation_flag = false;
|
|
bool resume_before_disconnect = true;
|
|
// Disable ServiceController API (using StoppableServiceController) when
|
|
// ServiceController is released to prevent calls to that API from
|
|
// other threads.
|
|
bool disable_released_service_controller = true;
|
|
// Ignore subsequent BWU Available events when we're still processing the
|
|
// first one.
|
|
bool disallow_out_of_order_bwu_avail_event = true;
|
|
bool enable_async_bandwidth_upgrade = true;
|
|
};
|
|
|
|
static const FeatureFlags& GetInstance() {
|
|
static const FeatureFlags* instance = new FeatureFlags();
|
|
return *instance;
|
|
}
|
|
|
|
const Flags& GetFlags() const ABSL_LOCKS_EXCLUDED(mutex_) {
|
|
absl::ReaderMutexLock lock(&mutex_);
|
|
return flags_;
|
|
}
|
|
|
|
private:
|
|
FeatureFlags() = default;
|
|
|
|
// MediumEnvironment is testing uitl class. Use friend class here to enable
|
|
// SetFlags for feature controlling need in test environment.
|
|
friend class MediumEnvironment;
|
|
void SetFlags(const Flags& flags) ABSL_LOCKS_EXCLUDED(mutex_) {
|
|
absl::MutexLock lock(&mutex_);
|
|
flags_ = flags;
|
|
}
|
|
Flags flags_ ABSL_GUARDED_BY(mutex_);
|
|
mutable absl::Mutex mutex_;
|
|
};
|
|
} // namespace nearby
|
|
} // namespace location
|
|
|
|
#endif // PLATFORM_BASE_FEATURE_FLAGS_H_
|