Kaa client C SDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
kaa_platform_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 
18 #ifndef KAA_PLATFORM_UTILS_H_
19 #define KAA_PLATFORM_UTILS_H_
20 
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 
25 #include "kaa_error.h"
26 #include "kaa_platform_common.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 
33 typedef struct {
34  uint8_t *begin;
35  uint8_t *current;
36  uint8_t *end;
38 
39 
40 typedef struct {
41  const uint8_t *begin;
42  const uint8_t *current;
43  const uint8_t *end;
45 
46 #define KAA_MESSAGE_WRITER(buffer, len) \
47  (kaa_platform_message_writer_t){ (buffer), (buffer), (buffer) + (len) }
48 
49 #define KAA_MESSAGE_READER(buffer, len) \
50  (kaa_platform_message_reader_t){ (buffer), (buffer), (buffer) + (len) }
51 
56  uint8_t *buf, size_t len);
57 
59 
61  , const void *data
62  , size_t data_size);
63 
65 
67  , const void *data
68  , size_t data_size);
69 
71  , uint32_t protocol_id
72  , uint16_t protocol_version);
73 
75  , uint16_t extension_type
76  , uint16_t options
77  , uint32_t payload_size);
78 
79 
80 
85  , const uint8_t *buffer
86  , size_t len);
87 
89 
91  , void *buffer
92  , size_t expected_size);
93 
95  , void *buffer
96  , size_t expected_size);
97 
99  , uint32_t *protocol_id
100  , uint16_t *protocol_version
101  , uint16_t *extension_count);
102 
104  , uint16_t *extension_type
105  , uint16_t *extension_options
106  , uint32_t *extension_payload_length);
107 
109  , size_t size);
110 
112 
113 #define KAA_ALIGNED_SIZE(s) ((s) + (KAA_ALIGNMENT - (s) % KAA_ALIGNMENT) % KAA_ALIGNMENT)
114 
115 static inline size_t kaa_aligned_size_get(size_t size)
116 {
117  return (size + (KAA_ALIGNMENT - (size % KAA_ALIGNMENT)) % KAA_ALIGNMENT);
118 }
119 
120 #define KAA_STATIC_ASSERT(name, expr) \
121  static char static_assertion_##name[expr] __attribute__((unused))
122 
123 #ifdef __cplusplus
124 } /* extern "C" */
125 #endif
126 
127 #endif /* KAA_PLATFORM_UTILS_H_ */
const uint8_t * end
Definition: kaa_platform_utils.h:43
kaa_error_t kaa_platform_message_read_aligned(kaa_platform_message_reader_t *reader, void *buffer, size_t expected_size)
Definition: kaa_platform_utils.h:40
#define KAA_ALIGNMENT
Definition: kaa_platform_common.h:27
void kaa_platform_message_writer_destroy(kaa_platform_message_writer_t *writer)
bool kaa_platform_message_is_buffer_large_enough(kaa_platform_message_reader_t *reader, size_t size)
kaa_error_t
Definition: kaa_error.h:31
kaa_error_t kaa_platform_message_read_extension_header(kaa_platform_message_reader_t *reader, uint16_t *extension_type, uint16_t *extension_options, uint32_t *extension_payload_length)
uint8_t * begin
Definition: kaa_platform_utils.h:34
Definition: kaa_platform_utils.h:33
const uint8_t * current
Definition: kaa_platform_utils.h:42
kaa_error_t kaa_platform_message_write(kaa_platform_message_writer_t *writer, const void *data, size_t data_size)
kaa_error_t kaa_platform_message_reader_create(kaa_platform_message_reader_t **reader_p, const uint8_t *buffer, size_t len)
Kaa error codes.
const uint8_t * begin
Definition: kaa_platform_utils.h:41
kaa_error_t kaa_platform_message_write_aligned(kaa_platform_message_writer_t *writer, const void *data, size_t data_size)
kaa_error_t kaa_platform_message_header_read(kaa_platform_message_reader_t *reader, uint32_t *protocol_id, uint16_t *protocol_version, uint16_t *extension_count)
void kaa_platform_message_reader_destroy(kaa_platform_message_reader_t *reader)
uint8_t * current
Definition: kaa_platform_utils.h:35
kaa_error_t kaa_platform_message_header_write(kaa_platform_message_writer_t *writer, uint32_t protocol_id, uint16_t protocol_version)
uint8_t * end
Definition: kaa_platform_utils.h:36
kaa_error_t kaa_platform_message_write_extension_header(kaa_platform_message_writer_t *writer, uint16_t extension_type, uint16_t options, uint32_t payload_size)
kaa_error_t kaa_platform_message_writer_create(kaa_platform_message_writer_t **writer_p, uint8_t *buf, size_t len)
kaa_error_t kaa_platform_message_write_alignment(kaa_platform_message_writer_t *writer)
kaa_error_t kaa_platform_message_read(kaa_platform_message_reader_t *reader, void *buffer, size_t expected_size)
static size_t kaa_aligned_size_get(size_t size)
Definition: kaa_platform_utils.h:115
kaa_error_t kaa_platform_message_skip(kaa_platform_message_reader_t *reader, size_t size)