@@ -36,10 +36,8 @@ bool AgentsManagerClass::begin() {
3636 }
3737
3838 for (std::list<ConfiguratorAgent *>::iterator agent = _agentsList.begin (); agent != _agentsList.end (); ++agent) {
39- if ((*agent)->getAgentType () == ConfiguratorAgent::AgentTypes::BLE) {
40- if (!_bleAgentEnabled) {
41- continue ;
42- }
39+ if ( _enabledAgents[(int )(*agent)->getAgentType ()] == false ) {
40+ continue ;
4341 }
4442 if ((*agent)->begin () == ConfiguratorAgent::AgentConfiguratorStates::ERROR) {
4543 DEBUG_ERROR (" AgentsManagerClass::%s agent type %d fails" , __FUNCTION__, (int )(*agent)->getAgentType ());
@@ -64,21 +62,51 @@ AgentsManagerStates AgentsManagerClass::poll() {
6462 return _state;
6563}
6664
67- void AgentsManagerClass::enableBLEAgent (bool enable) {
68- if (_bleAgentEnabled == enable) {
65+ void AgentsManagerClass::enableAgent (ConfiguratorAgent::AgentTypes type, bool enable) {
66+ bool _agentState = _enabledAgents[(int )type];
67+
68+ if (_agentState == enable) {
6969 return ;
7070 }
71- _bleAgentEnabled = enable;
7271
72+ _enabledAgents[(int )type] = enable;
7373 if (enable) {
74- startBLEAgent ( );
74+ startAgent (type );
7575 } else {
76- stopBLEAgent ( );
76+ stopAgent (type );
7777 }
7878}
7979
80- bool AgentsManagerClass::isBLEAgentEnabled () {
81- return _bleAgentEnabled;
80+ bool AgentsManagerClass::isAgentEnabled (ConfiguratorAgent::AgentTypes type) {
81+ return _enabledAgents[(int )type];
82+ }
83+
84+ bool AgentsManagerClass::startAgent (ConfiguratorAgent::AgentTypes type) {
85+ if (_state == AgentsManagerStates::END) {
86+ return false ;
87+ }
88+
89+ for (std::list<ConfiguratorAgent *>::iterator agent = _agentsList.begin (); agent != _agentsList.end (); ++agent) {
90+ if ((*agent)->getAgentType () == type) {
91+ (*agent)->begin ();
92+ return true ;
93+ }
94+ }
95+ return false ;
96+ }
97+
98+ bool AgentsManagerClass::stopAgent (ConfiguratorAgent::AgentTypes type) {
99+ for (std::list<ConfiguratorAgent *>::iterator agent = _agentsList.begin (); agent != _agentsList.end (); ++agent) {
100+ if ((*agent)->getAgentType () == type) {
101+ (*agent)->end ();
102+ if (*agent == _selectedAgent) {
103+ handlePeerDisconnected ();
104+ _state = AgentsManagerStates::INIT;
105+ }
106+ return true ;
107+ }
108+ }
109+ return false ;
82110}
83111
84112bool AgentsManagerClass::end () {
@@ -187,11 +215,12 @@ AgentsManagerClass::AgentsManagerClass():
187215 _returnNetworkSettingsCb{ nullptr },
188216 _selectedAgent{ nullptr },
189217 _instances{ 0 },
190- _bleAgentEnabled{ true },
191218 _initStatusMsg{ StatusMessage::NONE },
192219 _statusRequest{ .completion = 0 , .pending = false , .key = RequestType::NONE },
193220 _state{ AgentsManagerStates::END }
194- {}
221+ {
222+ memset (_enabledAgents, 0x01 , sizeof (_enabledAgents));
223+ }
195224
196225AgentsManagerStates AgentsManagerClass::handleInit () {
197226 AgentsManagerStates nextState = _state;
@@ -369,38 +398,17 @@ bool AgentsManagerClass::sendStatus(StatusMessage msg) {
369398void AgentsManagerClass::handlePeerDisconnected () {
370399 // Peer disconnected, restore all stopped agents
371400 for (std::list<ConfiguratorAgent *>::iterator agent = _agentsList.begin (); agent != _agentsList.end (); ++agent) {
401+ if (_enabledAgents[(int )(*agent)->getAgentType ()] == false ) {
402+ (*agent)->end ();
403+ continue ;
404+ }
405+
372406 if (*agent != _selectedAgent) {
373- if ((*agent)->getAgentType () == ConfiguratorAgent::AgentTypes::BLE && !_bleAgentEnabled) {
374- continue ;
375- }
376407 (*agent)->begin ();
377408 }
378409 }
379410 _selectedAgent = nullptr ;
380411 return ;
381412}
382413
383- void AgentsManagerClass::stopBLEAgent () {
384- for (std::list<ConfiguratorAgent *>::iterator agent = _agentsList.begin (); agent != _agentsList.end (); ++agent) {
385- if ((*agent)->getAgentType () == ConfiguratorAgent::AgentTypes::BLE) {
386- (*agent)->end ();
387- if (*agent == _selectedAgent) {
388- handlePeerDisconnected ();
389- _state = AgentsManagerStates::INIT;
390- }
391- }
392- }
393- }
394-
395- void AgentsManagerClass::startBLEAgent () {
396- if (_state == AgentsManagerStates::END || !_bleAgentEnabled) {
397- return ;
398- }
399- std::for_each (_agentsList.begin (), _agentsList.end (), [](ConfiguratorAgent *agent) {
400- if (agent->getAgentType () == ConfiguratorAgent::AgentTypes::BLE) {
401- agent->begin ();
402- }
403- });
404- }
405-
406414#endif // NETWORK_CONFIGURATOR_COMPATIBLE
0 commit comments