Added service of message_config_user_name
[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] command Command that arrived.
40  */
41 typedef void (*command_received_cb)(command_s command);
42
43 /**
44  * @brief Called whenever new user name arrives.
45  * @param[in] name User name that arrived.
46  */
47 typedef void (*user_name_received_cb)(const char *name);
48
49 /**
50  * @brief Starts listening on the given port for messages.
51  * @return 0 on success, -1 otherwise.
52  * @remarks This function allocates resources and that has to be freed with controller_connection_manager_release.
53  */
54 int controller_connection_manager_listen();
55
56 /**
57  * @brief Gets currect connection state.
58  * @return Connection state.
59  */
60 controller_connection_state_e controller_connection_manager_get_state();
61
62 /**
63  * @brief Sets callback function called whenever connection state changes.
64  * @param[in] callback Callback function to be set.
65  */
66 void controller_connection_manager_set_state_change_cb(connection_state_cb callback);
67
68 /**
69  * @brief Handles arriving message.
70  * @param[in] message Message to handle
71  */
72 void controller_connection_manager_handle_message(message_t *message);
73
74 /**
75  * @brief Sets callback function called whenever new message arrives.
76  * @param[in] callback Callback function to be set.
77  */
78 void controller_connection_manager_set_command_received_cb(command_received_cb callback);
79
80 /**
81  * @brief Sets callback function called whenever new message arrives.
82  * @param[in] callback Callback function to be set.
83  */
84 void controller_connection_manager_set_user_name_received_cb(user_name_received_cb callback);
85
86 /**
87  * @brief Stops listening for messages and release resources connected with it.
88  */
89 void controller_connection_manager_release();
90
91 #endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */