1 /* 2 * Copyright (c) 2022 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_PASTEBOARD_SERVICES_DEVICE_DM_ADAPTER_H 17 #define OHOS_PASTEBOARD_SERVICES_DEVICE_DM_ADAPTER_H 18 #include <mutex> 19 #include <string> 20 #include "api/visibility.h" 21 #include "common/concurrent_map.h" 22 namespace OHOS::MiscServices { 23 class API_EXPORT DMAdapter { 24 public: 25 static constexpr size_t MAX_ID_LEN = 64; 26 class DMObserver { 27 public: 28 virtual void Online(const std::string &device) = 0; 29 virtual void Offline(const std::string &device) = 0; 30 }; 31 static DMAdapter &GetInstance(); 32 bool Initialize(const std::string &pkgName); 33 const std::string &GetLocalDevice(); 34 std::string GetDeviceName(const std::string &udid); 35 void Register(DMObserver *observer); 36 void Unregister(DMObserver *observer); 37 38 private: 39 static constexpr const char *NAME_EX = "dm_adapter"; 40 static constexpr const char *DEVICE_INVALID_NAME = "unknown"; 41 DMAdapter(); 42 ~DMAdapter(); 43 44 std::string pkgName_; 45 const std::string invalidDeviceId_{}; 46 mutable std::mutex mutex_{}; 47 std::string localDeviceId_{}; 48 ConcurrentMap<DMObserver *, DMObserver *> observers_; 49 }; 50 } // namespace OHOS::MiscServices 51 #endif // OHOS_PASTEBOARD_SERVICES_DEVICE_DM_ADAPTER_H 52