• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 
21 #include "api/visibility.h"
22 #include "common/concurrent_map.h"
23 #include "dm_device_info.h"
24 
25 namespace OHOS::MiscServices {
26 using namespace OHOS::DistributedHardware;
27 class API_EXPORT DMAdapter {
28 public:
29     static constexpr size_t MAX_ID_LEN = 64;
30     static constexpr size_t RESULT_OK = 0;
31     class DMObserver {
32     public:
33         virtual void Online(const std::string &device) = 0;
34         virtual void Offline(const std::string &device) = 0;
35     };
36     static DMAdapter &GetInstance();
37     bool Initialize(const std::string &pkgName);
38     const std::string &GetLocalDevice();
39     const std::string GetLocalNetworkId();
40     int32_t GetRemoteDeviceInfo(const std::string &networkId, DmDeviceInfo &remoteDevice);
41     std::string GetDeviceName(const std::string &networkId);
42     void Register(DMObserver *observer);
43     void Unregister(DMObserver *observer);
44 
45 private:
46     static constexpr const char *NAME_EX = "dm_adapter";
47     static constexpr const char *DEVICE_INVALID_NAME = "unknown";
48     DMAdapter();
49     ~DMAdapter();
50 
51     std::string pkgName_;
52     const std::string invalidDeviceId_{};
53     const std::string invalidNetworkId_{};
54     mutable std::mutex mutex_{};
55     std::string localDeviceId_{};
56     ConcurrentMap<DMObserver *, DMObserver *> observers_;
57 };
58 } // namespace OHOS::MiscServices
59 #endif // OHOS_PASTEBOARD_SERVICES_DEVICE_DM_ADAPTER_H
60