Merge "Implement functionality to set PSK credentials for DTLS in OC stack."
[platform/upstream/iotivity.git] / resource / csdk / connectivity / common / inc / uqueue.h
1 /******************************************************************
2  *
3  * Copyright 2014 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 uqueue.h
23  * @brief This file contains the APIs for queue to be implemented
24  */
25 #ifndef __U_QUEUE_H_
26 #define __U_QUEUE_H_
27
28 #include "cacommon.h"
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif /* __cplusplus */
34
35 /**
36  * @struct u_queue_message
37  * @brief Queue message format
38  */
39 typedef struct u_queue_message_t
40 {
41     /* Pointer to message*/
42     void *msg;
43     /* message size */
44     uint32_t size;
45 } u_queue_message_t;
46
47 typedef struct u_queue_element_t u_queue_element;
48
49 /**
50  * @struct u_queue_element
51  * @brief Queue element format
52  */
53 struct u_queue_element_t
54 {
55     /* pointer to queue message */
56     u_queue_message_t* message;
57     /* Pointer to next queue element*/
58     u_queue_element* next;
59 };
60
61 /**
62  * @struct u_queue_t
63  * @brief Queue structure
64  */
65 typedef struct u_queue_t
66 {
67     /* Head of the queue */
68     u_queue_element* element;
69     /* Number of messages in Queue*/
70     uint32_t count;
71 } u_queue_t;
72
73 /**
74  * @brief API to creates queue and initializes the elements.
75  * @return  u_queue_t pointer if Success, NULL otherwise
76  */
77 u_queue_t* u_queue_create();
78
79 /**
80  * @fn u_queue_delete
81  * @brief Resets and deletes the queue
82  * @param queue- queue pointer
83  * @return CAResult_t - CA_STATUS_OK, if Success
84  * @return            CA_STATUS_FAILED - otherwise
85  */
86 CAResult_t u_queue_delete(u_queue_t* queue);
87
88 /**
89  * @fn u_queue_add_element
90  * @brief Adds message at the end of the queue
91  * @param queue - pointer to queue
92  * @param message - Pointer to message
93  * @return CAResult_t - CA_STATUS_OK, if Success
94  * @return            CA_STATUS_FAILED - otherwise
95  */
96 CAResult_t u_queue_add_element(u_queue_t* queue, u_queue_message_t *message);
97
98 /**
99  * @fn u_queue_get_element
100  * @brief Returns the first message in the queue and removes queue element.
101  * Head is moved to next element.
102  * @param queue - pointer to queue
103  * @return pointer to Message, if Success
104  * @return NULL - otherwise
105  */
106 u_queue_message_t* u_queue_get_element(u_queue_t* queue);
107
108 /**
109  * @fn u_queueRemoveElement
110  * @brief Removes head element of the queue
111  * @param queue - pointer to queue
112  * @return CAResult_t - CA_STATUS_OK, if Success
113  * @return            CA_STATUS_FAILED - otherwise
114  */
115 CAResult_t u_queue_remove_element(u_queue_t* queue);
116
117 /**
118  * @fn u_queue_get_size
119  * Returns number of elements in queue
120  * Input : queue - pointer to queue
121  * Return : number of elements in queue
122  */
123 uint32_t u_queue_get_size(u_queue_t* queue);
124
125 /**
126  * @fn u_queue_reset
127  * @brief Removes all the messages from Queue and reset message count
128  * @param queue - pointer to queue
129  * @return CAResult_t - CA_STATUS_OK, if Success
130  * @return            CA_STATUS_FAILED - otherwise
131  */
132 CAResult_t u_queue_reset(u_queue_t* queue);
133
134 /**
135  * @fn u_queue_get_head
136  * @brief Returns the first message in queue, but not remove the element
137  * @param queue - pointer to queue
138  * @return pointer to Message, if Success
139  * @return NULL - otherwise
140  */
141 u_queue_message_t* u_queue_get_head(u_queue_t* queue);
142
143 #ifdef __cplusplus
144 } /* extern "C" */
145 #endif /* __cplusplus */
146
147 #endif /* _U_QUEUE_H_ */