My Project
shell_loop_all.cpp
1 /*
2  * uuid-console - Microcontroller console shell
3  * Copyright 2019,2021 Simon Arlott
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <uuid/console.h>
20 
21 #include <memory>
22 #include <set>
23 
24 namespace uuid {
25 
26 namespace console {
27 
28 std::set<std::shared_ptr<Shell>>& Shell::registered_shells() {
29  static std::set<std::shared_ptr<Shell>> shells;
30 
31  return shells;
32 }
33 
35  auto& shells = registered_shells();
36 
37  for (auto shell = shells.begin(); shell != shells.end(); ) {
38  shell->get()->loop_one();
39 
40  // This avoids copying the shared_ptr every time loop_one() is called
41  if (!shell->get()->running()) {
42  shell = shells.erase(shell);
43  } else {
44  shell++;
45  }
46  }
47 }
48 
49 } // namespace console
50 
51 } // namespace uuid
uuid
Common utilities.
Definition: get_uptime_ms.cpp:28
uuid::console::Shell::registered_shells
static std::set< std::shared_ptr< Shell > > & registered_shells()
Get registered running shells to be executed.
Definition: shell_loop_all.cpp:28
uuid::console::Shell::loop_all
static void loop_all()
Loop through all registered shell objects.
Definition: shell_loop_all.cpp:34