Fix doxygen
[platform/core/api/nfc.git] / src / net_nfc_client_data.c
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 #include <string.h>
18
19 #include "net_nfc_data.h"
20 #include "net_nfc_typedef_internal.h"
21 #include "net_nfc_util_internal.h"
22
23 #ifndef NET_NFC_EXPORT_API
24 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
25 #endif
26
27 /* LCOV_EXCL_START */
28
29 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only(data_h *data)
30 {
31         return net_nfc_create_data(data, NULL, 0);
32 }
33
34 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h *data,
35         const uint8_t *bytes, size_t length)
36 {
37         data_s *tmp_data = NULL;
38
39         if (data == NULL)
40                 return NET_NFC_NULL_PARAMETER;
41
42         *data = NULL;
43
44         tmp_data = net_nfc_util_create_data(length);
45         if (tmp_data == NULL)
46                 return NET_NFC_ALLOC_FAIL;
47
48         if (length > 0 && bytes != NULL)
49                 memcpy(tmp_data->buffer, bytes, length);
50
51         *data = (data_h)tmp_data;
52
53         return NET_NFC_OK;
54 }
55
56 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data(const data_h data,
57         uint8_t **bytes, size_t *length)
58 {
59         data_s *tmp_data = (data_s *)data;
60
61         if (bytes == NULL || length == NULL)
62                 return NET_NFC_NULL_PARAMETER;
63
64         *bytes = NULL;
65         *length = 0;
66
67         if (data == NULL)
68                 return NET_NFC_NULL_PARAMETER;
69
70         *bytes = tmp_data->buffer;
71         *length = tmp_data->length;
72
73         return NET_NFC_OK;
74 }
75
76 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(data_h data,
77         const uint8_t *bytes, size_t length)
78 {
79         data_s *tmp_data = (data_s *)data;
80
81         if (data == NULL)
82                 return NET_NFC_NULL_PARAMETER;
83
84         if (tmp_data->buffer == bytes && tmp_data->length == length)
85                 return NET_NFC_OK;
86
87         net_nfc_util_clear_data(tmp_data);
88
89         if (length > 0) {
90                 net_nfc_util_init_data(tmp_data, length);
91
92                 if (bytes != NULL)
93                         memcpy(tmp_data->buffer, bytes, length);
94         }
95
96         return NET_NFC_OK;
97 }
98
99 NET_NFC_EXPORT_API size_t net_nfc_get_data_length(const data_h data)
100 {
101         data_s *tmp_data = (data_s *)data;
102
103         if (data == NULL)
104                 return 0;
105
106         return tmp_data->length;
107 }
108
109 NET_NFC_EXPORT_API uint8_t *net_nfc_get_data_buffer(const data_h data)
110 {
111         data_s *tmp_data = (data_s *)data;
112
113         if (data == NULL)
114                 return NULL;
115
116         return tmp_data->buffer;
117 }
118
119 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data)
120 {
121         data_s *tmp_data = (data_s *)data;
122
123         if (data == NULL)
124                 return NET_NFC_NULL_PARAMETER;
125
126         if (tmp_data->buffer != NULL)
127                 _net_nfc_util_free_mem(tmp_data->buffer);
128
129         _net_nfc_util_free_mem(tmp_data);
130
131         return NET_NFC_OK;
132 }
133
134 /* LCOV_EXCL_STOP */
135