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_
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 message arrives.
39 * @param[in] message Message tat arrived.
41 typedef void (*message_received_cb)(command_s command);
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.
49 int controller_connection_manager_listen(int port);
52 * @brief Gets currect connection state.
53 * @return Connection state.
55 controller_connection_state_e controller_connection_manager_get_state();
58 * @brief Sets callback function called whenever connection state changes.
59 * @param[in] callback Callback function to be set.
61 void controller_connection_set_manager_state_change_cb(connection_state_cb callback);
64 * @brief Sets callback function called whenever new message arrives.
65 * @param[in] callback Callback function to be set.
67 void controller_connection_manager_set_message_received_cb(message_received_cb callback);
70 * @brief Stops listening for messages and release resources connected with it.
72 void controller_connection_manager_release();
74 #endif /* INC_CONTROLLER_CONNECTION_MANAGER_H_ */