Service.md 8.8 KB
Newer Older
W
wenjun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
# Service<a name="ZH-CN_TOPIC_0000001055675026"></a>

## **Overview**<a name="section409198877191902"></a>

**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**<a name="section439584113191902"></a>

## Data Fields<a name="pub-attribs"></a>

<a name="table2142070268191902"></a>
<table><thead align="left"><tr id="row60713272191902"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p1885507364191902"><a name="p1885507364191902"></a><a name="p1885507364191902"></a>Variable Name</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p1819630238191902"><a name="p1819630238191902"></a><a name="p1819630238191902"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1127049834191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1518556210191902"><a name="p1518556210191902"></a><a name="p1518556210191902"></a><a href="Service.md#a7d6fe59023a0e6ad2ad7c625c0d117d6">GetName</a> )(<a href="Service.md">Service</a> *service)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p698842218191902"><a name="p698842218191902"></a><a name="p698842218191902"></a>const char *(*&nbsp;</p>
<p id="p1989507559191902"><a name="p1989507559191902"></a><a name="p1989507559191902"></a>Obtains the name of a service. </p>
</td>
</tr>
<tr id="row1947051997191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p780095557191902"><a name="p780095557191902"></a><a name="p780095557191902"></a><a href="Service.md#a80b0715ef9129631d5f622cb199ff8ae">Initialize</a> )(<a href="Service.md">Service</a> *service, <a href="Identity.md">Identity</a> identity)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1520955573191902"><a name="p1520955573191902"></a><a name="p1520955573191902"></a>BOOL(*&nbsp;</p>
<p id="p292486864191902"><a name="p292486864191902"></a><a name="p292486864191902"></a>Initializes the service. </p>
</td>
</tr>
<tr id="row1253690594191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p1289134008191902"><a name="p1289134008191902"></a><a name="p1289134008191902"></a><a href="Service.md#aa2b7015639906efbadd36aa87eea269b">MessageHandle</a> )(<a href="Service.md">Service</a> *service, <a href="Request.md">Request</a> *request)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1122784469191902"><a name="p1122784469191902"></a><a name="p1122784469191902"></a>BOOL(*&nbsp;</p>
<p id="p1876415842191902"><a name="p1876415842191902"></a><a name="p1876415842191902"></a>Processes service messages. </p>
</td>
</tr>
<tr id="row1605592521191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p261288775191902"><a name="p261288775191902"></a><a name="p261288775191902"></a><a href="Service.md#abc4b1868a77fafe434fe63c8a4685aeb">GetTaskConfig</a> )(<a href="Service.md">Service</a> *service)</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p1373909554191902"><a name="p1373909554191902"></a><a name="p1373909554191902"></a><a href="TaskConfig.md">TaskConfig</a>(*&nbsp;</p>
<p id="p523408060191902"><a name="p523408060191902"></a><a name="p523408060191902"></a>Obtains task configurations of a service. </p>
</td>
</tr>
</tbody>
</table>

## **Details**<a name="section273198917191902"></a>

## **Field Documentation**<a name="section1986485814191902"></a>

## GetName<a name="a7d6fe59023a0e6ad2ad7c625c0d117d6"></a>

```
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:**

<a name="table400506977191902"></a>
<table><thead align="left"><tr id="row2057375397191902"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p1406449946191902"><a name="p1406449946191902"></a><a name="p1406449946191902"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p1086582767191902"><a name="p1086582767191902"></a><a name="p1086582767191902"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1931982288191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">service</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the pointer to the service. </td>
</tr>
</tbody>
</table>

**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<a name="abc4b1868a77fafe434fe63c8a4685aeb"></a>

```
[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:**

<a name="table981642248191902"></a>
<table><thead align="left"><tr id="row316063158191902"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p30009119191902"><a name="p30009119191902"></a><a name="p30009119191902"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p1532921989191902"><a name="p1532921989191902"></a><a name="p1532921989191902"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1402887261191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">service</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the pointer to the service. </td>
</tr>
</tbody>
</table>

**Returns:**

Returns  [TaskConfig](TaskConfig.md).



## Initialize<a name="a80b0715ef9129631d5f622cb199ff8ae"></a>

```
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:**

<a name="table1409379728191902"></a>
<table><thead align="left"><tr id="row683424521191902"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p361182725191902"><a name="p361182725191902"></a><a name="p361182725191902"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p148554492191902"><a name="p148554492191902"></a><a name="p148554492191902"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row100386001191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">service</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the pointer to the service. </td>
</tr>
<tr id="row1894032351191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">identity</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the ID allocated by the system to the service. For details, see <a href="Identity.md">Identity</a>. </td>
</tr>
</tbody>
</table>

**Returns:**

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



## MessageHandle<a name="aa2b7015639906efbadd36aa87eea269b"></a>

```
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:**

<a name="table1717508402191902"></a>
<table><thead align="left"><tr id="row348320836191902"><th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.1"><p id="p1220423646191902"><a name="p1220423646191902"></a><a name="p1220423646191902"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p1915262792191902"><a name="p1915262792191902"></a><a name="p1915262792191902"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1437435348191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">service</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the pointer to the service. </td>
</tr>
<tr id="row1412591400191902"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 ">request</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 ">Indicates the pointer to the request data. </td>
</tr>
</tbody>
</table>

**Returns:**

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