• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 DRIVER_REPORT_SYS_EVENT_H
17 #define DRIVER_REPORT_SYS_EVENT_H
18 
19 #include <string>
20 #include <vector>
21 #include <mutex>
22 #include <memory>
23 #include <map>
24 
25 namespace OHOS {
26 namespace ExternalDeviceManager {
27 class DeviceInfo;
28 class DriverInfo;
29 struct PkgInfoTable;
30 
31 enum EXTDEV_EXP_EVENT {  // 操作类型枚举
32     DRIVER_BIND = 1,             // 绑定设备驱动
33     DRIVER_UNBIND,               // 解绑设备驱动
34     DRIVER_PACKAGE_DATA_REFRESH, // 驱动包数据刷新
35     DRIVER_PACKAGE_CYCLE_MANAGE, // 驱动包管理生命周期
36     GET_DEVICE_INFO,             // 设备信息获取
37     CHANGE_FUNC,                 // 切换过程中生命周期
38     DRIVER_DEVICE_MATCH,         // 设备与驱动匹配
39 };
40 
41 typedef struct ExtDevEvent {
42     int32_t deviceClass;       // 设备类型
43     int32_t deviceSubClass;    // 设备子类型
44     int32_t deviceProtocol;    // 设备协议
45     std::string snNum;         // 设备SN号
46     int32_t vendorId;          // 厂商Id
47     int32_t productId;         // 产品Id
48     uint64_t deviceId;          // 设备Id
49     std::string driverUid;     // 驱动Uid
50     std::string driverName;    // 驱动名称
51     std::string versionCode;   // 驱动版本
52     std::string vids;          // 驱动配置的vid
53     std::string pids;          // 驱动配置的pid
54     int32_t userId;            // 用户Id
55     std::string bundleName;    // 驱动包名
56     int32_t operatType;        // 操作类型
57     std::string interfaceName; // 接口名称
58     std::string message;       // 信息
59     int32_t errCode;           // 故障码
60 
61     ExtDevEvent(std::string interfaceName = "", const int32_t operatType = 0, const uint64_t deviceId = 0)
62         : deviceClass(0), deviceSubClass(0), deviceProtocol(0), vendorId(0), productId(0), deviceId(deviceId),
63           userId(0), operatType(operatType), interfaceName(std::move(interfaceName)), errCode(0) {}
64 } ExtDevEvent;
65 
66 class ExtDevReportSysEvent {
67 public:
68     enum class EventErrCode {
69         SUCCESS = 0,
70         BIND_JS_CALLBACK_FAILED = 10001,
71         CONNECT_DRIVER_EXTENSION_FAILED,
72         BIND_ACCESS_NOT_ALLOWED,
73         UNBIND_DRIVER_EMPTY = 20001,
74         UNBIND_RELATION_NOT_FOUND,
75         DISCONNECT_DRIVER_EXTENSION_FAILED,
76         QUERY_DRIVER_EXTENSION_FAILED = 30001,
77         UPDATE_DATABASE_FAILED,
78         LIFECYCLE_FUNCTION_FAILED = 40001,
79         OPEN_DEVICE_FAILED = 50001,
80         GET_DEVICE_DESCRIPTOR_FAILED,
81         DEVICE_DESCRIPTOR_LENGTH_INVALID,
82         GET_INTERFACE_DESCRIPTOR_FAILED,
83         STOP_DRIVER_EXTENSION_FAILED = 60001,
84         QUERY_DRIVER_INFO_FAILED = 70001,
85         NO_MATCHING_DRIVER_FOUND
86     };
87 
88     static const std::map<EventErrCode, std::string> ErrMsgs;
89 
90     static void ReportExternalDeviceEvent(const std::shared_ptr<ExtDevEvent> &extDevEvent);
91 
92     static void ReportExternalDeviceEvent(const std::shared_ptr<ExtDevEvent> &extDevEvent, const EventErrCode errCode);
93 
94     static void ParseToExtDevEvent(const std::shared_ptr<DeviceInfo> &deviceInfo,
95         const std::shared_ptr<ExtDevEvent> &eventObj);
96 
97     static void ParseToExtDevEvent(const std::shared_ptr<DriverInfo> &driverInfo,
98         const std::shared_ptr<ExtDevEvent> &eventObj);
99 
100     static void ParseToExtDevEvent(const std::shared_ptr<DeviceInfo> &deviceInfo,
101         const std::shared_ptr<DriverInfo> &driverInfo, const std::shared_ptr<ExtDevEvent> &eventObj);
102 
103     static std::string ParseIdVector(std::vector<uint16_t> ids);
104 };
105 
106 } // namespace ExternalDeviceManager
107 } // namespace OHOS
108 #endif // DRIVER_REPORT_SYS_EVENT_H