コード例 #1
0
void CTestBlockController::CreateObjectL(TTEFBlockItem& aCommand)
	{
	// Retrieve the object name from the ini file
	TPtrC	name;
	if( GetStringFromConfig(aCommand.iSection, KName, name) &&
		0 != aCommand.iSection.Compare(KTEFNull) )
		{
		// Create the wrapper
		CDataWrapper*	data = CreateDataL(aCommand.iObjectType);
		if( NULL != data)
			{
			CleanupStack::PushL(data);
			data->SetTestBlockController(this);
			data->SetDataDictionary(&iDataDictionary);
			data->InitialiseL();
			// Add it to the dictionary with the lookup name provided
			iDataDictionary.AddDataL(name, data);
			CleanupStack::Pop(data);
			}
		else
			{
			aCommand.iError = KErrNotFound;
			ERR_PRINTF2( KErrWrapperCreate, &name );
			}
		}
	else
		{
		ERR_PRINTF1(KErrNoName);
		aCommand.iError = KErrNotFound;
		}
	}
コード例 #2
0
void CTestBlockController::RestoreObjectL(TTEFBlockItem& aCommand)
	{
	if( IsSharedDataMode() )
		{
		// Retrieve the object name from the ini file
		TPtrC	name;
		if( 0 != aCommand.iSection.Compare(KTEFNull) &&
			GetStringFromConfig(aCommand.iSection, KName, name) )
			{
			// Create the wrapper
			CDataWrapper*	data = CreateDataL(aCommand.iObjectType);

			if( NULL != data)
				{
				CleanupStack::PushL(data);
				data->SetTestBlockController(this);
				data->SetDataDictionary(&iDataDictionary);
				data->InitialiseL();

				// Add it to the dictionary with the lookup name provided
				iDataDictionary.AddDataL(name, data);

				// Retrieve the object from the persistent store
				TAny*	object = NULL;
				TRAPD( err, object = iSharedData->GetObjectAndOwnL(name) );
				if( KErrNone == err )
					{
					CleanupStack::PushL(object);
					// Update the object contained within the wrapper
					iDataDictionary.SetObjectL(name, object);
					CleanupStack::Pop(object);
					}
				else
					{
					ERR_PRINTF1(KErrNotExist);
					iDataDictionary.DeleteDataL(name);
					aCommand.iError = KErrNotFound;
					}
				CleanupStack::Pop(data);
				}
			else
				{
				aCommand.iError = KErrNotFound;
				ERR_PRINTF2( KErrWrapperCreate, &name );
				}
			}
		else
			{
			ERR_PRINTF1(KErrNoName);
			aCommand.iError = KErrNotFound;
			}
		}
	else
		{
		ERR_PRINTF1(KErrSharedData);
		aCommand.iError = KErrNotSupported;
		}
	}