added k60d100m project
[adk-bluetooth-test.git] / adk-stack / sgBuf.h
blob4ebb45dd6b0e7f312f71d42e2ec273c8e8c07688
1 /*
2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifdef ADK_INTERNAL
17 #ifndef _SG_BUF_H_
18 #define _SG_BUF_H_
22 sg_buf is a linked-list based buffer which makes it easy to encapsulate
23 data in places like bluetooth, where each layer needs to add some data
24 to the packet on its way out. This is batter than normal buffers since
25 no data has to be moved and header sizes need nto be known ahead of time.
28 typedef struct sg_buf_node{
30 struct sg_buf_node* next;
31 uint32_t info;
32 const uint8_t* data;
34 }sg_buf_node;
36 typedef struct{
38 sg_buf_node* first;
39 sg_buf_node* last;
40 uint32_t totalLen;
42 }sg_buf;
44 typedef void* sg_iter;
46 #define SG_BUF_STATIC_INITIALIZER {NULL, NULL, 0}
48 #define SG_FLAG_NEEDS_FREEING 1
49 #define SG_FLAG_MAKE_A_COPY 2
51 void sg_init(sg_buf* buf);
52 sg_buf* sg_alloc(void);
53 void sg_free(sg_buf* buf);
54 uint32_t sg_length(const sg_buf* buf);
55 char sg_add_front(sg_buf* buf, const uint8_t* data, uint32_t len, uint8_t flags); //0 on fail
56 char sg_add_back(sg_buf* buf, const uint8_t* data, uint32_t len, uint8_t flags); //0 on fail
58 void sg_concat_front(sg_buf* buf, sg_buf* second); //prepend second to buf
59 void sg_concat_back(sg_buf* buf, sg_buf* second); //append second to buf
61 sg_iter sg_iter_start(const sg_buf* buf);
62 char sg_iter_next(sg_iter* iterP, const uint8_t** buf, uint32_t* sz);
64 void sg_copyto(const sg_buf* buf, uint8_t* dst);
66 #endif
67 #endif