2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://floralicense.org/license/
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.
17 #ifndef INC_UDP_CONNECTION_H_
18 #define INC_UDP_CONNECTION_H_
21 * @brief Called whenever new UDP data arrives.
22 * @param[in] data Pointer to data that arrived.
23 * @param[in] size Size of data in bytes.
24 * @param[in] address Address of source of data.
25 * @param[in] port Port of data source.
27 typedef void (*udp_receive_cb)(const char *data, unsigned int size, const char *address, int port);
30 * @brief Structure of data about udp_connection.
32 typedef struct udp_connection udp_connection_t;
35 * @brief Creates UDP connection object.
36 * @param[in] port Local port on which creation should be stablished.
37 * @return new udp_connection object on success, NULL otherwise.
38 * @remarks Function allocates resources that have to be freed with udp_communication_destroy.
40 udp_connection_t *udp_connection_create(int port);
43 * @brief Sends data on given address.
44 * @param[in] connection UDP connection object.
45 * @param[in] data Data to be sent.
46 * @param[in] size Size in bytes of data pointed by data pointer.
47 * @param[in] address IP address of receiver.
48 * @param[in] port Port of receiver.
49 * @return 0 on success, -1 otherwise.
51 int udp_connection_send(udp_connection_t *connection, const char *data, unsigned short int size, const char *address, int port);
54 * @brief Sets callback for receiving data.
55 * @param[in] connection UDP connection object.
56 * @param[in] callback Callback to be set or NULL to unregister.
57 * @remarks Function is passed pointer to data and its size.
59 void udp_connection_set_receive_cb(udp_connection_t *connection, udp_receive_cb callback);
62 * @brief Stops UDP communication and releases all resources allocated by udp_communication_create.
63 * @param[in] connection UDP connection object.
65 void udp_connection_destroy(udp_connection_t *connection);
67 #endif /* INC_UDP_CONNECTION_H_ */