| #ifndef PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SAFEPOWER_AGENT_H_ |
| #define PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SAFEPOWER_AGENT_H_ |
| |
| #include <memory> |
| #include <ostream> |
| #include <utility> |
| |
| #include "action_context.h" |
| #include "safepower_agent.grpc.pb.h" |
| #include "safepower_agent.pb.h" |
| #include "service_impl.h" |
| #include "state_updater.h" |
| #include "absl/base/nullability.h" |
| #include "grpcpp/server_context.h" |
| #include "grpcpp/support/server_callback.h" |
| |
| namespace safepower_agent { |
| class SafepowerLocalAgentImpl |
| : public safepower_agent_proto::SafepowerLocalAgent::CallbackService { |
| public: |
| // system_state_updater is used to update the state of the local node. |
| // global_system_state_updater is used to update the state of the entire |
| // machine (updates are relayed back to the node by the safepower service). |
| // The action_context_manager should be pre-initialized with the supported |
| // actions and their implementations. |
| explicit SafepowerLocalAgentImpl( |
| const |
| std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>>& |
| system_state_updater, |
| const |
| std::shared_ptr<StateUpdater<safepower_agent_proto::SystemState>>& |
| global_system_state_updater, |
| std::unique_ptr<ActionContextManager> action_context_manager) |
| : service_impl_(system_state_updater, global_system_state_updater, |
| std::move(action_context_manager)) {} |
| |
| grpc::ServerUnaryReactor* StartAction( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::StartActionRequest* request, |
| safepower_agent_proto::StartActionResponse* response) override; |
| |
| grpc::ServerWriteReactor<safepower_agent_proto::ActionStateLog>* |
| MonitorAction( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::MonitorActionRequest* request) override; |
| |
| grpc::ServerWriteReactor<safepower_agent_proto::SystemState>* MonitorState( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::MonitorStateRequest* request) override; |
| |
| grpc::ServerUnaryReactor* GetSupportedActions( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::GetSupportedActionsRequest* request, |
| safepower_agent_proto::GetSupportedActionsResponse* response) override; |
| |
| grpc::ServerUnaryReactor* GetFeatures( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::GetFeaturesRequest* request, |
| safepower_agent_proto::GetFeaturesResponse* response) override; |
| |
| grpc::ServerUnaryReactor* SystemStateUpdate( |
| grpc::CallbackServerContext* context, |
| const safepower_agent_proto::SystemState* request, |
| safepower_agent_proto::SystemStateUpdateResponse* response) override; |
| |
| |
| // Dumps the internal state of the SafepowerLocalAgentImpl to the provided |
| // stream. |
| void DumpSafepowerState(std::ostream& os) const; |
| |
| // Runs the event loop. Blocks until Stop() is called. |
| void Run(); |
| |
| // Stops the event loop. |
| void Stop(); |
| |
| private: |
| ServiceImpl service_impl_; |
| }; |
| |
| } // namespace safepower_agent |
| |
| #endif // PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_SAFEPOWER_AGENT_H_ |