Commit 753b05f7 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add basic infrastructure for NORNSCTL_COMMAND_SHUTDOWN

The nornsctl_send_command function now supports a new nornsctl_command_t
command called NORNSCTL_COMMAND_SHUTDOWN, which is accepted and
acknowledged by the server.
parent 311b9eaa
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ typedef enum {
    NORNSCTL_COMMAND_PING = 1000,
    NORNSCTL_COMMAND_PAUSE_ACCEPT,
    NORNSCTL_COMMAND_RESUME_ACCEPT,
    NORNSCTL_COMMAND_SHUTDOWN,
} nornsctl_command_t;


+4 −0
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ norns::command_type decode_command(::google::protobuf::uint32 type) {
            return command_type::pause_accept;
        case NORNSCTL_COMMAND_RESUME_ACCEPT:
            return command_type::resume_accept;
        case NORNSCTL_COMMAND_SHUTDOWN:
            return command_type::shutdown;
        default:
            return command_type::unknown;
    }
@@ -431,6 +433,8 @@ std::string command_request::to_string() const {
            return "PAUSE_ACCEPT";
        case command_type::resume_accept:
            return "RESUME_ACCEPT";
        case command_type::shutdown:
            return "SHUTDOWN";
        default:
            return "UNKNOWN";
    }
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ enum class command_type {
    ping,
    pause_accept,
    resume_accept,
    shutdown,
    unknown
};

+4 −0
Original line number Diff line number Diff line
@@ -595,6 +595,10 @@ urd::command_handler(const request_ptr base_request) {
                m_is_paused = false;
            }
            break;
        case command_type::shutdown:
            // TODO
            LOGGER_WARN("Shutdown requested!");
            break;
        case command_type::unknown:
            resp->set_error_code(urd_error::bad_args);
            break;
+9 −0
Original line number Diff line number Diff line
@@ -88,5 +88,14 @@ SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") {
                REQUIRE(rv == NORNS_SUCCESS);
            }
        }

        WHEN("a NORNSCTL_COMMAND_SHUTDOWN command is sent") {

            norns_error_t rv = nornsctl_send_command(NORNSCTL_COMMAND_SHUTDOWN, NULL);

            THEN("nornsctl_send_command() returns NORNS_SUCCESS") {
                REQUIRE(rv == NORNS_SUCCESS);
            }
        }
    }
}