1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_DP_SWITCH_ADAPTER_H 17 #define OHOS_DP_SWITCH_ADAPTER_H 18 19 #include <mutex> 20 #include <string> 21 #include <utility> 22 23 #include "distributed_kv_data_manager.h" 24 #include "kv_adapter.h" 25 #include "kvstore_observer.h" 26 #include "single_instance.h" 27 28 namespace OHOS { 29 namespace DistributedDeviceProfile { 30 class SwitchAdapter { 31 DECLARE_SINGLE_INSTANCE(SwitchAdapter); 32 33 public: 34 void Init(); 35 void Uninit(); 36 int32_t PutSwitch(const std::string& appId, uint32_t value, uint16_t length); 37 int32_t GetSwitch(const std::string& appId, const std::string& networkId, uint32_t& value, uint32_t& switchLength); 38 int32_t SubscribeSwitchData(const std::string& appId); 39 int32_t UnsubscribeSwitchData(const std::string& appId); 40 41 private: 42 std::shared_ptr<DistributedKv::KvStoreObserver> observer_; 43 DistributedKv::DistributedKvDataManager kvDataMgr_; 44 std::mutex switchAdapterMutex_; 45 }; 46 47 } // namespace DistributedDeviceProfile 48 } // namespace OHOS 49 #endif // OHOS_DP_SWITCH_ADAPTER_H 50