1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef SYNCML_DM_ARCHIVE_H 18#define SYNCML_DM_ARCHIVE_H 19 20#ifndef __cplusplus 21#error "This is a C++ header file; it requires C++ to compile." 22#endif 23 24/*================================================================================================== 25 26 Header Name: SyncML_DM_Archive.H 27 28 General Description: This file contains the declaration for the SyncML_DM_Archive class. 29 SyncML_DM_Archive is the ABC (Abstract Base Class) of all Archive classes 30 31==================================================================================================*/ 32 33#include "xpl_Time.h" 34#include "dmMemory.h" 35#include "dmEventLogger.h" 36#ifdef LOB_SUPPORT 37#include "SyncML_Commit_Log.H" 38#endif 39 40/*================================================================================================== 41CLASS DECLARATION 42==================================================================================================*/ 43 44class DMNode; 45class DMTree; 46class CEnv; 47 48class SyncML_DM_Archive 49{ 50 public: 51 52 DMEventLogger& GetEventLogger() { return oEventLogger; } 53 54 /* Class constructor 55 * The caller is responsible for allocating/freeing the two fields 56 * to this function 57 */ 58 SyncML_DM_Archive(CEnv* env, CPCHAR pURI, CPCHAR path) ; 59 60 /* Class destructor (virtual because of the inheritance of 61 * other classes who might be referenced as SyncML_DM_Archive) 62 */ 63 virtual ~SyncML_DM_Archive() ; 64 65 virtual SYNCML_DM_RET_STATUS_T Init(DMTree* pTree); 66 67 /* Serialization and Deserialization methods must be overridden 68 * by any concrete archive implementation 69 * The caller is responsible for allocating/freeing the DMTree 70 * for the serialize function 71 */ 72 virtual SYNCML_DM_RET_STATUS_T serialize(DMTree* tree) = 0; 73 virtual SYNCML_DM_RET_STATUS_T deserialize(DMTree* tree, 74 BOOLEAN bIsReload = FALSE) = 0; 75 76 /* Operators to allocate and delete memory for operation */ 77 inline void* operator new(size_t sz) 78 { 79 return (DmAllocMem(sz)); 80 } 81 82 inline void operator delete(void* buf) 83 { 84 DmFreeMem(buf); 85 } 86 87 /* Accessor for the last modification time of the archive 88 */ 89 virtual XPL_CLK_CLOCK_T getLastModifiedTime() = 0; 90 91 /* Get last persisted time */ 92 virtual XPL_CLK_CLOCK_T getLastSavedTime() = 0; 93 94 /* Check permission */ 95 virtual BOOLEAN verifyPermission(XPL_FS_OPEN_MODE_T permission) const {return TRUE;} 96 97 /* Update last accessed time */ 98 void setLastAccessedTime(XPL_CLK_CLOCK_T lastAccessedTime); 99 100 /* Get last accessed time */ 101 XPL_CLK_CLOCK_T getLastAccessedTime(); 102 103 BOOLEAN isWritableExist() const {return m_bWritableExist;} 104 105 void setWritableExist( BOOLEAN bWritableExist ) {m_bWritableExist = bWritableExist;} 106 107 //Re-Set last persisted time 108 virtual void serializeDone() = 0; 109 110 /* Accessors for setting/getting the string representing the URI 111 * of the archive in the memory tree 112 * 113 * The caller is responsible for allocating/freeing memory for the 114 * set function but has no responsibilities when using the get 115 * function 116 */ 117 CPCHAR getURI() const {return m_pURI;} 118 119 /* Accessor for setting the root node of the archive of the DMNode type 120 * The destructor of this class later frees the created DMAddNodeProp 121 * object 122 */ 123 virtual void setRootNode(DMNode* node) { rootTreeNode=node; } 124 125 virtual DMNode* getRootNode() { return rootTreeNode; } 126 127 BOOLEAN isDirty() { return dirty; } 128 129 void setDirty(BOOLEAN dirty) { this->dirty=dirty; } 130 131 void getFilePath(char * path, CPCHAR ext); 132 133 SyncML_DM_Archive * getParentArchive() { return parent; } 134 135 void setParentArchive(SyncML_DM_Archive * parent) { this->parent=parent; } 136 137 BOOLEAN LoadSkeleton(DMTree* pTree) ; 138#ifdef LOB_SUPPORT 139 virtual SYNCML_DM_RET_STATUS_T rollbackESN(DMTree* tree) = 0; 140 virtual SYNCML_DM_RET_STATUS_T commitESN(DMTree* tree) = 0; 141 virtual SyncML_Commit_Log* GetCommitLogHandler() = 0; 142 virtual SYNCML_DM_RET_STATUS_T CloseCommitLog() = 0; 143 virtual SYNCML_DM_RET_STATUS_T PlayCommitLog() = 0; 144#endif 145 146 protected: 147 148 DMEventLogger oEventLogger; 149 150 //Parent archive of this archive. when loaded, parent MUST Have already been loaded 151 SyncML_DM_Archive * parent; 152 153 /* The top-level URI of the archive */ 154 CPCHAR m_pURI; 155 156 /* The filesystem path string of the archive file */ 157 CPCHAR m_path; 158 /* full name to file in WFS */ 159 DMString m_strWFSFileName; 160 161 /* if the tree associated with the archive is dirty or not.*/ 162 BOOLEAN dirty; 163 BOOLEAN m_bWritableExist; 164 165 /* permission mask on archive */ 166 int m_permission; 167 168 DMNode* rootTreeNode; //Different from rootNode which is a serialized form 169 XPL_CLK_CLOCK_T m_lastAccessedTime; 170 DMTree* m_pTree; 171 172}; 173 174#endif /* SYNCML_DM_ARCHIVE_H */ 175