iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / occoap / include / occoap.h
1 //******************************************************************
2 ///
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #ifndef OCCOAP_H_
22 #define OCCOAP_H_
23
24 //-----------------------------------------------------------------------------
25 // Includes
26 //-----------------------------------------------------------------------------
27 #include "ocstack.h"
28 #include "occoaptoken.h"
29 #include "ocstackinternal.h"
30 #include "occoaphelper.h"
31 #include <stdint.h>
32
33 //-----------------------------------------------------------------------------
34 // Function Prototypes
35 //-----------------------------------------------------------------------------
36
37 uint32_t GetTime(float afterSeconds);
38
39 /**
40  * Initialize the CoAP client or server with the its IPv4 address and CoAP port
41  *
42  * @param ipAddr
43  *     IP Address of host device
44  * @param port
45  *     Port of host device
46  * @param mode
47  *     Host device is client, server, or client-server
48  *
49  * @return
50  *   0   - success
51  *   TBD - TBD error
52  */
53 OCStackResult OCInitCoAP(const char *address, uint16_t port, OCMode mode);
54
55 /**
56  * Discover OC resources
57  *
58  * @param method          - method to perform on the resource
59  * @param qos             - CON or NON requests
60  * @param token           - pointer to the token data structure
61  * @param Uri             - URI of the resource to interact with
62  * @param payload         - CoAP PDU payload
63  * @param options         - The address of an array containing the vendor specific
64  *                          header options to be sent with the request
65  * @param numOptions      - The number of header options to be included
66  * @return
67  *   0   - success
68  *   TBD - TBD error
69  */
70 OCStackResult OCDoCoAPResource(OCMethod method, OCQualityOfService qos, OCCoAPToken * token,
71         const char *Uri, const char *payload, OCHeaderOption * options, uint8_t numOptions);
72
73 /**
74  * Send a response to a request.
75  *
76  * @param response - pointer to OCServerProtocolResponse that contains all request and
77  *                   response info necessary to send the response to the client
78  * @return
79  *     OC_STACK_OK               - No errors; Success
80  *     OC_STACK_ERROR            - Error sending response
81  */
82 OCStackResult OCDoCoAPResponse(OCServerProtocolResponse *response);
83
84 /**
85  * Stop the CoAP client or server processing
86  *
87  * @return 0 - success, else - TBD error
88  */
89 OCStackResult OCStopCoAP();
90
91 /**
92  * Called in main loop of CoAP client or server.  Allows low-level CoAP processing of
93  * send, receive, timeout, discovery, callbacks, etc.
94  *
95  * @return 0 - success, else - TBD error
96  */
97 OCStackResult OCProcessCoAP();
98
99 /**
100  * This method is called to generate a token of MAX_TOKEN_LENGTH.
101  * This token is used to co-relate client requests with server responses.
102  *
103  */
104 void OCGenerateCoAPToken(OCCoAPToken * token);
105
106 /**
107  * Retrieve the end-point info where resource is being hosted.
108  * Currently, this method only provides the IP port with which the socket
109  * is bound. This internal method may be extended in future to retrieve
110  * more info (such as IP address, transport technology) about the hosting end-point.
111  *
112  * @param resPtr    - pointer to the resource
113  * @param info      - pointer to 16-bit integer to hold port number
114  * @return 0 - success, else - TBD error
115  */
116 OCStackResult OCGetResourceEndPointInfo (OCResource *resPtr, void *info);
117
118 #endif /* OCCOAP_H_ */