# Service - [Overview](#section1287791382165636) - [Summary](#section65587967165636) - [Data Fields](#pub-attribs) - [Details](#section1393409351165636) - [Field](#section702608981165636) - [GetName](#a7d6fe59023a0e6ad2ad7c625c0d117d6) - [GetTaskConfig](#abc4b1868a77fafe434fe63c8a4685aeb) - [Initialize](#a80b0715ef9129631d5f622cb199ff8ae) - [MessageHandle](#aa2b7015639906efbadd36aa87eea269b) ## **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 ** ## 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.