Home | History | Annotate | Download | only in hdr
      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 DMMETADATANODE_H
     18 #define DMMETADATANODE_H
     19 
     20 #ifndef __cplusplus
     21 #error "This is a C++ header file; it requires C++ to compile."
     22 #endif
     23 
     24 #include "dmConstraints.h"
     25 
     26 /**
     27  * DMMetaDataNode represents a metadata node.
     28  */
     29 class DMMetaDataNode
     30 {
     31 
     32   friend class DMMetaDataManager;
     33 
     34 public:
     35   DMMetaDataNode();
     36 
     37   /**
     38   * Operator to allocate memory
     39   * \param sz [in] - number of bytes to be allocated
     40   */
     41   inline void* operator new(size_t sz)
     42   {
     43     return (DmAllocMem(sz));
     44   }
     45 
     46   /**
     47   * Operator to free memory
     48   * \param buf [in] - pointer on buffer to be freed
     49   */
     50   inline void operator delete(void* buf)
     51   {
     52     DmFreeMem(buf);
     53   }
     54 
     55   /**
     56   * Retrieves pointer on constraints associated with meta node
     57   * \return pointer on DMConstraints object
     58   */
     59   DMConstraints * GetConstraints() const;
     60 
     61    /**
     62   * Checks if meta node has child defined as multinode
     63   * \return TRUE if has
     64   */
     65   inline BOOLEAN IsHasMultiNodes() const { return m_bIsHasMultiChildren; }
     66 
     67    /**
     68   * Checks if meta node is a multinode
     69   * \return TRUE if it is a multinode
     70   */
     71   inline BOOLEAN IsMultiNode() const { return m_bIsMultiNode; }
     72 
     73    /**
     74   * Checks if node is a plugin node
     75   * \return TRUE if it is a multinode
     76   */
     77   inline BOOLEAN IsPluginNode() const { return m_bPluginNode; }
     78 
     79    /**
     80   * Sets offset in the Meta Data buffer on specified child
     81   * \param pBuffer [in] - pointer on Meta Data buffer
     82   * \param index [in] - child index ( starts from 0 )
     83   * \return Return Type (SYNCML_DM_RET_STATUS_T)
     84   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
     85   * - All other codes indicate failure.
     86   */
     87   SYNCML_DM_RET_STATUS_T SetChildrenOffset(DMMetaDataBuffer * pBuffer,
     88                                                               UINT8 index);
     89 
     90   /**
     91   * Retrieves full path of meta
     92   * \return Return Type (DMBuffer &)
     93   */
     94   const DMBuffer & GetPath() const { return m_oPath; }
     95 
     96   /**
     97   * Sets starting path of meta node
     98   * \param szPath [in] - starting path of multinode
     99   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    100   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    101   * - All other codes indicate failure.
    102   */
    103   SYNCML_DM_RET_STATUS_T SetPath(CPCHAR szPath);
    104 
    105   /**
    106   * Allocates memory for full MDF path
    107   * \param size [in] - number of bites to allocate
    108   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    109   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    110   * - All other codes indicate failure.
    111   */
    112   SYNCML_DM_RET_STATUS_T AllocatePath(UINT32 size);
    113 
    114   /**
    115   * Appends node name to built MDF path
    116   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    117   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    118   * - All other codes indicate failure.
    119   */
    120   SYNCML_DM_RET_STATUS_T AppendSegment();
    121 
    122   /**
    123   * Sets access type for node inherited from parent node
    124   * \param accessType [in] - access type
    125   */
    126   void SetAccessType(SYNCML_DM_ACCESS_TYPE_T accessType);
    127 
    128   /**
    129   * Retrieves mime type
    130   * \param strType [out] - myme type
    131   */
    132   void GetMimeType(DMString & strType);
    133 
    134   /**
    135   * Checks if node has a "Local" attribute
    136   * \return TRUE if "Local" attribute  is set
    137   */
    138   BOOLEAN IsLocal();
    139 
    140   /**
    141   * Checks if node is a leaf
    142   * \return TRUE if is a leaf
    143   */
    144   BOOLEAN IsLeaf();
    145 
    146   /**
    147   * Verifies if access is specified for meta node
    148   * \param accessType [in] - access type to check
    149   * \return TRUE if operation is allowed
    150   */
    151   BOOLEAN VerifyAccessType(SYNCML_DM_ACCESS_TYPE_T accessType) const;
    152 
    153   /**
    154   * Verifies mime type
    155   * \param mimeType [in] - mime type to checks
    156   * \return TRUE if mime type is correct
    157   */
    158   BOOLEAN VerifyMimeType(CPCHAR mimeType) const;
    159 
    160   /**
    161   * Verifies max number of children multinodes that can by created under a node
    162   * \param count [in] - current number of nodes
    163   * \param bOPiDataParent [in] - specifies if node is a parent of node containing plug-in data
    164   * \return TRUE if max number isn't reached
    165   */
    166   BOOLEAN VerifyChildrenMultiNodesCount(UINT16 count,
    167                                      BOOLEAN& bOPiDataParent) const;
    168 
    169   /**
    170   * Reads max number of children multinodes may by created under a node
    171   * \param oBuffer [in] - Meta Data buffer
    172   * \param bOPiDataParent [in] - specifies if node is a parent of node containing plug-in data
    173   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    174   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    175   * - All other codes indicate failure.
    176   */
    177   SYNCML_DM_RET_STATUS_T GetMaxMultiNodeChildren(DMMetaDataBuffer oBuffer);
    178 
    179   /**
    180   * Reads node info from MDF file
    181   * \param oBuffer [in] - Meta Data buffer
    182   * \param bReadConstraints [in] - specifies if node constraints should be read
    183   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    184   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    185   * - All other codes indicate failure.
    186   */
    187   SYNCML_DM_RET_STATUS_T Read(DMMetaDataBuffer oBuffer,
    188                         BOOLEAN bReadConstraints);
    189 
    190   /**
    191   * Reads node name from MDF file
    192   * \param oBuffer [in] - Meta Data buffer
    193   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    194   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    195   * - All other codes indicate failure.
    196   */
    197   SYNCML_DM_RET_STATUS_T ReadName(DMMetaDataBuffer oBuffer);
    198 
    199   /**
    200   * Verifies if node is a overlay plug-in node
    201   * \param szID [out] - node id
    202   * \param wAccessType [out] - node access type
    203   * \param nNodeFormat [out] - node format
    204   * \return TRUE if node ia a overlay plug-in node
    205   */
    206   BOOLEAN VerifyOPINode(CPCHAR& szID,
    207                         SYNCML_DM_ACCESS_TYPE_T&  wAccessType,
    208                         SYNCML_DM_FORMAT_T& nNodeFormat)  const;
    209 
    210  /**
    211   * Verifies if node is a parent of node containing plg-in data
    212   * \return TRUE if node is a parent of node containing plg-in data
    213   */
    214  inline BOOLEAN IsOPiDataParent() const { return m_bOPiDataParent;}
    215 
    216 #ifdef LOB_SUPPORT
    217  /**
    218   * Verifies if node is a large object
    219   * \return TRUE if node is a large object
    220   */
    221  inline BOOLEAN IsESN() const { return m_bESN;}
    222 
    223  /**
    224   * Verifies if node is a progress bar is required for large object
    225   * \return TRUE if progress bar is required
    226   */
    227  inline BOOLEAN IsProgressBarNeeded() const { return m_bProgressBarNeeded;}
    228 #endif
    229 
    230 private:
    231   enum {
    232     /* Mask for node type verification */
    233     nodeTypeMask = 0x7f,
    234     /* Specifies if node a multinode */
    235     nodeMultiNode = 0x80,
    236     /* Specifies if node stores plug-in data */
    237     nodeStoresPD = 0x100,
    238     /* Specifies if node a ovelraly plug-in node */
    239     nodePluginNode = 0x200,
    240     /* Specifies if node has an ID */
    241     nodeHasID = 0x400,
    242 #ifdef LOB_SUPPORT
    243     /* Specifies if node is a large object */
    244     nodeESN = 0x800,
    245     /* Specifies if progress bar is needed */
    246     nodeProgressBar = 0x1000
    247 #endif
    248   };
    249 
    250   /**
    251   * Verifies if node has multinode children
    252   * \return TRUE if hode has multinode children
    253   */
    254   void CheckHasMultiNode(DMMetaDataBuffer oBuffer);
    255 
    256    /**
    257   * Initializes object
    258   */
    259   void Init();
    260 
    261   /* Node name */
    262   CPCHAR m_psName;
    263    /* Node ID for overlay plug-in node */
    264   CPCHAR m_szID;
    265    /* Full MDF path to a node */
    266   DMBuffer m_oPath;
    267   /* Access type */
    268   SYNCML_DM_ACCESS_TYPE_T m_wAccessType;
    269   /* Node format */
    270   SYNCML_DM_FORMAT_T m_nNodeFormat;
    271   /* Mime Type */
    272   SYNCML_DM_DDF_MIME_TYPE_T m_nMimeType;
    273   /* Number of constraints a node has */
    274   UINT8 m_nNumConstraints;
    275   /* Number of children a node has */
    276   UINT16 m_nNumChildren;
    277   /* Offset to first child */
    278   UINT32 m_nOffsetChildren;
    279   /* Node constraints */
    280   DMConstraints m_oConstraints;
    281   /* Max number of multinode children */
    282   UINT16 m_nMaxChildrenMultiNodes;
    283   /* Specifies if node has multinode children */
    284   BOOLEAN m_bIsHasMultiChildren;
    285   /* Specifies if node is a multinode */
    286   BOOLEAN m_bIsMultiNode;
    287   /* Specifies if node stores a plug-in data */
    288   BOOLEAN m_bStoresPD;
    289   /* Specifies if node is a overlay plug-in node */
    290   BOOLEAN m_bPluginNode;
    291   /* Specifies if node is a parent of node that stores a plug-in data */
    292   BOOLEAN m_bOPiDataParent;
    293 #ifdef LOB_SUPPORT
    294   /* Specifies if node is a large object */
    295   BOOLEAN m_bESN;
    296   /* Specifies if progress bar is needed */
    297   BOOLEAN m_bProgressBarNeeded;
    298 #endif
    299 };
    300 
    301 #endif
    302