Implemented controler connection manager
[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 #include "messages/message.h"
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 command arrives.
39  * @param[in] message Message tat arrived.
40  */
41 typedef void (*command_received_cb)(command_s command);
42
43 /**
44  * @brief Starts listening on the given port for messages.
45  * @return 0 on success, -1 otherwise.
46  * @remarks This function allocates resources and that has to be freed with controller_connection_manager_release.
47  */
48 int controller_connection_manager_listen();
49
50 /**
51  * @brief Gets currect connection state.
52  * @return Connection state.
53  */
54 controller_connection_state_e controller_connection_manager_get_state();
55
56 /**
57  * @brief Sets callback function called whenever connection state changes.
58  * @param[in] callback Callback function to be set.
59  */
60 void controller_connection_manager_set_state_change_cb(connection_state_cb callback);
61
62 /**
63  * @brief Handles arriving message.
64  * @param[in] message Message to handle
65  */
66 void controller_connection_manager_handle_message(message_t *message);
67
68 /**
69  * @brief Sets callback function called whenever new message arrives.
70  * @param[in] callback Callback function to be set.
71  */
72 void controller_connection_manager_set_command_received_cb(command_received_cb callback);
73
74 /**
75  * @brief Stops listening for messages and release resources connected with it.
76  */
77 void controller_connection_manager_release();
78
79 #endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */