00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef SESSION_MANAGER 00011 #define SESSION_MANAGER 00012 00013 #include "ConfigurationSettings.h" 00014 #include "EnumWrapper.h" 00015 #include "Service.h" 00016 #include "Subject.h" 00017 00018 #include <string> 00019 #include <vector> 00020 00021 class Progress; 00022 class SessionItem; 00023 class SessionSaveLock; 00024 00025 /** 00026 * \ingroup ServiceModule 00027 * Provides interfaces for saving and restoring the session and for creating 00028 * a new session. 00029 * 00030 * The session-save process is as follows: 00031 * 1) The session manager retrieves a pointer to each SessionItem, including: 00032 * a) Data Elements 00033 * b) Windows 00034 * c) Views 00035 * d) Layers 00036 * e) PlotSets 00037 * f) Plot Widgets 00038 * g) Animation Controllers 00039 * i) Animations 00040 * j) Modules 00041 * k) PlugIn Descriptors 00042 * l) PlugIn instances 00043 * 2) The session directory is created, if necessary 00044 * 3) The session directory is cleared of obsolete SessionItem files 00045 * 4) For each SessionItem, it creates a SessionItemSerializer and calls SessionItem::serialize() 00046 * 5) The Session index file is written. 00047 * 00048 * This subclass of Subject will notify upon the following conditions: 00049 * - The session is closed. 00050 * - Everything else documented in Subject. 00051 * 00052 * @see SessionItem, SessionItemSerializer 00053 */ 00054 class SessionManager : public Subject 00055 { 00056 public: 00057 /** 00058 * Specifies the success of an attempt to serialize the session. 00059 */ 00060 enum SerializationStatusEnum 00061 { 00062 SUCCESS, /**< All session items were successfully saved */ 00063 PARTIAL_SUCCESS, /**< Some session items were successfully saved */ 00064 LOCKED, /**< Session saving has been temporarily locked */ 00065 FAILURE /**< No session items were successfully saved */ 00066 }; 00067 00068 /** 00069 * @EnumWrapper SessionManager::SerializationStatusEnum. 00070 */ 00071 typedef EnumWrapper<SerializationStatusEnum> SerializationStatus; 00072 00073 SETTING(QueryForSave, SessionManager, SessionSaveType, SESSION_QUERY_SAVE) 00074 SETTING(AutoSaveEnabled, SessionManager, bool, false) 00075 SETTING(AutoSaveInterval, SessionManager, unsigned int, 30) 00076 00077 /** 00078 * Emitted with a null boost::any just prior to saving a session. 00079 */ 00080 SIGNAL_METHOD(SessionManager, AboutToSaveSession) 00081 00082 /** 00083 * Emitted with a null boost::any just prior to restoring a session. 00084 */ 00085 SIGNAL_METHOD(SessionManager, AboutToRestore) 00086 00087 /** 00088 * Emitted with a null boost::any when the session has finished restoring itself. 00089 */ 00090 SIGNAL_METHOD(SessionManager, SessionRestored) 00091 00092 /** 00093 * Emitted after the session save has finished with a boost::any<std::pair<\link SessionManager::SerializationStatus SerializationStatus\endlink, std::string>> 00094 * containing the status of the serialization and the filename of the saved session. If the status 00095 * is \link SessionManager::FAILURE FAILURE\endlink, the filename string will be empty. 00096 */ 00097 SIGNAL_METHOD(SessionManager, SessionSaved) 00098 00099 /** 00100 * Emitted when a session is closed. 00101 * 00102 * The session is still fully created when this signal is emitted. 00103 */ 00104 SIGNAL_METHOD(SessionManager, Closed) 00105 00106 /** 00107 * Gets the name of the current session. 00108 * 00109 * This method returns the unique name given to the session when it was 00110 * created. This will be in the form of a UUID. 00111 * 00112 * @return The name of the session. 00113 */ 00114 virtual std::string getName() const = 0; 00115 00116 /** 00117 * Saves the current session. 00118 * 00119 * This method saves all data, windows, layers, animations and active 00120 * plug-ins to disk so they can be restored to the same state later. 00121 * 00122 * @param filename 00123 * The full pathname of the file the session is to be saved in. 00124 * @param pProgress 00125 * If not \c NULL, progress during session save will be reported 00126 * to the supplied Progress object. 00127 * 00128 * @return A pair of values indicating the success of the save and, if 00129 * the session was only partially saved, which session items 00130 * failed to save. The std::string in the std::pair contains 00131 * a user readable type of the associated SessionItem. This type 00132 * should only be used for display to the user and logging. 00133 */ 00134 virtual std::pair<SerializationStatus,std::vector<std::pair<SessionItem*, std::string> > > serialize(const std::string &filename, Progress *pProgress) = 0; 00135 00136 /** 00137 * Retrieves a SessionItem during session restore based on its id. 00138 * 00139 * This method retrieves a specified session item during restore. It is only 00140 * guaranteed to work during session restore. 00141 * 00142 * @param id 00143 * The session id of the SessionItem to retrieve 00144 * 00145 * @return The pointer to the corresponding SessionItem, if found or \c NULL otherwise. 00146 */ 00147 virtual SessionItem *getSessionItem(const std::string &id) = 0; 00148 00149 /** 00150 * Is the session currently saving? 00151 * 00152 * @return True if session serialization is in progress, false if it is not. 00153 */ 00154 virtual bool isSessionSaving() const = 0; 00155 00156 /** 00157 * Is the session currently loading? 00158 * 00159 * @return True if session deserialization is in progress, false if it is not. 00160 */ 00161 virtual bool isSessionLoading() const = 0; 00162 00163 /** 00164 * Is session save locked? 00165 * 00166 * If this returns true, calls to serialize() will fail. 00167 * 00168 * @return True if session save is currently locked, false if it is allowed. 00169 */ 00170 virtual bool isSessionSaveLocked() const = 0; 00171 00172 protected: 00173 /** 00174 * This will be cleaned up during application close. Plug-ins do not 00175 * need to destroy it. 00176 */ 00177 virtual ~SessionManager() {} 00178 00179 /** 00180 * Prevent the session from saving. 00181 * 00182 * Locking session save will cause calls to serialize() to fail. 00183 * @see SessionSaveLock to use this feature. 00184 */ 00185 virtual void lockSessionSave() = 0; 00186 00187 /** 00188 * Unlock session saving. 00189 * 00190 * This reverses a previous call to lockSessionSave(). If multiple calls to 00191 * lockSessionSave() have been made, this unlocks one of those calls. 00192 * @see SessionSaveLock to use this feature. 00193 */ 00194 virtual void unlockSessionSave() = 0; 00195 friend class SessionSaveLock; 00196 }; 00197 00198 #endif