diff options
author | Alexander Tkachev | 2016-05-11 15:15:23 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:05:07 +0600 |
commit | 7446ffd73bd184610d550a354a8e252b0b7f334d (patch) | |
tree | 66527d233886549ed881230f275cb3ebeb9c94a4 | |
parent | 52240c68c7301b941f51ea315994ee7e4665707b (diff) | |
download | scummvm-rg350-7446ffd73bd184610d550a354a8e252b0b7f334d.tar.gz scummvm-rg350-7446ffd73bd184610d550a354a8e252b0b7f334d.tar.bz2 scummvm-rg350-7446ffd73bd184610d550a354a8e252b0b7f334d.zip |
CLOUD: Integrate CloudThread into OSystem
Would be changed soon.
-rw-r--r-- | backends/cloud/cloudthread.cpp | 21 | ||||
-rw-r--r-- | backends/cloud/cloudthread.h | 11 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 7 | ||||
-rw-r--r-- | base/main.cpp | 8 | ||||
-rw-r--r-- | common/system.h | 29 |
5 files changed, 67 insertions, 9 deletions
diff --git a/backends/cloud/cloudthread.cpp b/backends/cloud/cloudthread.cpp index f8d93d2baa..813354f43f 100644 --- a/backends/cloud/cloudthread.cpp +++ b/backends/cloud/cloudthread.cpp @@ -23,6 +23,8 @@ #include "cloudthread.h" #include "common/debug.h" #include "common/json.h" +#include "common/system.h" +#include "common/timer.h" void example1(); void example2(); @@ -30,10 +32,10 @@ void example3(); void cloudThread(void *thread) { CloudThread *cloudThread = (CloudThread *)thread; - cloudThread->work(); + cloudThread->handler(); }; -void CloudThread::work() { +void CloudThread::handler() { if (_firstTime) { _firstTime = false; @@ -43,6 +45,21 @@ void CloudThread::work() { } else { } } +void CloudThread::setTimeout(int interval) { + Common::TimerManager *manager = g_system->getTimerManager(); + if (!manager->installTimerProc(cloudThread, interval, this, "Cloud Thread")) + warning("Failed to create cloud thread"); +} + +void CloudThread::unsetTimeout() { + Common::TimerManager *manager = g_system->getTimerManager(); + manager->removeTimerProc(cloudThread); +} + +void CloudThread::start() { + setTimeout(1000000); //in one second +} + /// SimpleJSON examples: using Common::JSON; diff --git a/backends/cloud/cloudthread.h b/backends/cloud/cloudthread.h index ce448b7274..334a163dde 100644 --- a/backends/cloud/cloudthread.h +++ b/backends/cloud/cloudthread.h @@ -23,14 +23,19 @@ #ifndef BACKENDS_CLOUD_CLOUDTHREAD_H #define BACKENDS_CLOUD_CLOUDTHREAD_H -void cloudThread(void *thread); //this one is passed to TimerManager in main() - class CloudThread { + friend void cloudThread(void*); //calls private handler() + bool _firstTime; + + void handler(); + void setTimeout(int interval); + void unsetTimeout(); + public: CloudThread(): _firstTime(true) {}; - void work(); + void start(); }; #endif diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index dca6891fef..84aa5c8421 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -33,6 +33,7 @@ #include "gui/EventRecorder.h" #include "common/taskbar.h" #include "common/textconsole.h" +#include "backends/cloud/cloudthread.h" #include "backends/saves/default/default-saves.h" @@ -158,6 +159,12 @@ void OSystem_SDL::init() { _taskbarManager = new Common::TaskbarManager(); #endif +//TODO: define USE_CLOUD +//#if defined(USE_CLOUD) + if (_cloudThread == 0) + _cloudThread = new CloudThread(); +//#endif + } void OSystem_SDL::initBackend() { diff --git a/base/main.cpp b/base/main.cpp index 593179d80e..ce69117bc6 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -477,10 +477,10 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) { } #endif - CloudThread thread; - Common::TimerManager *manager = system.getTimerManager(); - if (!manager->installTimerProc(cloudThread, 1000000, &thread, "Cloud Thread")) - warning("Failed to create cloud thread"); + //TODO: define USE_CLOUD +//#ifdef USE_CLOUD + system.getCloudThread()->start(); +//#endif // Unless a game was specified, show the launcher dialog if (0 == ConfMan.getActiveDomain()) diff --git a/common/system.h b/common/system.h index 6d185d3075..1af45fb1fc 100644 --- a/common/system.h +++ b/common/system.h @@ -58,6 +58,12 @@ class KeymapperDefaultBindings; #endif } +//TODO: define USE_CLOUD +//TODO: probably move to common and name CloudManager +//#if defined(USE_CLOUD) +class CloudThread; +//#endif + class AudioCDManager; class FilesystemFactory; class PaletteManager; @@ -178,6 +184,16 @@ protected: Common::UpdateManager *_updateManager; #endif +//TODO: define USE_CLOUD +//#if defined(USE_CLOUD) + /** + * No default value is provided for _cloudThread by OSystem. + * + * @note _cloudThread is deleted by the OSystem destructor. + */ + CloudThread *_cloudThread; +//#endif + /** * No default value is provided for _fsFactory by OSystem. * @@ -1116,6 +1132,19 @@ public: } #endif +//TODO: define USE_CLOUD +//#if defined(USE_CLOUD) + /** + * Returns the CloudThread, used to sync save games and + * upload/download files from user's cloud storage. + * + * @return the CloudThread for the current architecture + */ + virtual CloudThread *getCloudThread() { + return _cloudThread; + } +//#endif + /** * Returns the FilesystemFactory object, depending on the current architecture. * |