Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 1 | #ifndef AOS_STARTER_STARTER_RPC_LIB_H_ |
| 2 | #define AOS_STARTER_STARTER_RPC_LIB_H_ |
| 3 | |
| 4 | #include <chrono> |
milind upadhyay | a87957a | 2021-03-06 20:46:30 -0800 | [diff] [blame] | 5 | #include <optional> |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 6 | |
| 7 | #include "aos/configuration.h" |
| 8 | #include "aos/starter/starter_generated.h" |
| 9 | #include "aos/starter/starter_rpc_generated.h" |
| 10 | |
| 11 | namespace aos { |
| 12 | namespace starter { |
| 13 | |
| 14 | // Finds the status of an individual application within a starter status message |
| 15 | // Returns nullptr if no application found by the given name. |
| 16 | const aos::starter::ApplicationStatus *FindApplicationStatus( |
| 17 | const aos::starter::Status &status, std::string_view name); |
| 18 | |
milind upadhyay | 4272f38 | 2021-04-07 18:03:08 -0700 | [diff] [blame] | 19 | // Checks if the name is an executable name and if it is, it returns that |
| 20 | // application's name, otherwise returns name as given |
| 21 | std::string_view FindApplication(const std::string_view &name, |
| 22 | const aos::Configuration *config); |
| 23 | |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 24 | // Sends the given command to the application with the name name. Creates a |
| 25 | // temporary event loop from the provided config for sending the command and |
| 26 | // receiving back status messages. Returns true if the command executed |
| 27 | // successfully, or false otherwise. Returns false if the desired state was not |
| 28 | // achieved within timeout. |
| 29 | bool SendCommandBlocking(aos::starter::Command, std::string_view name, |
| 30 | const aos::Configuration *config, |
| 31 | std::chrono::milliseconds timeout); |
| 32 | |
Austin Schuh | e4b748a | 2021-10-16 14:19:58 -0700 | [diff] [blame^] | 33 | // Sends lots of commands and waits for them all to succeed. There must not be |
| 34 | // more than 1 conflicting command in here which modifies the state of a single |
| 35 | // application otherwise it will never succeed. An example is having both a |
| 36 | // start and stop command for a single application. |
| 37 | bool SendCommandBlocking( |
| 38 | std::vector<std::pair<aos::starter::Command, std::string_view>> commands, |
| 39 | const aos::Configuration *config, std::chrono::milliseconds timeout); |
| 40 | |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 41 | // Fetches the status of the application with the given name. Creates a |
| 42 | // temporary event loop from the provided config for fetching. Returns an empty |
| 43 | // flatbuffer if the application is not found. |
| 44 | const aos::FlatbufferDetachedBuffer<aos::starter::ApplicationStatus> GetStatus( |
| 45 | std::string_view name, const aos::Configuration *config); |
| 46 | |
Philipp Schrader | 0853749 | 2021-01-23 16:17:55 -0800 | [diff] [blame] | 47 | // Fetches the entire status message of starter. Creates a temporary event loop |
| 48 | // from the provided config for fetching. |
milind upadhyay | 4272f38 | 2021-04-07 18:03:08 -0700 | [diff] [blame] | 49 | std::optional<const aos::FlatbufferVector<aos::starter::Status>> |
| 50 | GetStarterStatus(const aos::Configuration *config); |
Philipp Schrader | 0853749 | 2021-01-23 16:17:55 -0800 | [diff] [blame] | 51 | |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 52 | } // namespace starter |
| 53 | } // namespace aos |
| 54 | |
| 55 | #endif // AOS_STARTER_STARTER_RPC_LIB_H_ |