metadataengine/client/src/mdelogiccondition.cpp
changeset 0 c53acadfccc6
child 14 646a02f170b9
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mdelogiccondition.h"
       
    19 #include "mdeobjectcondition.h"
       
    20 #include "mdeboolpropertycondition.h"
       
    21 #include "mderelationcondition.h"
       
    22 #include "mdeeventcondition.h"
       
    23 #include "mdcserializationbuffer.h"
       
    24 #include "mdcquery.h"
       
    25 
       
    26 #include "mdepanic.h"
       
    27 
       
    28 EXPORT_C CMdELogicCondition* CMdELogicCondition::NewL(TLogicConditionOperator aOperator)
       
    29     {
       
    30     CMdELogicCondition *self = NewLC(aOperator);
       
    31     CleanupStack::Pop(self);
       
    32     return self;
       
    33     }
       
    34 
       
    35 
       
    36 EXPORT_C CMdELogicCondition* CMdELogicCondition::NewLC(TLogicConditionOperator aOperator)
       
    37     {
       
    38     CMdELogicCondition *self = new(ELeave) CMdELogicCondition(aOperator);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     return self;    
       
    42     }
       
    43 
       
    44 
       
    45 CMdELogicCondition::CMdELogicCondition(TLogicConditionOperator aOperator)
       
    46         : CMdECondition(EConditionTypeLogic), iOperator(aOperator)
       
    47     {
       
    48     }
       
    49 
       
    50 
       
    51 void CMdELogicCondition::ConstructL()
       
    52     {
       
    53     // Base class construction.
       
    54     ConditionConstruct();
       
    55     }
       
    56 
       
    57 
       
    58 
       
    59 CMdELogicCondition::~CMdELogicCondition()
       
    60     {
       
    61     iChildren.ResetAndDestroy();
       
    62     iChildren.Close();
       
    63     }
       
    64 
       
    65 
       
    66 EXPORT_C TLogicConditionOperator CMdELogicCondition::Operator() const
       
    67     {
       
    68     return iOperator;
       
    69     }
       
    70 
       
    71 
       
    72 EXPORT_C void CMdELogicCondition::SetOperator(TLogicConditionOperator aLogicOperator)
       
    73     {
       
    74     AssertNotLocked();
       
    75     
       
    76     __ASSERT_DEBUG(aLogicOperator > ELogicConditionOperatorFirst 
       
    77                     && aLogicOperator < ELogicConditionOperatorLast,
       
    78                     TMdEPanic::Panic(TMdEPanic::EInternal));
       
    79     
       
    80     iOperator = aLogicOperator;
       
    81     }
       
    82 
       
    83 
       
    84 EXPORT_C TInt CMdELogicCondition::Count() const
       
    85     {
       
    86     return iChildren.Count();
       
    87     }
       
    88     
       
    89 
       
    90 EXPORT_C CMdECondition& CMdELogicCondition::Condition(TInt aIndex) const
       
    91     {
       
    92     __ASSERT_DEBUG(aIndex >= 0 && aIndex < Count(),
       
    93                     TMdEPanic::Panic(TMdEPanic::EInternal));
       
    94     
       
    95     return *iChildren[aIndex];
       
    96     }
       
    97 
       
    98 
       
    99 EXPORT_C void CMdELogicCondition::Remove(TInt aIndex)
       
   100     {
       
   101     AssertNotLocked();
       
   102 
       
   103     __ASSERT_DEBUG(aIndex >= 0 && aIndex < Count(),
       
   104                     TMdEPanic::Panic(TMdEPanic::EInternal));
       
   105                     
       
   106     iChildren.Remove(aIndex);
       
   107     }
       
   108 
       
   109 void CMdELogicCondition::SetLocked(TBool aLocked)
       
   110     {
       
   111     // Base class locking.
       
   112     CMdECondition::SetLocked(aLocked);    
       
   113     
       
   114     const TInt count = iChildren.Count();
       
   115     
       
   116     // Lock children as well.
       
   117     for(TInt i = 0; i < count; ++i)
       
   118         {
       
   119         iChildren[i]->SetLocked(aLocked);
       
   120         }
       
   121     }
       
   122 
       
   123 TUint32 CMdELogicCondition::InternalQueryOptimizationFlags(TUint32& aFlags)
       
   124 	{
       
   125 	const TInt count = iChildren.Count();
       
   126 	
       
   127 	// get flag from childrens
       
   128 	for( TInt i = 0 ; i < count; i++)
       
   129 		{
       
   130 		iOptimizationFlags |= iChildren[i]->InternalQueryOptimizationFlags(aFlags);
       
   131 		}
       
   132 
       
   133 	return 0;
       
   134 	}
       
   135 
       
   136 
       
   137 TUint32 CMdELogicCondition::RequiredBufferSize() const
       
   138 	{
       
   139 	TUint32 bufferSize = sizeof( TMdCLogicCondition );
       
   140 
       
   141 	const TInt count = iChildren.Count();
       
   142 
       
   143 	// required size for children offsets (children count * TUint32)
       
   144 	bufferSize += count * CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   145 
       
   146 	// Required size for childrens
       
   147 	for( TInt i = 0 ; i < count; i++)
       
   148 		{
       
   149 		bufferSize += iChildren[i]->RequiredBufferSize();
       
   150 		}
       
   151 
       
   152 	return bufferSize;
       
   153 	}
       
   154 
       
   155 void CMdELogicCondition::SerializeL(CMdCSerializationBuffer& aBuffer, 
       
   156 		TMdCOffset& aFreespaceOffset) const
       
   157 	{
       
   158 	const TUint32 childrenCount = (TUint32)iChildren.Count();
       
   159 
       
   160 	// position after logic condition
       
   161 	const TUint32 conditionOffset = aBuffer.Position() + sizeof( TMdCLogicCondition );
       
   162 
       
   163 	TMdCLogicCondition condition;
       
   164 
       
   165 	condition.iConditionType = iType;
       
   166 	condition.iNegated = iNegated;
       
   167 	condition.iOperator = iOperator;
       
   168 	condition.iOptimizationFlags = iOptimizationFlags;
       
   169 	condition.iChildConditions.iPtr.iCount = childrenCount;
       
   170 	condition.iChildConditions.iPtr.iOffset = conditionOffset;
       
   171 
       
   172 	condition.SerializeL( aBuffer );
       
   173 
       
   174 	// begin position of child condition offsets
       
   175 	TUint32 childOffsetPosition = conditionOffset;
       
   176 
       
   177 	// begin position of child conditions
       
   178 	TUint32 childPosition = childOffsetPosition + 
       
   179 			CMdCSerializationBuffer::KRequiredSizeForTUint32 * childrenCount;
       
   180 
       
   181 	for( TInt i = 0 ; i < childrenCount; i++)
       
   182 		{
       
   183 		// Move to correct position of children offsets
       
   184 		aBuffer.PositionL( childOffsetPosition );
       
   185 
       
   186 		// Insert offset for current child
       
   187 		childOffsetPosition = aBuffer.InsertL( childPosition );
       
   188 
       
   189 		// Move to correct position of child
       
   190 		aBuffer.PositionL( childPosition );
       
   191 
       
   192 		// Insert current child
       
   193 		iChildren[i]->SerializeL( aBuffer, childPosition );		
       
   194 		}
       
   195 
       
   196 	// take position after subconditions
       
   197 	aFreespaceOffset = aBuffer.Position();
       
   198 	}
       
   199 
       
   200 EXPORT_C CMdELogicCondition& 
       
   201 CMdELogicCondition::AddLogicConditionL(TLogicConditionOperator aLogicOperator)
       
   202     {
       
   203     AssertNotLocked();
       
   204 
       
   205     CMdELogicCondition* condition = NewLC(aLogicOperator);
       
   206     AddL(condition);
       
   207     CleanupStack::Pop(condition);
       
   208     return *condition;
       
   209     }
       
   210 
       
   211 
       
   212 EXPORT_C CMdEObjectCondition& 
       
   213 CMdELogicCondition::AddObjectConditionL(const CMdEObjectDef& aObjectDef)
       
   214     {
       
   215     AssertNotLocked();
       
   216 
       
   217     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   218     		EObjectConditionCompareObjectDef,
       
   219     		KNoId, &aObjectDef );
       
   220     AddL(condition);
       
   221     CleanupStack::Pop(condition);
       
   222     return *condition;    
       
   223     }
       
   224 
       
   225 
       
   226 EXPORT_C CMdEObjectCondition& 
       
   227 CMdELogicCondition::AddObjectConditionL(TItemId aObjectId)
       
   228     {
       
   229     AssertNotLocked();
       
   230 
       
   231     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   232     		EObjectConditionCompareId, aObjectId );
       
   233     AddL(condition);
       
   234     CleanupStack::Pop(condition);
       
   235     return *condition;    
       
   236     }
       
   237 
       
   238 EXPORT_C CMdEObjectCondition& 
       
   239 CMdELogicCondition::AddObjectConditionL(const RArray<TItemId>& aObjectIds)
       
   240     {
       
   241     AssertNotLocked();
       
   242 
       
   243     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   244     		EObjectConditionCompareIds, &aObjectIds );
       
   245     AddL(condition);
       
   246     CleanupStack::Pop(condition);
       
   247     return *condition;    
       
   248     }
       
   249 
       
   250 EXPORT_C CMdEObjectCondition& 
       
   251 CMdELogicCondition::AddObjectConditionL(TInt64 aObjectGuidHigh, TInt64 aObjectGuidLow)
       
   252 	{
       
   253     AssertNotLocked();
       
   254 
       
   255     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   256     		EObjectConditionCompareGuid, KNoId, NULL, aObjectGuidHigh, aObjectGuidLow);
       
   257     AddL(condition);
       
   258     CleanupStack::Pop(condition);
       
   259     return *condition;
       
   260 	}
       
   261 
       
   262 EXPORT_C CMdEObjectCondition& 
       
   263 CMdELogicCondition::AddObjectConditionL(TObjectConditionCompareMethod aCompareMethod, 
       
   264                                         const TDesC& aString)
       
   265     {
       
   266     AssertNotLocked();
       
   267 
       
   268     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   269     		aCompareMethod, NULL, &aString );
       
   270     AddL(condition);
       
   271     CleanupStack::Pop(condition);
       
   272     return *condition;
       
   273     }
       
   274 
       
   275 EXPORT_C CMdEObjectCondition& 
       
   276 CMdELogicCondition::AddObjectConditionL(const TMdEUintRange& aRange)
       
   277     {
       
   278     AssertNotLocked();
       
   279 
       
   280     CMdEObjectCondition* condition = CMdEObjectCondition::NewLC( 
       
   281     		EObjectConditionCompareUsageCount, NULL, NULL, &aRange );
       
   282     AddL(condition);
       
   283     CleanupStack::Pop(condition);
       
   284     return *condition;
       
   285     }
       
   286 
       
   287 
       
   288 EXPORT_C CMdEPropertyCondition& 
       
   289 CMdELogicCondition::AddPropertyConditionL(const CMdEPropertyDef& aPropertyDef)
       
   290     {
       
   291     AssertNotLocked();
       
   292 
       
   293     CMdEPropertyCondition* condition 
       
   294         = CMdEPropertyCondition::NewLC(aPropertyDef);
       
   295     AddL(condition);
       
   296     CleanupStack::Pop(condition);
       
   297     return *condition;
       
   298     }
       
   299 
       
   300 
       
   301 EXPORT_C CMdEBoolPropertyCondition& 
       
   302 CMdELogicCondition::AddPropertyConditionL(const CMdEPropertyDef& aPropertyDef,
       
   303                                           TBool aBoolValue)
       
   304     {
       
   305     AssertNotLocked();
       
   306 
       
   307     CMdEBoolPropertyCondition* condition 
       
   308         = CMdEBoolPropertyCondition::NewLC(aPropertyDef, aBoolValue);
       
   309     AddL(condition);
       
   310     CleanupStack::Pop(condition);
       
   311     return *condition;
       
   312     }
       
   313     
       
   314 
       
   315 #define MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(RangeType) \
       
   316 EXPORT_C CMdE##RangeType##RangePropertyCondition& \
       
   317 CMdELogicCondition::AddPropertyConditionL(const CMdEPropertyDef& aPropertyDef, \
       
   318                                           const TMdE##RangeType##Range& aRange) \
       
   319     { \
       
   320     AssertNotLocked(); \
       
   321     CMdE##RangeType##RangePropertyCondition* condition  \
       
   322         = CMdE##RangeType##RangePropertyCondition::NewLC(aPropertyDef, aRange); \
       
   323     AddL(condition); \
       
   324     CleanupStack::Pop(condition); \
       
   325     return *condition; \
       
   326     }
       
   327 
       
   328 MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(Int)
       
   329 MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(Int64)
       
   330 MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(Uint)
       
   331 MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(Real)
       
   332 MDE_IMPLEMENT_ADD_RANGE_PROPERTY_CONDITION(Time)
       
   333 
       
   334 EXPORT_C CMdETextPropertyCondition& 
       
   335 CMdELogicCondition::AddPropertyConditionL(const CMdEPropertyDef& aPropertyDef,
       
   336                                           TTextPropertyConditionCompareMethod aCompareMethod,
       
   337                                           const TDesC& aText)
       
   338     {
       
   339     AssertNotLocked();
       
   340 
       
   341     CMdETextPropertyCondition* condition 
       
   342         = CMdETextPropertyCondition::NewLC(aPropertyDef, aCompareMethod, aText);
       
   343     AddL(condition);
       
   344     CleanupStack::Pop(condition);
       
   345     return *condition;
       
   346     }
       
   347 
       
   348 EXPORT_C CMdERelationCondition& 
       
   349 CMdELogicCondition::AddRelationConditionL(TItemId aRelationId, TRelationConditionSide aSide)
       
   350     {
       
   351     AssertNotLocked();
       
   352 
       
   353     CMdERelationCondition* condition = CMdERelationCondition::NewLC(aRelationId, NULL, aSide);
       
   354     AddL(condition);
       
   355     CleanupStack::Pop(condition);
       
   356     return *condition;
       
   357     }
       
   358 
       
   359 EXPORT_C CMdERelationCondition& CMdELogicCondition::AddRelationConditionL(
       
   360 		RArray<TItemId>& aRelationIds, TRelationConditionSide aSide)
       
   361     {
       
   362     AssertNotLocked();
       
   363 
       
   364     CMdERelationCondition* condition = CMdERelationCondition::NewLC(
       
   365     		KNoId, &aRelationIds, aSide);
       
   366     AddL(condition);
       
   367     CleanupStack::Pop(condition);
       
   368     return *condition;
       
   369     }
       
   370 
       
   371 EXPORT_C CMdERelationCondition& 
       
   372 CMdELogicCondition::AddRelationConditionL(TRelationConditionSide aSide)
       
   373     {
       
   374     AssertNotLocked();
       
   375 
       
   376     CMdERelationCondition* condition = CMdERelationCondition::NewLC(KNoId, NULL, aSide);
       
   377     AddL(condition);
       
   378     CleanupStack::Pop(condition);
       
   379     return *condition;
       
   380     }
       
   381     
       
   382     
       
   383 EXPORT_C CMdERelationCondition& 
       
   384 CMdELogicCondition::AddRelationConditionL(const CMdERelationDef& aRelationDef,
       
   385                                           TRelationConditionSide aSide)
       
   386     {
       
   387     AssertNotLocked();
       
   388 
       
   389     CMdERelationCondition* condition = CMdERelationCondition::NewLC( 
       
   390     		KNoId, NULL, aSide, &aRelationDef );
       
   391     AddL(condition);
       
   392     CleanupStack::Pop(condition);
       
   393     return *condition;
       
   394     }
       
   395 
       
   396 
       
   397 EXPORT_C CMdERelationCondition& 
       
   398 CMdELogicCondition::AddRelationConditionL(const CMdERelationDef& aRelationDef,
       
   399     const TMdEIntRange& aParameterRange,
       
   400     TRelationConditionSide aSide)
       
   401     {
       
   402     AssertNotLocked();
       
   403 
       
   404     CMdERelationCondition* condition = CMdERelationCondition::NewLC( KNoId, 
       
   405     		NULL, aSide, &aRelationDef, &aParameterRange );
       
   406     AddL(condition);
       
   407     CleanupStack::Pop(condition);
       
   408     return *condition;
       
   409     }
       
   410 
       
   411 EXPORT_C CMdEEventCondition& 
       
   412 CMdELogicCondition::AddEventConditionL(TItemId aEventId)
       
   413     {
       
   414     AssertNotLocked();
       
   415 
       
   416     CMdEEventCondition* condition = CMdEEventCondition::NewLC(aEventId);
       
   417     AddL(condition);
       
   418     CleanupStack::Pop(condition);
       
   419     return *condition;
       
   420     }
       
   421 
       
   422 EXPORT_C CMdEEventCondition& 
       
   423 CMdELogicCondition::AddEventConditionL(const CMdEEventDef& aEventDef)
       
   424     {
       
   425     AssertNotLocked();
       
   426 
       
   427     CMdEEventCondition* condition = CMdEEventCondition::NewLC(KNoId,&aEventDef);
       
   428     AddL(condition);
       
   429     CleanupStack::Pop(condition);
       
   430     return *condition;
       
   431     }
       
   432 
       
   433 
       
   434 EXPORT_C CMdEEventCondition& 
       
   435 CMdELogicCondition::AddEventConditionL()
       
   436     {
       
   437     AssertNotLocked();
       
   438 
       
   439     CMdEEventCondition* condition = CMdEEventCondition::NewLC();
       
   440     AddL(condition);
       
   441     CleanupStack::Pop(condition);
       
   442     return *condition;
       
   443     }
       
   444 
       
   445 
       
   446 EXPORT_C CMdEEventCondition& 
       
   447 CMdELogicCondition::AddEventConditionL(const TMdETimeRange& aCreationTimeRange)
       
   448     {
       
   449     AssertNotLocked();
       
   450 
       
   451     CMdEEventCondition* condition = CMdEEventCondition::NewLC(KNoId, NULL, &aCreationTimeRange);
       
   452     AddL(condition);
       
   453     CleanupStack::Pop(condition);
       
   454     return *condition;
       
   455     }
       
   456 
       
   457 
       
   458 EXPORT_C CMdEEventCondition& 
       
   459 CMdELogicCondition::AddEventConditionL(TEventConditionCompareMethod aCompareMethod, 
       
   460                                        const TDesC& aString)
       
   461     {
       
   462     AssertNotLocked();
       
   463 
       
   464     CMdEEventCondition* condition = CMdEEventCondition::NewLC(KNoId, NULL, NULL, aCompareMethod, &aString);
       
   465     AddL(condition);
       
   466     CleanupStack::Pop(condition);
       
   467     return *condition;
       
   468     }
       
   469 
       
   470 
       
   471 EXPORT_C CMdEEventCondition& 
       
   472 CMdELogicCondition::AddEventConditionL(const TMdETimeRange& aCreationTimeRange,
       
   473                                        TEventConditionCompareMethod aCompareMethod, 
       
   474                                        const TDesC& aString)
       
   475     {
       
   476     AssertNotLocked();
       
   477 
       
   478     CMdEEventCondition* condition = CMdEEventCondition::NewLC(KNoId, NULL, &aCreationTimeRange, aCompareMethod, &aString);
       
   479     AddL(condition);
       
   480     CleanupStack::Pop(condition);
       
   481     return *condition;
       
   482     }
       
   483 
       
   484 
       
   485 CMdECondition& CMdELogicCondition::AddL(CMdECondition* aCondition)
       
   486     {
       
   487     AssertNotLocked();
       
   488 
       
   489     iChildren.AppendL( aCondition );
       
   490     return *aCondition;
       
   491     }