• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef EXT_OBJECT_H
16 #define EXT_OBJECT_H
17 
18 #include <memory>
19 #include <string>
20 #include "edm_errors.h"
21 namespace OHOS {
22 namespace ExternalDeviceManager {
23 enum BusType : uint32_t {
24     BUS_TYPE_INVALID = 0,
25     BUS_TYPE_USB = 1,
26     BUS_TYPE_MAX,
27     BUS_TYPE_TEST,
28 };
29 
30 class DrvBundleStateCallback;
31 class DriverInfoExt {
32 public:
33     virtual ~DriverInfoExt() = default;
34     virtual int32_t Serialize(std::string &str) = 0;
35     virtual int32_t UnSerialize(const std::string &str) = 0;
36 };
37 
38 class DriverInfo : public DriverInfoExt {
39 public:
40     int32_t Serialize(std::string &str) override;
41     int32_t UnSerialize(const std::string &str) override;
GetBusName()42     std::string GetBusName() const
43     {
44         return bus_;
45     }
GetInfoExt()46     std::shared_ptr<DriverInfoExt> GetInfoExt() const
47     {
48         return driverInfoExt_;
49     }
50 private:
51     friend class DrvBundleStateCallback;
52     std::string bus_;
53     std::string vendor_;
54     std::string version_;
55     std::shared_ptr<DriverInfoExt> driverInfoExt_;
56 };
57 
58 class DeviceInfo {
59 public:
60     DeviceInfo(
61         uint32_t busDeviceId,
62         BusType busType = BusType::BUS_TYPE_INVALID,
description_(description)63         const std::string &description = "") : description_(description)
64     {
65         devInfo_.devBusInfo.busType = busType;
66         devInfo_.devBusInfo.busDeviceId = busDeviceId;
67     }
68     virtual ~DeviceInfo() = default;
GetBusType()69     BusType GetBusType() const
70     {
71         return devInfo_.devBusInfo.busType;
72     }
GetDeviceId()73     uint64_t GetDeviceId() const
74     {
75         return devInfo_.deviceId;
76     }
GetBusDevId()77     uint32_t GetBusDevId() const
78     {
79         return devInfo_.devBusInfo.busDeviceId;
80     }
GetDeviceDescription()81     const std::string& GetDeviceDescription() const
82     {
83         return description_;
84     }
85 
86 private:
87     union DevInfo {
88         uint64_t deviceId;
89         struct {
90             BusType busType;
91             uint32_t busDeviceId;
92         } devBusInfo;
93     } devInfo_;
94     std::string description_ {""};
95 };
96 } // namespace ExternalDeviceManager
97 } // namespace OHOS
98 #endif // EXT_OBJECT_H