Azure IoT common library

Fork of azure_c_shared_utility by Azure IoT

Committer:
AzureIoTClient
Date:
Sat Jan 28 09:35:22 2017 -0800
Revision:
19:2e0811512ceb
Parent:
0:fa2de1b79154
1.1.6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:fa2de1b79154 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:fa2de1b79154 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:fa2de1b79154 3
Azure.IoT Build 0:fa2de1b79154 4 #include "azure_c_shared_utility/doublylinkedlist.h"
Azure.IoT Build 0:fa2de1b79154 5
Azure.IoT Build 0:fa2de1b79154 6 void
Azure.IoT Build 0:fa2de1b79154 7 DList_InitializeListHead(
Azure.IoT Build 0:fa2de1b79154 8 PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 9 )
Azure.IoT Build 0:fa2de1b79154 10 {
Azure.IoT Build 0:fa2de1b79154 11 /* Codes_SRS_DLIST_06_005: [DList_InitializeListHead will initialize the Flink & Blink to the address of the DLIST_ENTRY.] */
Azure.IoT Build 0:fa2de1b79154 12 ListHead->Flink = ListHead->Blink = ListHead;
Azure.IoT Build 0:fa2de1b79154 13 return;
Azure.IoT Build 0:fa2de1b79154 14 }
Azure.IoT Build 0:fa2de1b79154 15
Azure.IoT Build 0:fa2de1b79154 16 int
Azure.IoT Build 0:fa2de1b79154 17 DList_IsListEmpty(
Azure.IoT Build 0:fa2de1b79154 18 const PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 19 )
Azure.IoT Build 0:fa2de1b79154 20 {
Azure.IoT Build 0:fa2de1b79154 21 /* Codes_SRS_DLIST_06_003: [DList_IsListEmpty shall return a non-zero value if there are no DLIST_ENTRY's on this list other than the list head.] */
Azure.IoT Build 0:fa2de1b79154 22 /* Codes_SRS_DLIST_06_004: [DList_IsListEmpty shall return 0 if there is one or more items in the list.] */
Azure.IoT Build 0:fa2de1b79154 23 return (ListHead->Flink == ListHead);
Azure.IoT Build 0:fa2de1b79154 24 }
Azure.IoT Build 0:fa2de1b79154 25
Azure.IoT Build 0:fa2de1b79154 26 int
Azure.IoT Build 0:fa2de1b79154 27 DList_RemoveEntryList(
Azure.IoT Build 0:fa2de1b79154 28 PDLIST_ENTRY Entry
Azure.IoT Build 0:fa2de1b79154 29 )
Azure.IoT Build 0:fa2de1b79154 30 {
Azure.IoT Build 0:fa2de1b79154 31 /* Codes_SRS_DLIST_06_008: [DList_RemoveEntryList shall remove a listEntry from whatever list it is properly part of.] */
Azure.IoT Build 0:fa2de1b79154 32 /* Codes_SRS_DLIST_06_009: [The remaining list is properly formed.] */
Azure.IoT Build 0:fa2de1b79154 33 /* Codes_SRS_DLIST_06_010: [DList_RemoveEntryList shall return non-zero if the remaining list is empty.] */
Azure.IoT Build 0:fa2de1b79154 34 /* Codes_SRS_DLIST_06_011: [DList_RemoveEntryList shall return zero if the remaining list is NOT empty.] */
Azure.IoT Build 0:fa2de1b79154 35 PDLIST_ENTRY Blink;
Azure.IoT Build 0:fa2de1b79154 36 PDLIST_ENTRY Flink;
Azure.IoT Build 0:fa2de1b79154 37
Azure.IoT Build 0:fa2de1b79154 38 Flink = Entry->Flink;
Azure.IoT Build 0:fa2de1b79154 39 Blink = Entry->Blink;
Azure.IoT Build 0:fa2de1b79154 40 Blink->Flink = Flink;
Azure.IoT Build 0:fa2de1b79154 41 Flink->Blink = Blink;
Azure.IoT Build 0:fa2de1b79154 42 return (Flink == Blink);
Azure.IoT Build 0:fa2de1b79154 43 }
Azure.IoT Build 0:fa2de1b79154 44
Azure.IoT Build 0:fa2de1b79154 45 PDLIST_ENTRY
Azure.IoT Build 0:fa2de1b79154 46 DList_RemoveHeadList(
Azure.IoT Build 0:fa2de1b79154 47 PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 48 )
Azure.IoT Build 0:fa2de1b79154 49 {
Azure.IoT Build 0:fa2de1b79154 50 /* Codes_SRS_DLIST_06_012: [DList_RemoveHeadList removes the oldest entry from the list defined by the listHead parameter and returns a pointer to that entry.] */
Azure.IoT Build 0:fa2de1b79154 51 /* Codes_SRS_DLIST_06_013: [DList_RemoveHeadList shall return listHead if that's the only item in the list.] */
Azure.IoT Build 0:fa2de1b79154 52
Azure.IoT Build 0:fa2de1b79154 53 PDLIST_ENTRY Flink;
Azure.IoT Build 0:fa2de1b79154 54 PDLIST_ENTRY Entry;
Azure.IoT Build 0:fa2de1b79154 55
Azure.IoT Build 0:fa2de1b79154 56 Entry = ListHead->Flink;
Azure.IoT Build 0:fa2de1b79154 57 Flink = Entry->Flink;
Azure.IoT Build 0:fa2de1b79154 58 ListHead->Flink = Flink;
Azure.IoT Build 0:fa2de1b79154 59 Flink->Blink = ListHead;
Azure.IoT Build 0:fa2de1b79154 60 return Entry;
Azure.IoT Build 0:fa2de1b79154 61 }
Azure.IoT Build 0:fa2de1b79154 62
Azure.IoT Build 0:fa2de1b79154 63
Azure.IoT Build 0:fa2de1b79154 64
Azure.IoT Build 0:fa2de1b79154 65 void
Azure.IoT Build 0:fa2de1b79154 66 DList_InsertTailList(
Azure.IoT Build 0:fa2de1b79154 67 PDLIST_ENTRY ListHead,
Azure.IoT Build 0:fa2de1b79154 68 PDLIST_ENTRY Entry
Azure.IoT Build 0:fa2de1b79154 69 )
Azure.IoT Build 0:fa2de1b79154 70 {
Azure.IoT Build 0:fa2de1b79154 71 PDLIST_ENTRY Blink;
Azure.IoT Build 0:fa2de1b79154 72
Azure.IoT Build 0:fa2de1b79154 73 /* Codes_SRS_DLIST_06_006: [DListInsertTailList shall place the DLIST_ENTRY at the end of the list defined by the listHead parameter.] */
Azure.IoT Build 0:fa2de1b79154 74 Blink = ListHead->Blink;
Azure.IoT Build 0:fa2de1b79154 75 Entry->Flink = ListHead;
Azure.IoT Build 0:fa2de1b79154 76 Entry->Blink = Blink;
Azure.IoT Build 0:fa2de1b79154 77 Blink->Flink = Entry;
Azure.IoT Build 0:fa2de1b79154 78 ListHead->Blink = Entry;
Azure.IoT Build 0:fa2de1b79154 79 return;
Azure.IoT Build 0:fa2de1b79154 80 }
Azure.IoT Build 0:fa2de1b79154 81
Azure.IoT Build 0:fa2de1b79154 82
Azure.IoT Build 0:fa2de1b79154 83 void
Azure.IoT Build 0:fa2de1b79154 84 DList_AppendTailList(
Azure.IoT Build 0:fa2de1b79154 85 PDLIST_ENTRY ListHead,
Azure.IoT Build 0:fa2de1b79154 86 PDLIST_ENTRY ListToAppend
Azure.IoT Build 0:fa2de1b79154 87 )
Azure.IoT Build 0:fa2de1b79154 88 {
Azure.IoT Build 0:fa2de1b79154 89 /* Codes_SRS_DLIST_06_007: [DList_AppendTailList shall place the list defined by listToAppend at the end of the list defined by the listHead parameter.] */
Azure.IoT Build 0:fa2de1b79154 90 PDLIST_ENTRY ListEnd = ListHead->Blink;
Azure.IoT Build 0:fa2de1b79154 91
Azure.IoT Build 0:fa2de1b79154 92 ListHead->Blink->Flink = ListToAppend;
Azure.IoT Build 0:fa2de1b79154 93 ListHead->Blink = ListToAppend->Blink;
Azure.IoT Build 0:fa2de1b79154 94 ListToAppend->Blink->Flink = ListHead;
Azure.IoT Build 0:fa2de1b79154 95 ListToAppend->Blink = ListEnd;
Azure.IoT Build 0:fa2de1b79154 96 return;
Azure.IoT Build 0:fa2de1b79154 97 }
Azure.IoT Build 0:fa2de1b79154 98
Azure.IoT Build 0:fa2de1b79154 99
Azure.IoT Build 0:fa2de1b79154 100 /*Codes_SRS_DLIST_02_002: [DList_InsertHeadList inserts a singular entry in the list having as head listHead after "head".]*/
Azure.IoT Build 0:fa2de1b79154 101 void DList_InsertHeadList(PDLIST_ENTRY listHead, PDLIST_ENTRY entry)
Azure.IoT Build 0:fa2de1b79154 102 {
Azure.IoT Build 0:fa2de1b79154 103 entry->Blink = listHead;
Azure.IoT Build 0:fa2de1b79154 104 entry->Flink = listHead->Flink;
Azure.IoT Build 0:fa2de1b79154 105 listHead->Flink->Blink = entry;
Azure.IoT Build 0:fa2de1b79154 106 listHead->Flink = entry;
Azure.IoT Build 0:fa2de1b79154 107 }