@@ -36,10 +36,8 @@ bool AgentsManagerClass::begin() {
36
36
}
37
37
38
38
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 ;
43
41
}
44
42
if ((*agent)->begin () == ConfiguratorAgent::AgentConfiguratorStates::ERROR) {
45
43
DEBUG_ERROR (" AgentsManagerClass::%s agent type %d fails" , __FUNCTION__, (int )(*agent)->getAgentType ());
@@ -64,21 +62,51 @@ AgentsManagerStates AgentsManagerClass::poll() {
64
62
return _state;
65
63
}
66
64
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) {
69
69
return ;
70
70
}
71
- _bleAgentEnabled = enable;
72
71
72
+ _enabledAgents[(int )type] = enable;
73
73
if (enable) {
74
- startBLEAgent ( );
74
+ startAgent (type );
75
75
} else {
76
- stopBLEAgent ( );
76
+ stopAgent (type );
77
77
}
78
78
}
79
79
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 ;
82
110
}
83
111
84
112
bool AgentsManagerClass::end () {
@@ -187,11 +215,12 @@ AgentsManagerClass::AgentsManagerClass():
187
215
_returnNetworkSettingsCb{ nullptr },
188
216
_selectedAgent{ nullptr },
189
217
_instances{ 0 },
190
- _bleAgentEnabled{ true },
191
218
_initStatusMsg{ StatusMessage::NONE },
192
219
_statusRequest{ .completion = 0 , .pending = false , .key = RequestType::NONE },
193
220
_state{ AgentsManagerStates::END }
194
- {}
221
+ {
222
+ memset (_enabledAgents, 0x01 , sizeof (_enabledAgents));
223
+ }
195
224
196
225
AgentsManagerStates AgentsManagerClass::handleInit () {
197
226
AgentsManagerStates nextState = _state;
@@ -369,38 +398,17 @@ bool AgentsManagerClass::sendStatus(StatusMessage msg) {
369
398
void AgentsManagerClass::handlePeerDisconnected () {
370
399
// Peer disconnected, restore all stopped agents
371
400
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
+
372
406
if (*agent != _selectedAgent) {
373
- if ((*agent)->getAgentType () == ConfiguratorAgent::AgentTypes::BLE && !_bleAgentEnabled) {
374
- continue ;
375
- }
376
407
(*agent)->begin ();
377
408
}
378
409
}
379
410
_selectedAgent = nullptr ;
380
411
return ;
381
412
}
382
413
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
-
406
414
#endif // NETWORK_CONFIGURATOR_COMPATIBLE
0 commit comments