| Daniel Erat | be43a39 | 2015-09-08 13:20:02 -0600 | [diff] [blame] | 1 | /* | 
 | 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 |  | 
 | 23 | namespace android { | 
 | 24 |  | 
 | 25 | // Singleton instance. | 
 | 26 | BinderWrapper* BinderWrapper::instance_ = nullptr; | 
 | 27 |  | 
 | 28 | // static | 
 | 29 | void BinderWrapper::Create() { | 
 | 30 |   CHECK(!instance_) << "Already initialized; missing call to Destroy()?"; | 
 | 31 |   instance_ = new RealBinderWrapper(); | 
 | 32 | } | 
 | 33 |  | 
 | 34 | // static | 
 | 35 | void BinderWrapper::InitForTesting(BinderWrapper* wrapper) { | 
 | 36 |   CHECK(!instance_) << "Already initialized; missing call to Destroy()?"; | 
 | 37 |   instance_ = wrapper; | 
 | 38 | } | 
 | 39 |  | 
 | 40 | // static | 
 | 41 | void BinderWrapper::Destroy() { | 
 | 42 |   CHECK(instance_) << "Not initialized; missing call to Create()?"; | 
 | 43 |   delete instance_; | 
 | 44 |   instance_ = nullptr; | 
 | 45 | } | 
 | 46 |  | 
 | 47 | // static | 
 | 48 | BinderWrapper* BinderWrapper::Get() { | 
 | 49 |   CHECK(instance_) << "Not initialized; missing call to Create()?"; | 
 | 50 |   return instance_; | 
 | 51 | } | 
 | 52 |  | 
| Alex Vakulenko | 08c9891 | 2016-01-04 12:22:05 -0800 | [diff] [blame] | 53 | // static | 
 | 54 | BinderWrapper* BinderWrapper::GetOrCreateInstance() { | 
 | 55 |   if (!instance_) | 
 | 56 |     instance_ = new RealBinderWrapper(); | 
 | 57 |   return instance_; | 
 | 58 | } | 
 | 59 |  | 
| Daniel Erat | be43a39 | 2015-09-08 13:20:02 -0600 | [diff] [blame] | 60 | }  // namespace android |