Implementation of connectivity abstraction feature Release v0.61
[platform/upstream/iotivity.git] / resource / csdk / connectivity / common / inc / uarraylist.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 #ifndef __U_ARRAYLIST_H_
22 #define __U_ARRAYLIST_H_
23
24 #include <stdint.h>
25 #include "cacommon.h"
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 /**
33  * Use this default size when initialized
34  */
35 #define U_ARRAYLIST_DEFAULT_SIZE 1
36
37 /**
38  * @struct u_arraylist_t
39  * @brief array list structure
40  */
41 typedef struct u_arraylist_t
42 {
43     void **data;
44     uint32_t length;
45     uint32_t size;
46 } u_arraylist_t;
47
48 /**
49  * @brief API to creates array list and initializes the elements.
50  * @return  u_arraylist_t if Success, NULL otherwise
51  */
52 u_arraylist_t *u_arraylist_create();
53
54 /**
55  * @brief Resets and deletes the array list
56  * application should free the memory of data in array list
57  * @param list- u_arraylist pointer
58  * @return CAResult_t
59  * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise
60  */
61 CAResult_t u_arraylist_free(u_arraylist_t *list);
62
63 /**
64  * @brief Returns the data of the index from the array list
65  * @param list
66  *     [IN] pointer of array list
67  * @param index
68  *     [IN] index of array list
69  * @return void pointer of the data
70  */
71 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
72
73 /**
74  * @brief Add data in the array list
75  * @param list
76  *     [IN] pointer of array list
77  * @param data
78  *     [IN] pointer of data
79  * @return CAResult_t
80  * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise
81  */
82 CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
83
84 /**
85  * @brief Remove the data of the index from the array list
86  * @param list
87  *     [IN] pointer of array list
88  * @param index
89  *     [IN] index of array list
90  * @return void pointer of the data
91  */
92 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
93
94 /**
95  * @brief Returns the length of the array list
96  * @param list
97  *     [IN] pointer of array list
98  * @return length of the array list
99  */
100 uint32_t u_arraylist_length(const u_arraylist_t *list);
101
102 /**
103  * @brief Returns whether the data exists or not
104  * @param list
105  *     [IN] pointer of array list
106  * @param data
107  *     [IN] pointer of data
108  * @return 1 if exists, 0 otherwise
109  */
110 uint8_t u_arraylist_contains(const u_arraylist_t *list, void *data);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* _U_ARRAYLIST_H_ */