258bc3107e5835599353c32c723c44eca90bd6ff
[apps/native/gear-racing-car.git] / inc / controller_connection_manager.h
1 /*
2  * Copyright (c) 2018 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 #ifndef INC_CONTROLLER_CONNECTION_MANAGER_H_
18 #define INC_CONTROLLER_CONNECTION_MANAGER_H_
19
20 #include "command.h"
21
22 /**
23  * @brief Describes state of connection.
24  */
25 typedef enum controller_connection_state {
26         CONTROLLER_CONNECTION_STATE_READY, /** Listens and waits for controller. */
27         CONTROLLER_CONNECTION_STATE_RESERVED /** Currently unavailable to connect. */
28 } controller_connection_state_e;
29
30 /**
31  * @brief Called whenever state of connection changes.
32  * @param[in] previous Previous state of connection.
33  * @param[in] current Current state of connection.
34  */
35 typedef void (*connection_state_cb)(controller_connection_state_e previous, controller_connection_state_e current);
36
37 /**
38  * @brief Called whenever new message arrives.
39  * @param[in] message Message tat arrived.
40  */
41 typedef void (*message_received_cb)(command_s command);
42
43 /**
44  * @brief Starts listening on the given port for messages.
45  * @param[in] port Port on which application will be listening.
46  * @return 0 on success, -1 otherwise.
47  * @remarks This function allocates resources and that has to be freed with controller_connection_manager_release.
48  */
49 int controller_connection_manager_listen(int port);
50
51 /**
52  * @brief Gets currect connection state.
53  * @return Connection state.
54  */
55 controller_connection_state_e controller_connection_manager_get_state();
56
57 /**
58  * @brief Sets callback function called whenever connection state changes.
59  * @param[in] callback Callback function to be set.
60  */
61 void controller_connection_set_manager_state_change_cb(connection_state_cb callback);
62
63 /**
64  * @brief Sets callback function called whenever new message arrives.
65  * @param[in] callback Callback function to be set.
66  */
67 void controller_connection_manager_set_message_received_cb(message_received_cb callback);
68
69 /**
70  * @brief Stops listening for messages and release resources connected with it.
71  */
72 void controller_connection_manager_release();
73
74 #endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */