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