/* * Copyright (C) 2014 Pavel Kirienko */ #ifndef UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED #define UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED #include #include #include namespace uavcan { /** * Implement this interface in the application to support the standard node restart service. */ class UAVCAN_EXPORT IRestartRequestHandler { public: virtual ~IRestartRequestHandler() { } /** * This method shall do either: * - restart the local node immediately; * - initiate the restart procedure to complete it asynchronously; * - reject the restart request and return false. * * If the restart requets was accepted, this method shall either return true or don't return at all. */ virtual bool handleRestartRequest(NodeID request_source) = 0; }; /** * Convenience class for supporting the standard node restart service. * Highly recommended to use. */ class UAVCAN_EXPORT RestartRequestServer : Noncopyable { typedef MethodBinder&, protocol::RestartNode::Response&) const> RestartNodeCallback; ServiceServer srv_; IRestartRequestHandler* handler_; void handleRestartNode(const ReceivedDataStructure& request, protocol::RestartNode::Response& response) const; public: explicit RestartRequestServer(INode& node) : srv_(node) , handler_(NULL) { } /** * Restart request handler configuration. * All restart requests will be explicitly rejected if there's no handler installed. */ IRestartRequestHandler* getHandler() const { return handler_; } void setHandler(IRestartRequestHandler* handler) { handler_ = handler; } /** * Starts the server. * Returns negative error code. */ int start(); }; } #endif // UAVCAN_PROTOCOL_RESTART_REQUEST_SERVER_HPP_INCLUDED