metadataengine/server/src/mdseventdef.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:  Class to hold description about one object and it's properties
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mdseventdef.h"
       
    19 
       
    20 #include "mdcdef.h"
       
    21 #include "mdssqliteconnection.h"
       
    22 #include "mdsindexer.h"
       
    23 
       
    24 /**
       
    25  * NewLC
       
    26  */
       
    27 CMdsEventDef* CMdsEventDef::NewLC( const TDesC& aName, const TInt32 aPriority )
       
    28 	{
       
    29 	CMdsEventDef* ret = new( ELeave ) CMdsEventDef(  );
       
    30 	CleanupStack::PushL( ret );
       
    31 	ret->ConstructL( aName, aPriority );
       
    32 	return ret;
       
    33 	}
       
    34 	
       
    35 /**
       
    36  * NewL
       
    37  */
       
    38 CMdsEventDef* CMdsEventDef::NewL( const TDesC& aName, const TInt32 aPriority )
       
    39 	{
       
    40 	CMdsEventDef* ret = CMdsEventDef::NewLC( aName, aPriority );
       
    41 	CleanupStack::Pop( ret );
       
    42 	return ret;
       
    43 	}
       
    44 
       
    45 /**
       
    46  * ConstructL
       
    47  */
       
    48 void CMdsEventDef::ConstructL( const TDesC& aName, TInt32 aPriority )
       
    49 	{
       
    50 	// check that only allowed characters (A-Z, a-z) are used
       
    51 	CheckAllowerCharatersL( aName, EFalse );
       
    52 
       
    53 	CMdsItemDef::ConstructL( aName );
       
    54 	iPriority = aPriority;
       
    55 	}
       
    56 
       
    57 /**
       
    58  * Destructor
       
    59  */
       
    60 CMdsEventDef::~CMdsEventDef()
       
    61 	{
       
    62 	}
       
    63 	
       
    64 void CMdsEventDef::StoreToDBL( const TInt aNamespaceDefId )
       
    65 	{
       
    66 	_LIT( KMdsSqlClauseAddEventDef, "INSERT INTO EventDef (NamespaceDefId, Priority, Name ) Values(?, ?, ?);" );	
       
    67 	
       
    68 	if ( GetStoredInDB() )
       
    69 		{
       
    70 		return;
       
    71 		}
       
    72 
       
    73     RRowData rowData;
       
    74     CleanupClosePushL( rowData );
       
    75 	rowData.AppendL( TColumn( aNamespaceDefId ) );
       
    76 	rowData.AppendL( TColumn( iPriority ) );
       
    77 	rowData.AppendL( TColumn( GetName().AllocL() ) );
       
    78 
       
    79 	TDefId id = MMdSIndexer::ExecuteAndGetIndexL(KMdsSqlClauseAddEventDef, rowData );
       
    80 
       
    81 	SetId( id );
       
    82  	SetStoredInDB();
       
    83 
       
    84 	CleanupStack::PopAndDestroy( &rowData );
       
    85 	}
       
    86 
       
    87 TBool CMdsEventDef::operator==( const CMdsEventDef& aEventDef ) const
       
    88 	{
       
    89 	return GetName() == aEventDef.GetName() && iPriority == aEventDef.iPriority;
       
    90 	}
       
    91 
       
    92 TUint32 CMdsEventDef::RequiredBufferSize()
       
    93 	{
       
    94 	return sizeof(TMdCEventDef) + CMdsItemDef::RequiredBufferSize();
       
    95 	}
       
    96 
       
    97 TMdCOffset CMdsEventDef::SerializeL(CMdCSerializationBuffer& aBuffer, TMdCOffset aFreeSpace)
       
    98 	{
       
    99 	TMdCEventDef eventDef;
       
   100 	eventDef.iDefId = GetId();
       
   101 	
       
   102 	// store name
       
   103 	eventDef.iName.iPtr.iCount = GetName().Length();
       
   104 	eventDef.iName.iPtr.iOffset = aFreeSpace;
       
   105 	eventDef.SerializeL( aBuffer );
       
   106 	
       
   107 	aBuffer.PositionL( aFreeSpace );
       
   108 	return CMdsItemDef::SerializeL( aBuffer );
       
   109 	}