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 INTERFACES_INNER_API_INCLUDE_USB_DEVICE_ID_H 17 #define INTERFACES_INNER_API_INCLUDE_USB_DEVICE_ID_H 18 19 #include <string> 20 #include "message_parcel.h" 21 22 namespace OHOS { 23 namespace EDM { 24 class UsbDeviceId { 25 public: 26 bool Marshalling(MessageParcel &parcel) const; 27 static bool Unmarshalling(MessageParcel &parcel, UsbDeviceId &usbDeviceId); 28 29 void SetVendorId(int32_t vendorId); 30 void SetProductId(int32_t productId); 31 32 [[nodiscard]] int32_t GetVendorId() const; 33 [[nodiscard]] int32_t GetProductId() const; 34 35 bool operator<(const UsbDeviceId &other) const 36 { 37 return (GetVendorId() == other.GetVendorId()) ? 38 (GetProductId() < other.GetProductId()) : (GetVendorId() < other.GetVendorId()); 39 } 40 41 private: 42 int32_t vendorId_ = -1; 43 int32_t productId_ = -1; 44 }; 45 46 struct Comp { operatorComp47 bool operator()(const UsbDeviceId& id1, const UsbDeviceId& id2) 48 { 49 return (id1.GetVendorId() == id2.GetVendorId()) ? 50 (id1.GetProductId() < id2.GetProductId()) : (id1.GetVendorId() < id2.GetVendorId()); 51 } 52 }; 53 } // namespace EDM 54 } // namespace OHOS 55 56 #endif // INTERFACES_INNER_API_INCLUDE_USB_DEVICE_ID_H 57