metadataengine/client/src/mdeeventcondition.cpp
changeset 0 c53acadfccc6
child 40 910a23996aa0
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:  Representation of query event condition
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mdeeventcondition.h"
       
    19 #include "mdelogiccondition.h"
       
    20 #include "mdeeventdef.h"
       
    21 #include "mdscommoninternal.h"
       
    22 #include "mdepanic.h"
       
    23 #include "mdcserializationbuffer.h"
       
    24 #include "mdcquery.h"
       
    25 
       
    26 CMdEEventCondition* CMdEEventCondition::NewL( TItemId aEventId, const CMdEEventDef* aEventDef,
       
    27 		const TMdETimeRange* aCreationTimeRange, TEventConditionCompareMethod aCompareMethod,
       
    28         const TDesC* aString )
       
    29     {
       
    30     CMdEEventCondition* self = CMdEEventCondition::NewLC( aEventId, aEventDef, aCreationTimeRange,
       
    31     		aCompareMethod, aString );
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 	
       
    36 CMdEEventCondition* CMdEEventCondition::NewLC(TItemId aEventId, const CMdEEventDef* aEventDef,
       
    37 		const TMdETimeRange* aCreationTimeRange, TEventConditionCompareMethod aCompareMethod,
       
    38         const TDesC* aString )
       
    39     {
       
    40     CMdEEventCondition* self = new (ELeave) CMdEEventCondition( aEventId, aEventDef );
       
    41 	CleanupStack::PushL( self );
       
    42 	self->ConstructL( aCreationTimeRange, aCompareMethod, aString );
       
    43 	return self;
       
    44     }
       
    45 
       
    46 CMdEEventCondition::CMdEEventCondition(TItemId aEventId, const CMdEEventDef* aEventDef)
       
    47 	: CMdECondition(EConditionTypeEvent), iEventId(aEventId), iEventDef(aEventDef)
       
    48 	{
       
    49     iCompareMethod = EEventConditionCompareNone;
       
    50     iCreationTimeRange = NULL;
       
    51     iObjectConditions = NULL;
       
    52     iSourceConditions = NULL;
       
    53     iParticipantConditions = NULL;
       
    54     iURI = NULL;
       
    55 	}
       
    56 
       
    57 void CMdEEventCondition::ConstructL(const TMdETimeRange* aCreationTimeRange,
       
    58                                     TEventConditionCompareMethod aCompareMethod,
       
    59                                     const TDesC* aString)
       
    60     {
       
    61     iCompareMethod = aCompareMethod;
       
    62     
       
    63     if(aCreationTimeRange)
       
    64         {
       
    65         // Make a copy of the creation time range.
       
    66         iCreationTimeRange = new (ELeave) TMdETimeRange(*aCreationTimeRange);
       
    67         }
       
    68 
       
    69     if(aString)
       
    70         {            
       
    71         switch(aCompareMethod)
       
    72             {
       
    73             case EEventConditionCompareNone:
       
    74                 // No comparison specified.
       
    75                 break;
       
    76             
       
    77             case EEventConditionCompareSourceURI:
       
    78                 // Make a copy of the source URI descriptor.
       
    79                 iURI = aString->AllocL();
       
    80                 break;
       
    81 
       
    82             case EEventConditionCompareParticipantURI:
       
    83                 // Make a copy of the participant URI descriptor.
       
    84                 iURI = aString->AllocL();
       
    85                 break;
       
    86 
       
    87             default:
       
    88                 __ASSERT_DEBUG( EFalse, TMdEPanic::Panic(TMdEPanic::EInternal) );
       
    89             }
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 CMdEEventCondition::~CMdEEventCondition()
       
    95 	{
       
    96     delete iCreationTimeRange;
       
    97     delete iObjectConditions;
       
    98     delete iSourceConditions;
       
    99     delete iParticipantConditions;
       
   100     delete iURI;
       
   101 	}
       
   102 
       
   103 
       
   104 EXPORT_C CMdELogicCondition& CMdEEventCondition::ObjectConditionsL()
       
   105     {
       
   106 	if( !iObjectConditions )
       
   107 		{
       
   108 		iObjectConditions = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); 
       
   109 		}
       
   110 
       
   111     return *iObjectConditions;
       
   112     }
       
   113 
       
   114 
       
   115 EXPORT_C CMdELogicCondition& CMdEEventCondition::SourceObjectConditionsL()
       
   116 	{
       
   117 	if( !iSourceConditions )
       
   118 		{
       
   119 		iSourceConditions = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); 
       
   120 		}
       
   121 
       
   122     return *iSourceConditions;
       
   123 	}
       
   124 
       
   125 
       
   126 EXPORT_C CMdELogicCondition& CMdEEventCondition::ParticipantObjectConditionsL()
       
   127 	{
       
   128 	if( !iParticipantConditions )
       
   129 		{
       
   130 		iParticipantConditions = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); 
       
   131 		}
       
   132 
       
   133     return *iParticipantConditions;
       
   134 	}
       
   135 
       
   136 
       
   137 EXPORT_C TItemId CMdEEventCondition::EventId() const
       
   138     {
       
   139     return iEventId;
       
   140     }
       
   141 
       
   142 
       
   143 EXPORT_C const CMdEEventDef* CMdEEventCondition::EventDef() const
       
   144     {
       
   145     return iEventDef;
       
   146     }
       
   147     
       
   148 
       
   149 EXPORT_C const TMdETimeRange* CMdEEventCondition::TimeRange() const
       
   150     {
       
   151     return iCreationTimeRange;
       
   152     }
       
   153 
       
   154 
       
   155 EXPORT_C const TDesC* CMdEEventCondition::SourceURI() const
       
   156     {
       
   157     if ( iCompareMethod == EEventConditionCompareSourceURI )
       
   158     	{
       
   159     	return iURI;
       
   160     	}
       
   161     
       
   162     return NULL;
       
   163     }
       
   164 
       
   165 
       
   166 EXPORT_C const TDesC* CMdEEventCondition::ParticipantURI() const
       
   167     {
       
   168     if ( iCompareMethod == EEventConditionCompareParticipantURI )
       
   169     	{
       
   170     	return iURI;
       
   171     	}
       
   172     
       
   173     return NULL;
       
   174     }
       
   175 
       
   176 TUint32 CMdEEventCondition::InternalQueryOptimizationFlags(TUint32& aFlags)
       
   177 	{
       
   178 	aFlags |= EContainsEventCondition;
       
   179 	return EContainsEventCondition;
       
   180 	}
       
   181 
       
   182 TUint32 CMdEEventCondition::RequiredBufferSize() const
       
   183 	{
       
   184 	TUint32 bufferSize = sizeof( TMdCEventCondition );
       
   185 
       
   186 	// size of each object to be serialized
       
   187 	if( iCreationTimeRange )
       
   188 		{		
       
   189 		bufferSize += iCreationTimeRange->RequiredBufferSize();
       
   190 		}
       
   191 
       
   192 	if( iObjectConditions )
       
   193 		{
       
   194 		bufferSize += iObjectConditions->RequiredBufferSize();
       
   195 		}
       
   196 
       
   197 	if( iSourceConditions )
       
   198 		{
       
   199 		bufferSize += iSourceConditions->RequiredBufferSize();
       
   200 		}
       
   201 
       
   202 	if( iParticipantConditions )
       
   203 		{
       
   204 		bufferSize += iParticipantConditions->RequiredBufferSize();
       
   205 		}
       
   206 
       
   207 	if ( iURI )
       
   208 		{
       
   209 		bufferSize += CMdCSerializationBuffer::RequiredSize( *iURI );
       
   210 		}
       
   211 
       
   212 	return bufferSize;
       
   213 	}
       
   214 
       
   215 
       
   216 void CMdEEventCondition::SerializeL(CMdCSerializationBuffer& aBuffer,
       
   217 		TMdCOffset& aFreespaceOffset) const
       
   218 	{
       
   219 	TMdCEventCondition condition;
       
   220 
       
   221 	condition.iConditionType = iType;
       
   222 	condition.iNegated = iNegated;
       
   223 	condition.iCompareMethod = iCompareMethod;
       
   224 	condition.iEventId = iEventId;
       
   225 
       
   226 	if( iEventDef )
       
   227 		{	
       
   228 		condition.iEventDefId = iEventDef->Id();
       
   229 		}
       
   230 	else
       
   231 		{
       
   232 		condition.iEventDefId = KNoDefId;
       
   233 		}
       
   234 	
       
   235 	// init offsets to "zero", updated later if needed
       
   236 	condition.iCreationTimeRange = KNoOffset;
       
   237 	condition.iObjectCondition = KNoOffset;
       
   238 	condition.iSourceCondition = KNoOffset;
       
   239 	condition.iParticipantCondition = KNoOffset;
       
   240 	condition.iUriCondition = KNoOffset;
       
   241 
       
   242 	const TUint32 conditionOffset = aBuffer.Position();
       
   243 
       
   244 	// get position after condition
       
   245 	aFreespaceOffset = conditionOffset + sizeof( TMdCEventCondition );
       
   246 	aBuffer.PositionL( aFreespaceOffset );
       
   247 
       
   248 	if( iCreationTimeRange )
       
   249 		{		
       
   250 		condition.iCreationTimeRange = aFreespaceOffset;
       
   251 
       
   252 		iCreationTimeRange->SerializeL( aBuffer );
       
   253 
       
   254 		aFreespaceOffset = aBuffer.Position();
       
   255 		}
       
   256 
       
   257 	if( iObjectConditions )
       
   258 		{		
       
   259 		condition.iObjectCondition = aFreespaceOffset;
       
   260 		
       
   261 		iObjectConditions->SerializeL( aBuffer, aFreespaceOffset );
       
   262 		
       
   263 		aFreespaceOffset = aBuffer.Position();
       
   264 		}
       
   265 
       
   266 	if( iSourceConditions )
       
   267 		{		
       
   268 		condition.iSourceCondition = aFreespaceOffset;
       
   269 
       
   270 		iSourceConditions->SerializeL( aBuffer, aFreespaceOffset );
       
   271 
       
   272 		aFreespaceOffset = aBuffer.Position();
       
   273 		}
       
   274 
       
   275 	if( iParticipantConditions )
       
   276 		{		
       
   277 		condition.iParticipantCondition = aFreespaceOffset;
       
   278 
       
   279 		iParticipantConditions->SerializeL( aBuffer, aFreespaceOffset );
       
   280 
       
   281 		aFreespaceOffset = aBuffer.Position();
       
   282 		}
       
   283 
       
   284 	if ( ( EEventConditionCompareSourceURI == iCompareMethod ) || 
       
   285 		( EEventConditionCompareParticipantURI == iCompareMethod ) )
       
   286 		{
       
   287 		condition.iUriCondition = aFreespaceOffset;
       
   288 
       
   289 		aBuffer.InsertL( *iURI );
       
   290 
       
   291 		aFreespaceOffset = aBuffer.Position();
       
   292 		}
       
   293 
       
   294 	aBuffer.PositionL( conditionOffset );
       
   295 
       
   296 	condition.SerializeL( aBuffer );
       
   297 	}