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 NSConsumerQueueObject * next = (NSConsumerQueueObject *)node->next;
47 NSOICFree(node->data);
56 bool NSPushQueue(NSConsumerQueue * queue, NSConsumerQueueObject * object)
58 NS_VERIFY_NOT_NULL(queue, false);
59 NS_VERIFY_NOT_NULL(object, false);
67 (queue->tail)->next = object;
76 NSConsumerQueueObject * NSPopQueue(NSConsumerQueue * queue)
78 NSConsumerQueueObject * retObject = NULL;
80 NS_VERIFY_NOT_NULL(queue, NULL);
81 NS_VERIFY_NOT_NULL(queue->head, NULL);
88 retObject = queue->head;
90 queue->head = (NSConsumerQueueObject *)(retObject->next);
95 retObject->next = NULL;
101 int NSGetQueueSize(NSConsumerQueue * queue)
106 bool NSIsQueueEmpty(NSConsumerQueue * queue)
108 return (queue->size <= 0);