| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
#include <stdlib.h> |
| 24 |
#include <errno.h> |
| 25 |
#include "collection_stack.h" |
| 26 |
#include "trace.h" |
| 27 |
|
| 28 |
|
| 29 |
int col_create_stack(struct collection_item **stack) |
| 30 |
{ |
| 31 |
int error = EOK; |
| 32 |
|
| 33 |
TRACE_FLOW_STRING("col_create_stack", "Entry point."); |
| 34 |
|
| 35 |
error = col_create_collection(stack, COL_NAME_STACK, COL_CLASS_STACK); |
| 36 |
|
| 37 |
TRACE_FLOW_STRING("col_create_stack", "Exit."); |
| 38 |
return error; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
void col_destroy_stack(struct collection_item *stack) |
| 43 |
{ |
| 44 |
TRACE_FLOW_STRING("col_destroy_stack", "Entry point."); |
| 45 |
|
| 46 |
col_destroy_collection(stack); |
| 47 |
|
| 48 |
TRACE_FLOW_STRING("col_destroy_stack", "Exit"); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
int col_push_str_property(struct collection_item *stack, |
| 54 |
const char *property, const char *string, int length) |
| 55 |
{ |
| 56 |
int error = EOK; |
| 57 |
|
| 58 |
TRACE_FLOW_STRING("col_push_str_property", "Entry point."); |
| 59 |
|
| 60 |
|
| 61 |
if (stack == NULL) { |
| 62 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 63 |
return EINVAL; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 68 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 69 |
return EINVAL; |
| 70 |
} |
| 71 |
|
| 72 |
error = col_add_str_property(stack, NULL, property, string, length); |
| 73 |
|
| 74 |
TRACE_FLOW_STRING("col_push_str_property", "Exit."); |
| 75 |
return error; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
int col_push_binary_property(struct collection_item *stack, |
| 80 |
const char *property, |
| 81 |
void *binary_data, |
| 82 |
int length) |
| 83 |
{ |
| 84 |
int error = EOK; |
| 85 |
|
| 86 |
TRACE_FLOW_STRING("col_push_binary_property", "Entry point."); |
| 87 |
|
| 88 |
|
| 89 |
if (stack == NULL) { |
| 90 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 91 |
return EINVAL; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 96 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 97 |
return EINVAL; |
| 98 |
} |
| 99 |
|
| 100 |
error = col_add_binary_property(stack, NULL, property, binary_data, length); |
| 101 |
|
| 102 |
TRACE_FLOW_STRING("col_push_binary_property", "Exit."); |
| 103 |
return error; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
int col_push_int_property(struct collection_item *stack, |
| 109 |
const char *property, |
| 110 |
int32_t number) |
| 111 |
{ |
| 112 |
int error = EOK; |
| 113 |
|
| 114 |
TRACE_FLOW_STRING("col_push_int_property", "Entry point."); |
| 115 |
|
| 116 |
|
| 117 |
if (stack == NULL) { |
| 118 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 119 |
return EINVAL; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 124 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 125 |
return EINVAL; |
| 126 |
} |
| 127 |
|
| 128 |
error = col_add_int_property(stack, NULL, property, number); |
| 129 |
|
| 130 |
TRACE_FLOW_STRING("col_push_int_property", "Exit."); |
| 131 |
return error; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
int col_push_unsigned_property(struct collection_item *stack, |
| 136 |
const char *property, |
| 137 |
uint32_t number) |
| 138 |
{ |
| 139 |
int error = EOK; |
| 140 |
|
| 141 |
TRACE_FLOW_STRING("col_push_unsigned_property", "Entry point."); |
| 142 |
|
| 143 |
|
| 144 |
if (stack == NULL) { |
| 145 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 146 |
return EINVAL; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 151 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 152 |
return EINVAL; |
| 153 |
} |
| 154 |
|
| 155 |
error = col_add_unsigned_property(stack, NULL, property, number); |
| 156 |
|
| 157 |
TRACE_FLOW_STRING("col_push_unsigned_property", "Exit."); |
| 158 |
return error; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
int col_push_long_property(struct collection_item *stack, |
| 164 |
const char *property, |
| 165 |
int64_t number) |
| 166 |
{ |
| 167 |
int error = EOK; |
| 168 |
|
| 169 |
TRACE_FLOW_STRING("col_push_long_property", "Entry point."); |
| 170 |
|
| 171 |
|
| 172 |
if (stack == NULL) { |
| 173 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 174 |
return EINVAL; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 179 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 180 |
return EINVAL; |
| 181 |
} |
| 182 |
|
| 183 |
error = col_add_long_property(stack, NULL, property, number); |
| 184 |
|
| 185 |
TRACE_FLOW_STRING("col_push_long_property", "Exit."); |
| 186 |
return error; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
int col_push_ulong_property(struct collection_item *stack, |
| 191 |
const char *property, |
| 192 |
uint64_t number) |
| 193 |
{ |
| 194 |
int error = EOK; |
| 195 |
|
| 196 |
TRACE_FLOW_STRING("col_push_ulong_property", "Entry point."); |
| 197 |
|
| 198 |
|
| 199 |
if (stack == NULL) { |
| 200 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 201 |
return EINVAL; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 206 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 207 |
return EINVAL; |
| 208 |
} |
| 209 |
|
| 210 |
error = col_add_ulong_property(stack, NULL, property, number); |
| 211 |
|
| 212 |
TRACE_FLOW_STRING("col_push_ulong_property", "Exit."); |
| 213 |
return error; |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
int col_push_double_property(struct collection_item *stack, |
| 218 |
const char *property, |
| 219 |
double number) |
| 220 |
{ |
| 221 |
int error = EOK; |
| 222 |
|
| 223 |
TRACE_FLOW_STRING("col_push_double_property", "Entry point."); |
| 224 |
|
| 225 |
|
| 226 |
if (stack == NULL) { |
| 227 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 228 |
return EINVAL; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 233 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 234 |
return EINVAL; |
| 235 |
} |
| 236 |
|
| 237 |
error = col_add_double_property(stack, NULL, property, number); |
| 238 |
|
| 239 |
TRACE_FLOW_STRING("col_push_double_property", "Exit."); |
| 240 |
return error; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
int col_push_bool_property(struct collection_item *stack, |
| 245 |
const char *property, |
| 246 |
unsigned char logical) |
| 247 |
{ |
| 248 |
int error = EOK; |
| 249 |
|
| 250 |
TRACE_FLOW_STRING("col_push_bool_property", "Entry point."); |
| 251 |
|
| 252 |
|
| 253 |
if (stack == NULL) { |
| 254 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 255 |
return EINVAL; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 260 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 261 |
return EINVAL; |
| 262 |
} |
| 263 |
|
| 264 |
error = col_add_bool_property(stack, NULL, property, logical); |
| 265 |
|
| 266 |
TRACE_FLOW_STRING("push_double_property", "Exit."); |
| 267 |
return error; |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
int col_push_any_property(struct collection_item *stack, |
| 272 |
const char *property, |
| 273 |
int type, |
| 274 |
void *data, |
| 275 |
int length) |
| 276 |
{ |
| 277 |
int error = EOK; |
| 278 |
|
| 279 |
TRACE_FLOW_STRING("col_push_any_property", "Entry point."); |
| 280 |
|
| 281 |
|
| 282 |
if (stack == NULL) { |
| 283 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 284 |
return EINVAL; |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 289 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 290 |
return EINVAL; |
| 291 |
} |
| 292 |
|
| 293 |
error = col_add_any_property(stack, NULL, property, type, data, length); |
| 294 |
|
| 295 |
TRACE_FLOW_STRING("col_push_any_property", "Exit."); |
| 296 |
return error; |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
int col_push_item(struct collection_item *stack, |
| 301 |
struct collection_item *item) |
| 302 |
{ |
| 303 |
int error = EOK; |
| 304 |
|
| 305 |
TRACE_FLOW_STRING("col_push_item", "Entry point."); |
| 306 |
|
| 307 |
|
| 308 |
if (stack == NULL) { |
| 309 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 310 |
return EINVAL; |
| 311 |
} |
| 312 |
|
| 313 |
|
| 314 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 315 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 316 |
return EINVAL; |
| 317 |
} |
| 318 |
|
| 319 |
error = col_insert_item_into_current(stack, |
| 320 |
item, |
| 321 |
COL_DSP_END, |
| 322 |
NULL, |
| 323 |
0, |
| 324 |
COL_INSERT_NOCHECK); |
| 325 |
|
| 326 |
TRACE_FLOW_STRING("col_push_item", "Exit."); |
| 327 |
return error; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
int col_pop_item(struct collection_item *stack, |
| 332 |
struct collection_item **item) |
| 333 |
{ |
| 334 |
int error = EOK; |
| 335 |
|
| 336 |
TRACE_FLOW_STRING("col_pop_item", "Entry point."); |
| 337 |
|
| 338 |
|
| 339 |
if (stack == NULL) { |
| 340 |
TRACE_ERROR_STRING("Stack can't be NULL", ""); |
| 341 |
return EINVAL; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
if (!col_is_of_class(stack, COL_CLASS_STACK)) { |
| 346 |
TRACE_ERROR_STRING("Wrong class", ""); |
| 347 |
return EINVAL; |
| 348 |
} |
| 349 |
|
| 350 |
error = col_extract_item_from_current(stack, |
| 351 |
COL_DSP_END, |
| 352 |
NULL, |
| 353 |
0, |
| 354 |
0, |
| 355 |
item); |
| 356 |
|
| 357 |
TRACE_FLOW_STRING("col_pop_item", "Exit."); |
| 358 |
return error; |
| 359 |
} |