k_buffer.h
Go to the documentation of this file.
1 /*
2  * KubOS Core Flight Services
3  * Copyright (C) 2016 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
33 #ifndef K_BUFFER_H
34 #define K_BUFFER_H
35 
36 #include <stdlib.h>
37 #include "kubos-core/k_alloc.h"
38 #include "kubos-core/k_alloc_csp.h"
40 
41 #define K_ALLOC_MALLOC
42 
43 typedef struct k_buffer {
44  struct k_buffer * next;
45  size_t size;
46  void * data;
47 } k_buffer_t;
48 
49 void k_buffer_init();
50 
51 k_buffer_t *k_buffer_alloc(struct k_buffer * next, void * data, size_t size, k_alloc_t * alloc);
52 
53 int k_buffer_realloc_new(k_buffer_t * buffer, size_t new_size, k_alloc_t * alloc);
54 
55 void k_buffer_free_new(k_buffer_t * buffer, k_alloc_t * alloc);
56 
57 
58 k_buffer_t *k_buffer_new(void * data, size_t size);
59 
60 k_buffer_t *k_buffer_add(struct k_buffer* next, void * data, size_t size);
61 
62 size_t k_buffer_size(k_buffer_t * buffer);
63 
64 int k_buffer_realloc(k_buffer_t * buffer, size_t new_size);
65 
66 void k_buffer_free(k_buffer_t * buffer);
67 
68 
69 #ifdef K_ALLOC_MALLOC
70  #define K_BUFFER_NEW(n, d, s) K_BUFFER_NEW_MALLOC(n, d, s)
71  #define K_BUFFER_FREE(b) K_BUFFER_FREE_MALLOC(b)
72  #define K_BUFFER_REALLOC(b, s) K_BUFFER_REALLOC_MALLOC(b, s)
73 #elif defined K_ALLOC_CSP
74  #define K_BUFFER_NEW(n, d, s) K_BUFFER_NEW_CSP(n, d, s)
75  #define K_BUFFER_FREE(b) K_BUFFER_FREE_CSP(b)
76  #define K_BUFFER_REALLOC(b, s) K_BUFFER_REALLOC_CSP(b, s)
77 #else
78  #error "k_buffer requires K_ALLOC_XX define."
79 #endif
80 
81 #endif
82 
83 /* @} */
void k_buffer_free_new(k_buffer_t *buffer, k_alloc_t *alloc)
Stdlib Allocator Implementation.
k_buffer_t * k_buffer_add(struct k_buffer *next, void *data, size_t size)
Buffer Allocator Wrapper.
struct k_buffer k_buffer_t
CSP Allocator Implementation.
int k_buffer_realloc(k_buffer_t *buffer, size_t new_size)
size_t k_buffer_size(k_buffer_t *buffer)
struct k_buffer * next
Definition: k_buffer.h:44
k_buffer_t * k_buffer_alloc(struct k_buffer *next, void *data, size_t size, k_alloc_t *alloc)
void * data
Definition: k_buffer.h:46
Definition: k_buffer.h:43
void k_buffer_free(k_buffer_t *buffer)
size_t size
Definition: k_buffer.h:45
Definition: k_alloc.h:38
k_buffer_t * k_buffer_new(void *data, size_t size)
int k_buffer_realloc_new(k_buffer_t *buffer, size_t new_size, k_alloc_t *alloc)
void k_buffer_init()