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 
22 Shutdown::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 
31 {
32 }
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 }
Shutdown.h
Shutdown::~Shutdown
virtual ~Shutdown()
Destructor.
Definition: Shutdown.cpp:30
PrivExec
API::Result PrivExec(const PrivOperation op, const Address param=0)
Prototype for user applications.
Definition: PrivExec.h:52
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Shutdown::Shutdown
Shutdown(int argc, char **argv)
Constructor.
Definition: Shutdown.cpp:22
Application::Success
@ Success
Definition: Application.h:55
Application::arguments
const ArgumentContainer & arguments() const
Get program arguments.
Definition: Application.cpp:112
Shutdown::exec
virtual Result exec()
Execute the application.
Definition: Shutdown.cpp:34
ArgumentParser::setDescription
void setDescription(const String &desc)
Set program description.
Definition: ArgumentParser.cpp:95
RebootSystem
@ RebootSystem
Definition: PrivExec.h:37
printf
int printf(const char *format,...)
Output a formatted string to standard output.
Definition: printf.cpp:22
stdio.h
Application::Result
Result
Result codes.
Definition: Application.h:53
ArgumentParser::registerFlag
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
Definition: ArgumentParser.cpp:100
Application::parser
ArgumentParser & parser()
Get program arguments parser.
Definition: Application.cpp:102
ShutdownSystem
@ ShutdownSystem
Definition: PrivExec.h:38