syncmlfw/ds/dsutils/ProfileUtil/src/NsmlProfileUtil.cpp
changeset 0 b497e44ab2fc
child 66 08c8318ec9cb
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  Used in Auto-Restart to read/write profile to cenrep, read from
       
    15 *                settings database etc.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // USER INCLUDES
       
    21 #include "NsmlProfileUtil.h"
       
    22 #include <nsmldebug.h>
       
    23 		
       
    24 #ifndef __WINS__
       
    25 // This lowers the unnecessary compiler warning (armv5) to remark.
       
    26 // "Warning:  #174-D: expression has no effect..." is caused by 
       
    27 // DBG_ARGS8 macro in no-debug builds.
       
    28 #pragma diag_remark 174
       
    29 #endif
       
    30 
       
    31 // CONSTANTS
       
    32 const TInt KNsmlDsAutoStartProfileKey = 2; // 0x00000002 defined in DS cenrep
       
    33 const TInt KNsmlDsIapId 			  = 5; // 0x00000005 defined in DS cenrep
       
    34 const TInt KNsmlDsAutoStartSession    = 6; // 0x00000006 defined in DS cenrep
       
    35 const TInt KNsmlDsAutoStartTaskIdKey  = 9; // 0x00000009 defined in DS cenrep
       
    36 const TInt KNsmlMaxCenrepBufferSize   = 1024;
       
    37 const TUid KRepositoryId              = { 0x2000CF7E };
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CNsmlProfileUtil::NewLC
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 EXPORT_C CNsmlProfileUtil* CNsmlProfileUtil::NewLC()
       
    46 {
       
    47     DBG_FILE(_S8("CNsmlProfileUtil::NewLC, BEGIN"));
       
    48     CNsmlProfileUtil* self=new (ELeave) CNsmlProfileUtil();
       
    49 	CleanupStack::PushL(self);
       
    50 	self->ConstructL();
       
    51 	DBG_FILE(_S8("CNsmlProfileUtil::NewLC, END"));
       
    52 	return self;
       
    53 }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CNsmlProfileUtil::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 EXPORT_C CNsmlProfileUtil* CNsmlProfileUtil::NewL()
       
    60 {
       
    61     DBG_FILE(_S8("CNsmlProfileUtil::NewL, BEGIN"));
       
    62 	CNsmlProfileUtil* self=CNsmlProfileUtil::NewLC();
       
    63 	CleanupStack::Pop();
       
    64 	DBG_FILE(_S8("CNsmlProfileUtil::NewL, END"));
       
    65 	return self;
       
    66 }
       
    67 	
       
    68 // -----------------------------------------------------------------------------
       
    69 // CNsmlProfileUtil::~CNsmlProfileUtil
       
    70 // Destructor.
       
    71 // -----------------------------------------------------------------------------
       
    72 CNsmlProfileUtil::~CNsmlProfileUtil() 
       
    73 {
       
    74 
       
    75     DBG_FILE(_S8("CNsmlProfileUtil::~CNsmlProfileUtil, BEGIN"));
       
    76     // Free up buffers
       
    77     if ( iDisplayName ) 
       
    78     {
       
    79     	delete iDisplayName;
       
    80     }
       
    81     
       
    82     if ( iServerId ) 
       
    83     {
       
    84     	delete iServerId;
       
    85     }
       
    86     
       
    87     if ( iServerURI ) 
       
    88     {
       
    89     	delete iServerURI;
       
    90     }
       
    91     
       
    92     if ( iSyncMLUserName ) 
       
    93     {    
       
    94     	delete iSyncMLUserName;
       
    95     }
       
    96     
       
    97     if ( iSyncMLPassword ) 
       
    98     {
       
    99     	delete iSyncMLPassword;
       
   100     }
       
   101     
       
   102     if ( iSyncHTTPAuthUserName ) 
       
   103     {
       
   104     	delete iSyncHTTPAuthUserName;
       
   105     }
       
   106     
       
   107     if ( iSyncHTTPAuthPassword ) 
       
   108     {
       
   109     	delete iSyncHTTPAuthPassword;
       
   110     }
       
   111 
       
   112     // Free up content objects
       
   113     iContents.ResetAndDestroy();
       
   114     
       
   115     DBG_FILE(_S8("CNsmlProfileUtil::~CNsmlProfileUtil, END"));
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CNsmlProfileUtil::ConstructL
       
   120 // Second-phase constructor.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CNsmlProfileUtil::ConstructL() 
       
   124 {      
       
   125     // Nothing to do
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CNsmlProfileUtil::WriteToStreamL
       
   130 // 
       
   131 // -----------------------------------------------------------------------------
       
   132 void CNsmlProfileUtil::WriteToStreamL(RDesWriteStream& aStream, const TDesC& aString)
       
   133 {
       
   134     DBG_FILE(_S8("CNsmlProfileUtil::WriteToStreamL, BEGIN"));
       
   135     TInt len = aString.Length();
       
   136 	// Write string length
       
   137     aStream.WriteInt32L(len);   
       
   138    // Write content 
       
   139     if ( len == 0 )
       
   140     {
       
   141     	aStream << KNullDesC8;
       
   142     }
       
   143     else 
       
   144     {
       
   145     	aStream << aString;
       
   146     }
       
   147     DBG_FILE(_S8("CNsmlProfileUtil::WriteToStreamL, END"));
       
   148     
       
   149 }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CNsmlProfileUtil::InternalizeFromProfileL
       
   153 // 
       
   154 // -----------------------------------------------------------------------------
       
   155 EXPORT_C void CNsmlProfileUtil::InternalizeFromSettingsDBL(TInt aProfileId)
       
   156 {
       
   157 
       
   158     DBG_FILE(_S8("CNsmlProfileUtil::InternalizeFromSettingsDBL, BEGIN"));
       
   159     // Read the profile details from settings database
       
   160 	CNSmlDSSettings* dsSettings = CNSmlDSSettings::NewL();	       
       
   161 	CNSmlDSProfile* profile = dsSettings->ProfileL( aProfileId );
       
   162 	
       
   163 	iProfileId = aProfileId;	
       
   164 	iDisplayName = 	profile->StrValue( EDSProfileDisplayName ).AllocL();
       
   165 	iProtocolVer = static_cast<TSmlProtocolVersion>( profile->IntValue( EDSProfileProtocolVersion ) );	
       
   166 	iTransportId=static_cast<TSmlTransportId>( profile->IntValue( EDSProfileTransportId ) );
       
   167 	iIapId=profile->IntValue(EDSProfileIAPId);
       
   168 	iSanRequest=static_cast<TSmlServerAlertedAction>(profile->IntValue(EDSProfileServerAlertedAction));
       
   169 	iServerId = profile->StrValue( EDSProfileServerId ).AllocL();	
       
   170 	iSyncMLUserName = profile->StrValue( EDSProfileSyncServerUsername ).AllocL();	
       
   171 	iSyncMLPassword = profile->StrValue( EDSProfileSyncServerPassword ).AllocL();	
       
   172 	iServerURI = profile->StrValue( EDSProfileServerURL ).AllocL();	
       
   173 	iSyncHTTPAuthUserName = profile->StrValue( EDSProfileHttpAuthUsername ).AllocL();		
       
   174 	iSyncHTTPAuthPassword = profile->StrValue( EDSProfileHttpAuthPassword ).AllocL();
       
   175 
       
   176 
       
   177 	// Read content types
       
   178 	for ( int i = 0; i < profile->iContentTypes->Count(); i++ ) 
       
   179 	{
       
   180 	    CNsmlContentData* contentData = CNsmlContentData::NewL();
       
   181 	    
       
   182 	    // From settings DB
       
   183 	    CNSmlDSContentType* contentType = static_cast<CNSmlDSContentType*>(profile->iContentTypes->At(i));
       
   184 	   
       
   185 	    // Fill the local content data 			
       
   186 	    contentData->SetServerDataSourceL(contentType->StrValue(EDSAdapterServerDataSource));		    
       
   187 	    contentData->SetImplementationId(contentType->IntValue(EDSAdapterImplementationId));	    
       
   188 	    contentData->SetContentEnabled(contentType->IntValue(EDSAdapterEnabled));
       
   189 	    
       
   190 	    //SyncType is same for all the contents from UI
       
   191 	    iSyncType=static_cast<TSmlSyncType>(contentType->IntValue(EDSAdapterSyncType));
       
   192 	    // Add to this object
       
   193 	    iContents.Append(contentData);			
       
   194 	}
       
   195 	
       
   196 	// Cleanup
       
   197 	delete profile;
       
   198 	delete dsSettings;
       
   199 	DBG_FILE(_S8("CNsmlProfileUtil::InternalizeFromSettingsDBL, END"));
       
   200 }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CNsmlProfileUtil::InternalizeFromCenrepL
       
   204 // 
       
   205 // -----------------------------------------------------------------------------
       
   206 EXPORT_C void CNsmlProfileUtil::InternalizeFromCenrepL()
       
   207 {
       
   208     DBG_FILE(_S8("CNsmlProfileUtil::InternalizeFromCenrepL, BEGIN"));
       
   209 	// Create a temporary buffer
       
   210     HBufC8*  buffer = HBufC8::NewLC(KNsmlMaxCenrepBufferSize);
       
   211     TPtr8 ptr = buffer->Des();
       
   212     
       
   213     // Read from cenrep
       
   214     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   215     TInt err = repository->Get(KNsmlDsAutoStartProfileKey, ptr);
       
   216     User::LeaveIfError(err);    
       
   217     CleanupStack::PopAndDestroy(repository);
       
   218     
       
   219     // Open a Read stream  
       
   220     RDesReadStream stream(ptr);
       
   221     stream.PushL();
       
   222     
       
   223     //Read the size of the stream
       
   224     TInt streamsize = ptr.Size();
       
   225     DBG_FILE_CODE(streamsize,_S8("CNsmlProfileUtil::InternalizeFromCenrepL, The Size of Stream is"));
       
   226     //BPSS-7GBFF3
       
   227     if(streamsize <= 2)
       
   228     {
       
   229     	iProfileId = -99;
       
   230     }
       
   231     else
       
   232     {
       
   233 	    iProfileId = stream.ReadInt32L();
       
   234 	    
       
   235 	    iProtocolVer = static_cast<TSmlProtocolVersion>( stream.ReadInt32L() );
       
   236 	    
       
   237 	    iTransportId=static_cast<TSmlTransportId>( stream.ReadInt32L() );
       
   238 	    
       
   239 	    iIapId=stream.ReadInt32L();
       
   240 	    
       
   241 	    iSanRequest=static_cast<TSmlServerAlertedAction>( stream.ReadInt32L() );
       
   242 	    
       
   243 	    TInt size = stream.ReadInt32L();
       
   244 	    iDisplayName = HBufC::NewL(stream, size);
       
   245 	    
       
   246 	    size = stream.ReadInt32L();
       
   247 		iServerId = HBufC::NewL(stream, size);
       
   248 		
       
   249 		size = stream.ReadInt32L();
       
   250 		iSyncMLUserName = HBufC::NewL(stream, size);
       
   251 		
       
   252 		size = stream.ReadInt32L();
       
   253 		iSyncMLPassword = HBufC::NewL(stream, size);
       
   254 		
       
   255 		size = stream.ReadInt32L();
       
   256 		iServerURI = HBufC::NewL(stream, size);
       
   257 		
       
   258 		size = stream.ReadInt32L();
       
   259 		iSyncHTTPAuthUserName = HBufC::NewL(stream, size);
       
   260 		
       
   261 		size = stream.ReadInt32L();
       
   262 		iSyncHTTPAuthPassword = HBufC::NewL(stream, size);
       
   263 		    
       
   264 	    // Read the content types
       
   265 	    TInt numContentTypes = stream.ReadInt32L();
       
   266 	    for ( int i = 0; i < numContentTypes; i++ )
       
   267 	    {
       
   268 	        // Create a new content object and fill contents
       
   269 	        CNsmlContentData* data = CNsmlContentData::NewL();
       
   270 	        
       
   271 	        data->SetImplementationId(stream.ReadInt32L());
       
   272 	        
       
   273 	        size = stream.ReadInt32L();
       
   274 	        HBufC* source = HBufC::NewL(stream, size);
       
   275 	        data->SetServerDataSourceL(*source); 
       
   276 	        delete source; // Memory allocate in SetServerDataSource 
       
   277 	        
       
   278 	        data->SetContentEnabled(stream.ReadInt32L()); 	
       
   279 	        
       
   280 	        iContents.Append(data);
       
   281 	    }
       
   282 	    
       
   283 	    iSyncType=static_cast<TSmlSyncType>(stream.ReadInt32L());
       
   284     }
       
   285       
       
   286     // Close
       
   287     stream.Close();      
       
   288     CleanupStack::PopAndDestroy(2, buffer);
       
   289     
       
   290     DBG_FILE(_S8("CNsmlProfileUtil::InternalizeFromCenrepL, END"));
       
   291 }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CNsmlProfileUtil::ExternalizeToCenrepL
       
   295 // 
       
   296 // -----------------------------------------------------------------------------
       
   297 EXPORT_C void CNsmlProfileUtil::ExternalizeToCenrepL()
       
   298 {
       
   299    DBG_FILE(_S8("CNsmlProfileUtil::ExternalizeToCenrepL, BEGIN"));
       
   300 	// Create a temporary buffer
       
   301     HBufC8*  buffer = HBufC8::NewLC(KNsmlMaxCenrepBufferSize);
       
   302     TPtr8 ptr = buffer->Des();
       
   303     
       
   304     //Opens the Write stream  
       
   305     RDesWriteStream stream(ptr);
       
   306     stream.PushL();
       
   307     
       
   308     stream.WriteInt32L(iProfileId);
       
   309     stream.WriteInt32L(iProtocolVer);
       
   310     stream.WriteInt32L(iTransportId);
       
   311     stream.WriteInt32L(iIapId);
       
   312     stream.WriteInt32L(iSanRequest);
       
   313     
       
   314     WriteToStreamL(stream, *iDisplayName);
       
   315     WriteToStreamL(stream, *iServerId);
       
   316     WriteToStreamL(stream, *iSyncMLUserName);
       
   317     WriteToStreamL(stream, *iSyncMLPassword);
       
   318     WriteToStreamL(stream, *iServerURI);
       
   319     WriteToStreamL(stream, *iSyncHTTPAuthUserName);
       
   320     WriteToStreamL(stream, *iSyncHTTPAuthPassword);    
       
   321     
       
   322     // Write the content types
       
   323     stream.WriteInt32L(iContents.Count());
       
   324     for ( int i = 0; i < iContents.Count(); i++ )
       
   325     {
       
   326     	stream.WriteInt32L(iContents[i]->ImplementationId());
       
   327     	WriteToStreamL(stream, *(iContents[i]->ServerDataSource()));
       
   328     	stream.WriteInt32L(iContents[i]->ContentEnabled());
       
   329     }
       
   330     
       
   331     stream.WriteInt32L(iSyncType);
       
   332     stream.CommitL();
       
   333     stream.Close();
       
   334     CleanupStack::PopAndDestroy();
       
   335     
       
   336 	// Write to cenrep
       
   337     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   338     TInt err = repository->Set(KNsmlDsAutoStartProfileKey, ptr);
       
   339     User::LeaveIfError(err);
       
   340 
       
   341     // Cleanup    
       
   342     CleanupStack::PopAndDestroy(2, buffer);
       
   343     
       
   344      DBG_FILE(_S8("CNsmlProfileUtil::ExternalizeToCenrepL, END"));
       
   345 }
       
   346 
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CNsmlProfileUtil::ProfileId
       
   350 //
       
   351 // -----------------------------------------------------------------------------
       
   352 EXPORT_C TSmlProfileId CNsmlProfileUtil::ProfileId()
       
   353 {
       
   354 	return iProfileId;
       
   355 }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CNsmlProfileUtil::CompareIntValues
       
   359 //
       
   360 // -----------------------------------------------------------------------------
       
   361 
       
   362 TBool CNsmlProfileUtil::CompareIntValues(TInt aNewValue,TInt aCurrentValue)
       
   363 {
       
   364 	if(aNewValue==aCurrentValue)
       
   365 	   return ETrue;
       
   366 	else
       
   367 	   return EFalse;
       
   368 } 
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CNsmlProfileUtil::CompareStringValues
       
   372 //
       
   373 // -----------------------------------------------------------------------------
       
   374 
       
   375 TBool CNsmlProfileUtil::CompareStringValues(TPtr16 aNewValue, TPtr16 aCurrentValue)
       
   376 {
       
   377 
       
   378 	if(aNewValue.Compare(aCurrentValue))
       
   379 	  return EFalse;
       
   380 	else
       
   381 	  return ETrue;
       
   382 }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CNsmlProfileUtil::ProfileId
       
   386 //
       
   387 // -----------------------------------------------------------------------------
       
   388 EXPORT_C TBool CNsmlProfileUtil::IsSame(CNsmlProfileUtil& aNewProfile)
       
   389 {
       
   390     
       
   391     DBG_FILE(_S8("CNsmlProfileUtil::IsSame, BEGIN"));
       
   392     RArray<TBool> array;
       
   393     TBool chk;
       
   394     TInt i=0;
       
   395     if(aNewProfile.iProfileId==this->iProfileId)
       
   396     {
       
   397           //Do the comparision for all the fields stored in the Cenrep and the settings DB
       
   398           
       
   399           chk=CompareStringValues(aNewProfile.iDisplayName->Des(),iDisplayName->Des());
       
   400           array.Insert(chk,i++);
       
   401 	      chk =CompareIntValues(aNewProfile.iProtocolVer,iProtocolVer);
       
   402 	      array.Insert(chk,i++);
       
   403 	      chk= CompareIntValues(aNewProfile.iTransportId,iTransportId);
       
   404 	      array.Insert(chk,i++);
       
   405 	      chk=CompareIntValues(aNewProfile.iIapId,this->iIapId);
       
   406 	      DBG_FILE_CODE(aNewProfile.iIapId , _S8("CNsmlProfileUtil::IsSame, The New Profile Accessss Point ID is:"));                
       
   407 	      DBG_FILE_CODE(this->iIapId , _S8("CNsmlProfileUtil::IsSame, The Last used Accessss Point ID is:"));                
       
   408 	      if(!chk)
       
   409 	      {
       
   410 	      	TInt accesspointId;
       
   411 	      	TInt err(KErrNone);
       
   412 	      	TRAP(err, AccessPointIdL(accesspointId));
       
   413 	      	DBG_FILE_CODE(accesspointId , _S8("CNsmlProfileUtil::IsSame, The Access Point selected by the user is:"));                
       
   414 	      	chk=CompareIntValues(aNewProfile.iIapId,accesspointId);
       
   415 	      }
       
   416 	      array.Insert(chk,i++);
       
   417 	      chk=CompareStringValues(aNewProfile.iServerURI->Des(),iServerURI->Des());
       
   418 	      array.Insert(chk,i++);
       
   419 	      chk =CompareIntValues(aNewProfile.iServerPort,iServerPort);
       
   420 	      array.Insert(chk,i++);
       
   421 	      chk=CompareStringValues(aNewProfile.iSyncMLUserName->Des(),iSyncMLUserName->Des()); 
       
   422 	      array.Insert(chk,i++);
       
   423 	      chk=CompareStringValues(aNewProfile.iSyncMLPassword->Des(),iSyncMLPassword->Des()); 
       
   424 	      array.Insert(chk,i++);
       
   425 	      chk=CompareIntValues(aNewProfile.iSanRequest,iSanRequest);
       
   426 	      array.Insert(chk,i++);
       
   427 	      chk=CompareStringValues(aNewProfile.iSyncHTTPAuthUserName->Des(),iSyncHTTPAuthUserName->Des()); 
       
   428 	      array.Insert(chk,i++);
       
   429 	      chk=CompareStringValues(aNewProfile.iSyncHTTPAuthPassword->Des(),iSyncHTTPAuthPassword->Des());
       
   430 	      array.Insert(chk,i++); 
       
   431 	      chk=CompareIntValues(aNewProfile.iSyncType,iSyncType);
       
   432 	      array.Insert(chk,i++);
       
   433 	    
       
   434 	      //loop through all the contents for current profile
       
   435 	      if(iContents.Count() == aNewProfile.iContents.Count())
       
   436 	      {
       
   437 	        for(TInt k=0;k<this->iContents.Count();k++)
       
   438 	        {
       
   439 	           chk=EFalse;
       
   440 	      	    for(TInt p=0;p< aNewProfile.iContents.Count(); p++)
       
   441 	      	    {
       
   442 	      	      if(iContents[k]->ImplementationId()==aNewProfile.iContents[p]->ImplementationId()&& 
       
   443 	      	              iContents[k]->ContentEnabled()==aNewProfile.iContents[p]->ContentEnabled())
       
   444 	      	        {
       
   445 	      	             HBufC *buff1=iContents[k]->ServerDataSource();
       
   446 	      	             HBufC *buff2=aNewProfile.iContents[p]->ServerDataSource();
       
   447 	      	             chk=CompareStringValues(buff1->Des(),buff2->Des());
       
   448 	      	   	         array.Insert(chk,i++);
       
   449 	      	   	         break;
       
   450 	      	        }
       
   451 	      	     
       
   452 	      	     }
       
   453 	      	    if(!chk)
       
   454 	      	       {
       
   455 	      	    	 array.Insert(chk,i++);
       
   456 	      	    	 break;
       
   457 	      	       }
       
   458 	         }
       
   459 	      }
       
   460 	      else
       
   461 	      {
       
   462 	      	chk=EFalse;
       
   463 	      	array.Insert(chk,i++);
       
   464 	      }
       
   465    
       
   466       }
       
   467      
       
   468     for(TInt j=0;j<array.Count();j++)
       
   469     {
       
   470     	if(array[j]==EFalse)
       
   471     	{
       
   472     	    return EFalse;
       
   473     	}
       
   474     	    
       
   475     	
       
   476     }
       
   477     array.Close();
       
   478     DBG_FILE(_S8("CNsmlProfileUtil::IsSame, END"));
       
   479     return(ETrue);
       
   480     
       
   481    
       
   482 }
       
   483 
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CNsmlContentData::NewLC
       
   487 //
       
   488 // -----------------------------------------------------------------------------
       
   489 EXPORT_C CNsmlContentData* CNsmlContentData::NewLC() 
       
   490 {
       
   491     DBG_FILE(_S8("CNsmlContentData::NewLC, BEGIN"));
       
   492     CNsmlContentData* self=new (ELeave) CNsmlContentData();
       
   493     CleanupStack::PushL(self);
       
   494     self->ConstructL();
       
   495     DBG_FILE(_S8("CNsmlContentData::NewLC, END"));
       
   496     return self;
       
   497 }
       
   498        
       
   499 // -----------------------------------------------------------------------------
       
   500 // CNsmlContentData::NewL
       
   501 //
       
   502 // -----------------------------------------------------------------------------
       
   503 EXPORT_C CNsmlContentData* CNsmlContentData::NewL() 
       
   504 {   
       
   505     DBG_FILE(_S8("CNsmlContentData::NewL, BEGIN"));
       
   506     CNsmlContentData* self=CNsmlContentData::NewLC();
       
   507     CleanupStack::Pop();
       
   508     DBG_FILE(_S8("CNsmlContentData::NewL, END"));
       
   509     return self;
       
   510 }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CNsmlContentData::ConstructL
       
   514 //
       
   515 // -----------------------------------------------------------------------------
       
   516 void CNsmlContentData::ConstructL() 
       
   517 {
       
   518   //nothing to do
       
   519 }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CNsmlContentData::~CNsmlContentData
       
   523 //
       
   524 // -----------------------------------------------------------------------------
       
   525 CNsmlContentData::~CNsmlContentData() 
       
   526 {
       
   527     if ( iServerDataSource != NULL ) {
       
   528 		delete iServerDataSource;
       
   529     }   
       
   530 }       
       
   531        
       
   532 // -----------------------------------------------------------------------------
       
   533 // CNsmlContentData::ServerDataSource
       
   534 //
       
   535 // -----------------------------------------------------------------------------
       
   536 EXPORT_C HBufC* CNsmlContentData::ServerDataSource() 
       
   537 {
       
   538     return iServerDataSource;
       
   539 }
       
   540        
       
   541 // -----------------------------------------------------------------------------
       
   542 // CNsmlContentData::SetServerDataSource
       
   543 //
       
   544 // -----------------------------------------------------------------------------
       
   545 EXPORT_C void CNsmlContentData::SetServerDataSourceL(const TDesC& aServerDataSource)
       
   546 {
       
   547     iServerDataSource = aServerDataSource.AllocL();
       
   548 }
       
   549        
       
   550 // -----------------------------------------------------------------------------
       
   551 // CNsmlContentData::ImplementationId
       
   552 //
       
   553 // -----------------------------------------------------------------------------
       
   554 EXPORT_C TInt CNsmlContentData::ImplementationId() 
       
   555 {
       
   556     return iImplementationId;
       
   557 }
       
   558        
       
   559 // -----------------------------------------------------------------------------
       
   560 // CNsmlContentData::SetImplementationId
       
   561 //
       
   562 // -----------------------------------------------------------------------------
       
   563 EXPORT_C void CNsmlContentData::SetImplementationId(const TInt aImplementationId)
       
   564 {
       
   565     iImplementationId = aImplementationId;
       
   566 }
       
   567    
       
   568 // -----------------------------------------------------------------------------
       
   569 // CNsmlContentData::SetContentEnabled
       
   570 //
       
   571 // -----------------------------------------------------------------------------
       
   572 EXPORT_C void CNsmlContentData::SetContentEnabled(const TInt aContentEnabled) 
       
   573 {
       
   574     iEnabled = aContentEnabled;
       
   575 }    
       
   576  
       
   577 // -----------------------------------------------------------------------------
       
   578 // CNsmlContentData::ContentEnabled
       
   579 //
       
   580 // -----------------------------------------------------------------------------
       
   581 EXPORT_C TInt CNsmlContentData::ContentEnabled() 
       
   582 {
       
   583     return iEnabled;
       
   584 }
       
   585 
       
   586 // ---------------------------------------------------------
       
   587 // CNsmlProfileUtil::WriteInterruptFlagL()
       
   588 // Write the Interrupt Flag in the CenRep
       
   589 // ---------------------------------------------------------
       
   590 EXPORT_C void CNsmlProfileUtil::WriteInterruptFlagL(TInt aFlag)
       
   591 {
       
   592 	DBG_FILE(_S8("CNsmlProfileUtil::WriteInterruptFlagL() begins"));
       
   593    
       
   594    	// Write to cenrep
       
   595 	CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   596     TInt err = repository->Set(KNsmlDsAutoStartSession, aFlag);
       
   597     User::LeaveIfError(err);
       
   598     CleanupStack::PopAndDestroy(repository);
       
   599     
       
   600     DBG_FILE(_S8("CNsmlProfileUtil::WriteInterruptFlagL() ends"));
       
   601 }
       
   602 
       
   603 // ---------------------------------------------------------
       
   604 // CNsmlProfileUtil::IsValidResumeL()
       
   605 // Gets Interrupt Flag from the CenRep
       
   606 // ---------------------------------------------------------
       
   607 EXPORT_C void CNsmlProfileUtil::IsValidResumeL(TBool& aValue)
       
   608 {
       
   609 	DBG_FILE(_S8("CNsmlProfileUtil::IsValidResumeL() begins"));
       
   610    	
       
   611    	TInt IsInterrupt = 0;
       
   612    
       
   613     // Read from cenrep
       
   614     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   615     TInt err = repository->Get(KNsmlDsAutoStartSession, IsInterrupt);
       
   616     User::LeaveIfError(err);    
       
   617     CleanupStack::PopAndDestroy(repository);
       
   618     
       
   619      
       
   620     if(IsInterrupt == -1)
       
   621     {
       
   622     	aValue = ETrue;    	
       
   623     }    	
       
   624     else
       
   625     {
       
   626     	aValue = EFalse;
       
   627     }
       
   628     
       
   629     DBG_FILE(_S8("CNsmlProfileUtil::IsValidResumeL() ends"));
       
   630 }
       
   631 
       
   632 // ---------------------------------------------------------
       
   633 // CNsmlContentData::WriteAccessPointIdL()
       
   634 // Writes the AccessPointID in to the CenRep
       
   635 // ---------------------------------------------------------
       
   636 EXPORT_C void CNsmlProfileUtil::WriteAccessPointIdL(TInt aIAPId)
       
   637 {
       
   638 	DBG_FILE(_S8("CNsmlProfileUtil::WriteAccessPointIdL() begins"));
       
   639    
       
   640    	// Write to cenrep
       
   641 	CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   642     TInt err = repository->Set(KNsmlDsIapId, aIAPId);
       
   643     User::LeaveIfError(err);
       
   644     CleanupStack::PopAndDestroy(repository);
       
   645     
       
   646     DBG_FILE(_S8("CNsmlProfileUtil::WriteAccessPointIdL() ends"));
       
   647 }
       
   648 
       
   649 // ---------------------------------------------------------
       
   650 // CNsmlProfileUtil::AccessPointIdL()
       
   651 // Return the AccessPointId
       
   652 // ---------------------------------------------------------
       
   653 EXPORT_C void CNsmlProfileUtil::AccessPointIdL(TInt& aIAPId)
       
   654 {
       
   655 	DBG_FILE(_S8("CNsmlProfileUtil::AccessPointIdL() begins"));
       
   656    
       
   657     // Read from cenrep
       
   658     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   659     TInt err = repository->Get(KNsmlDsIapId, aIAPId);
       
   660     User::LeaveIfError(err);    
       
   661     CleanupStack::PopAndDestroy(repository);
       
   662     
       
   663     DBG_FILE(_S8("CNsmlProfileUtil::AccessPointIdL() ends"));
       
   664 }
       
   665 
       
   666 // ---------------------------------------------------------
       
   667 // CNsmlProfileUtil::InternalizeTaskIdL()
       
   668 // Read the TaskIds' from the Cenrep
       
   669 // ---------------------------------------------------------
       
   670 EXPORT_C void CNsmlProfileUtil::InternalizeTaskIdL(RArray<TSmlTaskId>& aTaskIdArray)
       
   671 {
       
   672 	DBG_FILE(_S8("CNsmlProfileUtil::InternalizeTaskIdL, BEGIN"));
       
   673 	
       
   674 	aTaskIdArray.Reset();
       
   675 	
       
   676 	// Create a temporary buffer
       
   677     HBufC8*  buffer = HBufC8::NewLC(KNsmlMaxCenrepBufferSize);
       
   678     TPtr8 ptr = buffer->Des();
       
   679     
       
   680     // Read from cenrep
       
   681     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   682     TInt err = repository->Get(KNsmlDsAutoStartTaskIdKey, ptr);
       
   683     User::LeaveIfError(err);    
       
   684     CleanupStack::PopAndDestroy(repository);
       
   685     
       
   686     // Open a Read stream  
       
   687     RDesReadStream stream(ptr);
       
   688     stream.PushL();
       
   689     
       
   690     // Read the Task Id
       
   691     DBG_FILE(_S8("CNsmlProfileUtil::InternalizeTaskIdL, Reading the TaskID"));
       
   692     TInt numTaskId = stream.ReadInt32L();
       
   693     for ( TInt i = 0; i < numTaskId; i++ )
       
   694     {
       
   695         aTaskIdArray.Append(static_cast<TSmlTaskId>(stream.ReadInt32L())); 	
       
   696     }
       
   697           
       
   698     // Close
       
   699     stream.Close();      
       
   700     CleanupStack::PopAndDestroy(2, buffer);
       
   701     
       
   702     DBG_FILE(_S8("CNsmlProfileUtil::InternalizeTaskIdL, END"));
       
   703     
       
   704 }
       
   705 
       
   706 // ---------------------------------------------------------
       
   707 // CNsmlProfileUtil::ExternalizeTaskIdL()
       
   708 // Write the TaskIds' from the Cenrep
       
   709 // ---------------------------------------------------------
       
   710 EXPORT_C void CNsmlProfileUtil::ExternalizeTaskIdL(RArray<TSmlTaskId> aTaskIdArray)
       
   711 {
       
   712 	DBG_FILE(_S8("CNsmlProfileUtil::ExternalizeTaskIdL, BEGIN"));
       
   713 	
       
   714 	// Create a temporary buffer
       
   715     HBufC8*  buffer = HBufC8::NewLC(KNsmlMaxCenrepBufferSize);
       
   716     TPtr8 ptr = buffer->Des();
       
   717     
       
   718     //Opens the Write stream  
       
   719     RDesWriteStream stream(ptr);
       
   720     stream.PushL();
       
   721     
       
   722     // Write the content types
       
   723     stream.WriteInt32L(aTaskIdArray.Count());
       
   724     for ( TInt i = 0; i < aTaskIdArray.Count(); i++ )
       
   725     {
       
   726     	stream.WriteInt32L(aTaskIdArray[i]);
       
   727     }
       
   728     
       
   729     stream.CommitL();
       
   730     stream.Close();
       
   731     
       
   732     CleanupStack::PopAndDestroy();
       
   733     
       
   734 	// Write to cenrep
       
   735 	DBG_FILE(_S8("CNsmlProfileUtil::ExternalizeTaskIdL, Writting the TaskID"));
       
   736     CRepository* repository = CRepository::NewLC(KRepositoryId);
       
   737     TInt err = repository->Set(KNsmlDsAutoStartTaskIdKey, ptr);
       
   738     User::LeaveIfError(err);
       
   739     
       
   740     // Cleanup    
       
   741     CleanupStack::PopAndDestroy(2, buffer);
       
   742     
       
   743     DBG_FILE(_S8("CNsmlProfileUtil::ExternalizeTaskIdL, END"));	
       
   744 }
       
   745 
       
   746 
       
   747 //End of file
       
   748