javauis/mmapi_qt/baseline/inc/cmmaplayerproperties.h
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is used for storing and parsing properties
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMMAPLAYERPROPERTIES_H
       
    20 #define CMMAPLAYERPROPERTIES_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 // STRUCTS
       
    26 
       
    27 /**
       
    28  * These structs are used for storing array of strings
       
    29  */
       
    30 NONSHARABLE_STRUCT(TMMAStaticStr)
       
    31 {
       
    32     TInt iLength;
       
    33     const TText* iStr;
       
    34 
       
    35     inline const TPtrC operator()() const
       
    36     {
       
    37         return TPtrC(iStr, iLength);
       
    38     }
       
    39 };
       
    40 
       
    41 NONSHARABLE_STRUCT(TMMAStaticStrArray)
       
    42 {
       
    43     const TMMAStaticStr* iStr;
       
    44     inline const TPtrC operator()() const
       
    45     {
       
    46         return TPtrC(iStr->iStr, iStr->iLength);
       
    47     }
       
    48 };
       
    49 
       
    50 #define MMA_PARAMETER_ARRAY(name) const TMMAStaticStrArray name[] =
       
    51 #define MMA_PARAMETER_STR(name, s) static const TMMAStaticStr name = {sizeof(L##s)/sizeof(TText)-1, (TText*)L##s}
       
    52 #define MMA_PARAMETER_ARRAY_SIZE(name) (sizeof(name)/sizeof((name)[0]))
       
    53 
       
    54 //  CLASS DECLARATION
       
    55 /**
       
    56 *   This class is base class for storing and validating
       
    57 */
       
    58 
       
    59 NONSHARABLE_CLASS(MMMAParameterRule)
       
    60 {
       
    61 public:
       
    62     /**
       
    63      * Validates key-value pair based on rule. If derived class is leaf with specified key
       
    64      * then it must store value if it is valid.
       
    65      */
       
    66     virtual TBool ValidateAndStoreL(const TDesC& aKey, const TDesC& aValue) = 0;
       
    67 
       
    68     /**
       
    69      * Compares key-value pair based on rule and stored value.
       
    70      */
       
    71     virtual TBool Compare(const TDesC& aKey, const TDesC& aValue) = 0;
       
    72     virtual TBool Compare(const TDesC& aKey, const TInt aValue) = 0;
       
    73 
       
    74     /**
       
    75      * Gets value for specified key, returns EFalse if specified key is not found
       
    76      */
       
    77     virtual TBool FindProperty(const TDesC& aKey, TPtrC& aValue) = 0;
       
    78     virtual TBool FindProperty(const TDesC& aKey, TInt& aValue) = 0;
       
    79 };
       
    80 
       
    81 //  CLASS DECLARATION
       
    82 /**
       
    83 *   This class is used for storing and parsing properties
       
    84 *   The property string is in format "name=value&name=value&..."
       
    85 *
       
    86 */
       
    87 
       
    88 NONSHARABLE_CLASS(CMMAPlayerProperties): public CBase
       
    89 {
       
    90 public:// Construction and destruction
       
    91     /**
       
    92     * Two-phased constructor.
       
    93     */
       
    94     static CMMAPlayerProperties* NewL(const TDesC& aProperties,
       
    95     MMMAParameterRule& aRule);
       
    96     /**
       
    97     * Destructor.
       
    98     */
       
    99     ~CMMAPlayerProperties();
       
   100 
       
   101 protected: // default constructor and second phase construction
       
   102     CMMAPlayerProperties(const TDesC& aProperties, MMMAParameterRule& aRule);
       
   103 
       
   104 public: // new methods
       
   105     /**
       
   106      * Gets property for given key. Returns EFalse if key cannot
       
   107      * be found
       
   108      */
       
   109     TBool GetProperty(const TDesC& aKey, TInt& aValue) const;
       
   110     TBool GetProperty(const TDesC& aKey, TPtrC& aValue) const;
       
   111 
       
   112     /**
       
   113      * Compares that given key and value pair can be found in
       
   114      * given properties string. Notice that this returns EFalse also
       
   115      * if given key is not found.
       
   116      */
       
   117     TBool Compare(const TDesC& aKey, const TInt& aValue) const;
       
   118     TBool Compare(const TDesC& aKey, const TDesC& aValue) const;
       
   119 
       
   120     /**
       
   121      * Validates given properties with given rule(s), leaves with
       
   122      * KErrArgument if properties was not valid.
       
   123      */
       
   124 
       
   125     void ValidateL() const;
       
   126 
       
   127 private: //data
       
   128     // properties
       
   129     const TDesC& iProperties;
       
   130     // rule composition
       
   131     MMMAParameterRule& iRule;
       
   132 };
       
   133 
       
   134 
       
   135 
       
   136 //  CLASS DECLARATION
       
   137 /**
       
   138 *   Composite class for storing rule set
       
   139 */
       
   140 
       
   141 NONSHARABLE_CLASS(CMMAParameterRuleSet): public CBase, public MMMAParameterRule
       
   142 {
       
   143 public: // Construction and destruction
       
   144     /**
       
   145     * Two-phased constructor.
       
   146     */
       
   147     static CMMAParameterRuleSet* NewLC();
       
   148 
       
   149     /**
       
   150     * Destructor.
       
   151     */
       
   152     ~CMMAParameterRuleSet();
       
   153 
       
   154 protected: // default constructor and second phase construction
       
   155     CMMAParameterRuleSet();
       
   156     virtual void ConstructL();
       
   157 
       
   158 public: // From MMMAParameterRule
       
   159     TBool ValidateAndStoreL(const TDesC& aKey, const TDesC& aValue);
       
   160     TBool Compare(const TDesC& aKey, const TDesC& aValue);
       
   161     TBool Compare(const TDesC& aKey, const TInt aValue);
       
   162     TBool FindProperty(const TDesC& aKey, TPtrC& aValue);
       
   163     TBool FindProperty(const TDesC& aKey, TInt& aValue);
       
   164 
       
   165 public: // new methods
       
   166     void AppendRuleL(MMMAParameterRule* aRule);
       
   167 
       
   168 private: // data
       
   169     // list of rules in this composite, owned
       
   170     CArrayPtrSeg< MMMAParameterRule >* iRules;
       
   171 };
       
   172 
       
   173 //  CLASS DECLARATION
       
   174 /**
       
   175 *   Base class for property rules
       
   176 */
       
   177 NONSHARABLE_CLASS(TMMAParameterRuleBase): public MMMAParameterRule
       
   178 {
       
   179 public: // constructor
       
   180     TMMAParameterRuleBase(const TDesC& aKey);
       
   181 
       
   182 public: // From MMMAParameterRule
       
   183     TBool ValidateAndStoreL(const TDesC& aKey, const TDesC& aValue);
       
   184     TBool Compare(const TDesC& aKey, const TDesC& aValue);
       
   185     TBool Compare(const TDesC& aKey, const TInt aValue);
       
   186     TBool FindProperty(const TDesC& aKey, TPtrC& aValue);
       
   187     TBool FindProperty(const TDesC& aKey, TInt& aValue);
       
   188 
       
   189 protected: // new methods
       
   190     /**
       
   191      * Returns EFalse if value is not valid for this rule
       
   192      * Derived class must also store value if it is accepted
       
   193      */
       
   194     virtual TBool ValidateValueL(const TDesC& aValue) = 0;
       
   195 
       
   196 protected: //data
       
   197     const TDesC& iKey;
       
   198     TBool iAssigned;
       
   199 };
       
   200 
       
   201 //  CLASS DECLARATION
       
   202 /**
       
   203 *   Rule for TInt
       
   204 */
       
   205 NONSHARABLE_CLASS(TMMAParameterRuleInt): public TMMAParameterRuleBase
       
   206 {
       
   207 public: // constructors
       
   208     TMMAParameterRuleInt(const TDesC& aKey);
       
   209 
       
   210     TMMAParameterRuleInt(const TDesC& aKey,
       
   211                          const TInt aLowerLimit);
       
   212 
       
   213     TMMAParameterRuleInt(const TDesC& aKey,
       
   214                          const TInt aLowerLimit,
       
   215                          const TInt aUpperLimit);
       
   216 
       
   217 public: // From MMMAParameterRule
       
   218     TBool ValidateValueL(const TDesC& aValue);
       
   219     TBool Compare(const TDesC& aKey, const TInt aValue);
       
   220     TBool FindProperty(const TDesC& aKey, TInt& aValue);
       
   221 
       
   222 
       
   223 
       
   224 private: // data
       
   225     TInt iValue;
       
   226     const TInt iUpperLimit;
       
   227     const TInt iLowerLimit;
       
   228 };
       
   229 
       
   230 //  CLASS DECLARATION
       
   231 /**
       
   232 *   Rule for TDesC
       
   233 */
       
   234 NONSHARABLE_CLASS(TMMAParameterRuleDes): public TMMAParameterRuleBase
       
   235 {
       
   236 public: // constructors
       
   237     TMMAParameterRuleDes(const TDesC& aKey);
       
   238 
       
   239     TMMAParameterRuleDes(const TDesC& aKey,
       
   240                          const TMMAStaticStrArray* aValidValues,
       
   241                          const TInt aArraySize);
       
   242 
       
   243 public: // From MMMAParameterRule
       
   244     TBool ValidateValueL(const TDesC& aValue);
       
   245     TBool Compare(const TDesC& aKey, const TDesC& aValue);
       
   246     TBool FindProperty(const TDesC& aKey, TPtrC& aValue);
       
   247 
       
   248 
       
   249 private: // data
       
   250     TPtrC iValue;
       
   251     // not owned
       
   252     const TMMAStaticStrArray* iValidValues;
       
   253     const TInt iArraySize;
       
   254 };
       
   255 #endif // CMMAPLAYERPROPERTIES_H