00001 /* $Id: save_blocker.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2009 - 2012 by Daniel Franke. 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef SAVE_BLOCKER_H_INCLUDED 00017 #define SAVE_BLOCKER_H_INCLUDED 00018 00019 #include "SDL_mutex.h" 00020 00021 #include <cassert> 00022 00023 class play_controller; 00024 00025 /** While any instance of this class exists, attempts to save the game via 00026 * any call to play_controller will be temporarily postponed: the call will 00027 * return immediately without performing the save, but the save method will 00028 * then be reinvoked from this class's destructor. If multiple save attempts 00029 * are performed, only the last will be carried out. 00030 */ 00031 class save_blocker { 00032 public: 00033 save_blocker(); 00034 ~save_blocker(); 00035 static bool saves_are_blocked(); 00036 static void on_unblock(play_controller* controller, void (play_controller::*callback)()); 00037 00038 protected: 00039 friend class play_controller; 00040 static void block(); 00041 static bool try_block(); 00042 static void unblock(); 00043 00044 /** An exception-safe means of making sure that unblock() gets called 00045 * after try_block(). 00046 */ 00047 class save_unblocker { 00048 public: 00049 save_unblocker() {} 00050 ~save_unblocker() { save_blocker::unblock(); } 00051 }; 00052 00053 private: 00054 static play_controller *controller_; 00055 static void (play_controller::*callback_)(); 00056 static SDL_sem* sem_; 00057 }; 00058 00059 #endif
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:08 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |