• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 HID_DDK_SERVICE_H
17 #define HID_DDK_SERVICE_H
18 
19 #include "hid_adapter.h"
20 #include "v1_1/ihid_ddk.h"
21 #include <mutex>
22 #include <unordered_map>
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace Input {
27 namespace Ddk {
28 namespace V1_1 {
29 class HidDdkService : public IHidDdk {
30 public:
HidDdkService(std::shared_ptr<HidOsAdapter> & osAdapter)31     HidDdkService(std::shared_ptr<HidOsAdapter>& osAdapter) : osAdapter_(osAdapter) {}
32     virtual ~HidDdkService() = default;
33 
34     int32_t CreateDevice(const Hid_Device& hidDevice,
35          const Hid_EventProperties& hidEventProperties, uint32_t& deviceId) override;
36 
37     int32_t EmitEvent(uint32_t deviceId, const std::vector<Hid_EmitItem>& items) override;
38 
39     int32_t DestroyDevice(uint32_t deviceId) override;
40 
41     int32_t Init() override;
42 
43     int32_t Release() override;
44 
45     int32_t Open(uint64_t deviceId, uint8_t interfaceIndex, HidDeviceHandle& dev) override;
46 
47     int32_t Close(const HidDeviceHandle& dev) override;
48 
49     int32_t Write(const HidDeviceHandle& dev, const std::vector<uint8_t>& data, uint32_t& bytesWritten) override;
50 
51     int32_t ReadTimeout(const HidDeviceHandle& dev, std::vector<uint8_t>& data, uint32_t buffSize, int32_t timeout,
52         uint32_t& bytesRead) override;
53 
54     int32_t SetNonBlocking(const HidDeviceHandle& dev, int32_t nonBlock) override;
55 
56     int32_t GetRawInfo(const HidDeviceHandle& dev, HidRawDevInfo& rawDevInfo) override;
57 
58     int32_t GetRawName(const HidDeviceHandle& dev, std::vector<uint8_t>& data, uint32_t buffSize) override;
59 
60     int32_t GetPhysicalAddress(const HidDeviceHandle& dev, std::vector<uint8_t>& data, uint32_t buffSize) override;
61 
62     int32_t GetRawUniqueId(const HidDeviceHandle& dev, std::vector<uint8_t>& data, uint32_t buffSize) override;
63 
64     int32_t SendReport(const HidDeviceHandle& dev, HidReportType reportType, const std::vector<uint8_t>& data) override;
65 
66     int32_t GetReport(const HidDeviceHandle& dev, HidReportType reportType, uint8_t reportNumber,
67         std::vector<uint8_t>& data, uint32_t buffSize) override;
68 
69     int32_t GetReportDescriptor(const HidDeviceHandle& dev, std::vector<uint8_t>& buf, uint32_t buffSize,
70         uint32_t& bytesRead) override;
71 
72 private:
73     std::shared_ptr<HidOsAdapter> osAdapter_;
74     std::mutex fileDescriptorLock_;
75     std::unordered_map<uint32_t, FILE*> fileDescriptorMap_;
76 };
77 } // V1_1
78 } // Ddk
79 } // Input
80 } // HDI
81 } // OHOS
82 
83 #endif // HID_DDK_SERVICE_H