syncmlfw/dm/treemodule/src/nsmldmmodule.cpp
changeset 0 b497e44ab2fc
child 25 b183ec05bd8c
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2005 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:  DM Tree module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <nsmldebug.h>
       
    21 #include <nsmldmmodule.h>
       
    22 #include "nsmldmddf.h"
       
    23 #include "nsmldmcommandbuffer.h"
       
    24 #include "nsmldmtreeconstants.h"
       
    25 #include "nsmldmuri.h"
       
    26 #include <featmgr.h>
       
    27 
       
    28 _LIT8(KNSmlDmUriDDF, "DDF");
       
    29 _LIT8(KNSmlDmPropetyACL, "ACL");
       
    30 _LIT8(KNSmlDmPropetyFormat, "Format");
       
    31 _LIT8(KNSmlDmPropetyName, "Name");
       
    32 _LIT8(KNSmlDmPropetySize, "Size");
       
    33 _LIT8(KNSmlDmPropetyType, "Type");
       
    34 _LIT8(KNSmlDmPropertyCaseSense, "CaseSense");
       
    35 _LIT8(KNSmlDmDDFDevInfoModDDF, "DevInfo/Ext/ModDDF");
       
    36 
       
    37 // ===========================================================================
       
    38 // CSmlDmModule
       
    39 // ===========================================================================
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CNSmlDmModule::~CNSmlDmModule()
       
    43 // ----------------------------------------------------------------------------
       
    44 CNSmlDmModule::~CNSmlDmModule()
       
    45 	{
       
    46 	delete iDDF;
       
    47 	delete iCommandBuffer;
       
    48 	iPropResults.ResetAndDestroy();
       
    49 	FeatureManager::UnInitializeLib();
       
    50 	}
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CNSmlDmModule* CNSmlDmModule::NewL( MNSmlDmModuleCallBack* aCallBack)
       
    54 // ----------------------------------------------------------------------------
       
    55 EXPORT_C CNSmlDmModule* CNSmlDmModule::NewL( MNSmlDmModuleCallBack* aCallBack)
       
    56 	{
       
    57 	CNSmlDmModule* self = new (ELeave) CNSmlDmModule();
       
    58 	CleanupStack::PushL(self);
       
    59 	self->ConstructL();
       
    60 	self->iCallBack = aCallBack;
       
    61 	CleanupStack::Pop();
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // void CNSmlDmModule::SetServerL(const TDesC& aServer)
       
    68 // Sets the server
       
    69 // ----------------------------------------------------------------------------
       
    70 EXPORT_C void CNSmlDmModule::SetServerL(const TDesC8& aServer)
       
    71 	{
       
    72 	_DBG_FILE("CNSmlDmModule::SetServer() : begin");
       
    73 	iDDF->SetServerL(aServer);
       
    74 	_DBG_FILE("CNSmlDmModule::SetServer() : end");
       
    75 	}
       
    76 
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // void CNSmlDmModule::AddObjectL(const TDesC8& aURI, const TDesC8& aObject,
       
    80 //		const TDesC8& aType, TInt aStatusRef )
       
    81 // Add operation in DM protocoll
       
    82 // ----------------------------------------------------------------------------
       
    83 EXPORT_C void CNSmlDmModule::AddObjectL(const TDesC8& aURI,
       
    84 	const TDesC8& aObject,
       
    85 	const TDesC8& aType,
       
    86 	TInt aStatusRef,
       
    87 	TBool aLargeItem )
       
    88 	{
       
    89 	_DBG_FILE("CNSmlDmModule::AddObjectL() : begin");
       
    90 
       
    91 	TPtrC8 uri = NSmlDmURI::RemoveDotSlash(aURI);
       
    92 
       
    93 	if(iInTransaction)
       
    94 		{
       
    95 		if(aLargeItem)
       
    96 			{
       
    97 			DoSetStatusL(aStatusRef,KNSmlDmStatusCommandFailed);
       
    98 			return;
       
    99 			}
       
   100 		//command buffering
       
   101 		iCommandBuffer->AddObjectL(uri,aObject,aType,aStatusRef);
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		TInt status = KNSmlDmNoStatus;
       
   106 		CNSmlDmDDF::TAccess access = iDDF->CheckURIL(NSmlDmURI::RemoveProp(uri),EAclAdd);
       
   107 
       
   108 		if(access == CNSmlDmDDF::EOk )
       
   109 			{
       
   110 			//check if property asked
       
   111 			TInt offset = uri.Find(KNSmlDmProperty);
       
   112 			if(offset==KErrNotFound)
       
   113 				{
       
   114 				//property is not asked, put the request to adapter
       
   115 				iDDF->AddObjectL(uri,aObject,aType,aStatusRef,aLargeItem);
       
   116 				}
       
   117 			else
       
   118 				{
       
   119 				status = KNSmlDmStatusCommandNotAllowed;
       
   120 				}
       
   121 			}
       
   122 		else if(access==CNSmlDmDDF::ENotAccess)
       
   123 			{
       
   124 			status = KNSmlDmStatusCommandNotAllowed;
       
   125 			}
       
   126 		else
       
   127 			{
       
   128 			status = KNSmlDmStatusNotFound;
       
   129 			}
       
   130 		if(status!=KNSmlDmNoStatus)
       
   131 			{
       
   132 			DoSetStatusL(aStatusRef,status);
       
   133 			}
       
   134 		}
       
   135 	_DBG_FILE("CNSmlDmModule::AddObjectL() : end");
       
   136 	}
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // void CNSmlDmModule::UpdateObjectL(const TDesC8& aURI, const TDesC8& aObject,
       
   140 // const TDesC8& aType, TInt aStatusRef )
       
   141 // Replace operation in DM protocoll
       
   142 // ----------------------------------------------------------------------------
       
   143 EXPORT_C void CNSmlDmModule::UpdateObjectL(const TDesC8& aURI,
       
   144 	const TDesC8& aObject,
       
   145 	const TDesC8& aType,
       
   146 	TInt aStatusRef,
       
   147 	TBool aLargeItem,
       
   148 	// FOTA
       
   149 	TInt aTotSizeOfLarge
       
   150 	// FOTA end
       
   151 	 )
       
   152 	{
       
   153 	_DBG_FILE("CNSmlDmModule::UpdateObjectL() : begin");
       
   154 
       
   155 	TPtrC8 uri = NSmlDmURI::RemoveDotSlash(aURI);
       
   156 
       
   157 	if(iInTransaction)
       
   158 		{
       
   159 		if(aLargeItem)
       
   160 			{
       
   161 			DoSetStatusL(aStatusRef,KNSmlDmStatusCommandFailed);
       
   162 			return;
       
   163 			}
       
   164 		//command buffering
       
   165 		iCommandBuffer->UpdateObjectL(uri,aObject,aType,aStatusRef);
       
   166 		}
       
   167 	else
       
   168 		{
       
   169 		TInt status = KNSmlDmNoStatus;
       
   170 		TInt offset = uri.Find(KNSmlDmProperty);
       
   171 		CNSmlDmDDF::TAccess access = iDDF->CheckURIL(
       
   172 			NSmlDmURI::RemoveProp(uri),EAclReplace);
       
   173 
       
   174 		if(access == CNSmlDmDDF::EOk)
       
   175 			{
       
   176 			//check if property asked
       
   177 			if(offset==KErrNotFound)
       
   178 				{
       
   179 				//property is not asked, put the request to adapter
       
   180 				// FOTA
       
   181 				iDDF->UpdateObjectL(uri,aObject,aType,aStatusRef,aLargeItem,aTotSizeOfLarge);
       
   182 				// FOTA end
       
   183 				}
       
   184 			else
       
   185 				{
       
   186 				UpdatePropertyL(uri,aObject,aType,offset+
       
   187 					KNSmlDmProperty().Length(),aStatusRef);
       
   188 				}
       
   189 			}
       
   190 		else if(access == CNSmlDmDDF::ENotAccess)
       
   191 			{
       
   192 			status = KNSmlDmStatusCommandNotAllowed;
       
   193 			}
       
   194 		else
       
   195 			{
       
   196 			status = KNSmlDmStatusNotFound;
       
   197 			}
       
   198 
       
   199 		if(status!=KNSmlDmNoStatus)
       
   200 			{
       
   201 			DoSetStatusL(aStatusRef,status);
       
   202 			}
       
   203 		} //end else(iInTransAction)
       
   204 	_DBG_FILE("CNSmlDmModule::UpdateObjectL() : end");
       
   205 	}
       
   206 
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // void CNSmlDmModule::FetchObjectL(const TDesC8& aURI, const TDesC8& aType,
       
   210 // const TDesC8& aCmdRef, TInt aStatusRef,TBool aAclPass )
       
   211 // Get operation in DM protocoll
       
   212 // ----------------------------------------------------------------------------
       
   213 EXPORT_C void CNSmlDmModule::FetchObjectL(const TDesC8& aURI,
       
   214 	const TDesC8& aType,
       
   215 	const TInt aResultsRef,
       
   216 	TInt aStatusRef,
       
   217 	TBool aAclPass)
       
   218 	{
       
   219 	_DBG_FILE("CNSmlDmModule::FetchObjectL() : begin");
       
   220 	CBufBase *object=NULL;
       
   221 	TPtrC8 uri = NSmlDmURI::RemoveDotSlash(aURI);
       
   222 
       
   223 	if (uri.Compare(KNSmlDmUriDDF)==0)
       
   224 		{
       
   225 		object = CBufFlat::NewL(1024);
       
   226 		CleanupStack::PushL(object);
       
   227 		iDDF->GenerateDDFL(*object/*,iDbHandler*/);
       
   228 		iCallBack->SetResultsL(aResultsRef,*object,aType,KNSmlDmFormatChr,
       
   229 			object->Size());
       
   230 		iCallBack->SetStatusL(aStatusRef,KNSmlDmStatusOK);
       
   231 		CleanupStack::PopAndDestroy(); //object
       
   232 		}
       
   233 	else if(uri.Compare(KNSmlDmDDFDevInfoModDDF)==0)
       
   234 		{
       
   235 		object = CBufFlat::NewL(10);
       
   236 		CleanupStack::PushL(object);
       
   237 		TBuf8<10> ddfCRC;
       
   238 		ddfCRC.Num(iDDFCrc);
       
   239 		object->InsertL(0,ddfCRC);
       
   240 		
       
   241 		iCallBack->SetResultsL(aResultsRef,*object,aType,KNSmlDmFormatChr,
       
   242 			object->Size());
       
   243 		iCallBack->SetStatusL(aStatusRef,KNSmlDmStatusOK);
       
   244 		CleanupStack::PopAndDestroy(); //object
       
   245 		}
       
   246 	else
       
   247 		{
       
   248 		if(iInTransaction)
       
   249 			{
       
   250 			//command buffering
       
   251 			iCommandBuffer->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   252 			}
       
   253 		else
       
   254 			{
       
   255 			TInt status = KNSmlDmNoStatus;
       
   256 			CNSmlDmDDF::TAccess access = iDDF->CheckURIL(
       
   257 				NSmlDmURI::RemoveProp(uri),EAclGet);
       
   258 	
       
   259 			if(access == CNSmlDmDDF::EOk)
       
   260 				{
       
   261 				//check if property asked
       
   262 				TInt offset = uri.Find(KNSmlDmProperty);
       
   263 				if(offset==KErrNotFound)
       
   264 					{
       
   265 					if(uri.Find(KNSmlDmQuestionMark)>=0)
       
   266 						{
       
   267 						status = KNSmlDmStatusOptionalFeatureNotSupported;
       
   268 						}
       
   269 					else
       
   270 						{
       
   271 						//property is not asked, put the request to adapter
       
   272 						iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef,
       
   273 							aAclPass);
       
   274 						}
       
   275 					}
       
   276 				else
       
   277 					{
       
   278 					GetPropertyL(uri,aType,KNSmlDmProperty().Length()+
       
   279 						offset,aResultsRef,aStatusRef);
       
   280 					}
       
   281 				}
       
   282 			else if(access == CNSmlDmDDF::ENotAccess)
       
   283 				{
       
   284 				status = KNSmlDmStatusCommandNotAllowed;
       
   285 				//check if property asked
       
   286 
       
   287 				}
       
   288 			else
       
   289 				{
       
   290 				status = KNSmlDmStatusNotFound;
       
   291 				}
       
   292 	
       
   293 			if(status!=KNSmlDmNoStatus)
       
   294 				{
       
   295 				DoSetStatusL(aStatusRef,status);
       
   296 				}
       
   297 			} //end else iInTransAction
       
   298 		} //end else DDF
       
   299 	_DBG_FILE("CNSmlDmModule::FetchObjectL() : end");
       
   300 	}
       
   301 
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // void CNSmlDmModule::DeleteObjectL( const TDesC8& aURI, TInt aStatusRef )
       
   305 // Delete operation in DM protocoll
       
   306 // ----------------------------------------------------------------------------
       
   307 EXPORT_C void CNSmlDmModule::DeleteObjectL( const TDesC8& aURI,
       
   308 TInt aStatusRef )
       
   309 	{
       
   310 	_DBG_FILE("CNSmlDmModule::DeleteObjectL() : begin");
       
   311 	TPtrC8 uri = NSmlDmURI::RemoveDotSlash(aURI);
       
   312 
       
   313 	if(iInTransaction)
       
   314 		{
       
   315 		//command buffering
       
   316 		iCommandBuffer->DeleteObjectL(uri,aStatusRef);
       
   317 		}
       
   318 	else
       
   319 		{
       
   320 		TInt status = KNSmlDmNoStatus;
       
   321 		CNSmlDmDDF::TAccess access = iDDF->CheckURIL(
       
   322 			NSmlDmURI::RemoveProp(uri),EAclDelete);
       
   323 		if(access==CNSmlDmDDF::EOk)
       
   324 			{
       
   325 			//check if property asked
       
   326 			TInt offset = uri.Find(KNSmlDmProperty);
       
   327 			if(offset==KErrNotFound)
       
   328 				{
       
   329 				//property is not asked, put the request to adapter
       
   330 				iDDF->DeleteObjectL(uri,aStatusRef);
       
   331 				}
       
   332 			else
       
   333 				{
       
   334 				status = KNSmlDmStatusCommandNotAllowed;
       
   335 				}
       
   336 			}
       
   337 		else if(access==CNSmlDmDDF::ENotAccess)
       
   338 			{
       
   339 			status = KNSmlDmStatusCommandNotAllowed;
       
   340 			}
       
   341 		else
       
   342 			{
       
   343 			status = KNSmlDmStatusNotFound;
       
   344 			}
       
   345 
       
   346 		if(status!=KNSmlDmNoStatus)
       
   347 			{
       
   348 			DoSetStatusL(aStatusRef,status);
       
   349 			}
       
   350 		}
       
   351 	_DBG_FILE("CNSmlDmModule::DeleteObjectL() : end");
       
   352 	}
       
   353 
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 // void CNSmlDmModule::ExecuteObjectL( const TDesC8& aURI,
       
   357 // const TDesC8& aObject, const TDesC8& aType, TInt aStatusRef)
       
   358 // Execute operation in DM protocoll
       
   359 // ----------------------------------------------------------------------------
       
   360 EXPORT_C void CNSmlDmModule::ExecuteObjectL( const TDesC8& aURI,
       
   361 	const TDesC8& aObject,
       
   362 	const TDesC8& aType,
       
   363 	TInt aStatusRef,
       
   364 	// FOTA
       
   365 	const TDesC8& aCorrelator,
       
   366 	// FOTA end	
       
   367 	TBool aLargeItem )
       
   368 	{
       
   369 	_DBG_FILE("CNSmlDmModule::ExecuteObjectL() : begin");
       
   370 
       
   371 	TPtrC8 uri = NSmlDmURI::RemoveDotSlash(aURI);
       
   372 
       
   373 	if(iInTransaction)
       
   374 		{
       
   375 		if(aLargeItem)
       
   376 			{
       
   377 			DoSetStatusL(aStatusRef,KNSmlDmStatusCommandFailed);
       
   378 			return;
       
   379 			}
       
   380 		//command buffering
       
   381 		// FOTA
       
   382 		// It is not expected that the FOTA adapter will get atomic commands.
       
   383 		// That's why correlator is not forwarded to the command buffer.
       
   384 		// FOTA end		
       
   385 		iCommandBuffer->ExecuteObjectL(uri,aObject,aType,aStatusRef);
       
   386 		}
       
   387 	else
       
   388 		{
       
   389 		TInt status = KNSmlDmNoStatus;
       
   390 		TInt offset = uri.Find(KNSmlDmProperty);
       
   391 		CNSmlDmDDF::TAccess access = iDDF->CheckURIL(
       
   392 			NSmlDmURI::RemoveProp(uri),EAclExecute);
       
   393 
       
   394 		if(access == CNSmlDmDDF::EOk)
       
   395 			{
       
   396 			//check if property asked
       
   397 			if(offset==KErrNotFound)
       
   398 				{
       
   399 				//property is not asked, put the request to adapter
       
   400 				// FOTA
       
   401 				iDDF->ExecuteObjectL(uri,aObject,aType,aStatusRef,aCorrelator,aLargeItem);
       
   402 				// FOTA end
       
   403 				}
       
   404 			else
       
   405 				{
       
   406 				status = KNSmlDmStatusCommandNotAllowed;
       
   407 				}
       
   408 			}
       
   409 		else if(access == CNSmlDmDDF::ENotAccess)
       
   410 			{
       
   411 			//check if property asked
       
   412 			status = KNSmlDmStatusCommandNotAllowed;
       
   413 			}
       
   414 		else
       
   415 			{
       
   416 			status = KNSmlDmStatusNotFound;
       
   417 			}
       
   418 
       
   419 		if(status!=KNSmlDmNoStatus)
       
   420 			{
       
   421 			DoSetStatusL(aStatusRef,status);
       
   422 			}
       
   423 		} //end else(iInTransAction)
       
   424 	_DBG_FILE("CNSmlDmModule::ExecuteObjectL() : end");
       
   425 	}
       
   426 
       
   427 // ----------------------------------------------------------------------------
       
   428 // void CNSmlDmModule::CopyObjectL( const TDesC8& aURI,
       
   429 //	const TDesC8& aObject, const TDesC8& aType, TInt aStatusRef)
       
   430 // Copy operation in DM protocoll.
       
   431 // ----------------------------------------------------------------------------
       
   432 EXPORT_C void CNSmlDmModule::CopyObjectL( const TDesC8& aTargetURI,
       
   433 	const TDesC8& aSourceURI,
       
   434 	const TDesC8& aType,
       
   435 	TInt aStatusRef)
       
   436 	{
       
   437 	_DBG_FILE("CNSmlDmModule::CopyObjectL() : begin");
       
   438 
       
   439 	TPtrC8 sourceUri = NSmlDmURI::RemoveDotSlash(aSourceURI);
       
   440 	TPtrC8 targetUri = NSmlDmURI::RemoveDotSlash(aTargetURI);
       
   441 
       
   442 	if(iInTransaction)
       
   443 		{
       
   444 		//command buffering
       
   445 		iCommandBuffer->CopyObjectL(targetUri,sourceUri,aType,aStatusRef);
       
   446 		}
       
   447 	else
       
   448 		{
       
   449 		TInt status = KNSmlDmNoStatus;
       
   450 		TInt offset = sourceUri.Find(KNSmlDmProperty);
       
   451 		CNSmlDmDDF::TAccess access = iDDF->CheckURIL(
       
   452 			NSmlDmURI::RemoveProp(sourceUri),EAclCopy);
       
   453 
       
   454 		if(access == CNSmlDmDDF::EOk)
       
   455 			{
       
   456 			//check if property asked
       
   457 			if(offset==KErrNotFound)
       
   458 				{
       
   459 				//property is not asked, put the request to adapter
       
   460 				iDDF->CopyObjectL(targetUri,sourceUri,aType,aStatusRef);
       
   461 				}
       
   462 			else
       
   463 				{
       
   464 				status = KNSmlDmStatusCommandNotAllowed;
       
   465 				}
       
   466 			}
       
   467 		else if(access == CNSmlDmDDF::ENotAccess)
       
   468 			{
       
   469 			//check if property asked
       
   470 			status = KNSmlDmStatusCommandNotAllowed;
       
   471 			}
       
   472 		else
       
   473 			{
       
   474 			status = KNSmlDmStatusNotFound;
       
   475 			}
       
   476 
       
   477 		if(status!=KNSmlDmNoStatus)
       
   478 			{
       
   479 			DoSetStatusL(aStatusRef,status);
       
   480 			}
       
   481 		} //end else(iInTransAction)
       
   482 	_DBG_FILE("CNSmlDmModule::CopyObjectL() : end");
       
   483 	}
       
   484 
       
   485 
       
   486 // ----------------------------------------------------------------------------
       
   487 // void CNSmlDmModule::StartTransactionL( )
       
   488 // Start Atomic operation
       
   489 // Tells that the following commands must be buffered
       
   490 // ----------------------------------------------------------------------------
       
   491 EXPORT_C void CNSmlDmModule::StartTransactionL( )
       
   492 	{
       
   493 	iInTransaction = ETrue;
       
   494 	if(iCommandBuffer==0)
       
   495 		{
       
   496 		iCommandBuffer = CNSmlDmCommandBuffer::NewL(*this);
       
   497 		}
       
   498 	}
       
   499 
       
   500 // ----------------------------------------------------------------------------
       
   501 // void CNSmlDmModule::CommitTransactionL( )
       
   502 // Commit Atomic operation
       
   503 // The buffered commands can be executed
       
   504 // ----------------------------------------------------------------------------
       
   505 EXPORT_C void CNSmlDmModule::CommitTransactionL( )
       
   506 	{
       
   507 	iInTransaction = EFalse;
       
   508 	if(iCommandBuffer)
       
   509 		{
       
   510 		iCommandBuffer->CommitL(*iDDF);
       
   511 		delete iCommandBuffer;
       
   512 		iCommandBuffer = 0;
       
   513 		}
       
   514 	}
       
   515 
       
   516 // ----------------------------------------------------------------------------
       
   517 // void CNSmlDmModule::RollBackL( )
       
   518 // Rollback Atomic operation
       
   519 // The buffered commands are removed from buffer and they are not executed
       
   520 // ----------------------------------------------------------------------------
       
   521 EXPORT_C void CNSmlDmModule::RollBackL( )
       
   522 	{
       
   523 	iInTransaction = EFalse;
       
   524 	if(iCommandBuffer)
       
   525 		{
       
   526 		delete iCommandBuffer;
       
   527 		iCommandBuffer = 0;
       
   528 		}
       
   529 	}
       
   530 
       
   531 
       
   532 // ----------------------------------------------------------------------------
       
   533 // void CNSmlDmModule::EndMessageL( )
       
   534 // Indicates message ending
       
   535 // ----------------------------------------------------------------------------
       
   536 EXPORT_C void CNSmlDmModule::EndMessageL( )
       
   537 	{
       
   538 	_DBG_FILE("CNSmlDmModule::EndMessageL() : begin");
       
   539 	iDDF->EndMessageL();
       
   540 	iPropResults.ResetAndDestroy();
       
   541 	iInternalStatusRef = 0;
       
   542 	_DBG_FILE("CNSmlDmModule::EndMessageL() : end");
       
   543 	}
       
   544 
       
   545 // ----------------------------------------------------------------------------
       
   546 // TInt CNSmlDmModule::IsDDFChangedL( )
       
   547 // Returns a checksum of ddf versions. Checksum changes if the ddf changes
       
   548 // ----------------------------------------------------------------------------
       
   549 EXPORT_C TInt CNSmlDmModule::IsDDFChangedL( )
       
   550 	{
       
   551 	return iDDFCrc;
       
   552 	}
       
   553 
       
   554 // ----------------------------------------------------------------------------
       
   555 // void CNSmlDmModule::MoreDataL(CBufBase*& adata)
       
   556 // Gets more data in case of largeobject
       
   557 // ----------------------------------------------------------------------------
       
   558 EXPORT_C void CNSmlDmModule::MoreDataL(CBufBase*& aData)
       
   559 	{
       
   560 	iDDF->MoreDataL(aData);
       
   561 	}
       
   562 
       
   563 
       
   564 // ----------------------------------------------------------------------------
       
   565 // void CNSmlDmModule::UpdatePropertyL(const TDesC8& aURI,
       
   566 //	const TDesC8& aObject, const TDesC8& aType, TInt aOffset)
       
   567 // Replace property operation in DM protocoll
       
   568 // ----------------------------------------------------------------------------
       
   569 void CNSmlDmModule::UpdatePropertyL(const TDesC8& aURI,
       
   570 	const TDesC8& aObject,
       
   571 	const TDesC8& /*aType*/,
       
   572 	TInt aOffset,
       
   573 	const TInt aStatusRef )
       
   574 	{
       
   575 
       
   576 	if(aURI.Mid(aOffset).Compare(KNSmlDmPropetyACL)==0)
       
   577 		{
       
   578 		iDDF->UpdateAclL(NSmlDmURI::RemoveProp(aURI),aObject,aStatusRef);
       
   579 		}
       
   580 	else
       
   581 		{
       
   582 		DoSetStatusL(aStatusRef,KNSmlDmStatusCommandNotAllowed);
       
   583 		}
       
   584 	}
       
   585 
       
   586 
       
   587 
       
   588 // ----------------------------------------------------------------------------
       
   589 // void CNSmlDmModule::GetPropertyL(const TDesC8& aURI, const TDesC8& aType,
       
   590 //	const TDesC8& aCmdRef, TInt aOffset )
       
   591 // Get property operation in DM protocoll
       
   592 // ----------------------------------------------------------------------------
       
   593 void CNSmlDmModule::GetPropertyL(const TDesC8& aURI,
       
   594 	const TDesC8& aType,
       
   595 	TInt aOffset,
       
   596 	TInt aResultsRef,
       
   597 	TInt aStatusRef)
       
   598 	{
       
   599 	TPtrC8 uri = NSmlDmURI::RemoveProp(aURI);
       
   600 	if(iDDF->CheckAclL(uri,EAclGet))
       
   601 		{
       
   602 		CNSmlGetPropertyElement* propGet =
       
   603 			 new (ELeave)CNSmlGetPropertyElement();
       
   604 		CleanupStack::PushL(propGet);
       
   605 		propGet->iResultsRef = aResultsRef;
       
   606 		propGet->iStatusRef = aStatusRef;
       
   607 		propGet->iStatusCode = KNSmlDmNoStatus;
       
   608 		propGet->iUri = uri.AllocL();
       
   609 
       
   610 		if(aURI.Mid(aOffset).Compare(KNSmlDmPropetyACL)==0)
       
   611 			{
       
   612 			propGet->iProp = EPropACL;
       
   613 			iPropResults.AppendL(propGet);
       
   614 			CleanupStack::Pop(); // propGet
       
   615 			if(uri.Compare(KNSmlDmDDFDevInfoModDDF)==0)
       
   616 				{
       
   617 				DoSetStatusL(aStatusRef,KNSmlDmStatusOK);
       
   618 				CBufBase* object = CBufFlat::NewL(128);
       
   619 				CleanupStack::PushL(object);
       
   620 				DoSetResultsL(aResultsRef,*object,aType,KNullDesC8,0,ETrue);
       
   621 				CleanupStack::PopAndDestroy(); //object
       
   622 				}
       
   623 			else
       
   624 				{
       
   625 				iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   626 				}
       
   627 			}
       
   628 		else if(aURI.Mid(aOffset).Compare(KNSmlDmPropetyFormat)==0)
       
   629 			{
       
   630 			propGet->iProp = EPropFormat;
       
   631 			iPropResults.AppendL(propGet);
       
   632 			CleanupStack::Pop(); // propGet
       
   633 			iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   634 			}
       
   635 		else if(aURI.Mid(aOffset).Compare(KNSmlDmPropetyName)==0)
       
   636 			{
       
   637 			propGet->iProp = EPropName;
       
   638 			iPropResults.AppendL(propGet);
       
   639 			CleanupStack::Pop(); // propGet
       
   640 			iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   641 			}
       
   642 		else if(aURI.Mid(aOffset).Compare(KNSmlDmPropetySize)==0)
       
   643 			{
       
   644 //			if(iDDF->IsLeafL(uri)==CNSmlDmDDF::ELeaf)
       
   645 			if(iDDF->IsLeafL(uri)==ENSmlDmDDFLeaf)
       
   646 				{
       
   647 				propGet->iProp = EPropSize;
       
   648 				iPropResults.AppendL(propGet);
       
   649 				CleanupStack::Pop(); // propGet
       
   650 				iDDF->FetchObjectSizeL(uri,aType,aResultsRef,aStatusRef);
       
   651 				}
       
   652 			else
       
   653 				{
       
   654 				delete propGet->iUri;
       
   655 				propGet->iUri = 0;
       
   656 				CleanupStack::PopAndDestroy(); // propGet
       
   657 				DoSetStatusL(aStatusRef,KNSmlDmStatusOptionalFeatureNotSupported);
       
   658 				}
       
   659 			}
       
   660 		else if(aURI.Mid(aOffset).Compare(KNSmlDmPropetyType)==0)
       
   661 			{
       
   662 			propGet->iProp = EPropType;
       
   663 			iPropResults.AppendL(propGet);
       
   664 			CleanupStack::Pop(); // propGet
       
   665 			iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   666 			}
       
   667 		else
       
   668 			{
       
   669 			if(!FeatureManager::FeatureSupported( KFeatureIdSyncMlDm112  ))
       
   670 			{
       
   671 				if(aURI.Mid(aOffset).Compare(KNSmlDmPropertyCaseSense)==0) 
       
   672 			    {
       
   673 			    propGet->iProp = EPropCaseSense;
       
   674 				iPropResults.AppendL(propGet);
       
   675 				CleanupStack::Pop(); // propGet
       
   676 				iDDF->FetchObjectL(uri,aType,aResultsRef,aStatusRef);
       
   677 			    }
       
   678 			    else
       
   679 			    {
       
   680 			    delete propGet->iUri;
       
   681 				propGet->iUri =0;
       
   682 				CleanupStack::PopAndDestroy(); // propGet
       
   683 				DoSetStatusL(aStatusRef,KNSmlDmStatusOptionalFeatureNotSupported);
       
   684 			    }
       
   685 			    
       
   686 			}
       
   687 			else
       
   688 			{
       
   689 				delete propGet->iUri;
       
   690 				propGet->iUri =0;
       
   691 				CleanupStack::PopAndDestroy(); // propGet
       
   692 				DoSetStatusL(aStatusRef,KNSmlDmStatusOptionalFeatureNotSupported);
       
   693 			}
       
   694 			}
       
   695 		}
       
   696 	else
       
   697 		{
       
   698 		DoSetStatusL(aStatusRef,KNSmlDmStatusPermissionDenied);
       
   699 		}
       
   700 	}
       
   701 
       
   702 
       
   703 // ----------------------------------------------------------------------------
       
   704 // TBool CNSmlDmModule::DeleteInTransactionL( )
       
   705 // Deletes te items added inside the atomic, in case that atomic fails
       
   706 // ----------------------------------------------------------------------------
       
   707 void CNSmlDmModule::DeleteInTransactionL(const TDesC8& aURI,
       
   708 	MNSmlDmModuleCallBack *aCallBack)
       
   709 	{
       
   710 	MNSmlDmModuleCallBack *tmpCallBack = iCallBack;
       
   711 	TBool tmpInTransaction = iInTransaction;
       
   712 	iInTransaction = EFalse;
       
   713 	iCallBack = aCallBack;
       
   714 	iInternalCommand = ETrue;
       
   715 	DeleteObjectL(aURI, iInternalStatusRef--);
       
   716 	iInternalCommand = EFalse;
       
   717 	iCallBack = tmpCallBack;
       
   718 	iInTransaction = tmpInTransaction;
       
   719 	}
       
   720 
       
   721 
       
   722 // ----------------------------------------------------------------------------
       
   723 // void CNSmlDmModule::DoSetStatusL( )
       
   724 // The status is provided throug this function to caller
       
   725 // ----------------------------------------------------------------------------
       
   726 void CNSmlDmModule::DoSetStatusL(TInt aStatusRef, TInt aStatusCode,
       
   727 	TBool aSkipCmdBuf)
       
   728 	{
       
   729 	if(!iInternalCommand&&aStatusRef==-1)
       
   730 		{
       
   731 		return;
       
   732 		}
       
   733 	TInt status = aStatusCode;
       
   734 	
       
   735 	//loop through if the command is for getting property
       
   736 	for(TInt i=0;i<iPropResults.Count();i++)
       
   737 		{
       
   738 		if(aStatusRef==iPropResults[i]->iStatusRef)
       
   739 			{
       
   740 			if(status>KNSmlDmStatusLargestOK)
       
   741 				{
       
   742 				//the property is asked, but the fetch for command is failed for
       
   743 				//some reason -> return status not allowed 
       
   744 				status = KNSmlDmStatusCommandNotAllowed;
       
   745 				if(iPropResults[i]->iStatusCode==0) //checks if status is allready handled
       
   746 					{
       
   747 					//status was not handled before
       
   748 					iPropResults[i]->iStatusCode=status;
       
   749 					}
       
   750 				else
       
   751 					{
       
   752 					//status was handled before in DoSetResultsL()
       
   753 					return;
       
   754 					}
       
   755 				}
       
   756 			else
       
   757 				{
       
   758 				return;
       
   759 				}
       
   760 			break;
       
   761 			}
       
   762 		}
       
   763 	if(iCommandBuffer!=0 && !aSkipCmdBuf &&
       
   764 		iCommandBuffer->CheckStatusRef(aStatusRef))
       
   765 		{
       
   766 		//command has came inside atomic
       
   767 		iCommandBuffer->SetStatus(aStatusRef,status);
       
   768 		}
       
   769 	else
       
   770 		{
       
   771 		iCallBack->SetStatusL(aStatusRef,status);
       
   772 		}
       
   773 	}
       
   774 
       
   775 
       
   776 // ----------------------------------------------------------------------------
       
   777 // void CNSmlDmModule::DoSetResultsL( )
       
   778 // Sets the result to caller by using callback interface
       
   779 // ----------------------------------------------------------------------------
       
   780 void CNSmlDmModule::DoSetResultsL(TInt aResultsRef, CBufBase& aObject,
       
   781 	const TDesC8& aType,
       
   782 	const TDesC8& aFormat,
       
   783 	TInt aTotalSize,
       
   784 	TBool aSkipCmdBuf)
       
   785 	{
       
   786 	if(!iInternalCommand&&aResultsRef==-1)
       
   787 		{
       
   788 		return;
       
   789 		}
       
   790 
       
   791 	TInt index = -1;
       
   792 	//loop throug the prop result buffer, the buffe contains element for
       
   793 	//each fetch to any property
       
   794 	for(TInt i=0;i<iPropResults.Count();i++)
       
   795 		{
       
   796 		if(aResultsRef==iPropResults[i]->iResultsRef &&
       
   797 			iPropResults[i]->iStatusCode<KNSmlDmStatusLargestOK)
       
   798 			{
       
   799 			//fetch to property found and status to fetch is
       
   800 			//OK status -> it is OK to return the asked property
       
   801 			index = i;
       
   802 			//the HandlePropertyResultsL gets the property to aObject
       
   803 			iPropResults[i]->iStatusCode = HandlePropertyResultsL(i,aObject);
       
   804 			break;
       
   805 			}
       
   806 		}
       
   807 
       
   808 	if(iCommandBuffer!=0 && !aSkipCmdBuf &&
       
   809 		iCommandBuffer->CheckResultsRef(aResultsRef))
       
   810 		{
       
   811 		//command has come inside atomic
       
   812 		if(index>=0)
       
   813 			{
       
   814 			//property is asked inside the atomic, the status and result are
       
   815 			//given back to command buffer
       
   816 			iCommandBuffer->SetStatus(iPropResults[index]->iStatusRef,
       
   817 				iPropResults[index]->iStatusCode);
       
   818 			}
       
   819 		iCommandBuffer->SetResultsL(aResultsRef,aObject,aType,aFormat);
       
   820 		}
       
   821 	else
       
   822 		{
       
   823 		//command has not come niside the atomic
       
   824 		if(index>=0)
       
   825 			{
       
   826 			//fetch for property found, the result and status are returned
       
   827 			//from property result buffer
       
   828 			iCallBack->SetStatusL(iPropResults[index]->iStatusRef,
       
   829 				iPropResults[index]->iStatusCode);
       
   830 			if(iPropResults[index]->iStatusCode<KNSmlDmStatusLargestOK)
       
   831 				{
       
   832 				iCallBack->SetResultsL(aResultsRef,aObject,aType,aFormat,
       
   833 					aTotalSize);
       
   834 				}
       
   835 			}
       
   836 		else
       
   837 			{
       
   838 			//gives the result to agent 
       
   839 			//this is the normal case, i.e. fetch to item (not property)
       
   840 			//and not inside the atomic
       
   841 			//However, if atomic has come inside the atomic, the
       
   842 			//command buffer finally callst this function with
       
   843 			//aSkipCmdBuf==ERrue -> execution comes to this branch
       
   844 			iCallBack->SetResultsL(aResultsRef,aObject,aType,aFormat,
       
   845 				aTotalSize);
       
   846 			}
       
   847 		}
       
   848 	}
       
   849 
       
   850 // ----------------------------------------------------------------------------
       
   851 // CNSmlDmModule::DisconnectFromOtherServers()
       
   852 //	Closes the connections to callback server and host servers.
       
   853 //	Separate function is needed, since the disconnecting cannot 
       
   854 //	be made after the active scheduler of the thread is stopped.
       
   855 // ----------------------------------------------------------------------------
       
   856 //
       
   857 EXPORT_C void CNSmlDmModule::DisconnectFromOtherServers()
       
   858 	{
       
   859 	iDDF->DisconnectFromOtherServers();
       
   860 	}
       
   861 
       
   862 // FOTA
       
   863 // ----------------------------------------------------------------------------
       
   864 // CNSmlDmModule::MarkGenAlertsSentL()
       
   865 //	When the generic alerts are successfully sent to the remote 
       
   866 //	server, the FOTA adapter needs to be informed about this.
       
   867 //	This command is chained through the DM engine.
       
   868 // ----------------------------------------------------------------------------
       
   869 //
       
   870 EXPORT_C void CNSmlDmModule::MarkGenAlertsSentL()
       
   871 	{
       
   872 	iDDF->MarkGenAlertsSentL();
       
   873 	}
       
   874 // FOTA end
       
   875 
       
   876 // ----------------------------------------------------------------------------
       
   877 // CNSmlDmModule::MarkGenAlertsSentL(const TDesC8& aURI)
       
   878 //	When the generic alerts are successfully sent to the remote 
       
   879 //	server, the repective adapter needs to be informed about this.
       
   880 //	This command is chained through the DM engine.
       
   881 //  This function is used if DM 1.2 version is enabled
       
   882 // ----------------------------------------------------------------------------
       
   883 //
       
   884 EXPORT_C void CNSmlDmModule::MarkGenAlertsSentL(const TDesC8& aURI)
       
   885 	{
       
   886 	_DBG_FILE(" CNSmlDmModule::MarkGenAlertsSentL (TDesC8& aURI )calling iDDF->MarkgenAlert  ");
       
   887    	iDDF->MarkGenAlertsSentL(aURI);
       
   888 	}
       
   889 
       
   890 
       
   891 // ----------------------------------------------------------------------------
       
   892 // void CNSmlDmModule::HandlePropertyResultsL(TInt aIndex,
       
   893 // CBufBase& aObject)
       
   894 // Sets the property result in case that property fetched
       
   895 // ----------------------------------------------------------------------------
       
   896 TInt CNSmlDmModule::HandlePropertyResultsL(TInt aIndex, CBufBase& aObject)
       
   897 	{
       
   898 	TInt status = KNSmlDmStatusOK;
       
   899 	if(iPropResults[aIndex]->iProp==EPropACL)
       
   900 		{
       
   901 		aObject.Reset();
       
   902 		iDDF->GetAclL(*iPropResults[aIndex]->iUri,aObject);
       
   903 		}
       
   904 	else if(iPropResults[aIndex]->iProp==EPropFormat)
       
   905 		{
       
   906 		aObject.Reset();
       
   907 		HBufC8* format8 = iDDF->GetFormatAllocL(*iPropResults[aIndex]->iUri);
       
   908 		CleanupStack::PushL(format8); //format8
       
   909 		aObject.InsertL(0,*format8);
       
   910 		CleanupStack::PopAndDestroy(); //format8
       
   911 		}
       
   912 	else if(iPropResults[aIndex]->iProp==EPropName)
       
   913 		{
       
   914 		aObject.Reset();
       
   915 		aObject.InsertL(0,NSmlDmURI::LastURISeg(*iPropResults[aIndex]->iUri));
       
   916 		}
       
   917 	else if(iPropResults[aIndex]->iProp==EPropSize)
       
   918 		{
       
   919 		}
       
   920 	else if(iPropResults[aIndex]->iProp==EPropType)
       
   921 		{
       
   922 		aObject.Reset();
       
   923 		iDDF->GetMimeTypeL(*iPropResults[aIndex]->iUri,aObject);
       
   924 		}
       
   925 	
       
   926 	else if(iPropResults[aIndex]->iProp==EPropCaseSense)
       
   927 		{
       
   928 		if(!FeatureManager::FeatureSupported( KFeatureIdSyncMlDm112  ))
       
   929 		{
       
   930 		aObject.Reset();
       
   931 		iDDF->GetCaseSenseL(*iPropResults[aIndex]->iUri,aObject);
       
   932 		}
       
   933 		else
       
   934 		{
       
   935 		status = KNSmlDmStatusOptionalFeatureNotSupported;
       
   936 		}
       
   937 		
       
   938 		}
       
   939 	else
       
   940 		{
       
   941 		status = KNSmlDmStatusOptionalFeatureNotSupported;
       
   942 		}
       
   943 	return status;
       
   944 	}
       
   945 
       
   946 // ----------------------------------------------------------------------------
       
   947 // void CNSmlDmModule::ConstructL( )
       
   948 // Second phase constructor
       
   949 // ----------------------------------------------------------------------------
       
   950 void CNSmlDmModule::ConstructL()
       
   951 	{
       
   952 	_DBG_FILE("CNSmlDmModule::ConstructL( ) : begin");
       
   953 	iDDF = CNSmlDmDDF::NewL(*this);
       
   954 	iDDFCrc = iDDF->IsDDFChangedL();
       
   955 	FeatureManager::InitializeLibL();
       
   956 	_DBG_FILE("CNSmlDmModule::ConstructL( ) : end");
       
   957 	}
       
   958 
       
   959 
       
   960 // ===========================================================================
       
   961 // CNSmlGetPropertyElement
       
   962 // ===========================================================================
       
   963 // ----------------------------------------------------------------------------
       
   964 // CNSmlGetPropertyElement::CNSmlGetPropertyElement( )
       
   965 // ----------------------------------------------------------------------------
       
   966 CNSmlGetPropertyElement::~CNSmlGetPropertyElement()
       
   967 	{
       
   968 	delete iUri;
       
   969 	}
       
   970 
       
   971 // End of file
       
   972