metadataengine/client/src/mderelation.cpp
changeset 0 c53acadfccc6
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 
       
    19 #include "mderelation.h"
       
    20 
       
    21 #include "mdcitem.h"
       
    22 #include "mdcserializationbuffer.h"
       
    23 #include "mderelationdef.h"
       
    24 #include "mdenamespacedef.h"
       
    25 
       
    26 
       
    27 //----------------------------------------------------------
       
    28 //               TMdERelation
       
    29 //----------------------------------------------------------
       
    30 
       
    31 TMdERelation::TMdERelation()
       
    32 	: iId( KNoId ), iLeftObjectId( KNoId ),
       
    33 	  iRightObjectId( KNoId ), iDef( NULL )
       
    34 	{
       
    35 	}
       
    36 
       
    37 EXPORT_C TItemId TMdERelation::Id() const
       
    38 	{
       
    39 	return iId;
       
    40 	}
       
    41 
       
    42 EXPORT_C CMdERelationDef& TMdERelation::DefL() const
       
    43 	{
       
    44 	if ( !iDef )
       
    45 		{
       
    46 		User::Leave( KErrNotFound );
       
    47 		}
       
    48 	return *iDef;
       
    49 	}
       
    50 
       
    51 EXPORT_C TItemId TMdERelation::LeftObjectId() const
       
    52 	{
       
    53 	return iLeftObjectId;
       
    54 	}
       
    55 
       
    56 EXPORT_C TItemId TMdERelation::RightObjectId() const
       
    57 	{
       
    58 	return iRightObjectId;
       
    59 	}
       
    60 
       
    61 TUint32 TMdERelation::RequiredBufferSize() const
       
    62 	{
       
    63 	return sizeof(TMdCRelation);
       
    64 	}
       
    65 
       
    66 void TMdERelation::DeSerializeL(CMdCSerializationBuffer& aBuffer, CMdENamespaceDef& aNamespaceDef)
       
    67 	{
       
    68 	const TMdCRelation& relation = TMdCRelation::GetFromBufferL( aBuffer );
       
    69 	iId = relation.iId;
       
    70 	iLeftObjectId = relation.iLeftObjectId;
       
    71 	iRightObjectId = relation.iRightObjectId;
       
    72 	if (iId == KNoId || iLeftObjectId == KNoId || iRightObjectId == KNoId)
       
    73 		{
       
    74 		User::Leave(KErrNotFound);
       
    75 		}
       
    76 	if(iLeftObjectId == iRightObjectId )
       
    77 		{
       
    78 		User::Leave( KErrArgument );
       
    79 		}
       
    80 	iDef = aNamespaceDef.GetRelationDefL( relation.iDefId );
       
    81 	}
       
    82 
       
    83 //----------------------------------------------------------
       
    84 //               CMdERelation
       
    85 //----------------------------------------------------------
       
    86 
       
    87 CMdERelation::CMdERelation(CMdESession* aSession, TItemId aId, 
       
    88 						   CMdERelationDef& aDef, TItemId aLeftObjectId, 
       
    89 						   TItemId aRightObjectId, TInt32 aParameter)
       
    90 		: CMdEInstanceItem(aSession, aId), iDef(aDef),
       
    91 		  iLeftObjectId(aLeftObjectId), iRightObjectId(aRightObjectId), 
       
    92 		  iParameter(aParameter), iGuidHigh( 0 ), iGuidLow( 0 ), iLastModifiedDate( 0 )
       
    93 	{
       
    94 	}
       
    95 
       
    96 
       
    97 void CMdERelation::ConstructL()
       
    98 	{
       
    99 	// Same object cannot be on both side of the relation
       
   100 	if(iLeftObjectId == iRightObjectId )
       
   101 		{
       
   102 		User::Leave( KErrArgument );
       
   103 		}
       
   104 
       
   105 	InstanceItemBaseConstruct();
       
   106 	}
       
   107 
       
   108 
       
   109 CMdERelation::~CMdERelation()
       
   110 	{
       
   111 	}
       
   112 
       
   113 CMdERelation* CMdERelation::NewL(CMdERelationDef& aDef, TItemId aLeftObjectId, 
       
   114 		 TItemId aRightObjectId, TInt32 aParameter)
       
   115 	{
       
   116 	CMdERelation* ret = CMdERelation::NewLC( aDef, aLeftObjectId, aRightObjectId, aParameter );
       
   117 	CleanupStack::Pop( ret );
       
   118 	return ret;
       
   119 	}
       
   120 
       
   121 CMdERelation* CMdERelation::NewLC(CMdERelationDef& aDef, TItemId aLeftObjectId, 
       
   122 		 TItemId aRightObjectId, TInt32 aParameter)
       
   123 	{
       
   124 	CMdERelation* ret = new (ELeave) CMdERelation( NULL, KNoId, aDef, aLeftObjectId, aRightObjectId, aParameter );
       
   125 	CleanupStack::PushL( ret );
       
   126 	ret->ConstructL();
       
   127 	return ret;
       
   128 	}
       
   129 
       
   130 CMdERelation* CMdERelation::NewL(CMdESession* aSession, CMdCSerializationBuffer& aBuffer, CMdENamespaceDef& aNamespaceDef)
       
   131 	{
       
   132 	CMdERelation* ret = CMdERelation::NewLC( aSession, aBuffer, aNamespaceDef );
       
   133 	CleanupStack::Pop( ret );
       
   134 	return ret;
       
   135 	}
       
   136 
       
   137 CMdERelation* CMdERelation::NewLC(CMdESession* aSession, CMdCSerializationBuffer& aBuffer, CMdENamespaceDef& aNamespaceDef)
       
   138 	{
       
   139 	const TMdCRelation& serializedRelation = TMdCRelation::GetFromBufferL( aBuffer );
       
   140 	if (serializedRelation.iId == KNoId)
       
   141 		{
       
   142 		User::Leave( KErrNotFound );
       
   143 		}
       
   144 	if (serializedRelation.iDefId == KNoDefId)
       
   145 		{
       
   146 		User::Leave( KErrNotFound );
       
   147 		}
       
   148 	CMdERelationDef* relationDef = aNamespaceDef.GetRelationDefL( serializedRelation.iDefId );
       
   149 	if ( !relationDef )
       
   150 		{
       
   151 		User::Leave( KErrNotFound );
       
   152 		}
       
   153 	if (serializedRelation.iLeftObjectId == KNoId)
       
   154 		{
       
   155 		User::Leave( KErrNotFound );
       
   156 		}
       
   157 	if (serializedRelation.iRightObjectId == KNoId)
       
   158 		{
       
   159 		User::Leave( KErrNotFound );
       
   160 		}
       
   161 
       
   162 	CMdERelation* relation = new (ELeave) CMdERelation( aSession, serializedRelation.iId, *relationDef,
       
   163 			serializedRelation.iLeftObjectId, serializedRelation.iRightObjectId, serializedRelation.iParameter );
       
   164 	CleanupStack::PushL( relation );
       
   165 
       
   166 	relation->SetGuid( serializedRelation.iGuidHigh, serializedRelation.iGuidLow );
       
   167 
       
   168 	relation->SetLastModifiedDate( serializedRelation.iLastModifiedDate );
       
   169 
       
   170 	return relation;
       
   171 	}
       
   172 
       
   173 EXPORT_C CMdERelationDef& CMdERelation::Def() const
       
   174 	{
       
   175 	return iDef;
       
   176 	}
       
   177 
       
   178 
       
   179 EXPORT_C TItemId CMdERelation::LeftObjectId() const
       
   180 	{
       
   181 	return iLeftObjectId;
       
   182 	}
       
   183 
       
   184 
       
   185 EXPORT_C TItemId CMdERelation::RightObjectId() const
       
   186 	{
       
   187 	return iRightObjectId;
       
   188 	}
       
   189 	
       
   190 EXPORT_C TInt32 CMdERelation::Parameter() const
       
   191 	{
       
   192 	return iParameter;
       
   193 	}
       
   194 
       
   195 EXPORT_C void CMdERelation::SetParameter(TInt32 aParameter)
       
   196 	{
       
   197 	iParameter = aParameter;
       
   198 	}
       
   199 	
       
   200 EXPORT_C void CMdERelation::SetLeftObjectIdL( TItemId aLeftObjectId )
       
   201 	{
       
   202 	// Same object cannot be on both side of the relation
       
   203 	if( aLeftObjectId == iRightObjectId )
       
   204 		{
       
   205 		User::Leave( KErrArgument );
       
   206 		}
       
   207 
       
   208 	iLeftObjectId = aLeftObjectId;
       
   209 	}
       
   210 
       
   211 EXPORT_C void CMdERelation::SetRightObjectIdL( TItemId aRightObjectId )
       
   212 	{
       
   213 	// Same object cannot be on both side of the relation
       
   214 	if( aRightObjectId == iLeftObjectId )
       
   215 		{
       
   216 		User::Leave( KErrArgument );
       
   217 		}
       
   218 
       
   219 	iRightObjectId = aRightObjectId;
       
   220 	}
       
   221 
       
   222 EXPORT_C void CMdERelation::Guid(TInt64& aGuidHigh, TInt64& aGuidLow) const
       
   223 	{
       
   224 	aGuidHigh = iGuidHigh;
       
   225 	aGuidLow = iGuidLow;
       
   226 	}
       
   227 
       
   228 EXPORT_C void CMdERelation::SetGuid(const TInt64& aGuidHigh, const TInt64& aGuidLow)
       
   229 	{
       
   230 	iGuidHigh = aGuidHigh;
       
   231 	iGuidLow = aGuidLow;
       
   232 	}
       
   233 
       
   234 EXPORT_C TTime CMdERelation::LastModifiedDate() const
       
   235 	{
       
   236 	return iLastModifiedDate;
       
   237 	}
       
   238 
       
   239 EXPORT_C void CMdERelation::SetLastModifiedDate(TTime aLastModifiedDate)
       
   240 	{
       
   241 	iLastModifiedDate = aLastModifiedDate;
       
   242 	}
       
   243 
       
   244 TUint32 CMdERelation::RequiredBufferSize() const
       
   245 	{
       
   246 	return sizeof(TMdCRelation);
       
   247 	}
       
   248 
       
   249 TMdCOffset CMdERelation::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreespaceOffset) const
       
   250 	{
       
   251 	TMdCRelation relation;
       
   252 	relation.iId = Id();
       
   253 	relation.iDefId = iDef.Id();
       
   254 	relation.iLeftObjectId = iLeftObjectId;
       
   255 	relation.iRightObjectId = iRightObjectId;
       
   256 	relation.iParameter = iParameter;
       
   257 	relation.iGuidHigh = iGuidHigh;
       
   258 	relation.iGuidLow = iGuidLow;
       
   259 	relation.iLastModifiedDate = iLastModifiedDate;
       
   260 	
       
   261 	relation.SerializeL( aBuffer );
       
   262 	return aFreespaceOffset;
       
   263 	}
       
   264 
       
   265 TMdEInstanceType CMdERelation::InstanceType() const
       
   266 	{
       
   267 	return EMdETypeRelation;
       
   268 	}