blob: ca9c1dfd93cce14063a0b73a75e4fcfefbf8482c [file] [log] [blame]
Daniel Eratbe43a392015-09-08 13:20:02 -06001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <binderwrapper/binder_wrapper.h>
18
19#include <base/logging.h>
20
21#include "real_binder_wrapper.h"
22
23namespace android {
24
25// Singleton instance.
26BinderWrapper* BinderWrapper::instance_ = nullptr;
27
28// static
29void BinderWrapper::Create() {
30 CHECK(!instance_) << "Already initialized; missing call to Destroy()?";
31 instance_ = new RealBinderWrapper();
32}
33
34// static
35void BinderWrapper::InitForTesting(BinderWrapper* wrapper) {
36 CHECK(!instance_) << "Already initialized; missing call to Destroy()?";
37 instance_ = wrapper;
38}
39
40// static
41void BinderWrapper::Destroy() {
42 CHECK(instance_) << "Not initialized; missing call to Create()?";
43 delete instance_;
44 instance_ = nullptr;
45}
46
47// static
48BinderWrapper* BinderWrapper::Get() {
49 CHECK(instance_) << "Not initialized; missing call to Create()?";
50 return instance_;
51}
52
Alex Vakulenko08c98912016-01-04 12:22:05 -080053// static
54BinderWrapper* BinderWrapper::GetOrCreateInstance() {
55 if (!instance_)
56 instance_ = new RealBinderWrapper();
57 return instance_;
58}
59
Daniel Eratbe43a392015-09-08 13:20:02 -060060} // namespace android