1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
24 * This file contains the APIs for queue to be implemented.
35 #endif /* __cplusplus */
38 * Queue message format.
40 typedef struct u_queue_message_t
42 /** Pointer to message. */
48 typedef struct u_queue_element_t u_queue_element;
51 * Queue element format.
53 struct u_queue_element_t
55 /** pointer to queue message. */
56 u_queue_message_t *message;
57 /** Pointer to next queue element. */
58 u_queue_element *next;
64 typedef struct u_queue_t
66 /** Head of the queue. */
67 u_queue_element *element;
68 /** Number of messages in Queue. */
73 * API to creates queue and initializes the elements.
74 * @return u_queue_t pointer if Success, NULL otherwise.
76 u_queue_t *u_queue_create();
79 * Resets and deletes the queue.
80 * @param queue- queue pointer.
81 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_FAILED otherwise.
83 CAResult_t u_queue_delete(u_queue_t *queue);
86 * Adds message at the end of the queue.
87 * @param queue pointer to queue.
88 * @param message Pointer to message.
89 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_FAILED otherwise.
91 CAResult_t u_queue_add_element(u_queue_t *queue, u_queue_message_t *message);
94 * Returns the first message in the queue and removes queue element.
95 * Head is moved to next element.
96 * @param queue pointer to queue.
97 * @return pointer to Message if Success, NULL otherwise.
99 u_queue_message_t *u_queue_get_element(u_queue_t *queue);
102 * Removes head element of the queue.
103 * @param queue pointer to queue.
104 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_FAILED otherwise.
106 CAResult_t u_queue_remove_element(u_queue_t *queue);
109 * @param queue pointer to queue.
110 * @return number of elements in queue.
112 uint32_t u_queue_get_size(u_queue_t *queue);
115 * Removes all the messages from Queue and reset message count.
116 * @param queue pointer to queue.
117 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_FAILED otherwise.
119 CAResult_t u_queue_reset(u_queue_t *queue);
122 * Returns the first message in queue, but not remove the element.
123 * @param queue pointer to queue.
124 * @return pointer to Message if Success, NULL otherwise.
126 u_queue_message_t *u_queue_get_head(u_queue_t *queue);
128 /** Data destroy function. **/
129 typedef void (*QueueDataDestroyFunction)(void *data, uint32_t size);
130 typedef bool (*QueueContextDataDestroy)(void *data, uint32_t size, void *ctx);
133 * Removes messages from anywhere in the queue
134 * @param queue pointer to queue
135 * @param callback Function returns true if element is to be destroyed
136 * @param ctx data that should be passed to callback
137 * @param destroy Function to destroy the data, if NULL OICFree will be used
138 * @return ::CA_STATUS_OK if Success, ::CA_STATUS_FAILED otherwise
140 CAResult_t u_queue_remove_req_elements(u_queue_t *queue,
141 QueueContextDataDestroy callback, void *ctx,
142 QueueDataDestroyFunction destroy);
146 #endif /* __cplusplus */
148 #endif /* U_QUEUE_H_ */