1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSConsumerQueue.h"
23 #include "NSConstants.h"
24 #include "oic_malloc.h"
25 #include "NSConsumerCommon.h"
27 NSConsumerQueue * NSCreateQueue()
29 NSConsumerQueue * newQueue = (NSConsumerQueue *)OICMalloc(sizeof(NSConsumerQueue));
30 NS_VERIFY_NOT_NULL(newQueue, NULL);
33 newQueue->head = NULL;
34 newQueue->tail = NULL;
39 void NSDestroyQueue(NSConsumerQueue * queue)
41 NS_VERIFY_NOT_NULL_V(queue);
43 NSConsumerQueueObject * node = NSPopQueue(queue);
46 NSOICFree(node->data);
49 node = NSPopQueue(queue);
53 bool NSPushConsumerQueue(NSConsumerQueue * queue, NSConsumerQueueObject * object)
55 NS_VERIFY_NOT_NULL(queue, false);
56 NS_VERIFY_NOT_NULL(object, false);
64 (queue->tail)->next = object;
73 NSConsumerQueueObject * NSPopQueue(NSConsumerQueue * queue)
75 NSConsumerQueueObject * retObject = NULL;
77 NS_VERIFY_NOT_NULL(queue, NULL);
78 NS_VERIFY_NOT_NULL(queue->head, NULL);
85 retObject = queue->head;
87 queue->head = (NSConsumerQueueObject *)(retObject->next);
92 retObject->next = NULL;
98 int NSGetQueueSize(NSConsumerQueue * queue)
103 bool NSIsQueueEmpty(NSConsumerQueue * queue)
105 return (queue->size <= 0);