/* * Copyright (c) 2021 Huawei Device Co., Ltd. * 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 THERMAL_OBSERVER_H #define THERMAL_OBSERVER_H #include #include #include #include #include #include "ithermal_action_callback.h" #include "ithermal_temp_callback.h" #include "thermal_srv_sensor_info.h" namespace OHOS { namespace PowerMgr { using TypeTempMap = std::map; class ThermalService; class ThermalObserver { public: using Callback = std::function; ThermalObserver() {}; explicit ThermalObserver(const wptr& tms); ~ThermalObserver(); bool Init(); void OnReceivedSensorInfo(const TypeTempMap& info); void SubscribeThermalTempCallback(const std::vector& typeList, const sptr& callback); void UnSubscribeThermalTempCallback(const sptr& callback); void SubscribeThermalActionCallback(const std::vector& actionList, const std::string& desc, const sptr& callback); void UnSubscribeThermalActionCallback(const sptr& callback); void FindSubscribeActionValue(); void NotifySensorTempChanged(IThermalTempCallback::TempCallbackMap& tempCbMap); void DecisionActionValue(const std::vector& actionList, IThermalActionCallback::ActionCallbackMap& filteredMap); bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo); void SetRegisterCallback(Callback& callback); void SetSensorTemp(const std::string& type, const int32_t& temp); void SetDecisionValue(const std::string& actionName, const std::string& actionValue); void UpdatePolicyState(std::string& state) { policyState_ = state; } int32_t GetTemp(const SensorType& type); std::map GetSensorType() { return typeMap_; } class SensorTempCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: SensorTempCallbackDeathRecipient() = default; virtual void OnRemoteDied(const wptr& remote); virtual ~SensorTempCallbackDeathRecipient() = default; }; class ActionCallbackDeathRecipient : public IRemoteObject::DeathRecipient { public: ActionCallbackDeathRecipient() = default; virtual void OnRemoteDied(const wptr& remote); virtual ~ActionCallbackDeathRecipient() = default; }; private: void PrintAction(); void InitSensorTypeMap(); void DecisionActionValue(const std::vector& actionList, IThermalActionCallback::ActionCallbackMap& filteredMap, const std::map& actionMap); struct classcomp { bool operator() (const sptr& l, const sptr& r) const { return l->AsObject() < r->AsObject(); } }; struct ClassActionComp { bool operator() (const sptr& l, const sptr& r) const { return l->AsObject() < r->AsObject(); } }; std::string policyState_; const wptr tms_; std::mutex mutexActionCallback_; std::mutex mutexTempCallback_; std::mutex mutexActionMap_; std::mutex mutexCallbackInfo_; TypeTempMap callbackinfo_; sptr sensorTempCBDeathRecipient_; sptr actionCBDeathRecipient_; std::set, classcomp> sensorTempListeners_; std::map, std::vector, classcomp> callbackTypeMap_; std::set, ClassActionComp> actionListeners_; std::map, std::vector, ClassActionComp> callbackActionMap_; Callback callback_; std::map typeMap_; std::map actionMap_; std::map actionCache_; }; } // namespace PowerMgr } // namespace OHOS #endif // THERMAL_OBSERVER_H