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 #ifndef SESSION_ITEM_DESERIALIZER_H 00010 #define SESSION_ITEM_DESERIALIZER_H 00011 00012 #include "AppConfig.h" 00013 #include "XercesIncludes.h" 00014 00015 #include <vector> 00016 00017 class XmlReader; 00018 00019 /** 00020 * Used by SessionItems during session deserialization to restore their state 00021 * from the saved session. 00022 * 00023 * @see SessionItem, SessionItemSerializer 00024 */ 00025 class SessionItemDeserializer 00026 { 00027 public: 00028 /** 00029 * Restores a portion of the data from a serialized SessionItem. 00030 * 00031 * This method reads some data from the session and provides it back to the 00032 * caller. The data will be retrieved from the current block. The data in a 00033 * block in the session can be retrieved incrementally via multiple calls 00034 * to this method. 00035 * 00036 * @param pData 00037 * A pointer to a buffer into which the data is to be placed. 00038 * The buffer must be big enough to hold the specified number 00039 * of bytes of data. 00040 * @param size 00041 * The number of bytes to be placed into the buffer 00042 * 00043 * @return True if the specified number of bytes were successfully 00044 * retrieved from the session or false otherwise. 00045 */ 00046 virtual bool deserialize(void *pData, unsigned int size) = 0; 00047 00048 /** 00049 * Restores a portion of the data from a serialized SessionItem. 00050 * 00051 * This method reads some data from the session and provides it back to the 00052 * caller. The data will be retrieved from the current block. The data in a 00053 * block in the session can be retrieved incrementally via multiple calls 00054 * to this method. 00055 * 00056 * @param data 00057 * A vector into which the data should be placed. The size of 00058 * the vector determines the amount of data that will be 00059 * retrieved from the session. 00060 * 00061 * @return True if enough data to fill the vector were successfully 00062 * retrieved from the session or false otherwise. 00063 */ 00064 virtual bool deserialize(std::vector<unsigned char> &data) = 0; 00065 00066 /** 00067 * Restores a portion of the data from a serialized SessionItem. 00068 * 00069 * This method reads all of the data from a block in the session, parses it 00070 * as XML and returns the root node. 00071 * 00072 * @param reader 00073 * The XmlReader to parse the session data with. 00074 * 00075 * @return The XML root node if the parse was successful, or NULL otherwise. 00076 */ 00077 virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *deserialize(XmlReader &reader) = 0; 00078 00079 /** 00080 * Restores a portion of the data from a serialized SessionItem. 00081 * 00082 * This is a convenience function that reads all of the data from a block 00083 * in the session, parses it as XML and returns the root node if the root 00084 * node has the specified name. 00085 * 00086 * @param reader 00087 * The XmlReader to parse the session data with. 00088 * 00089 * @param pRootElementName 00090 * The name of the root element. 00091 * 00092 * @return The XML root node if the parse was successful, or \c NULL otherwise. 00093 */ 00094 virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *deserialize(XmlReader &reader, const char *pRootElementName) = 0; 00095 00096 /** 00097 * Accessor for the current block index. 00098 * 00099 * @return The block number of the current block. 00100 */ 00101 virtual int getCurrentBlock() const = 0; 00102 00103 /** 00104 * Moves to the next block of the serialized session. 00105 * 00106 * This method moves the deserializer to the next block of serialized data 00107 * in the session. This method should be used when deserializing data from 00108 * a SessionItem that stored its data in multiple blocks via 00109 * SessionItemSerializer::endBlock(). 00110 * 00111 * @see SessionItemSerializer 00112 */ 00113 virtual void nextBlock() = 0; 00114 00115 /** 00116 * Returns the sizes of the blocks in the serialized item. 00117 * 00118 * This method returns the sizes of the blocks that were saved when the 00119 * SessionItem was serialized. 00120 * 00121 * @return A vector containing the size of each block. 00122 */ 00123 virtual std::vector<int64_t> getBlockSizes() const = 0; 00124 00125 protected: 00126 /** 00127 * Destroys the SessionItemDeserializer object. 00128 * 00129 * The SessionItemDeserializer object is automatically deleted by 00130 * SessionManager. Plug-ins do not need to destroy it. 00131 */ 00132 virtual ~SessionItemDeserializer() {} 00133 }; 00134 00135 #endif