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_CONTROLLER_CONNECTION_MANAGER_H_
18 #define INC_CONTROLLER_CONNECTION_MANAGER_H_
21 #include "messages/message.h"
23 * @brief Describes state of connection.
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;
31 * @brief Called whenever state of connection changes.
32 * @param[in] previous Previous state of connection.
33 * @param[in] current Current state of connection.
35 typedef void (*connection_state_cb)(controller_connection_state_e previous, controller_connection_state_e current);
38 * @brief Called whenever new command arrives.
39 * @param[in] command Command that arrived.
41 typedef void (*command_received_cb)(command_s command);
44 * @brief Called whenever new user name arrives.
45 * @param[in] name User name that arrived.
47 typedef void (*user_name_received_cb)(const char *name);
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.
54 int controller_connection_manager_listen();
57 * @brief Gets currect connection state.
58 * @return Connection state.
60 controller_connection_state_e controller_connection_manager_get_state();
63 * @brief Sets callback function called whenever connection state changes.
64 * @param[in] callback Callback function to be set.
66 void controller_connection_manager_set_state_change_cb(connection_state_cb callback);
69 * @brief Handles arriving message.
70 * @param[in] message Message to handle
72 void controller_connection_manager_handle_message(message_t *message);
75 * @brief Sets callback function called whenever new message arrives.
76 * @param[in] callback Callback function to be set.
78 void controller_connection_manager_set_command_received_cb(command_received_cb callback);
81 * @brief Sets callback function called whenever new message arrives.
82 * @param[in] callback Callback function to be set.
84 void controller_connection_manager_set_user_name_received_cb(user_name_received_cb callback);
87 * @brief Stops listening for messages and release resources connected with it.
89 void controller_connection_manager_release();
91 #endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */