Ticket #9063: psp_suspend_cleaned.diff
File psp_suspend_cleaned.diff, 22.8 KB (added by , 15 years ago) |
---|
-
backends/platform/psp/psp_main.cpp
31 31 #include <pspdebug.h> 32 32 #endif 33 33 34 #include <psppower.h> 35 34 36 #include <common/system.h> 35 37 #include <engines/engine.h> 36 38 #include <base/main.h> 37 39 #include <base/plugins.h> 40 #include "backends/platform/psp/powerman.h" 38 41 42 39 43 #include "osys_psp_gu.h" 40 44 #include "./trace.h" 41 45 … … 91 95 #endif 92 96 93 97 /* Exit callback */ 94 SceKernelCallbackFunction exit_callback(int /*arg1*/, int /*arg2*/, void * /*common*/) {98 int exit_callback(void) { 95 99 sceKernelExitGame(); 96 100 return 0; 97 101 } 98 102 103 /* Function for handling suspend/resume */ 104 void power_callback(int , int powerinfo) 105 { 106 PowerManager *pm = &(PowerManager::instance()); 107 108 if (powerinfo & PSP_POWER_CB_POWER_SWITCH || powerinfo & PSP_POWER_CB_SUSPENDING) { 109 pm->suspend(); 110 } else if (powerinfo & PSP_POWER_CB_RESUME_COMPLETE) { 111 pm->resume(); 112 } 113 } 114 99 115 /* Callback thread */ 100 116 int CallbackThread(SceSize /*size*/, void *arg) { 101 117 int cbid; 102 118 103 119 cbid = sceKernelCreateCallback("Exit Callback", (SceKernelCallbackFunction)exit_callback, NULL); 104 120 sceKernelRegisterExitCallback(cbid); 121 /* Set up callbacks for PSPIoStream */ 105 122 123 cbid = sceKernelCreateCallback("Power Callback", (SceKernelCallbackFunction)power_callback, 0); 124 if (cbid >= 0) { 125 if(scePowerRegisterCallback(-1, cbid) < 0) { 126 PSPDebugTrace("SetupCallbacks(): Couldn't register callback for power_callback\n"); 127 } 128 } 129 else { 130 PSPDebugTrace("SetupCallbacks(): Couldn't create a callback for power_callback\n"); 131 } 132 106 133 sceKernelSleepThreadCB(); 107 134 return 0; 108 135 } … … 119 146 120 147 #undef main 121 148 int main(void) { 149 150 PowerManager::instance(); // Setup power manager 151 122 152 SetupCallbacks(); 123 153 124 154 static const char *argv[] = { "scummvm", NULL }; … … 131 161 132 162 g_system->quit(); // TODO: Consider removing / replacing this! 133 163 164 PowerManager::destroy(); // get rid of PowerManager 165 134 166 sceKernelSleepThread(); 135 167 136 168 return res; -
backends/platform/psp/module.mk
1 1 MODULE := backends/platform/psp 2 2 3 3 MODULE_OBJS := \ 4 powerman.o \ 4 5 psp_main.o \ 5 6 osys_psp.o \ 6 7 osys_psp_gu.o \ -
backends/platform/psp/psp.spec
1 1 %rename lib old_lib 2 2 *lib: 3 %(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpsp sdk -lpspuser3 %(old_lib) -lpspdebug -lpspgu -lpspctrl -lpspge -lpspdisplay -lpsphprm -lpspsdk -lpsprtc -lpspaudio -lc -lpspuser -lpsputility -lpspkernel -lpspnet_inet -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower -
backends/platform/psp/powerman.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-13-1/backends/platform/psp/psp_main.cpp $ 22 * $Id: psp_main.cpp 34827 2008-10-19 21:06:26Z fingolfin $ 23 * 24 */ 25 26 #include "powerman.h" 27 #include "trace.h" 28 29 DECLARE_SINGLETON(PowerManager); 30 31 /******************************************* 32 * 33 * Constructor 34 * 35 ********************************************/ 36 PowerManager::PowerManager() { 37 _flagMutex = NULL; /* Init mutex handle */ 38 _listMutex = NULL; /* Init mutex handle */ 39 _cond = NULL; /* Init condition variable */ 40 41 _cond = SDL_CreateCond(); 42 if (_cond <= 0) { 43 PSPDebugTrace("PowerManager::PowerManager(): Couldn't create cond\n"); 44 } 45 46 _flagMutex = SDL_CreateMutex(); 47 if (_flagMutex <= 0) { 48 PSPDebugTrace("PowerManager::PowerManager(): Couldn't create flagMutex\n"); 49 } 50 51 _listMutex = SDL_CreateMutex(); 52 if (_listMutex <= 0) { 53 PSPDebugTrace("PowerManager::PowerManager(): Couldn't create listMutex\n"); 54 } 55 56 _suspendFlag = false; 57 } 58 59 /******************************************* 60 * 61 * Function to register to be notified when suspend/resume time comes 62 * 63 ********************************************/ 64 int PowerManager::registerSuspend(Suspendable *item) { 65 // Register in list 66 if (SDL_mutexP(_listMutex) != 0) { 67 PSPDebugTrace("PowerManager::registerSuspend(): Couldn't lock _listMutex %d\n", _listMutex); 68 } 69 70 _suspendList.push_front(item); 71 72 if (SDL_mutexV(_listMutex) != 0) { 73 PSPDebugTrace("PowerManager::registerSuspend(): Couldn't unlock _listMutex %d\n", _listMutex); 74 } 75 76 return 0; 77 } 78 79 /******************************************* 80 * 81 * Function to unregister to be notified when suspend/resume time comes 82 * 83 ********************************************/ 84 int PowerManager::unregisterSuspend(Suspendable *item) { 85 // Unregister from stream list 86 if (SDL_mutexP(_listMutex) != 0) { 87 PSPDebugTrace("PowerManager::unregisterSuspend(): Couldn't unlock _listMutex %d\n", _listMutex); 88 } 89 90 _suspendList.remove(item); 91 92 if (SDL_mutexV(_listMutex) != 0) { 93 PSPDebugTrace("PowerManager::unregisterSuspend(): Couldn't unlock _listMutex %d\n", _listMutex); 94 } 95 96 return 0; 97 } 98 99 /******************************************* 100 * 101 * Destructor 102 * 103 ********************************************/ 104 PowerManager::~PowerManager() { 105 SDL_DestroyCond(_cond); 106 _cond = 0; 107 108 SDL_DestroyMutex(_flagMutex); 109 _flagMutex = 0; 110 111 SDL_DestroyMutex(_listMutex); 112 _listMutex = 0; 113 } 114 115 116 /******************************************* 117 * 118 * Function to be called by threads wanting to block on the PSP entering suspend 119 * 120 ********************************************/ 121 int PowerManager::blockOnSuspend() const { 122 int ret = PowerManager::NotBlocked; 123 124 if (SDL_mutexP(_flagMutex) != 0) { 125 PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't lock flagMutex %d\n", _flagMutex); 126 ret = PowerManager::Error; 127 } 128 129 // Check the access flag 130 if (_suspendFlag) { 131 ret = PowerManager::Blocked; 132 133 // If it's true, we wait for a signal to continue 134 if (SDL_CondWait(_cond, _flagMutex) != 0) { 135 PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't wait on cond %d\n", _cond); 136 } 137 } 138 139 if (SDL_mutexV(_flagMutex) != 0) { 140 PSPDebugTrace("PowerManager::blockOnSuspend(): Couldn't unlock flagMutex %d\n", _flagMutex); 141 ret = PowerManager::Error; 142 } 143 144 return ret; 145 } 146 147 /******************************************* 148 * 149 * Callback function to be called to put every Suspendable to suspend 150 * 151 ********************************************/ 152 int PowerManager::suspend() { 153 int ret = 0; 154 155 // First we set the suspend flag to true 156 if (SDL_mutexP(_flagMutex) != 0) { 157 PSPDebugTrace("PowerManager::suspend(): Couldn't lock flagMutex %d\n", _flagMutex); 158 ret = -1; 159 } 160 161 _suspendFlag = true; 162 163 if (SDL_mutexV(_flagMutex) != 0) { 164 PSPDebugTrace("PowerManager::suspend(): Couldn't unlock flagMutex %d\n", _flagMutex); 165 ret = -1; 166 } 167 168 // Loop over list, calling suspend() 169 if (SDL_mutexP(_listMutex) != 0) { 170 PSPDebugTrace("PowerManager::suspend(): Couldn't lock listMutex %d\n", _listMutex); 171 ret = -1; 172 } 173 174 Common::List<Suspendable *>::iterator i = _suspendList.begin(); 175 176 for(; i != _suspendList.end(); i++) { 177 (*i)->suspend(); 178 } 179 180 if (SDL_mutexV(_listMutex) != 0) { 181 PSPDebugTrace("PowerManager::suspend(): Couldn't unlock listMutex %d\n", _listMutex); 182 ret = -1; 183 } 184 185 return ret; 186 } 187 188 /******************************************* 189 * 190 * Callback function to resume every Suspendable 191 * 192 ********************************************/ 193 int PowerManager::resume() { 194 int ret = 0; 195 196 // First we notify our Suspendables. Loop over list, calling resume() 197 if (SDL_mutexP(_listMutex) != 0) { 198 PSPDebugTrace("PowerManager::resume(): Couldn't lock listMutex %d\n", _listMutex); 199 ret = -1; 200 } 201 202 Common::List<Suspendable *>::iterator i = _suspendList.begin(); 203 204 for (; i != _suspendList.end(); i++) { 205 (*i)->resume(); 206 } 207 208 if (SDL_mutexV(_listMutex) != 0) { 209 PSPDebugTrace("PowerManager::resume(): Couldn't unlock listMutex %d\n", _listMutex); 210 ret = -1; 211 } 212 213 // Now we set the suspend flag to false 214 if (SDL_mutexP(_flagMutex) != 0) { 215 PSPDebugTrace("PowerManager::resume(): Couldn't lock flagMutex %d\n", _flagMutex); 216 ret = -1; 217 } 218 _suspendFlag = false; 219 220 // Signal the other threads to wake up 221 if( SDL_CondBroadcast(_cond) != 0) { 222 PSPDebugTrace("PowerManager::resume(): Couldn't broadcast condition %d\n", _cond); 223 ret = -1; 224 } 225 226 if (SDL_mutexV(_flagMutex) != 0) { 227 PSPDebugTrace("PowerManager::resume(): Couldn't unlock flagMutex %d\n", _flagMutex); 228 ret = -1; 229 } 230 231 return ret; 232 } -
backends/platform/psp/Makefile
75 75 CXXFLAGS+= -DUSE_VORBIS -DUSE_TREMOR 76 76 LIBS += -lvorbisidec 77 77 78 LIBS += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpsp sdk -lpspuser78 LIBS += `$(PSPBIN)/sdl-config --libs` -lz -lstdc++ -lc -lpspdisplay -lpspgu -lpspctrl -lpspsdk -lpspnet -lpspnet_inet -lpsputility -lpspuser -lpsppower 79 79 80 80 CXXFLAGS := $(CXXFLAGS) -fno-exceptions -fno-rtti 81 81 82 82 TARGET = scummvm-psp 83 OBJS := psp_main.o \ 83 OBJS := powerman.o \ 84 psp_main.o \ 84 85 osys_psp.o \ 85 86 osys_psp_gu.o \ 86 87 kbd_ss_c.o \ -
backends/platform/psp/powerman.h
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-0-13-1/backends/platform/psp/psp_main.cpp $ 22 * $Id: psp_main.cpp 34827 2008-10-19 21:06:26Z fingolfin $ 23 * 24 */ 25 26 #ifndef POWERMAN_H 27 #define POWERMAN_H 28 29 #include <SDL/SDL_thread.h> 30 #include <SDL/SDL_mutex.h> 31 #include "common/singleton.h" 32 #include "common/list.h" 33 34 /* Implement this class (interface) if you want to use PowerManager's suspend callback functionality */ 35 class Suspendable 36 { 37 public: 38 Suspendable() {} 39 virtual ~Suspendable() {} 40 virtual int suspend() = 0; 41 virtual int resume() = 0; 42 }; 43 44 /****************************************************************************************************** 45 * 46 * This class will call a Suspendable when the PSP goes to suspend/resumes. It also provides the ability to block 47 * a thread when the PSP is going to suspend/suspending, and to wake it up when the PSP is resumed. 48 * This ability is very useful for managing the PSPIoStream class, but may be found useful by other classes as well. 49 * 50 *******************************************************************************************************/ 51 class PowerManager: public Common::Singleton<PowerManager> 52 { 53 private: 54 friend class Common::Singleton<PowerManager>; 55 PowerManager(); 56 virtual ~PowerManager(); 57 58 Common::List<Suspendable *> _suspendList; /* list to register in */ 59 60 bool _suspendFlag; /* protected variable */ 61 SDL_mutex *_flagMutex; /* mutex to access access flag */ 62 SDL_mutex *_listMutex; /* mutex to access Suspendable list */ 63 SDL_cond *_cond; /* signal to synchronize accessing threads */ 64 65 public: 66 int blockOnSuspend() const; /* block if suspending */ 67 int registerSuspend(Suspendable *item); /* register to be called to suspend/resume */ 68 int unregisterSuspend(Suspendable *item); /* remove from suspend/resume list */ 69 int suspend(); /* callback to have all items in list suspend */ 70 int resume(); /* callback to have all items in list resume */ 71 72 enum 73 { 74 Error = -1, 75 NotBlocked = 0, 76 Blocked = 1 77 }; 78 79 }; 80 81 #endif /* POWERMAN_H */ -
backends/fs/psp/psp-stream.h
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * $URL: https://scummvm.svn.sourceforge.net:443/svnroot/scummvm/scummvm/trunk/backends/fs/stdiostream.h $ 22 * $Id: stdiostream.h 34549 2008-09-14 22:28:53Z wjpalenstijn $ 23 * 24 */ 25 26 #ifndef PSPSTREAM_H_ 27 #define PSPSTREAM_H_ 28 29 #include "backends/fs/stdiostream.h" 30 #include "backends/platform/psp/powerman.h" 31 #include "common/list.h" 32 33 34 class PSPIoStream : public StdioStream, public Suspendable { 35 protected: 36 /** File handle to the actual file. */ 37 Common::String _path; /* Need to maintain for reopening after suspend */ 38 bool _writeMode; /* "" */ 39 unsigned int _pos; /* "" */ 40 static PowerManager *pm; 41 42 43 public: 44 /** 45 * Given a path, invoke fopen on that path and wrap the result in a 46 * StdioStream instance. 47 */ 48 static PSPIoStream *makeFromPath(const Common::String &path, bool writeMode); 49 50 PSPIoStream(void *handle, const Common::String &path, bool writeMode); 51 virtual ~PSPIoStream(); 52 53 bool err() const; 54 void clearErr(); 55 bool eos() const; 56 57 virtual uint32 write(const void *dataPtr, uint32 dataSize); 58 virtual bool flush(); 59 60 virtual int32 pos() const; 61 virtual int32 size() const; 62 virtual bool seek(int32 offs, int whence = SEEK_SET); 63 virtual uint32 read(void *dataPtr, uint32 dataSize); 64 65 int suspend(); /* Suspendable interface */ 66 int resume(); /* " " */ 67 }; 68 69 #endif /* PSPSTREAM_H_ */ -
backends/fs/psp/psp-fs.cpp
26 26 27 27 #include "engines/engine.h" 28 28 #include "backends/fs/abstract-fs.h" 29 #include "backends/fs/ stdiostream.h"29 #include "backends/fs/psp/psp-stream.h" 30 30 31 31 #include <sys/stat.h> 32 32 #include <unistd.h> … … 35 35 36 36 #define ROOT_PATH "ms0:/" 37 37 38 #include "backends/platform/psp/trace.h" 38 39 /** 39 40 * Implementation of the ScummVM file system API based on PSPSDK API. 40 41 * … … 166 167 } 167 168 168 169 Common::SeekableReadStream *PSPFilesystemNode::createReadStream() { 169 return StdioStream::makeFromPath(getPath().c_str(), false);170 return PSPIoStream::makeFromPath(getPath(), false); 170 171 } 171 172 172 173 Common::WriteStream *PSPFilesystemNode::createWriteStream() { 173 return StdioStream::makeFromPath(getPath().c_str(), true);174 return PSPIoStream::makeFromPath(getPath(), true); 174 175 } 175 176 176 177 #endif //#ifdef __PSP__ -
backends/fs/psp/psp-stream.cpp
1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * $URL: https://scummvm.svn.sourceforge.net:443/svnroot/scummvm/scummvm/trunk/backends/fs/stdiostream.cpp $ 22 * $Id: stdiostream.cpp 39143 2009-03-06 00:26:48Z sunmax $ 23 * 24 */ 25 26 #ifdef __PSP__ 27 28 #include "backends/fs/psp/psp-stream.h" 29 #include "backends/platform/psp/trace.h" 30 #include <errno.h> 31 32 /* For static variable */ 33 PowerManager *PSPIoStream::pm = 0; 34 35 PSPIoStream::PSPIoStream(void *handle, const Common::String &path, bool writeMode) 36 : StdioStream(handle), _path(path), _writeMode(writeMode) { 37 assert(!path.empty()); 38 39 if(pm == 0) pm = &(PowerManager::instance()); 40 41 pm->registerSuspend(this); 42 } 43 44 PSPIoStream::~PSPIoStream() { 45 pm->unregisterSuspend(this); 46 47 fclose((FILE *)_handle); 48 } 49 50 bool PSPIoStream::err() const { 51 pm->blockOnSuspend(); 52 return ferror((FILE *)_handle) != 0; 53 } 54 55 void PSPIoStream::clearErr() { 56 pm->blockOnSuspend(); 57 clearerr((FILE *)_handle); 58 } 59 60 bool PSPIoStream::eos() const { 61 pm->blockOnSuspend(); 62 return feof((FILE *)_handle) != 0; 63 } 64 65 int32 PSPIoStream::pos() const { 66 pm->blockOnSuspend(); 67 return ftell((FILE *)_handle); 68 } 69 70 int32 PSPIoStream::size() const { 71 pm->blockOnSuspend(); 72 73 int32 oldPos = ftell((FILE *)_handle); 74 fseek((FILE *)_handle, 0, SEEK_END); 75 int32 length = ftell((FILE *)_handle); 76 fseek((FILE *)_handle, oldPos, SEEK_SET); 77 78 return length; 79 } 80 81 bool PSPIoStream::seek(int32 offs, int whence) { 82 int ret = 0; 83 84 // Check if we can access the file 85 pm->blockOnSuspend(); 86 87 // Act. If we fail, maybe it was because of a suspend 88 if ((ret = fseek((FILE *)_handle, offs, whence)) != 0 && (pm->blockOnSuspend() == PowerManager::Blocked)) { 89 ret = fseek((FILE *)_handle, offs, whence); 90 } 91 92 return ret == 0; 93 } 94 95 uint32 PSPIoStream::read(void *ptr, uint32 len) { 96 int ret = 0; 97 pm->blockOnSuspend(); 98 99 // Act. If we fail, maybe it was because of a suspend 100 ret = fread((byte *)ptr, 1, len, (FILE *)_handle); 101 if (ferror((FILE *)_handle) && pm->blockOnSuspend() == PowerManager::Blocked) { 102 clearerr((FILE *)_handle); 103 fseek((FILE *)_handle, -ret, SEEK_CUR); 104 ret = fread((byte *)ptr, 1, len, (FILE *)_handle); 105 } 106 return ret; 107 108 } 109 110 uint32 PSPIoStream::write(const void *ptr, uint32 len) { 111 int ret = 0; 112 113 pm->blockOnSuspend(); 114 115 // Act. If we fail, maybe it was because of a suspend 116 ret = fwrite(ptr, 1, len, (FILE *)_handle); 117 if (ferror((FILE *)_handle) && (pm->blockOnSuspend() == PowerManager::Blocked)) { 118 clearerr((FILE *)_handle); 119 fseek((FILE *)_handle, -ret, SEEK_CUR); 120 ret = fwrite(ptr, 1, len, (FILE *)_handle); 121 } 122 123 return ret; 124 } 125 126 bool PSPIoStream::flush() { 127 int ret = 0; 128 129 pm->blockOnSuspend(); 130 131 // Act. If we fail, maybe it was because of a suspend 132 if ((ret = fflush((FILE *)_handle)) != 0 && pm->blockOnSuspend() == PowerManager::Blocked) { 133 ret = fflush((FILE *)_handle); 134 } 135 136 return ret == 0; 137 } 138 139 PSPIoStream *PSPIoStream::makeFromPath(const Common::String &path, bool writeMode) { 140 FILE *handle = fopen(path.c_str(), writeMode ? "wb" : "rb"); 141 142 if (handle) 143 return new PSPIoStream(handle, path, writeMode); 144 145 return 0; 146 } 147 148 149 int PSPIoStream::suspend() { 150 // Save our position 151 _pos = ftell((FILE *)_handle); 152 153 // close our file descriptor 154 fclose((FILE *)_handle); 155 156 return 0; 157 } 158 159 int PSPIoStream::resume() { 160 int ret = 0; 161 162 // We reopen our file descriptor 163 _handle = fopen(_path.c_str(), _writeMode ? "wb" : "rb"); 164 if (_handle <= 0) { 165 PSPDebugTrace("PSPIoStream::resume(): Couldn't reopen file %s\n", _path.c_str()); 166 ret = -1;; 167 } 168 169 // Resume our previous position 170 fseek((FILE *)_handle, _pos, SEEK_SET); 171 172 return ret; 173 } 174 175 176 177 #endif /* __PSP__ */ -
backends/module.mk
11 11 fs/posix/posix-fs-factory.o \ 12 12 fs/ps2/ps2-fs-factory.o \ 13 13 fs/psp/psp-fs-factory.o \ 14 fs/psp/psp-stream.o \ 14 15 fs/symbian/symbian-fs-factory.o \ 15 16 fs/windows/windows-fs-factory.o \ 16 17 fs/wii/wii-fs-factory.o \