1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef LITE_MESSAGEINNER_H
16 #define LITE_MESSAGEINNER_H
17 
18 #include "message.h"
19 
20 #ifdef __cplusplus
21 #if __cplusplus
22 extern "C" {
23 #endif
24 #endif
25 
26 enum ExchangeType {
27     MSG_EXIT = -1,
28     MSG_NON = 0,
29     MSG_CON = 1,
30     MSG_ACK = 2,
31     MSG_SYNC = 3,
32     MSG_DIRECT = 4,
33 };
34 // Will be used for message interaction, so use one-byte alignment
35 #pragma pack(1)
36 typedef struct Exchange Exchange;
37 struct Exchange {
38     Identity id; /**< The target service or feature identity. */
39     Request request;
40     Response response;
41     short type;  /**< The exchange type. */
42     Handler handler;   /**< async response or immediately request callback function */
43     uint32 *sharedRef; /**< use to share the request and response for saving memory */
44 };
45 #pragma pack()
46 
47 int32 SAMGR_MsgRecv(MQueueId queueId, uint8 *interMsg, uint32 size);
48 
49 /**
50  * The function just release the Message->data and Message->sharedRef(use free), not release the msg entry.
51  * If you alloc the msg on the heep, you should release it by yourself, you`d better alloc on the stack.
52  * The function will be called automatically.
53  * Do not call this function manually, except the SM_SendRequest return error!
54  *
55  **/
56 int32 SAMGR_FreeMsg(Exchange *exchange);
57 
58 #ifdef __cplusplus
59 #if __cplusplus
60 }
61 #endif
62 #endif
63 #endif // LITE_MESSAGEINNER_H
64