FreeNOS
Shutdown.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/User.h>
19#include <stdio.h>
20#include "Shutdown.h"
21
22Shutdown::Shutdown(int argc, char **argv)
23 : POSIXApplication(argc, argv)
24{
25 parser().setDescription("Power off or restart the system");
26 parser().registerFlag('p', "poweroff", "Power off the system (the default)");
27 parser().registerFlag('r', "reboot", "Restart the system");
28}
29
33
35{
36 // If no arguments given, power off the system. */
37 if (arguments().getFlags().count() == 0)
38 {
39 printf("Power off\r\n");
41 }
42 // Print everything?
43 else if (arguments().get("reboot"))
44 {
45 printf("Reboot\r\n");
47 }
48
49 return Success;
50}
Result
Result codes.
Definition Application.h:54
const ArgumentContainer & arguments() const
Get program arguments.
ArgumentParser & parser()
Get program arguments parser.
void setDescription(const String &desc)
Set program description.
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
POSIX-compatible application.
virtual ~Shutdown()
Destructor.
Definition Shutdown.cpp:30
virtual Result exec()
Execute the application.
Definition Shutdown.cpp:34
Shutdown(int argc, char **argv)
Constructor.
Definition Shutdown.cpp:22
API::Result PrivExec(const PrivOperation op, const Address param=0)
Prototype for user applications.
Definition PrivExec.h:52
@ RebootSystem
Definition PrivExec.h:37
@ ShutdownSystem
Definition PrivExec.h:38
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22