diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..9d8e1bd
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,29 @@
+BasedOnStyle: Webkit
+ColumnLimit: 120
+PointerAlignment: Right
+AlignAfterOpenBracket: DontAlign
+AlignTrailingComments: true
+AlignConsecutiveMacros: Consecutive
+IndentCaseLabels: true
+BreakBeforeBinaryOperators: None
+SpaceBeforeParens: ControlStatementsExceptControlMacros
+SpacesInCStyleCastParentheses: false
+AlignEscapedNewlines: Left
+NamespaceIndentation: None
+FixNamespaceComments: true
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+BreakConstructorInitializers: AfterColon
+AlignArrayOfStructures: Left
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortLambdasOnASingleLine: Empty
+AlwaysBreakTemplateDeclarations: true
+SpaceInEmptyBlock: false
+LambdaBodyIndentation: Signature
+BreakBeforeTernaryOperators: false
+Cpp11BracedListStyle: true
+SpaceAroundPointerQualifiers: Both
+
+ForEachMacros:
+ - 'DLIST_FOR_EACH_ENTRY'
+ - 'DLIST_FOR_EACH_ENTRY_REVERSE'
+ - 'DLIST_FOR_EACH_ENTRY_SAFE'
\ No newline at end of file
diff --git a/README.md b/README.md
index 3f6ee6e..cf56c9a 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,26 @@
-# USB Manager
+# USB Manager ``
-- [Introduction](#section11660541593)
-- [Directory Structure](#section19472752217)
-- [Available APIs](#section19472752218)
-- [Development Example](#section19472752219)
-- [Repositories Involved](#section63151229062)
+- [Introduction](#section11660541593)
+- [Directory Structure](#section19472752217)
+- [Available APIs](#section19472752218)
+- [Development Example](#section19472752219)
+- [Repositories Involved](#section63151229062)
+
+## Introduction``
-## Introduction
The following figure shows the USB service architecture.
-**Figure 1** USB service architecture
+**Figure 1** USB service architecture``

The architecture logically consists of three layers:
+
1. USB API: provides USB APIs that implement various basic functions, for example, query of the USB device list, USB device plug notification, USB host and device mode switching, bulk transfer, control transfer, right management, and function switching in device mode.
2. USB Service: interacts with the HAL layer to receive, parse, and distribute data, manages foreground and background policies, and performs USB device management and right control.
3. USB HAL: provides driver capability APIs that can be directly called in user mode. The APIs are classified into the DDK initialization class, interface operation class, and request operation class by function. They can be used to perform DDK initialization, bind/release and open/close an interface, allocate/release a request, and implement isochronous or non-isochronous transfer. The USB HAL code is stored in [drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md).
-## Directory Structure
+## Directory Structure``
+
```
base/usb/usb_manager
├── interfaces # APIs
@@ -30,58 +33,70 @@ base/usb/usb_manager
└── test # Test cases
└── utils # Utilities
```
-## Available APIs
+
+## Available APIs``
+
### [External APIs](https://gitee.com/openharmony/usb_manager/blob/master/interfaces/kits/js/@ohos.usb.d.ts)
### Internal APIs
+
#### Host APIs
-| **API**| **Description**|
-| --- | --- |
-| int32_t OpenDevice(const UsbDevice &device, USBDevicePipe &pip); | Opens a USB device to set up a connection.|
-| bool Close(const USBDevicePipe &pip); | Closes a USB device to release all system resources related to the device.|
-| int32_t GetDevices(std::vector &deviceList); | Obtains the USB device list.|
-| int32_t SetConfiguration(USBDevicePipe &pip, const USBConfig &config); | Sets the current configuration of the USB device.|
-| int32_t ClaimInterface(USBDevicePipe &pip, const UsbInterface &interface, bool force); | Claims a USB interface exclusively. This must be done before data transfer.|
-| int32_t ReleaseInterface(USBDevicePipe &pip, const UsbInterface &interface); | Releases a USB interface. This is usually done after data transfer.|
-| int32_t SetInterface(USBDevicePipe &pipe, const UsbInterface &interface); | Sets the alternate settings for the specified USB interface. This allows you to switch between two interfaces with the same ID but different alternate settings.|
-| int32_t BulkTransfer(USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &vdata, int32_t timeout); | Writes data on a specified endpoint during bulk transfer.|
-| int32_t ControlTransfer(USBDevicePipe &pip, const UsbCtrlTransfer &ctrl, std::vector &vdata); | Performs control transfer for endpoint 0 of the device. The data transfer direction is determined by the request type. If the result of **requestType & USB_ENDPOINT_DIR_MASK** is **USB_DIR_OUT**, the endpoint is in the data writing direction; if the result is **USB_DIR_IN**, the endpoint is in the data reading direction.|
-| int32_t RequestInitialize(UsbRequest &request); | Initializes a request.|
-| int32_t RequestQueue(UsbRequest &request); | Sends or receives requests for isochronous transfer on a specified endpoint. The data transfer direction is determined by the endpoint direction.|
-| int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req); | Waits for the operation result of the isochronous transfer request in RequestQueue.|
-| int32_t RequestAbort(UsbRequest &request); | Cancels the data transfer requests to be processed.|
-| int32_t RequestFree(UsbRequest &request); | Requests for releasing data.|
-| bool HasRight(std::string deviceName); | Checks whether the application has permission to access the USB device.|
-| int32_t RequestRight(std::string deviceName); | Requests for permission to access the USB device.|
+| **API** | **Description** |
+| -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| int32_t OpenDevice(const UsbDevice &device, USBDevicePipe &pip); | Opens a USB device to set up a connection. |
+| bool Close(const USBDevicePipe &pip); | Closes a USB device to release all system resources related to the device. |
+| int32_t GetDevices(std::vector &deviceList); | Obtains the USB device list. |
+| int32_t SetConfiguration(USBDevicePipe &pip, const USBConfig &config); | Sets the current configuration of the USB device. |
+| int32_t ClaimInterface(USBDevicePipe &pip, const UsbInterface &interface, bool force); | Claims a USB interface exclusively. This must be done before data transfer. |
+| int32_t ReleaseInterface(USBDevicePipe &pip, const UsbInterface &interface); | Releases a USB interface. This is usually done after data transfer. |
+| int32_t SetInterface(USBDevicePipe &pipe, const UsbInterface &interface); | Sets the alternate settings for the specified USB interface. This allows you to switch between two interfaces with the same ID but different alternate settings. |
+| int32_t BulkTransfer(USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &vdata, int32_t timeout); | Writes data on a specified endpoint during bulk transfer. |
+| int32_t ControlTransfer(USBDevicePipe &pip, const UsbCtrlTransfer &ctrl, std::vector &vdata); | Performs control transfer for endpoint 0 of the device. The data transfer direction is determined by the request type. If the result of**requestType & USB_ENDPOINT_DIR_MASK** is **USB_DIR_OUT**, the endpoint is in the data writing direction; if the result is **USB_DIR_IN**, the endpoint is in the data reading direction. |
+| int32_t RequestInitialize(UsbRequest &request); | Initializes a request. |
+| int32_t RequestQueue(UsbRequest &request); | Sends or receives requests for isochronous transfer on a specified endpoint. The data transfer direction is determined by the endpoint direction. |
+| int32_t PipeRequestWait(USBDevicePipe &pip, int64_t timeout, UsbRequest &req); | Waits for the operation result of the isochronous transfer request in``RequestQueue``. |
+| int32_t RequestAbort(UsbRequest &request); | Cancels the data transfer requests to be processed. |
+| int32_t RequestFree(UsbRequest &request); | Requests for releasing data. |
+| bool HasRight(std::string deviceName); | Checks whether the application has permission to access the USB device. |
+| int32_t RequestRight(std::string deviceName); | Requests for permission to access the USB device. |
#### Device APIs
-| **API**| **Description**|
-| --- | --- |
-| int32_t GetCurrentFunctions(int32_t &funcs); | Obtains the list of functions (represented by bit field) supported by the current device.|
-| int32_t SetCurrentFunctions(int32_t funcs); | Sets the list of functions (represented by bit field) supported by the current device.|
-| int32_t UsbFunctionsFromString(std::string funcs); | Converts the string descriptor of a given USB function list to a numeric mask combination.|
-| std::string UsbFunctionsToString(int32_t funcs); | Converts the numeric mask combination of a given USB function list to a string descriptor.|
+
+| **API** | **Description** |
+| -------------------------------------------------- | ------------------------------------------------------------------------------------------ |
+| int32_t GetCurrentFunctions(int32_t &funcs); | Obtains the list of functions (represented by bit field) supported by the current device. |
+| int32_t SetCurrentFunctions(int32_t funcs); | Sets the list of functions (represented by bit field) supported by the current device. |
+| int32_t UsbFunctionsFromString(std::string funcs); | Converts the string descriptor of a given USB function list to a numeric mask combination. |
+| std::string UsbFunctionsToString(int32_t funcs); | Converts the numeric mask combination of a given USB function list to a string descriptor. |
#### Port APIs
-| **API**| **Description**|
-| --- | --- |
-| int32_t GetPorts(std::vector &usbPorts); | Obtains the port list.|
-| int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole); | Sets the port role.|
-| int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes); | Obtains the mask combination for the supported mode list of a given port.|
-## Development Example
+| **API** | **Description** |
+| ------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
+| int32_t GetPorts(std::vector &usbPorts); | Obtains the port list. |
+| int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole); | Sets the port role. |
+| int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes); | Obtains the mask combination for the supported mode list of a given port. |
+
+## Development Example``
+
The following provides some examples on how to use major APIs. For detailed service code, see [js_unittest](test/native/js_unittest).
+
#### Host Development
+
In this example, the USB device serves as the host and connects to the device to implement data transfer.
+
1. Obtain the USB device list.
+
```JS
// Import the USB API package.
import usb from '@ohos.usb';
// Obtain the USB device list.
var deviceList = usb.getDevices();
```
+
2. Obtain the device operation permissions.
+
```JS
// device name
var deviceName = deviceList[0].name;
@@ -92,14 +107,18 @@ usb.requestRight(deviceName).then(hasRight => {
console.info("usb device request right failed : " + error);
});
```
+
3. Open the USB device.
+
```JS
// Open the USB device, and obtain the device pipe for data transfer.
var pipe = usb.connectDevice(deviceList[0]);
// Claim the USB interface.
usb.claimInterface(pipe, interface, true); // Among the input arguments, interface refers to the one to be operated on the USB device.
```
+
4. Perform data transfer.
+
```JS
// Read data. Select the corresponding RX endpoint (endpoint.direction == 0x80) from deviceList for data transfer. The data data to be transferred is encapsulated in dataUint8Array.
usb.bulkTransfer(pipe, inEndpoint, dataUint8Array, 15000).then(dataLength => {
@@ -124,14 +143,20 @@ usb.bulkTransfer(this.pip, this.outEndpoint, dataUint8Array, 15000).then(dataLen
console.info("usb writeData error : " + JSON.stringify(error));
});
```
+
5. Release the USB interface, and close the USB device.
+
```JS
usb.releaseInterface(pipe, interface);
usb.closePipe(pipe);
```
+
#### Device Development
+
In this example, the USB device is used as the device to set the ACM, ECM, and HDC functions.
+
1. Set the USB functions.
+
```JS
usb.setCurrentFunctions(funType).then(data => {
console.info("usb setCurrentFunctions : " + data);
@@ -140,7 +165,7 @@ usb.setCurrentFunctions(funType).then(data => {
});
```
-## Repositories Involved
+## Repositories Involved``
[Drive Subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md)
diff --git a/bundle.json b/bundle.json
index 8e99a47..695b207 100644
--- a/bundle.json
+++ b/bundle.json
@@ -29,7 +29,8 @@
"libhilog",
"ipc_core",
"system_ability_fwk",
- "samgr_proxy"
+ "samgr_proxy",
+ "jsoncpp"
],
"third_party": []
},
diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn
index b447042..8614637 100644
--- a/interfaces/innerkits/BUILD.gn
+++ b/interfaces/innerkits/BUILD.gn
@@ -14,7 +14,10 @@
import("//base/usb/usb_manager/usbmgr.gni")
config("usbsrv_private_config") {
- include_dirs = [ "${usb_manager_path}/services/zidl/include" ]
+ include_dirs = [
+ "${usb_manager_path}/services/zidl/include",
+ "//third_party/jsoncpp/include/json",
+ ]
}
config("usbsrv_public_config") {
@@ -38,7 +41,7 @@ ohos_shared_library("usbsrv_client") {
public_configs = [ ":usbsrv_public_config" ]
- deps = []
+ deps = [ "//third_party/jsoncpp:jsoncpp" ]
external_deps = [
"eventhandler:libeventhandler",
diff --git a/interfaces/innerkits/native/include/usb_config.h b/interfaces/innerkits/native/include/usb_config.h
index 094139b..a997679 100644
--- a/interfaces/innerkits/native/include/usb_config.h
+++ b/interfaces/innerkits/native/include/usb_config.h
@@ -37,6 +37,20 @@ public:
this->name_ = name;
this->interfaces_ = interfaces;
}
+
+ explicit USBConfig(const Json::Value &config)
+ {
+ id_ = config["id"].asInt();
+ attributes_ = config["attributes"].asInt();
+ maxPower_ = config["maxPower"].asInt();
+ name_ = config["name"].asString();
+
+ Json::Value interfaces = config["interfaces"];
+ for (uint32_t idx = 0; idx < interfaces.size(); ++idx) {
+ interfaces_.emplace_back(interfaces[idx]);
+ }
+ }
+
USBConfig() {}
~USBConfig() {}
@@ -142,6 +156,25 @@ public:
return this->iConfiguration_;
}
+ Json::Value ToJson() const
+ {
+ Json::Value config;
+ config["id"] = id_;
+ config["attributes"] = attributes_;
+ config["maxPower"] = maxPower_;
+ config["name"] = name_;
+ config["isRemoteWakeup"] = IsRemoteWakeup();
+ config["isSelfPowered"] = IsSelfPowered();
+
+ Json::Value interfaces;
+ for (auto &intf : interfaces_) {
+ interfaces.append(intf.ToJson());
+ }
+ config["interfaces"] = interfaces;
+
+ return config;
+ }
+
private:
int32_t id_ = INVALID_USB_INT_VALUE;
int32_t attributes_ = INVALID_USB_INT_VALUE;
diff --git a/interfaces/innerkits/native/include/usb_device.h b/interfaces/innerkits/native/include/usb_device.h
index 8a61f6e..87d045d 100644
--- a/interfaces/innerkits/native/include/usb_device.h
+++ b/interfaces/innerkits/native/include/usb_device.h
@@ -46,6 +46,27 @@ public:
this->configs_ = configs;
}
+ explicit UsbDevice(const Json::Value &device)
+ {
+ busNum_ = device["busNum"].asUInt();
+ devAddr_ = device["devAddress"].asUInt();
+ serial_ = device["serial"].asString();
+ name_ = device["name"].asString();
+ manufacturerName_ = device["manufacturerName"].asString();
+ productName_ = device["productName"].asString();
+ version_ = device["version"].asString();
+ vendorId_ = device["vendorId"].asInt();
+ productId_ = device["productId"].asInt();
+ klass_ = device["clazz"].asInt();
+ subClass_ = device["subClass"].asInt();
+ protocol_ = device["protocol"].asInt();
+
+ Json::Value configs = device["configs"];
+ for (uint32_t idx = 0; idx < configs.size(); ++idx) {
+ configs_.emplace_back(configs[idx]);
+ }
+ }
+
UsbDevice() {}
~UsbDevice() {}
@@ -289,6 +310,31 @@ public:
return this->bcdDevice_;
}
+ Json::Value ToJson() const
+ {
+ Json::Value device;
+ device["busNum"] = busNum_;
+ device["devAddress"] = devAddr_;
+ device["serial"] = serial_;
+ device["name"] = name_;
+ device["manufacturerName"] = manufacturerName_;
+ device["productName"] = productName_;
+ device["version"] = version_;
+ device["vendorId"] = vendorId_;
+ device["productId"] = productId_;
+ device["clazz"] = klass_;
+ device["subClass"] = subClass_;
+ device["protocol"] = protocol_;
+
+ Json::Value configs;
+ for (auto &cfg : configs_) {
+ configs.append(cfg.ToJson());
+ }
+ device["configs"] = configs;
+
+ return device;
+ }
+
private:
std::string name_;
std::string manufacturerName_;
diff --git a/interfaces/innerkits/native/include/usb_endpoint.h b/interfaces/innerkits/native/include/usb_endpoint.h
index 0a07963..e6c6176 100644
--- a/interfaces/innerkits/native/include/usb_endpoint.h
+++ b/interfaces/innerkits/native/include/usb_endpoint.h
@@ -20,6 +20,7 @@
#include
#include
#include "usb_common.h"
+#include "json.h"
namespace OHOS {
namespace USB {
@@ -32,6 +33,16 @@ public:
this->interval_ = interval;
this->maxPacketSize_ = maxPacketSize;
}
+
+ explicit USBEndpoint(const Json::Value &endpoint)
+ {
+ address_ = endpoint["address"].asInt();
+ attributes_ = endpoint["attributes"].asInt();
+ interval_ = endpoint["interval"].asInt();
+ maxPacketSize_ = endpoint["maxPacketSize"].asInt();
+ interfaceId_ = endpoint["interfaceId"].asUInt();
+ }
+
USBEndpoint() {}
~USBEndpoint() {}
@@ -124,6 +135,21 @@ public:
return interfaceId_;
}
+ Json::Value ToJson() const
+ {
+ Json::Value endpoint;
+ endpoint["address"] = address_;
+ endpoint["attributes"] = attributes_;
+ endpoint["interval"] = interval_;
+ endpoint["maxPacketSize"] = maxPacketSize_;
+ endpoint["direction"] = GetDirection();
+ endpoint["number"] = GetEndpointNumber();
+ endpoint["type"] = GetType();
+ endpoint["interfaceId"] = interfaceId_;
+
+ return endpoint;
+ }
+
private:
int32_t address_ = INVALID_USB_INT_VALUE;
int32_t attributes_ = INVALID_USB_INT_VALUE;
diff --git a/interfaces/innerkits/native/include/usb_interface.h b/interfaces/innerkits/native/include/usb_interface.h
index cc445f5..69f780b 100644
--- a/interfaces/innerkits/native/include/usb_interface.h
+++ b/interfaces/innerkits/native/include/usb_interface.h
@@ -43,6 +43,21 @@ public:
this->endpoints_ = endpoints;
}
+ explicit UsbInterface(const Json::Value &interface)
+ {
+ id_ = interface["id"].asInt();
+ protocol_ = interface["protocol"].asInt();
+ klass_ = interface["clazz"].asInt();
+ subClass_ = interface["subClass"].asInt();
+ alternateSetting_ = interface["alternateSetting"].asInt();
+ name_ = interface["name"].asString();
+
+ Json::Value endpoints = interface["endpoints"];
+ for (uint32_t idx = 0; idx < endpoints.size(); ++idx) {
+ endpoints_.emplace_back(endpoints[idx]);
+ }
+ }
+
UsbInterface() {}
const std::string &GetName() const
@@ -161,6 +176,25 @@ public:
return this->iInterface_;
}
+ Json::Value ToJson() const
+ {
+ Json::Value interface;
+ interface["id"] = id_;
+ interface["protocol"] = protocol_;
+ interface["clazz"] = klass_;
+ interface["subClass"] = subClass_;
+ interface["alternateSetting"] = alternateSetting_;
+ interface["name"] = name_;
+
+ Json::Value endpoints;
+ for (const auto &ep : endpoints_) {
+ endpoints.append(ep.ToJson());
+ }
+ interface["endpoints"] = endpoints;
+
+ return interface;
+ }
+
private:
int32_t id_ = INT32_MAX;
int32_t protocol_ = INT32_MAX;
diff --git a/interfaces/innerkits/native/include/usb_srv_client.h b/interfaces/innerkits/native/include/usb_srv_client.h
index 8550947..823ce5c 100644
--- a/interfaces/innerkits/native/include/usb_srv_client.h
+++ b/interfaces/innerkits/native/include/usb_srv_client.h
@@ -21,6 +21,7 @@
#include
#include
#include
+
#include "iremote_object.h"
#include "iusb_srv.h"
#include "usb_device.h"
@@ -55,8 +56,8 @@ public:
std::string UsbFunctionsToString(int32_t funcs);
int32_t ClaimInterface(USBDevicePipe &pip, const UsbInterface &interface, bool force);
int32_t ReleaseInterface(USBDevicePipe &pip, const UsbInterface &interface);
- int32_t BulkTransfer(USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &bufferData,
- int32_t timeOut);
+ int32_t BulkTransfer(
+ USBDevicePipe &pip, const USBEndpoint &endpoint, std::vector &bufferData, int32_t timeOut);
int32_t ControlTransfer(USBDevicePipe &pip, const UsbCtrlTransfer &ctrl, std::vector &bufferData);
int32_t SetConfiguration(USBDevicePipe &pip, const USBConfig &config);
int32_t SetInterface(USBDevicePipe &pipe, const UsbInterface &interface);
diff --git a/interfaces/innerkits/native/include/usb_srv_support.h b/interfaces/innerkits/native/include/usb_srv_support.h
new file mode 100644
index 0000000..71b9e11
--- /dev/null
+++ b/interfaces/innerkits/native/include/usb_srv_support.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef USB_SRV_SUPPORT_H
+
+#include
+
+namespace OHOS {
+namespace USB {
+struct UsbSrvSupport {
+ static constexpr std::string_view CONNECTED {"connected"};
+ static constexpr std::string_view FUNCTION_NAME_NONE {"none"};
+ static constexpr std::string_view FUNCTION_NAME_HDC {"hdc"};
+ static constexpr std::string_view FUNCTION_NAME_ACM {"acm"};
+ static constexpr std::string_view FUNCTION_NAME_ECM {"ecm"};
+ static constexpr std::string_view FUNCTION_NAME_MTP {"mtp"};
+ static constexpr std::string_view FUNCTION_NAME_PTP {"ptp"};
+
+ enum PowerRole : int32_t {
+ POWER_ROLE_NONE,
+ POWER_ROLE_SOURCE,
+ POWER_ROLE_SINK,
+ };
+
+ enum DataRole : int32_t {
+ DTA_ROLE_NONE,
+ DATA_ROLE_HOST,
+ DATA_ROLE_DEVICE,
+ };
+
+ enum PortMode : int32_t {
+ PORT_MODE_NONE,
+ PORT_MODE_DEVICE,
+ PORT_MODE_HOST,
+ };
+
+ enum Function : uint32_t {
+ FUNCTION_NONE = 0,
+ FUNCTION_ACM = 1,
+ FUNCTION_ECM = 2,
+ FUNCTION_HDC = 4,
+ FUNCTION_MTP = 8,
+ FUNCTION_PTP = 16,
+ };
+};
+} // namespace USB
+} // namespace OHOS
+
+#define USB_SRV_SUPPORT_H
+#endif // USB_SRV_SUPPORT_H
\ No newline at end of file
diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn
index 4321ac2..789db78 100644
--- a/interfaces/kits/js/napi/BUILD.gn
+++ b/interfaces/kits/js/napi/BUILD.gn
@@ -18,6 +18,7 @@ config("usbnapi_private_config") {
"//foundation/arkui/napi/native_engine",
"//foundation/arkui/napi/interfaces/kits",
"//third_party/node/src",
+ "//third_party/jsoncpp/include/json",
"${usb_manager_path}/interfaces/kits/js/napi/include",
"${usb_manager_path}/interfaces/innerkits/native/include",
]
@@ -35,6 +36,7 @@ ohos_shared_library("usb") {
deps = [
"${usb_manager_path}/interfaces/innerkits:usbsrv_client",
"//foundation/arkui/napi:ace_napi",
+ "//third_party/jsoncpp:jsoncpp",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
diff --git a/interfaces/kits/js/napi/src/usb_info.cpp b/interfaces/kits/js/napi/src/usb_info.cpp
index 5237eb6..7f10c28 100644
--- a/interfaces/kits/js/napi/src/usb_info.cpp
+++ b/interfaces/kits/js/napi/src/usb_info.cpp
@@ -601,8 +601,8 @@ static napi_value CoreSetCurrentFunctions(napi_env env, napi_callback_info info)
napi_typeof(env, argv[INDEX_0], &type);
NAPI_ASSERT(env, type == napi_number, "Wrong argument type. Number expected.");
- int32_t funcs = 0;
- napi_get_value_int32(env, argv[INDEX_0], &funcs);
+ uint32_t funcs = 0;
+ napi_get_value_uint32(env, argv[INDEX_0], &funcs);
auto asyncContext = new(std::nothrow) USBFunctionAsyncContext();
NAPI_ASSERT(env, asyncContext != nullptr, "Create USBFunctionAsyncContext failed.");
diff --git a/services/BUILD.gn b/services/BUILD.gn
index 6496502..09ae11f 100644
--- a/services/BUILD.gn
+++ b/services/BUILD.gn
@@ -14,7 +14,7 @@
import("//base/usb/usb_manager/usbmgr.gni")
config("usbsrv_private_config") {
- include_dirs = []
+ include_dirs = [ "//third_party/jsoncpp/include/json" ]
}
config("usbsrv_public_config") {
@@ -29,7 +29,7 @@ ohos_shared_library("usbservice") {
sources = [
"${usb_manager_path}/services/zidl/src/usb_srv_stub.cpp",
"native/src/usb_descriptor_parser.cpp",
- "native/src/usb_function_manager.cpp",
+ "native/src/usb_device_manager.cpp",
"native/src/usb_host_manager.cpp",
"native/src/usb_port_manager.cpp",
"native/src/usb_right_manager.cpp",
@@ -46,7 +46,10 @@ ohos_shared_library("usbservice") {
public_configs = [ ":usbsrv_public_config" ]
- deps = [ "${usb_manager_path}/interfaces/innerkits:usbsrv_client" ]
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "//third_party/jsoncpp:jsoncpp",
+ ]
external_deps = [
"ability_base:want",
diff --git a/services/native/include/usb_function_manager.h b/services/native/include/usb_device_manager.h
similarity index 55%
rename from services/native/include/usb_function_manager.h
rename to services/native/include/usb_device_manager.h
index 2aef387..5b50371 100644
--- a/services/native/include/usb_function_manager.h
+++ b/services/native/include/usb_device_manager.h
@@ -19,33 +19,29 @@
#include