blob: fdea0b7a0e4a8ac82df9d31c7736cfd695cdf68e [file] [log] [blame]
Tyler Chatowa79419d2020-08-12 20:12:11 -07001#ifndef AOS_STARTER_STARTER_RPC_LIB_H_
2#define AOS_STARTER_STARTER_RPC_LIB_H_
3
4#include <chrono>
milind upadhyaya87957a2021-03-06 20:46:30 -08005#include <optional>
Tyler Chatowa79419d2020-08-12 20:12:11 -07006
7#include "aos/configuration.h"
8#include "aos/starter/starter_generated.h"
9#include "aos/starter/starter_rpc_generated.h"
10
11namespace aos {
12namespace 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.
16const aos::starter::ApplicationStatus *FindApplicationStatus(
17 const aos::starter::Status &status, std::string_view name);
18
milind upadhyay4272f382021-04-07 18:03:08 -070019// Checks if the name is an executable name and if it is, it returns that
20// application's name, otherwise returns name as given
21std::string_view FindApplication(const std::string_view &name,
22 const aos::Configuration *config);
23
Tyler Chatowa79419d2020-08-12 20:12:11 -070024// 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.
29bool SendCommandBlocking(aos::starter::Command, std::string_view name,
30 const aos::Configuration *config,
31 std::chrono::milliseconds timeout);
32
Austin Schuhe4b748a2021-10-16 14:19:58 -070033// 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.
37bool SendCommandBlocking(
38 std::vector<std::pair<aos::starter::Command, std::string_view>> commands,
39 const aos::Configuration *config, std::chrono::milliseconds timeout);
40
Tyler Chatowa79419d2020-08-12 20:12:11 -070041// 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.
44const aos::FlatbufferDetachedBuffer<aos::starter::ApplicationStatus> GetStatus(
45 std::string_view name, const aos::Configuration *config);
46
Philipp Schrader08537492021-01-23 16:17:55 -080047// Fetches the entire status message of starter. Creates a temporary event loop
48// from the provided config for fetching.
milind upadhyay4272f382021-04-07 18:03:08 -070049std::optional<const aos::FlatbufferVector<aos::starter::Status>>
50GetStarterStatus(const aos::Configuration *config);
Philipp Schrader08537492021-01-23 16:17:55 -080051
Tyler Chatowa79419d2020-08-12 20:12:11 -070052} // namespace starter
53} // namespace aos
54
55#endif // AOS_STARTER_STARTER_RPC_LIB_H_