Merge remote-tracking branch 'origin/routing-manager'
[platform/upstream/iotivity.git] / resource / csdk / routing / include / routingmessageparser.h
1 /* ****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the APIs for routing message parser.
24  */
25 #ifndef ROUTING_MESSAGE_PARSER_H_
26 #define ROUTING_MESSAGE_PARSER_H_
27
28 #include "ulinklist.h"
29 #include "uarraylist.h"
30 #include "octypes.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 /**
38  * Constructs payload with its Gateway ID. This payload is
39  * shared between the gateways during initial discovery.
40  * @param[in]       gatewayId               Gateway ID.
41  * @param[out]      payload                 Encoded Payload for Gateway ID.
42  * @return  ::OC_STACK_OK or Appropriate error code.
43  */
44 OCStackResult RMPConstructGatewayPayload(uint32_t gatewayId, OCRepPayload **payload);
45
46 /**
47  * Constructs payload with the Gateway ID and routing table
48  * This payload is shared for any observe response or notification.
49  * @param[in]      gatewayId               Gateway ID.
50  * @param[in]      seqNum                  Sequence Number of Gateway.
51  * @param[in]      routingtable            linklist with Routing Table Entries.
52  * @param[in]      isUpdateSeqNeeded       Response type of payload response/notification.
53  * @param[out]     payload                 Payload with gateway Data.
54  * @return  ::OC_STACK_OK or Appropriate error code.
55  */
56 OCStackResult RMPConstructObserveResPayload(uint32_t gatewayId, uint32_t seqNum,
57                                             const u_linklist_t *routingtable, bool isUpdateSeqNeeded,
58                                             OCRepPayload **payload);
59
60 /**
61  * Constructs payload with the own GatewayID and the nodes that are removed from the routing table.
62  * @param[in]       gatewayId           Gateway ID.
63  * @param[in]       seqNum              Sequence Number of Gateway.
64  * @param[in]       removedGateways     linklist with Removed gateway entries.
65  * @param[in]       isUpdateSeqNeeded   Response type of payload response/notification.
66  * @param[out]   removedPayload      Encoded Payloads of removed routing table entries.
67  * @return  ::OC_STACK_OK or Appropriate error code.
68  */
69 OCStackResult RMPConstructRemovalPayload(uint32_t gatewayId, uint32_t seqNum,
70                                          const u_linklist_t *removedGateways, bool isUpdateSeqNeeded,
71                                          OCRepPayload **removedPayload);
72
73 /**
74  * Parse payload for request and get gateway id.
75  * @param[in]   payload              Payload.
76  * @param[in]       payloadSize          Payload Size.
77  * @param[out]      gatewayId            Gateway Id.
78  * @return  ::OC_STACK_OK or Appropriate error code.
79  */
80 OCStackResult RMPParseRequestPayload(const uint8_t* payload, size_t payloadSize,
81                                      uint32_t *gatewayId);
82
83 /**
84  * Parse payload for response and get required info.
85  * @param[in]       payload              Payload with gateways route table encoded.
86  * @param[in/out]   seqNum               Sequence Number of Gateway.
87  * @param[in/out]   gatewayId            Gateway Id.
88  * @param[in/out]   gatewayTable         Parsed routing table from Payload.
89  * @param[out]      isUpdateSeqNeeded   Response type of payload response/notification.
90  * @return  ::OC_STACK_OK or Appropriate error code.
91  */
92 OCStackResult RMPParseResponsePayload(const OCRepPayload *payload, uint32_t *gatewayId,
93                                       uint32_t *seqNum, u_linklist_t **gatewayTable,
94                                       bool *isUpdateSeqNeeded);
95
96 /**
97  * Frees payload.
98  * @param[in/out]   payload              Encoded Payload for Gateway ID.
99  * @return  NONE.
100  */
101 void RMPFreePayload(OCRepPayload *payload);
102
103 #ifdef __cplusplus
104 } /* extern "C" */
105 #endif
106
107 #endif /* ROUTING_MESSAGE_PARSER_H_ */
108