1212#include " agents/ConfiguratorAgent.h"
1313#include " MessagesDefinitions.h"
1414
15+ /* *
16+ * @enum AgentsManagerStates
17+ * @brief Represents the various states of the AgentsManager.
18+ *
19+ * States:
20+ * - INIT:
21+ * The initial state where the AgentsManager is polling all the handled
22+ * agents waiting for a connected user client.
23+ *
24+ * - SEND_INITIAL_STATUS:
25+ * In this state, the AgentsManager sends an initial status message
26+ * to inform about errors or current state.
27+ *
28+ * - SEND_NETWORK_OPTIONS:
29+ * This state is responsible for sending network configuration options
30+ * to the connected agent. These options may include the list of available WiFi Networks
31+ *
32+ * - CONFIG_IN_PROGRESS:
33+ * Indicates that a configuration process is currently in progress.
34+ * The AgentsManager is actively handling commands or data related to
35+ * network configuration orprovisioning.
36+ *
37+ * - END:
38+ * The final state where the AgentsManager concludes its operations.
39+ * This may involve cleaning up resources and stopping agents
40+ */
1541enum class AgentsManagerStates { INIT,
1642 SEND_INITIAL_STATUS,
1743 SEND_NETWORK_OPTIONS,
@@ -30,27 +56,152 @@ enum class RequestType: int { NONE = -1,
3056 GET_WIFI_FW_VERSION = 4 ,
3157 GET_BLE_MAC_ADDRESS = 5 };
3258
59+ /* *
60+ * @class AgentsManagerClass
61+ * @brief Manages the lifecycle, communication, and state of multiple configurator agents.
62+ *
63+ * The AgentsManagerClass is a singleton class responsible for coordinating multiple
64+ * configurator agents. It provides methods to initialize, terminate, enable, disable,
65+ * and interact with agents. The agents handle a communication interface for configuring
66+ * network credentials and handle the claiming cloud process. The interfaces could be: BLE,
67+ * Serial and other.
68+ * The class also handles communication with agents, manages
69+ * their states, and provides callback mechanisms for handling requests and returning
70+ * data such as timestamps and network settings.
71+ *
72+ * Key functionalities include:
73+ * - Managing the state of the agents.
74+ * - Sending and receiving messages to/from agents.
75+ * - Adding and removing agents dynamically.
76+ * - Handling requests and callbacks for specific operations.
77+ * - Monitoring the progress of the execution of received commands.
78+ *
79+ */
3380class AgentsManagerClass {
3481public:
82+ /* *
83+ * @brief Get the singleton instance of the AgentsManagerClass.
84+ * @return Reference to the singleton instance.
85+ */
3586 static AgentsManagerClass &getInstance ();
87+
88+ /* *
89+ * @brief Initialize the AgentsManager, and starts the agents.
90+ * @return True if initialization is successful, false otherwise.
91+ */
3692 bool begin ();
93+
94+ /* *
95+ * @brief Terminate the AgentsManager.
96+ * @return True if termination is successful, false otherwise.
97+ */
3798 bool end ();
99+
100+ /* *
101+ * @brief Disconnect the currently connected agent.
102+ */
38103 void disconnect ();
104+
105+ /* *
106+ * @brief Update the state of the AgentsManager.
107+ * @return The current state of the AgentsManager.
108+ */
39109 AgentsManagerStates update ();
110+
111+ /* *
112+ * @brief Enable or disable a specific agent.
113+ * The agent will be automatically started or stopped
114+ * based on the enable parameter.
115+ * @param type The type of agent to enable or disable.
116+ * @param enable True to enable, false to disable.
117+ */
40118 void enableAgent (ConfiguratorAgent::AgentTypes type, bool enable);
119+
120+ /* *
121+ * @brief Check if a specific agent is enabled.
122+ * @param type The type of agent to check.
123+ * @return True if the agent is enabled, false otherwise.
124+ */
41125 bool isAgentEnabled (ConfiguratorAgent::AgentTypes type);
42- // Force starting agent even if disabled
126+
127+ /* *
128+ * @brief Force start an agent even if it is disabled.
129+ * @param type The type of agent to start.
130+ * @return True if the agent is found in the list, false otherwise.
131+ */
43132 bool startAgent (ConfiguratorAgent::AgentTypes type);
133+
134+ /* *
135+ * @brief Stop a specific agent.
136+ * @param type The type of agent to stop.
137+ * @return True if the agent is found in the list, false otherwise.
138+ */
44139 bool stopAgent (ConfiguratorAgent::AgentTypes type);
140+
141+ /* *
142+ * @brief Get the currently connected agent.
143+ * @return Pointer to the connected agent, or nullptr if no agent is connected.
144+ */
45145 ConfiguratorAgent *getConnectedAgent ();
146+
147+ /* *
148+ * @brief Send a message to the connected agent or queue a message
149+ * if no agent is connected.
150+ * @param msg The message to send.
151+ * @return True if the message is successfully sent, false otherwise.
152+ */
46153 bool sendMsg (ProvisioningOutputMessage &msg);
154+
155+ /* *
156+ * @brief Add an agent to be managed to the list.
157+ * @param agent The agent to add.
158+ * @return True if the agent is successfully added, false otherwise.
159+ */
47160 bool addAgent (ConfiguratorAgent &agent);
161+
162+ /* *
163+ * @brief Add an handler callback for a specific request type.
164+ * The callback is fired when the properly request is received
165+ * @param type The type of request to handle.
166+ * @param callback The callback function to handle the request.
167+ * @return True if the handler is successfully added, false otherwise.
168+ */
48169 bool addRequestHandler (RequestType type, ConfiguratorRequestHandler callback);
170+
171+ /* *
172+ * @brief Remove the handler callback for a specific request type.
173+ * @param type The type of request to remove the handler for.
174+ */
49175 void removeRequestHandler (RequestType type);
176+
177+ /* *
178+ * @brief Add a callback to be fired when the timestamp is received from the agent.
179+ * @param callback The callback function to return the timestamp.
180+ * @return True if the callback is successfully added, false otherwise.
181+ */
50182 bool addReturnTimestampCallback (ReturnTimestamp callback);
183+
184+ /* *
185+ * @brief Remove the callback for returning a timestamp.
186+ */
51187 void removeReturnTimestampCallback ();
188+
189+ /* *
190+ * @brief Add a callback to return network settings received from the agent.
191+ * @param callback The callback function to return the network settings.
192+ * @return True if the callback is successfully added, false otherwise.
193+ */
52194 bool addReturnNetworkSettingsCallback (ReturnNetworkSettings callback);
195+
196+ /* *
197+ * @brief Remove the callback for returning network settings.
198+ */
53199 void removeReturnNetworkSettingsCallback ();
200+
201+ /* *
202+ * @brief Check if a configuration process is in progress.
203+ * @return True if a configuration process is in progress, false otherwise.
204+ */
54205 bool isConfigInProgress ();
55206
56207private:
0 commit comments