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 _DM_TREE_NODE_CLASS_H 18 #define _DM_TREE_NODE_CLASS_H 19 20 #ifndef __cplusplus 21 #error "This is a C++ header file; it requires C++ to compile." 22 #endif 23 24 //------------------------------------------------------------------------ 25 // Header Name: dm_tree_node_class.H 26 // 27 // General Description: This file contains the definition of 28 // DMNode class. 29 //------------------------------------------------------------------------ 30 31 #include "syncml_dm_data_types.h" //For DM data type definitions 32 #include "xpl_Logger.h" 33 #include "dm_tree_typedef.h" //For tree type definitions 34 #include "dmstring.h" 35 #include "dmbuffer.h" 36 #include "dmdefs.h" 37 38 #include "dmt.hpp" 39 #include "dmtPlugin.hpp" 40 #include "dmPlugin.h" 41 42 class SyncML_DM_Archive; 43 44 class DMNode 45 { 46 protected: 47 //Those values should not be called directly as For 48 // plugin proxy node, you must access them through accessor function. 49 // For archiver, it is OK. 50 51 DMString abNodeName; 52 DMNode *pcParentOfNode; //Pointer to Parent of the node 53 DMNode *pcFirstChild; //Pointer to First Child of the node 54 DMNode *pcNextSibling; //Pointer to Next Sibling of the node 55 56 // psType cannot be accessed directly for mime type optimization 57 DMString psType_; 58 DMString m_strTitle; 59 SYNCML_DM_FORMAT_T bFormat; 60 UINT16 m_nFlags; // bit 0 set if plugin, bit 1 set if permanent: see next enum for details 61 62 63 #ifndef DM_IGNORE_TSTAMP_AND_VERSION 64 XPL_CLK_CLOCK_T wTStamp; 65 UINT16 wVerNo; 66 #endif 67 68 CPCHAR getType() const; 69 SYNCML_DM_RET_STATUS_T setType(const char * strType); 70 71 SYNCML_DM_RET_STATUS_T set(const DMGetData * pData); 72 73 SYNCML_DM_RET_STATUS_T set(CPCHAR strName, CPCHAR strTitle, const DMGetData * pData); 74 75 SYNCML_DM_RET_STATUS_T set(const DMAddNodeProp * pNodeProp); 76 77 public: 78 SyncML_DM_Archive * pArchive; 79 80 enum { 81 enum_NodePlugin = 1, 82 enum_NodePermanent = 2, 83 enum_NodeSkeleton = 4, // fake node for lazy loading 84 enum_NodeOverlayPI = 8, // mount point for Overlay Pi 85 enum_NodeStoresPID = 16, // multinode with Overlay PI data 86 enum_NodeOPISyncNeeded = 32, 87 enum_NodeOPISyncNotNeeded = 64, 88 enum_NodeNoGetAccess = 128, // multinode with Overlay PI data 89 enum_NodeOPISyncUptodate = 256, 90 enum_NodeESN = 512, 91 enum_NodeNotPersisted = enum_NodePlugin | enum_NodeSkeleton | enum_NodeOverlayPI |enum_NodeOPISyncUptodate 92 }; 93 94 friend class DMTree; 95 friend class SyncML_DM_Archive; 96 friend class DMMetaDataManager; 97 friend class SyncML_PlugIn_WBXMLLog; 98 friend class SyncML_DM_WBXMLWriter; 99 100 101 DMNode(BOOLEAN bPlugin); 102 virtual ~DMNode(); 103 //Overloading new and delete operators 104 105 inline void* operator new(size_t dwSize) 106 { 107 return (DmAllocMem(dwSize)); 108 } 109 110 inline void operator delete(void *pvBuf) 111 { 112 DmFreeMem(pvBuf); 113 } 114 115 inline DMNode *GetParent() {return pcParentOfNode;} 116 117 //The following are Pure virtual functions.Leaf or Interior node 118 //Classes deriving from this class MUST implement the functions. 119 virtual SYNCML_DM_RET_STATUS_T Add(DMAddData & oAddData) = 0; 120 121 virtual SYNCML_DM_RET_STATUS_T Delete(CPCHAR pbUri) = 0; 122 123 virtual SYNCML_DM_RET_STATUS_T Get(CPCHAR pbUri, DMGetData & oReturnData) = 0; 124 125 virtual SYNCML_DM_RET_STATUS_T Find(CPCHAR pbUri) = 0; 126 127 virtual SYNCML_DM_RET_STATUS_T SetAddedNode(CPCHAR pbUri) = 0; 128 129 virtual SYNCML_DM_RET_STATUS_T RemoveAddedNode(CPCHAR pbUri) = 0; 130 131 virtual SYNCML_DM_RET_STATUS_T GetFormat(CPCHAR pbUri, 132 SYNCML_DM_FORMAT_T * pdwRetPropertyData) = 0; 133 134 virtual SYNCML_DM_RET_STATUS_T GetSize(CPCHAR pbUri, 135 UINT32 *pdwRetPropertyData) = 0; 136 137 virtual SYNCML_DM_RET_STATUS_T GetType(CPCHAR pbUri, 138 DMString& strType) = 0; 139 140 virtual SYNCML_DM_RET_STATUS_T Replace(DMAddData & oReplaceData) = 0; 141 142 virtual SYNCML_DM_RET_STATUS_T Rename(CPCHAR pbUri, CPCHAR psNewNodeName) = 0; 143 144 virtual SYNCML_DM_RET_STATUS_T Rollback(SYNCML_DM_COMMAND_T bDMCommand, 145 CPCHAR pbUri) = 0; 146 147 virtual SYNCML_DM_RET_STATUS_T GetName(CPCHAR pbUri, DMString& strName); 148 149 virtual SYNCML_DM_RET_STATUS_T SetName(CPCHAR pbUri, CPCHAR pbNewName); 150 151 virtual SYNCML_DM_RET_STATUS_T GetTitle(CPCHAR pbUri, DMString& ppbTitle); 152 153 virtual SYNCML_DM_RET_STATUS_T SetTitle(CPCHAR pbUri, CPCHAR pbNewTitle); 154 155 #ifndef DM_IGNORE_TSTAMP_AND_VERSION 156 157 virtual XPL_CLK_CLOCK_T GetTStamp(CPCHAR /*pbUri*/) 158 { 159 // pbUri = NULL; 160 return wTStamp; 161 } 162 163 virtual SYNCML_DM_RET_STATUS_T SetTStamp(CPCHAR pbUri, XPL_CLK_CLOCK_T timeStamp); 164 165 virtual UINT16 GetVerNo(const char* /*pbUri*/) 166 { 167 // pbUri = NULL; 168 return wVerNo; 169 } 170 171 virtual SYNCML_DM_RET_STATUS_T SetVerNo (CPCHAR pbUri, UINT16 wVerNo); 172 #endif 173 174 // DP: leaf node data access 175 virtual DMBuffer * getData() { return NULL; } 176 virtual const DMBuffer * getData() const { return NULL; } 177 178 // overlay plug-in access 179 virtual DmtOverlayPluginData* getOverlayPIData() { return NULL;} 180 virtual const DmtOverlayPluginData* getOverlayPIData() const { return NULL;} 181 virtual PDMPlugin getOverlayPI() {return PDMPlugin();} 182 183 //-----------Work on THIS NODE ONLY -------------- 184 // And should used only by persistence layer etc. 185 //More methods implemented in the DMNode class. 186 187 //returns the Format of the node 188 inline SYNCML_DM_FORMAT_T getFormat() const { return(bFormat);} 189 190 inline BOOLEAN isPermanent() const {return (m_nFlags & enum_NodePermanent) != 0; } 191 192 inline BOOLEAN isPlugin() const {return (m_nFlags & enum_NodePlugin) != 0; } 193 194 inline BOOLEAN IsSkeletonNode() const {return (m_nFlags & enum_NodeSkeleton) != 0; } 195 196 // synchronization state of Overlay PI 197 inline BOOLEAN opiSyncNeeded() const {return (m_nFlags & enum_NodeOPISyncNeeded) != 0; } 198 inline BOOLEAN opiSyncNotNeeded() const {return (m_nFlags & enum_NodeOPISyncNotNeeded) != 0; } 199 inline BOOLEAN opiSyncMayNeeded() const {return (m_nFlags & (enum_NodeOPISyncNeeded |enum_NodeOPISyncNotNeeded)) == 0; } 200 inline BOOLEAN opiInSync() const {return (m_nFlags & enum_NodeOPISyncUptodate) != 0; } 201 inline BOOLEAN IsOverlayPI() const {return (m_nFlags & enum_NodeOverlayPI) != 0; } 202 inline BOOLEAN IsOverlayPIData() const {return (m_nFlags & enum_NodeStoresPID) != 0; } 203 virtual BOOLEAN IsGetAccess(CPCHAR pURI = NULL) const {return (m_nFlags & enum_NodeNoGetAccess) == 0; } 204 205 206 207 inline UINT16 getFlags() const {return m_nFlags;} 208 209 inline void setFlags( UINT16 n ) { m_nFlags = n;} 210 inline void addFlags( UINT16 n ) { m_nFlags |= n;} 211 212 inline CPCHAR getName() const { return abNodeName.c_str(); } 213 214 215 inline CPCHAR getTitle() const { return m_strTitle.c_str();} 216 217 DMNode* GetChildByName( const char* szName ) const; 218 219 DMNode* GetNextSerializeItem() ; 220 221 void ConvertPathToSkeleton( DMNode* psStartNode ) ; 222 #ifdef LOB_SUPPORT 223 inline BOOLEAN IsESN() const {return (m_nFlags & enum_NodeESN) != 0; } 224 virtual SYNCML_DM_RET_STATUS_T IsESN(CPCHAR pbUri, BOOLEAN& bESN); 225 inline void SetESN() { m_nFlags |= enum_NodeESN; } 226 #endif 227 228 }; 229 230 231 //------------------------------------------------------------------------ 232 #endif //_DM_TREE_NODE_CLASS_H 233