Service

Overview

Related Modules:

Samgr

Description:

Indicates the basic type of a service.

You need to implement the function pointers of Service.

Summary

Data Fields

Variable Name

Description

GetName )(Serviceservice)

const char ( 

Obtains the name of a service.

Initialize )(Service service, Identity identity)

BOOL( 

Initializes the service.

MessageHandle )(Service service, Requestrequest)

BOOL( 

Processes service messages.

GetTaskConfig )(Serviceservice)

TaskConfig

Obtains task configurations of a service.

Details

Field Documentation

GetName

  1. constchar*(*Service::GetName)([Service]($api-api-LinkIoT-Service.md)*service)

Description:

Obtains the name of a service.

This function is called by Samgr during service registration and startup. You need to implement this function.

Parameters:

Name

Description

serviceIndicates the pointer to the service.

Returns:

Returns a constant string no more than 16 bytes if the service name is obtained successfully; returns NULL if the service name fails to be obtained.

GetTaskConfig

  1. [TaskConfig]($api-api-LinkIoT-TaskConfig.md)(*Service::GetTaskConfig)([Service]($api-api-LinkIoT-Service.md)*service)

Description:

Obtains task configurations of a service.

This function is used to return task configurations. You need to implement this function.

Parameters:

Name

Description

serviceIndicates the pointer to the service.

Returns:

Returns TaskConfig.

Initialize

  1. BOOL(*Service::Initialize)([Service]($api-api-LinkIoT-Service.md)*service,[Identity]($api-api-LinkIoT-Identity.md) identity)

Description:

Initializes the service.

After Samgr assigns tasks to a service, the service calls the function in its own tasks. You need to implement this function.

Parameters:

Name

Description

serviceIndicates the pointer to the service.
identityIndicates the ID allocated by the system to the service. For details, see Identity.

Returns:

Returns TRUE if the initialization is successful; returns FALSE otherwise.

MessageHandle

  1. BOOL(*Service::MessageHandle)([Service]($api-api-LinkIoT-Service.md)*service,[Request]($api-api-LinkIoT-Request.md)*request)

Description:

Processes service messages.

This function is used to process requests sent by the caller through IUnknown. You need to implement this function.

Parameters:

Name

Description

serviceIndicates the pointer to the service.
requestIndicates the pointer to the request data.

Returns:

Returns TRUE if the message processing is successful; returns FALSE if the processing fails.