> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.bluetooth`](js-apis-bluetooth.md).
>
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import bluetooth from '@system.bluetooth';
```
## bluetooth.startBLEScan(OBJECT)
Scans for Bluetooth Low Energy (BLE) devices nearby. This operation consumes system resources. Call [bluetooth.stopBLEScan](#bluetoothstopblescanobject) to stop the scan after BLE devices are detected and connected.
**Required permissions**: ohos.permission.DISCOVER_BLUETOOTH and ohos.permission.LOCATION
| interval | number | No| Interval for reporting device information, in milliseconds. The default value is **0**, which means to report detected devices immediately and report other information at the given interval.|
| success | Function | No| Called when the operation is successful.|
| fail | Function | No| Called when the operation fails.|
| complete | Function | No| Called when the API call is complete.|
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.data.storage`](js-apis-data-storage.md) instead.
>
>
> - The APIs of this module are no longer maintained since API Version 6. You are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
@@ -18,19 +19,19 @@ import storage from '@system.storage';
...
@@ -18,19 +19,19 @@ import storage from '@system.storage';
@@ -185,12 +185,12 @@ The HDF-based driver development involves driver implementation and configuratio
...
@@ -185,12 +185,12 @@ The HDF-based driver development involves driver implementation and configuratio
caps = ["DAC_OVERRIDE", "DAC_READ_SEARCH"]; // Linux capabilities of the user-mode process.
caps = ["DAC_OVERRIDE", "DAC_READ_SEARCH"]; // Linux capabilities of the user-mode process.
device_sample :: device { // Sample device node.
device_sample :: device { // Sample device node.
device0 :: deviceNode { // DeviceNode of the sample driver.
device0 :: deviceNode { // DeviceNode of the sample driver.
policy = 1; // Policy for publishing the driver service. For details, see Driver Service Management.
policy = 1; // Policy for providing the driver service. For details, see Driver Service Management.
priority = 100; // Driver startup priority (0-200). A smaller value indicates a higher priority. The default value 100 is recommended. The drivers with the same priority start based on the time when the priority was configured. The driver configured first starts first.
priority = 100; // Driver startup priority (0-200). A smaller value indicates a higher priority. The default value 100 is recommended. The drivers with the same priority start based on the time when the priority was configured. The driver configured first starts first.
preload = 0; // The loading mode of the driver is on-demand loading. For details, see "NOTE" at the end of this document.
preload = 0; // The loading mode of the driver is on-demand loading. For details, see "NOTE" at the end of this document.
permission = 0664; // Permission for the driver to create a device node.
permission = 0664; // Permission for the driver to create a device node.
moduleName = "sample_driver"; // Driver name. The value must be the same as that of moduleName in the HdfDriverEntry structure.
moduleName = "sample_driver"; // Driver name. The value must be the same as that of moduleName in the HdfDriverEntry structure.
serviceName = "sample_service"; // Name of the service published by the driver. The service name must be unique.
serviceName = "sample_service"; // Name of the service provided by the driver. The service name must be unique.
deviceMatchAttr = "sample_config"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
deviceMatchAttr = "sample_config"; // Keyword for matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver.
}
}
}
}
...
@@ -253,7 +253,7 @@ The HDF-based driver development involves driver implementation and configuratio
...
@@ -253,7 +253,7 @@ The HDF-based driver development involves driver implementation and configuratio
>
>
> If **preload** is set to **1 (DEVICE_PRELOAD_ENABLE_STEP2)**, the driver is loaded after a quick start is complete. If the system does not support quick start, the value **1** has the same meaning as **DEVICE_PRELOAD_ENABLE**.
> If **preload** is set to **1 (DEVICE_PRELOAD_ENABLE_STEP2)**, the driver is loaded after a quick start is complete. If the system does not support quick start, the value **1** has the same meaning as **DEVICE_PRELOAD_ENABLE**.
>
>
> If **preload** is set to **2 (DEVICE_PRELOAD_DISABLE)** , the driver is dynamically loaded instead of being loaded during the system boot process. When a user-mode process requests the driver service, the HDF attempts to dynamically load the driver if the driver service does not exist. For more details, see [Driver Message Mechanism Management](driver-hdf-message-management.md).
> If **preload** is set to **2 (DEVICE_PRELOAD_DISABLE)** , the driver is dynamically loaded instead of being loaded during the system boot process. When a user-mode process requests the driver service, the HDF attempts to dynamically load the driver if the driver service does not exist. For more details, see [Driver Messaging Mechanism](driver-hdf-message-management.md).
>
>
> - Sequential loading (**preload** set to **0 (DEVICE_PRELOAD_ENABLE)**)<br/>
> - Sequential loading (**preload** set to **0 (DEVICE_PRELOAD_ENABLE)**)<br/>
> In the configuration file, the **priority** fields (value range: 0 to 200) determines the loading sequence of a host and a driver. For drivers in different hosts, a smaller host priority value indicates a higher driver loading priority; for drivers in the same host, a smaller driver priority value indicates a higher driver loading priority.
> In the configuration file, the **priority** fields (value range: 0 to 200) determines the loading sequence of a host and a driver. For drivers in different hosts, a smaller host priority value indicates a higher driver loading priority; for drivers in the same host, a smaller driver priority value indicates a higher driver loading priority.
| struct HdfIoService \*HdfIoServiceBind(const char \*serviceName); | Obtains a driver service. The **Dispatch()** method in the driver service obtained sends messages to the driver.|
</thead>
| void HdfIoServiceRecycle(struct HdfIoService \*service); | Releases a driver service.|
| int HdfDeviceRegisterEventListener(struct HdfIoService \*target, struct HdfDevEventlistener \*listener); | Registers the method for receiving events reported by the driver.|
<tdclass="cellrowborder"valign="top"width="53.620000000000005%"headers="mcps1.2.3.1.2 "><pid="p58272614113"><aname="p58272614113"></a><aname="p58272614113"></a>Obtains a specified driver service. After the service is obtained, the <strongid="b9799159433"><aname="b9799159433"></a><aname="b9799159433"></a>Dispatch</strong> function of the service is used to send messages to the driver.</p>
<tdclass="cellrowborder"valign="top"width="53.620000000000005%"headers="mcps1.2.3.1.2 "><pid="p18825261412"><aname="p18825261412"></a><aname="p18825261412"></a>Receives events sent by the drivers.</p>
2. Set the driver permission. By default, the **permission** field is set to **0666**, which allows the driver to create device nodes. You can set this field based on service requirements.
## How to Develop<a name="section946912121153"></a>
HDF_LOGE("sample driver lite A dispatch");
return 0;
1. Set the value of the **policy** field in the driver configuration information to **2**\(SERVICE\_POLICY\_CAPACITY, see [Driver Service Management](driver-hdf-servicemanage.md)\).
2. The **permission** field in the driver configuration information indicates the permission provided for the driver to create device nodes. The default value is **0666**. You can configure the value of this field based on the actual application scenario of the driver.
.ioService.Dispatch = SampleDriverDispatch,
3. Implement the **Dispatch** function of the service base member **IDeviceIoService** during service implementation.
.ServiceA = SampleDriverServiceA,
.ServiceB = SampleDriverServiceB,
```
};
// Process messages delivered by user-level applications.
# Driver Service Management<a name="EN-US_TOPIC_0000001052777057"></a>
# Driver Service Management
Driver services are objects of open capabilities provided by the HDF and are managed by the HDF in a unified manner. Using driver service management, you can release and obtain driver services.
Driver services are objects of capabilities provided by HDF driver devices to external systems and are managed by the HDF in a unified manner. Driver service management involves providing and obtaining driver services.
The HDF uses the **policy** field in the configuration file to define policies for drivers to release services externally. The values and meanings of this field are as follows:
The HDF uses the **policy** field in the configuration file to define policies for drivers to provide services externally. The values this field are as follows:
```
```
typedef enum {
typedef enum {
/* The driver does not provide services. */
/* The driver does not provide services. */
SERVICE_POLICY_NONE = 0,
SERVICE_POLICY_NONE = 0,
/* The driver provides services for kernel-space applications. */
/* The driver provides services only for kernel-mode applications. */
SERVICE_POLICY_PUBLIC = 1,
SERVICE_POLICY_PUBLIC = 1,
/* The driver provides services for both kernel- and user-space applications. */
/* The driver provides services for both kernel- and user-mode applications. */
SERVICE_POLICY_CAPACITY = 2,
SERVICE_POLICY_CAPACITY = 2,
/* The driver services are not released externally but can be subscribed to. */
/** The driver services are not provided externally but can be subscribed to. */
SERVICE_POLICY_FRIENDLY = 3,
SERVICE_POLICY_FRIENDLY = 3,
/* The driver services are private. They are neither released nor subscribed to. */
/* The driver private services cannot be provided externally or subscribed to. */
SERVICE_POLICY_PRIVATE = 4,
SERVICE_POLICY_PRIVATE = 4,
/* The service policy is incorrect. */
/** Invalid service policy. */
SERVICE_POLICY_INVALID
SERVICE_POLICY_INVALID
} ServicePolicy;
} ServicePolicy;
```
```
## When to Use<a name="section14244270117"></a>
The driver service management capability can be used if the driver provides capabilities using APIs.
## When to Use
## Available APIs<a name="section1432412561722"></a>
The table below describes the APIs used for driver service management.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p46015332591"><aname="p46015332591"></a><aname="p46015332591"></a>Binds a service interface to the HDF. You need to implement the <strongid="b876584084419"><aname="b876584084419"></a><aname="b876584084419"></a>Bind</strong> function.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p06029334597"><aname="p06029334597"></a><aname="p06029334597"></a>Subscribes to a specified driver service.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section393515164416"></a>
The development of driver service management includes compiling, binding, obtaining, and subscribing to driver services. The details are as follows:
1. Release a driver service.
```
Define the driver service structure.
struct ISampleDriverService {
struct IDeviceIoService ioService; // The first member of the service structure must be a member of the IDeviceIoService type.
int32_t (*ServiceA)(void); // The first service interface of the driver.
int32_t (*ServiceB)(uint32_t inputCode); // The second service interface of the driver. The rest can be deduced by analogy.
};
Implementation of the driver service interface
int32_t SampleDriverServiceA(void)
{
// You need to implement the service logic.
return 0;
}
int32_t SampleDriverServiceB(uint32_t inputCode)
{
// You need to implement the service logic.
return 0;
}
```
2. Bind the driver service to the HDF and implement the **Bind** function in the **HdfDriverEntry** structure.
// deviceObject indicates the pointer to the device object created by the HDF for each driver. It is used to store device-related private data and service interfaces.
If the kernel mode is unaware of the time for loading drivers \(on the same host\), use the subscription mechanism provided by the HDF to subscribe to the drivers. After the drivers are loaded, the HDF releases the driver services to you. The implementation is as follows:
```
// Subscription callback function. After the subscribed drivers are loaded, the HDF releases the driver services to you using this function.
// object indicates the pointer to the private data of the subscriber, and service indicates the pointer to the subscribed service.
The driver service management capability can be used if the driver provides capabilities using APIs.
## Available APIs
The table below describes the APIs for driver service management.
**Table 1** APIs for driver service management
| API| Description|
| -------- | -------- |
| int32_t (\*Bind)(struct HdfDeviceObject \*deviceObject); | Binds a service API to the HDF. You need to implement the **Bind()** function.|
| const struct HdfObject \*DevSvcManagerClntGetService(const char \*svcName); | Obtains a driver service.|
| int HdfDeviceSubscribeService(<br>struct HdfDeviceObject \*deviceObject, const char \*serviceName, struct SubscriberCallback callback); | Subscribes to a driver service.|
## How to Develop
The development procedure is as follows:
1. Define the services to be provided by the driver.
```
Define the driver service structure.
struct ISampleDriverService {
struct IDeviceIoService ioService; // The first member must be of the IDeviceIoService type.
int32_t (*ServiceA)(void); // API of the first driver service.
int32_t (*ServiceB)(uint32_t inputCode); // API of the second driver service. You can add more as required.
};
Implement the driver service APIs.
int32_t SampleDriverServiceA(void)
{
// You need to implement the service logic.
return 0;
}
int32_t SampleDriverServiceB(uint32_t inputCode)
{
// You need to implement the service logic.
return 0;
}
```
2. Bind the driver service to the HDF and implement the **Bind()** function in the **HdfDriverEntry** structure.
If the kernel mode is unaware of the time for loading drivers on the same host, use the subscription mechanism provided by the HDF to subscribe to the drivers. After the drivers are loaded, the HDF sends the driver services to the subscriber. The implementation is as follows:
```
// Callback invoked to return the driver services after the subscribed driver is loaded.
// object is the pointer to the private data of the subscriber, and service is the pointer to the subscribed service object.