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 DMCONFIGITEM_H
     18 #define DMCONFIGITEM_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: dmConfigItem.h
     27 
     28 General Description: This file contains declaration of the DMConfigItem class
     29 
     30 ==================================================================================================*/
     31 
     32 #include "dmvector.h"
     33 #include "dmstring.h"
     34 #include "jem_defs.hpp"
     35 #include "dmtPrincipal.hpp"
     36 #include "SyncML_DM_FileHandle.H"
     37 
     38 /**
     39  * DMConfigItem is the base class for configuration records such as ACL or Event subscriptions.
     40  */
     41 class DMConfigItem : public JemBaseObject {
     42 public:
     43 
     44  /**
     45  * Default constructor
     46  */
     47   DMConfigItem() {};
     48 
     49   /**
     50   * Constructor, which sets path of configuration item
     51   * \param szPath [in] - configuration path (URI of a node)
     52   */
     53   DMConfigItem(CPCHAR szPath);
     54 
     55  /**
     56   * Saves configuration record back to a file
     57   * \param dmf [in] - file handler object
     58   * \param aDict [in] - dictionary of principals
     59   * \return Return Type (SYNCML_DM_RET_STATUS_T)
     60   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
     61   * - All other codes indicate failure.
     62   */
     63  virtual SYNCML_DM_RET_STATUS_T Serialize(DMFileHandler& dmf,
     64                                          const DMMap<DMString, INT32>& aDict ) = 0 ;
     65 
     66  /**
     67   * Parses encoded configuration data and assign values of object members
     68   * \param szPath [in] - configuration path (URI of a node)
     69   * \param szConfig[in] - encoded configuration record
     70   * \param aDict [in] - dictionary of principals
     71   * \return Return Type (SYNCML_DM_RET_STATUS_T)
     72   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
     73   * - All other codes indicate failure.
     74   */
     75   virtual SYNCML_DM_RET_STATUS_T Set(CPCHAR szPath,
     76                                 CPCHAR szConfig,
     77                                 const DMMap<INT32, DMString>& aDict) = 0;
     78 
     79 
     80  /**
     81   * Adds principals stored in the configuration item into dictionary before serialization of config file
     82   * \param aDict [out] - dictionary of principals
     83   */
     84   virtual void UpdateDictionary(DMMap<DMString, INT32>& aDict ) = 0;
     85 
     86 
     87  /**
     88   * Attaches property into encoded configuration record before serialization of config item
     89   * \param strConfig [out] - encoded configuration data
     90   * \param cDelim[in] - delimeter to use for particular property
     91   * \param szProperty [in] - property to attach
     92   */
     93   static void AttachProperty(DMString & strConfig,
     94                           char cDelim,
     95                           CPCHAR szProperty );
     96 
     97  /**
     98   * Creates "key=value" config property  (example "G=1+2")
     99   * \param aPrincipals [in] - vector of principals to add into value
    100   * \param szKey[in] - key  ( example "G=" )
    101   * \param aDict [in] - dictionary of principals
    102   * \param szProperty [out] - created config property
    103   */
    104   static void CreateProperty(const DMVector<DmtPrincipal> aPrincipals,
    105                             CPCHAR szKey,
    106                             const DMMap<DMString, INT32>& aDict,
    107                             DMString & strProperty);
    108 
    109 /**
    110   * Returns configuration path
    111   */
    112   const DMString & GetPath() const { return m_strPath; }
    113 
    114 
    115 protected:
    116   /* Configuration path*/
    117   DMString m_strPath;
    118 
    119 /**
    120   * Saves configuration path back to a file
    121   * \param dmf [in] - file handler object
    122   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    123   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    124   * - All other codes indicate failure.
    125   */
    126   virtual SYNCML_DM_RET_STATUS_T Serialize( DMFileHandler& dmf );
    127 
    128 /**
    129   * Sets value of configuration path
    130   * \param szPath [in] - configuration path (URI of a node)
    131   * \return Return Type (SYNCML_DM_RET_STATUS_T)
    132   * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
    133   * - All other codes indicate failure.
    134   */
    135   virtual SYNCML_DM_RET_STATUS_T Set(CPCHAR szPath);
    136 
    137 };
    138 
    139 typedef JemSmartPtr<DMConfigItem> PDMConfigItem;
    140 
    141 #endif
    142