# Service ## **Overview** **Related Modules:** [Samgr](Samgr.md) **Description:** Indicates the basic type of a service. You need to implement the function pointers of **[Service](Service.md)**. ## **Summary** ## Data Fields

Variable Name

Description

GetName )(Service *service)

const char *(* 

Obtains the name of a service.

Initialize )(Service *service, Identity identity)

BOOL(* 

Initializes the service.

MessageHandle )(Service *service, Request *request)

BOOL(* 

Processes service messages.

GetTaskConfig )(Service *service)

TaskConfig(* 

Obtains task configurations of a service.

## **Details** ## **Field Documentation** ## GetName ``` const char*(* Service::GetName) ([Service](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

service Indicates 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 ``` [TaskConfig](TaskConfig.md)(* Service::GetTaskConfig) ([Service](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

service Indicates the pointer to the service.
**Returns:** Returns [TaskConfig](TaskConfig.md). ## Initialize ``` BOOL(* Service::Initialize) ([Service](Service.md) *service, [Identity](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

service Indicates the pointer to the service.
identity Indicates 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 ``` BOOL(* Service::MessageHandle) ([Service](Service.md) *service, [Request](Request.md) *request) ``` **Description:** Processes service messages. This function is used to process requests sent by the caller through [IUnknown](IUnknown.md). You need to implement this function. **Parameters:**

Name

Description

service Indicates the pointer to the service.
request Indicates the pointer to the request data.
**Returns:** Returns **TRUE** if the message processing is successful; returns **FALSE** if the processing fails.