omadm/omadmextensions/adapters/syncmlds/tsrc/src/TestDmDDFObject.cpp
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of DM adapter test component
       
    15 * 	This is part of omadmextensions/adapter test application.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 
       
    26 #include "TestDmDDFObject.h"
       
    27 #include "StifLogger.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 //extern  ?external_data;
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 //extern ?external_function( ?arg_type,?arg_type );
       
    34 
       
    35 // CONSTANTS
       
    36 //const ?type ?constant_var = ?constant;
       
    37 
       
    38 // MACROS
       
    39 //#define ?macro ?macro_def
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 //const ?type ?constant_var = ?constant;
       
    43 //#define ?macro_name ?macro_def
       
    44 
       
    45 // MODULE DATA STRUCTURES
       
    46 //enum ?declaration
       
    47 //typedef ?declaration
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 //?type ?function_name( ?arg_type, ?arg_type );
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 //class ?FORWARD_CLASSNAME;
       
    54 
       
    55 // ============================= LOCAL FUNCTIONS ===============================
       
    56 
       
    57 
       
    58 
       
    59 
       
    60 // ============================ MEMBER FUNCTIONS ===============================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CTestDmDDFObject::CTestDmDDFObject
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CTestDmDDFObject::CTestDmDDFObject( CStifLogger *aLog )
       
    69 	: iName( 0 )
       
    70 	, iAccessTypes()
       
    71 	, iDefaultValue( 0 )
       
    72 	, iDescription( 0 )
       
    73 	, iFormat( (TDFFormat)0 )
       
    74 	, iOccurence( (TOccurence)0 )
       
    75 	, iScope( (TScope)0 )
       
    76 	, iTitle ( 0 )
       
    77 	, iMimeType( 0 )
       
    78 	, iObjectGroup( EFalse )
       
    79 	, iLog( aLog )
       
    80 //	RPointerArray<CTestDmDDFObject> iChildren;
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CTestDmDDFObject::ConstructL
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CTestDmDDFObject::ConstructL()
       
    90     {
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CTestDmDDFObject::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CTestDmDDFObject* CTestDmDDFObject::NewL( CStifLogger *aLog )
       
    99     {
       
   100     CTestDmDDFObject* self = CTestDmDDFObject::NewLC( aLog );
       
   101     CleanupStack::Pop( self );
       
   102 
       
   103     return self;
       
   104     }
       
   105 
       
   106 CTestDmDDFObject* CTestDmDDFObject::NewLC( CStifLogger *aLog )
       
   107     {
       
   108     CTestDmDDFObject* self = new( ELeave ) CTestDmDDFObject( aLog );
       
   109     
       
   110     CleanupStack::PushL( self );
       
   111     self->ConstructL();
       
   112 
       
   113     return self;
       
   114     }
       
   115 
       
   116     
       
   117 // Destructor
       
   118 CTestDmDDFObject::~CTestDmDDFObject()
       
   119     {
       
   120 	delete iName;
       
   121 	delete iDefaultValue;
       
   122 	delete iDescription;
       
   123 	delete iTitle;
       
   124 	delete iMimeType;
       
   125 	iChildren.ResetAndDestroy();
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CTestDmDDFObject::?member_function
       
   131 // ?implementation_description
       
   132 // (other items were commented in a header).
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 /*?type CTestDmDDFObject::?member_function(
       
   136     ?arg_type arg,
       
   137     ?arg_type arg )
       
   138     {
       
   139     
       
   140     ?code
       
   141     
       
   142     }
       
   143 */
       
   144 
       
   145 void CTestDmDDFObject::SetAccessTypesL( TSmlDmAccessTypes aAccessTypes )
       
   146 	{
       
   147 	iLog->Log( _L8( "SetAccessTypesL, aAccessTypes=%d" ), aAccessTypes.GetACL() );
       
   148 	iAccessTypes = aAccessTypes;
       
   149 	}
       
   150 
       
   151 void CTestDmDDFObject::SetDefaultValueL( const TDesC8& aDefaultValue )
       
   152 	{
       
   153 	iLog->Log( _L8( "SetDefaultValueL, aDefaultValue='%S'" ), &aDefaultValue );
       
   154 	delete iDefaultValue;
       
   155 	iDefaultValue = 0;
       
   156 	iDefaultValue = aDefaultValue.AllocL();
       
   157 	}
       
   158 
       
   159 void CTestDmDDFObject::SetDescriptionL( const TDesC8& aDescription )
       
   160 	{
       
   161 	iLog->Log( _L8( "SetDescriptionL, aDescription='%S'" ), &aDescription );
       
   162 	delete iDescription;
       
   163 	iDescription = 0;
       
   164 	iDescription = aDescription.AllocL();
       
   165 	}
       
   166 	
       
   167 void CTestDmDDFObject::SetDFFormatL( TDFFormat aFormat )
       
   168 	{
       
   169 	iLog->Log( _L8( "SetDFFormatL, aFormat=%d" ), aFormat );
       
   170 	iFormat = aFormat;
       
   171 	}
       
   172 	
       
   173 void CTestDmDDFObject::SetOccurenceL( TOccurence aOccurence )
       
   174 	{
       
   175 	iLog->Log( _L8( "SetOccurenceL, aOccurence=%d" ), aOccurence );
       
   176 	iOccurence = aOccurence;
       
   177 	}
       
   178 	
       
   179 void CTestDmDDFObject::SetScopeL( TScope aScope )
       
   180 	{
       
   181 	iLog->Log( _L8( "SetScopeL, aScope=%d" ), aScope );
       
   182 	iScope = aScope;
       
   183 	}
       
   184 	
       
   185 void CTestDmDDFObject::SetDFTitleL( const TDesC8& aTitle )
       
   186 	{
       
   187 	iLog->Log( _L8( "SetDFTitleL, aTitle='%S'" ), &aTitle );
       
   188 	delete iTitle;
       
   189 	iTitle = 0;
       
   190 	iTitle = aTitle.AllocL();
       
   191 	}
       
   192 	
       
   193 void CTestDmDDFObject::AddDFTypeMimeTypeL( const TDesC8& aMimeType )
       
   194 	{
       
   195 	iLog->Log( _L8( "AddDFTypeMimeTypeL, aMimeType='%S'" ), &aMimeType );
       
   196 	delete iMimeType;
       
   197 	iMimeType = 0;
       
   198 	iMimeType = aMimeType.AllocL();
       
   199 	}
       
   200 	
       
   201 void CTestDmDDFObject::SetAsObjectGroup()
       
   202 	{
       
   203 	iLog->Log( _L8( "SetAsObjectGroup, true" ) );
       
   204 	iObjectGroup = ETrue;
       
   205 	}
       
   206 	
       
   207 MSmlDmDDFObject& CTestDmDDFObject::AddChildObjectL(const TDesC8& aNodeName)
       
   208 	{
       
   209 	iLog->Log( _L8( "AddChildObjectL, aNodeName='%S'" ), &aNodeName );
       
   210 	CTestDmDDFObject* child = CTestDmDDFObject::NewLC( iLog ); //, aNodeName );
       
   211 	child->SetNameL( aNodeName );
       
   212 	iChildren.AppendL( child );
       
   213 	CleanupStack::Pop( child ); // Don't destroy
       
   214 	return *child;
       
   215 	}
       
   216 
       
   217 MSmlDmDDFObject& CTestDmDDFObject::AddChildObjectGroupL()
       
   218 	{
       
   219 	iLog->Log( _L8( "AddChildObjectGroupL, ''" ) );
       
   220 	CTestDmDDFObject* child = CTestDmDDFObject::NewLC( iLog ); //, KNullDesC );
       
   221 	child->SetAsObjectGroup();
       
   222 	iChildren.AppendL( child );
       
   223 	CleanupStack::Pop( child ); // Don't destroy
       
   224 	return *child;
       
   225 	}
       
   226 
       
   227 // Own functions
       
   228 
       
   229 void CTestDmDDFObject::SetNameL( const TDesC8& aName )
       
   230 	{
       
   231 	delete iName;
       
   232 	iName = 0;
       
   233 	iName = aName.AllocL();
       
   234 	}
       
   235 
       
   236 void CTestDmDDFObject::DumpL( const TDesC8& aParentName, TBool aFullDump )
       
   237 	{
       
   238 	TPtrC8 name( _L8("<X>") );
       
   239 	if (iName && iName->Length() > 0)
       
   240 		{
       
   241 		name.Set( *iName );
       
   242 		}
       
   243 
       
   244 	HBufC8* fullName = HBufC8::NewLC( aParentName.Length() + name.Length() + 1 );
       
   245 	*fullName = aParentName;
       
   246 	if (aParentName.Length() > 0 && aParentName[ aParentName.Length() - 1 ] != '/')
       
   247 		{
       
   248 		fullName->Des().Append( _L8("/"));
       
   249 		}
       
   250 	fullName->Des().Append( name );
       
   251 
       
   252 	/* Translate some members to text for dumping */
       
   253 	TBuf8<20> strAccessTypes;
       
   254 	TUint8 accessTypes = iAccessTypes.GetACL();
       
   255 	if ((accessTypes & iAccessTypes.EAccessType_Add) != 0)
       
   256 		{
       
   257 		strAccessTypes.Append( _L8("A") );
       
   258 		}
       
   259 	if ((accessTypes & iAccessTypes.EAccessType_Copy) != 0)
       
   260 		{
       
   261 		strAccessTypes.Append( _L8("C") );
       
   262 		}
       
   263 	if ((accessTypes & iAccessTypes.EAccessType_Delete) != 0)
       
   264 		{
       
   265 		strAccessTypes.Append( _L8("D") );
       
   266 		}
       
   267 	if ((accessTypes & iAccessTypes.EAccessType_Exec) != 0)
       
   268 		{
       
   269 		strAccessTypes.Append( _L8("E") );
       
   270 		}
       
   271 	if ((accessTypes & iAccessTypes.EAccessType_Get) != 0)
       
   272 		{
       
   273 		strAccessTypes.Append( _L8("G") );
       
   274 		}
       
   275 	if ((accessTypes & iAccessTypes.EAccessType_Replace) != 0)
       
   276 		{
       
   277 		strAccessTypes.Append( _L8("R") );
       
   278 		}
       
   279 	
       
   280 	TBuf8<20> strFormat;
       
   281 	switch( iFormat )
       
   282 		{
       
   283 	case EB64:
       
   284 		strFormat = _L8("Base64");
       
   285 		break;
       
   286 	case EBool:
       
   287 		strFormat = _L8("Bool");
       
   288 		break;
       
   289 	case EChr:
       
   290 		strFormat = _L8("Chr");
       
   291 		break;
       
   292 	case EInt:
       
   293 		strFormat = _L8("Int");
       
   294 		break;
       
   295 	case ENode:
       
   296 		strFormat = _L8("Node");
       
   297 		break;
       
   298 	case ENull:
       
   299 		strFormat = _L8("Null");
       
   300 		break;
       
   301 	case EXml:
       
   302 		strFormat = _L8("Xml");
       
   303 		break;
       
   304 	case EBin:
       
   305 		strFormat = _L8("Bin");
       
   306 		break;
       
   307 	default:
       
   308 		break;
       
   309 		}
       
   310 
       
   311 
       
   312 	TBuf8<20> strOccurence;
       
   313 	switch( iOccurence )
       
   314 		{
       
   315 	case EOne:
       
   316 		/** The node appears exactly once */
       
   317 		strOccurence = _L8("M:1");
       
   318 		break;
       
   319 	case EZeroOrOne:
       
   320 		/** The node is optional and may appear zero or once */
       
   321 		strOccurence = _L8("O:0-1");
       
   322 		break;
       
   323 	case EZeroOrMore:
       
   324 		/** The node is optional and may appear zero or more times */
       
   325 		strOccurence = _L8("O:0-*");
       
   326 		break;
       
   327 	case EOneOrMore:
       
   328 		/** The node is mandatory and may appear once or more times */
       
   329 		strOccurence = _L8("M:1-*");
       
   330 		break;
       
   331 	case EZeroOrN:
       
   332 		/** The node is optional and may appear between once and 'N' times */
       
   333 		strOccurence = _L8("O:1-N");
       
   334 		break;
       
   335 	case EOneOrN:
       
   336 		/** The node is mandatory and may appear between once and 'N' times */
       
   337 		strOccurence = _L8("M:1-N");
       
   338 		break;
       
   339 	default:
       
   340 		break;
       
   341 		}
       
   342 	
       
   343 	
       
   344 	TBuf8<20> strScope;
       
   345 	switch( iScope)
       
   346 		{
       
   347 	case EPermanent:
       
   348 		/** The node appears exactly once */
       
   349 		strScope = _L8("Permanent");
       
   350 		break;
       
   351 	case EDynamic:
       
   352 		/** The node is optional and may appear zero or once */
       
   353 		strScope = _L8("O:Dynamic");
       
   354 		break;
       
   355 	default:
       
   356 		break;
       
   357 		}
       
   358 
       
   359 	
       
   360 	/* Dump main data */
       
   361 	if (aFullDump)
       
   362 		{
       
   363 		iLog->Log( _L8( "DDFObject: '%S'" ), fullName );
       
   364 		}
       
   365 		else
       
   366 		{
       
   367 		iLog->Log( _L8( "DDFObject: '%S'   (%S), %S, %S, %S" ),
       
   368 					fullName, &strAccessTypes, &strFormat, &strOccurence, &strScope );
       
   369 		}
       
   370 	
       
   371 	/* Dump members */
       
   372 	if (aFullDump)
       
   373 		{
       
   374 		TPtrC8 empty( _L8( "<null>" ) );
       
   375 		#define CHK_NULL(a) ((a)==0?(TDesC8*)(&empty):(TDesC8*)(a))
       
   376 
       
   377 		iLog->Log( _L8( "    iName=='%S'" ), iName );
       
   378 		iLog->Log( _L8( "    iAccessTypes=%d (%S)" ), iAccessTypes.GetACL(), &strAccessTypes );
       
   379 		iLog->Log( _L8( "    iDefaultValue='%S'" ), CHK_NULL(iDefaultValue));
       
   380 		iLog->Log( _L8( "    iDescription='%S'" ), CHK_NULL(iDescription ));
       
   381 		iLog->Log( _L8( "    iFormat=%d (%S)" ), iFormat, &strFormat );
       
   382 		iLog->Log( _L8( "    iOccurence=%d (%S)" ), iOccurence, &strOccurence );
       
   383 		iLog->Log( _L8( "    iScope=%d (%S)" ), iScope, &strScope );
       
   384 		iLog->Log( _L8( "    iTitle='%S'" ), CHK_NULL(iTitle ));
       
   385 		iLog->Log( _L8( "    iMimeType='%S'" ), CHK_NULL(iMimeType ));
       
   386 		iLog->Log( _L8( "----------------------------------" ) );
       
   387 		}
       
   388 	
       
   389 	/* Dump children */
       
   390 	for (TInt i = 0 ; i < iChildren.Count() ; i++)
       
   391 		{
       
   392 		iChildren[i]->DumpL( *fullName, aFullDump );
       
   393 		}
       
   394 
       
   395 	CleanupStack::PopAndDestroy( fullName );
       
   396 	}
       
   397 
       
   398 /*
       
   399 void CTestDmDDFObject::ExternalizeL(RWriteStream& aStream) const
       
   400 	{
       
   401 	X;
       
   402 	aStream << *iName << eol;
       
   403 	}
       
   404 */
       
   405 
       
   406 const TDesC8& CTestDmDDFObject::Name()
       
   407 	{
       
   408 	return (iName != 0) ? *iName : KNullDesC8();
       
   409 	}
       
   410 
       
   411 TSmlDmAccessTypes  CTestDmDDFObject::AccessTypes()
       
   412 	{
       
   413 	return iAccessTypes;
       
   414 	}
       
   415 
       
   416 const TDesC8& CTestDmDDFObject::DefaultValue()
       
   417 	{
       
   418 	return (iDefaultValue != 0) ? *iDefaultValue : KNullDesC8();
       
   419 	}
       
   420 
       
   421 const TDesC8& CTestDmDDFObject::Description()
       
   422 	{
       
   423 	return (iDescription != 0) ? *iDescription : KNullDesC8();
       
   424 	}
       
   425 
       
   426 CTestDmDDFObject::TDFFormat CTestDmDDFObject::DFFormat()
       
   427 	{
       
   428 	return iFormat;
       
   429 	}
       
   430 
       
   431 CTestDmDDFObject::TOccurence CTestDmDDFObject::Occurence()
       
   432 	{
       
   433 	return iOccurence;
       
   434 	}
       
   435 
       
   436 CTestDmDDFObject::TScope CTestDmDDFObject::Scope()
       
   437 	{
       
   438 	return iScope;
       
   439 	}
       
   440 
       
   441 const TDesC8& CTestDmDDFObject::DFTitle()
       
   442 	{
       
   443 	return (iTitle != 0) ? *iTitle : KNullDesC8();
       
   444 	}
       
   445 
       
   446 const TDesC8& CTestDmDDFObject::DFTypeMimeType()
       
   447 	{
       
   448 	return (iMimeType != 0) ? *iMimeType : KNullDesC8();
       
   449 	}
       
   450 
       
   451 TBool CTestDmDDFObject::ObjectGroup()
       
   452 	{
       
   453 	return iObjectGroup;
       
   454 	}
       
   455 
       
   456 TInt CTestDmDDFObject::ChildObjectCount()
       
   457 	{
       
   458 	return iChildren.Count();
       
   459 	}
       
   460 
       
   461 CTestDmDDFObject& CTestDmDDFObject::ChildObject( TInt aIndex )
       
   462 	{
       
   463 	return *iChildren[aIndex];
       
   464 	}
       
   465 
       
   466 CTestDmDDFObject* CTestDmDDFObject::FindChildObject( const TDesC8& aName )
       
   467 	{
       
   468 	CTestDmDDFObject* foundObject = 0;
       
   469 
       
   470 	for (TInt i = 0 ; i < iChildren.Count() ; i++)
       
   471 		{
       
   472 		if ( aName.CompareC( iChildren[i]->Name() ) == 0 )
       
   473 			{
       
   474 			foundObject = iChildren[i];
       
   475 			break;
       
   476 			}
       
   477 		}
       
   478 
       
   479 	return foundObject;
       
   480 	}
       
   481 
       
   482 TInt CTestDmDDFObject::SubObjectsCount()
       
   483 	{
       
   484 	TInt count = 0;
       
   485 
       
   486 	TInt i;
       
   487 	for (i = 0 ; i < iChildren.Count() ; i++)
       
   488 		{
       
   489 		count += iChildren[i]->SubObjectsCount();
       
   490 		}
       
   491 	count += i;
       
   492 
       
   493 	return count;
       
   494 	}
       
   495 
       
   496 /*
       
   497 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // ?function_name implements...
       
   501 // ?implementation_description.
       
   502 // Returns: ?value_1: ?description
       
   503 //          ?value_n: ?description
       
   504 //                    ?description
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 ?type  ?function_name(
       
   508     ?arg_type arg,  // ?description
       
   509     ?arg_type arg )  // ?description
       
   510     {
       
   511 
       
   512     ?code
       
   513 
       
   514     }
       
   515 */
       
   516 //  End of File