ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
poweroff.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 #
10 */
11 
12 #include <tamtypes.h>
13 #include <errno.h>
14 #include <kernel.h>
15 #include <sifrpc.h>
16 #include <loadfile.h>
17 #include <stdio.h>
18 
19 #include "libpwroff.h"
20 
21 static void poweroffCallback(void *arg)
22 {
23  printf("\'hi\' from Poweroff callback!\n");
24 
25  //Close all files and unmount all partitions.
26  //close(fd);
27 
28  //If you use PFS, close all files and unmount all partitions.
29  //fileXioDevctl("pfs:", PDIOC_CLOSEALL, NULL, 0, NULL, 0)
30 
31  //Shut down DEV9, if you used it.
32  //while(fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0) < 0){};
33 
34  printf("Shutdown!");
36 }
37 
38 int main(int argc, char *argv[])
39 {
40  int result;
41 
42  SifInitRpc(0);
43 
44  //Load modules.
46  if((result = SifLoadModule("host:poweroff.irx", 0, NULL)) < 0) {
47  printf("Could not load \"host:poweroff.irx\": %d\n", result);
48  return ENOENT;
49  }
50 
51  printf( "Welcome to the poweroff sample!\n\n");
52 
53  /* Poweroff is a library that substitutes for the missing poweroff
54  functionality in rom0:CDVDMAN, which is offered by newer CDVDMAN
55  modules (i.e. sceCdPoweroff). Other than allowing the PlayStation 2
56  to be switched off via software means, this is used to safeguard
57  against the user switching off/resetting the console before data
58  can be completely written to disk. */
59 
60  //Initialize poweroff library
61  poweroffInit();
62 
63  //If necessary, change thread priority.
64  //poweroffChangeThreadPriority(POWEROFF_THREAD_PRIORITY);
65 
66  //Set callback function
68 
69  /* The library has been initialized and a callback has been registered.
70  The callback thread runs at priority POWEROFF_THREAD_PRIORITY by default,
71  which can be changed with a call to poweroffChangeThreadPriority. */
72 
73  SleepThread();
74 
75  SifExitRpc();
76 
77  return 0;
78 }
#define ENOENT
Definition: errno.h:22
int SifLoadModule(const char *path, int arg_len, const char *args)
int SifLoadFileInit(void)
s32 SleepThread(void)
s32 result
Definition: rpc_client.c:23
static void poweroffCallback(void *arg)
Definition: poweroff.c:21
int main(int argc, char *argv[])
Definition: poweroff.c:38
void SifInitRpc(int mode)
void SifExitRpc(void)
void poweroffSetCallback(poweroff_callback cb, void *arg)
Definition: poweroff.c:95
int poweroffInit(void)
Definition: poweroff.c:57
void poweroffShutdown(void)
Definition: poweroff.c:103
#define NULL
Definition: tamtypes.h:91