/* * Copyright (c) 2020 The Android Open Source Project * * 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 * * http://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 CPP_WATCHDOG_SERVER_SRC_SERVICEMANAGER_H_ #define CPP_WATCHDOG_SERVER_SRC_SERVICEMANAGER_H_ #include "IoOveruseMonitor.h" #include "PressureMonitor.h" #include "WatchdogBinderMediator.h" #include "WatchdogPerfService.h" #include "WatchdogProcessService.h" #include "WatchdogServiceHelper.h" #include #include #include #include namespace android { namespace automotive { namespace watchdog { // Manages all the services that are run by the car watchdog daemon. class ServiceManager final : virtual public android::RefBase { public: ServiceManager() : mWatchdogProcessService(nullptr), mWatchdogPerfService(nullptr), mWatchdogBinderMediator(nullptr), mWatchdogServiceHelper(nullptr), mIoOveruseMonitor(nullptr), mPressureMonitor(nullptr) {} // Returns the singleton ServiceManager instance. static android::sp getInstance() { if (sServiceManager == nullptr) { sServiceManager = android::sp::make(); } return sServiceManager; } // Terminates all services and resets the singleton instance. static void terminate() { if (sServiceManager == nullptr) { return; } sServiceManager->terminateServices(); sServiceManager.clear(); } // Starts early-init services. android::base::Result startServices(const android::sp& mainLooper); // Returns the WatchdogProcessService instance. const android::sp& getWatchdogProcessService() { return mWatchdogProcessService; } // Returns the WatchdogServiceHelper instance. const android::sp& getWatchdogServiceHelper() { return mWatchdogServiceHelper; } // Returns the IoOveruseMonitor instance. const android::sp& getIoOveruseMonitor() { return mIoOveruseMonitor; } private: inline static android::sp sServiceManager = nullptr; void terminateServices(); android::base::Result startWatchdogProcessService(const android::sp& mainLooper); android::base::Result startPressureMonitor(); android::base::Result startWatchdogPerfService( const sp& watchdogServiceHelper); android::sp mWatchdogProcessService; android::sp mWatchdogPerfService; std::shared_ptr mWatchdogBinderMediator; android::sp mWatchdogServiceHelper; android::sp mIoOveruseMonitor; android::sp mPressureMonitor; }; } // namespace watchdog } // namespace automotive } // namespace android #endif // CPP_WATCHDOG_SERVER_SRC_SERVICEMANAGER_H_