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 DMCONSTRAINTS_H
     18 #define DMCONSTRAINTS_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: dmConstrians.h
     27 
     28 General Description: This file contains declaration of the DMConstraints class, which specifies MDF constraints
     29 
     30 ==================================================================================================*/
     31 
     32 #include "dmMetaDataBuffer.h"
     33 
     34 /* These enum values are used to indicate the node access type for SYNCML_DM_ACCESS_TYPE_T */
     35 enum
     36 {
     37     SYNCML_DM_ADD_ACCESS_TYPE       = SYNCML_DM_ACL_ADD,
     38     SYNCML_DM_DELETE_ACCESS_TYPE   = SYNCML_DM_ACL_DELETE,
     39     SYNCML_DM_GET_ACCESS_TYPE        = SYNCML_DM_ACL_GET,
     40     SYNCML_DM_REPLACE_ACCESS_TYPE = SYNCML_DM_ACL_REPLACE,
     41     SYNCML_DM_EXEC_ACCESS_TYPE      = SYNCML_DM_ACL_EXEC,
     42     SYNCML_DM_LOCAL_ACCESS_TYPE    = 0x020,
     43 };
     44 typedef UINT8 SYNCML_DM_ACCESS_TYPE_T;
     45 
     46 
     47 enum
     48 {
     49     SYNCML_DM_DDF_MIN = 1,
     50     SYNCML_DM_DDF_MAX,
     51     SYNCML_DM_DDF_VALUES,
     52     SYNCML_DM_DDF_DEFAULTVALUE,
     53     SYNCML_DM_DDF_MINLEN,
     54     SYNCML_DM_DDF_MAXLEN,
     55     SYNCML_DM_DDF_REGEXP,
     56     SYNCML_DM_DDF_NMAXLEN,
     57     SYNCML_DM_DDF_NVALUES,
     58     SYNCML_DM_DDF_NREGEXP,
     59     SYNCML_DM_DDF_AUTONODE,
     60     SYNCML_DM_DDF_RECUR_AFTER_SEGMENT,
     61     SYNCML_DM_DDF_MAX_RECURRANCE,
     62     SYNCML_DM_DDF_FK,
     63     SYNCML_DM_DDF_CHILD,
     64     SYNCML_DM_DDF_DEPEND,
     65     SYNCML_DM_DDF_MAX_MULTINODES
     66 
     67 };
     68 typedef UINT8 SYNCML_DM_DDF_CONSTRAINT_TYPE_T;
     69 
     70 
     71 /* These enum values are used to indicate the format of the data for SYNCML_DM_FORMAT_T */
     72 enum
     73 {
     74     SYNCML_DM_DDF_MIME_TYPE_TEXTPLAIN = 0
     75 };
     76 typedef UINT8 SYNCML_DM_DDF_MIME_TYPE_T;
     77 
     78 
     79 
     80 /**
     81 * DMConstraints represent MDF constraints
     82 */
     83 class DMConstraints
     84 {
     85 
     86   friend class DMMetaDataManager;
     87   friend class DMMetaDataNode;
     88 
     89 public:
     90    /**
     91  * Default constructor
     92  */
     93   DMConstraints();
     94 
     95    /**
     96  * Destructor
     97  */
     98   ~DMConstraints();
     99 
    100    /**
    101   * Operator to allocate memory
    102   * \param sz [in] - number of bytes to be allocated
    103   */
    104   inline void* operator new(size_t sz)
    105   {
    106     return (DmAllocMem(sz));
    107   }
    108 
    109   /**
    110   * Operator to free memory
    111   * \param buf [in] - pointer on buffer to be freed
    112   */
    113   inline void operator delete(void* buf)
    114   {
    115     DmFreeMem(buf);
    116   }
    117 
    118   /**
    119   * Reads constraints from MDF file
    120   * \param pBuffer [in] - pointer on Meta Data buffer
    121   * \param count [in] - number constraints to read
    122   * \param nNodeType [in] - node type
    123   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    124   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    125   * - All other codes indicate failure.
    126   */
    127   SYNCML_DM_RET_STATUS_T Read(DMMetaDataBuffer * pBuffer,
    128                                               UINT8 count,
    129                                               INT32 nNodeType);
    130 
    131    /**
    132   * Checks if default value may be set
    133   * \return TRUE if set
    134   */
    135    inline BOOLEAN IsDefaultSet() const
    136    {
    137        return m_nNodeType != SYNCML_DM_FORMAT_NULL;
    138    }
    139 
    140    /**
    141   * Retrieves default value as a string
    142   * \param strValue [out] - default value as a string
    143   */
    144    void GetDefaultString( DMString& strValue )const;
    145 
    146 private:
    147 
    148   /* Minimum value of int node*/
    149   INT32 m_nMin;
    150   /* Maximum value of int node*/
    151   INT32 m_nMax;
    152   /* Comma separated values */
    153   CPCHAR m_psValues;
    154   /* Node type */
    155   INT32 m_nNodeType;
    156   union  {
    157     /* Default value as a string */
    158     CPCHAR m_psDef_Value;
    159     /* Default int value */
    160     INT32   m_nDef_Value;
    161     /* Default float value */
    162     FLOAT   m_fDef_Value;
    163   };
    164 
    165   /* Maximum length of value */
    166   UINT16 m_nMaxLen;
    167   /* Minimum length of value */
    168   UINT16 m_nMinLen;
    169   /* Regular expression for value */
    170   CPCHAR m_psRegexp;
    171   /* Maximum length of node name */
    172   UINT8 m_nnMaxLen;
    173   /* Comma separated node names */
    174   CPCHAR m_psnValues;
    175   /* Regular expression for node name */
    176   CPCHAR m_psnRegexp;
    177   /* Auto nodes */
    178   CPCHAR m_psAutoNodes;
    179   /* Reccurrance pattern */
    180   CPCHAR m_psRecurAfterSegment;
    181   /* Maximum times the recurrance pattern can occur */
    182   UINT16 m_nMaxRecurrance;
    183   /* Foreign key */
    184   CPCHAR m_psForeignKey;
    185   /* Hard child dependency */
    186   CPCHAR m_psChild;
    187   /*  Soft child dependency */
    188   CPCHAR m_psDepend;
    189   /* Max number of multinodes to be created */
    190   UINT16 m_nMaxMultiNodes;
    191 
    192 
    193   /**
    194   * Initializes object
    195   */
    196   void Init();
    197 
    198   /**
    199   * Reads default value from MDF file
    200   * \param pBuffer [in] - pointer on Meta Data buffer
    201   * \param nNodeType [in] - node type
    202   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    203   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    204   * - All other codes indicate failure.
    205   */
    206   SYNCML_DM_RET_STATUS_T ReadDefaultValue(DMMetaDataBuffer * pBuffer,
    207                                           INT32 nNodeType);
    208 
    209 };
    210 
    211 #endif
    212