connectivitymodules/SeCon/wbxml/conmlhandler/src/sconxmlworkspace.cpp
branchRCL_3
changeset 42 0aa8cc770c8a
parent 40 453dfc402455
child 43 4a793f564d72
equal deleted inserted replaced
40:453dfc402455 42:0aa8cc770c8a
     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:  ConML parser/generator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // -----------------------------------------------------------------------------
       
    20 // Includes
       
    21 // -----------------------------------------------------------------------------
       
    22 #include "sconxmlworkspace.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CXMLWorkspace
       
    26 // -----------------------------------------------------------------------------
       
    27 CXMLWorkspace::CXMLWorkspace()
       
    28 	{
       
    29 	}
       
    30 	
       
    31 // -----------------------------------------------------------------------------
       
    32 // NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 CXMLWorkspace* CXMLWorkspace::NewL()
       
    35 	{
       
    36 	CXMLWorkspace* self = new (ELeave) CXMLWorkspace();
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(); // self
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // ConstructL
       
    45 // -----------------------------------------------------------------------------
       
    46 void CXMLWorkspace::ConstructL()
       
    47 	{
       
    48 	iBuffer = CBufFlat::NewL(32);
       
    49 	iTransactions = new (ELeave) RArray<TUint>();
       
    50 	}
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // ~CXMLWorkspace
       
    54 // -----------------------------------------------------------------------------
       
    55 CXMLWorkspace::~CXMLWorkspace()
       
    56 	{
       
    57 	delete iBuffer;
       
    58 	if( iTransactions )
       
    59 		{
       
    60 		iTransactions->Reset();
       
    61 		}
       
    62 	delete iTransactions;
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // BeginTransaction
       
    67 // -----------------------------------------------------------------------------
       
    68 void CXMLWorkspace::BeginTransaction()
       
    69 	{
       
    70 	iTransactions->Append(Size());
       
    71 	}
       
    72 	
       
    73 // -----------------------------------------------------------------------------
       
    74 // Commit
       
    75 // -----------------------------------------------------------------------------
       
    76 TInt CXMLWorkspace::Commit()
       
    77 	{
       
    78 	if( iTransactions->Count() == 0 )
       
    79 		{
       
    80 		return KErrGeneral;
       
    81 		}
       
    82 	iTransactions->Remove(iTransactions->Count() - 1);
       
    83 	return KErrNone;
       
    84 	}
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CommitAll
       
    88 // -----------------------------------------------------------------------------
       
    89 void CXMLWorkspace::CommitAll()
       
    90 	{
       
    91 	iTransactions->Reset();
       
    92 	}
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Rollback
       
    96 // -----------------------------------------------------------------------------
       
    97 TInt CXMLWorkspace::Rollback()
       
    98 	{
       
    99 	if( iTransactions->Count() == 0 )
       
   100 		{
       
   101 		return KErrGeneral;
       
   102 		}
       
   103 	TUint begin = iTransactions->operator[](iTransactions->Count() - 1);
       
   104 	Delete(begin, Size() - begin);
       
   105 	iTransactions->Remove(iTransactions->Count() - 1);
       
   106 	return KErrNone;
       
   107 	}
       
   108 	
       
   109 // -----------------------------------------------------------------------------
       
   110 // Reset
       
   111 // -----------------------------------------------------------------------------
       
   112 void CXMLWorkspace::Reset()
       
   113 	{
       
   114 	iBuffer->Reset();
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // WriteL
       
   119 // -----------------------------------------------------------------------------
       
   120 void CXMLWorkspace::WriteL( const TDesC8& aData )
       
   121 	{
       
   122 	TRAPD(err, iBuffer->InsertL(iBuffer->Size(), aData));
       
   123 	if( err != KErrNone )
       
   124 		{
       
   125 		User::Leave(KErrTooBig);
       
   126 		}
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // WriteL
       
   131 // -----------------------------------------------------------------------------
       
   132 void CXMLWorkspace::WriteL( const TUint8 aData )
       
   133 	{
       
   134 	WriteL(TPtrC8(&aData, 1));
       
   135 	}
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // Buffer
       
   139 // -----------------------------------------------------------------------------
       
   140 TPtrC8 CXMLWorkspace::Buffer()
       
   141 	{
       
   142 	return iBuffer->Ptr(0);
       
   143 	}
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // FreeSize
       
   147 // -----------------------------------------------------------------------------
       
   148 TInt CXMLWorkspace::FreeSize()
       
   149 	{
       
   150 	return (KMaxTInt32 - Size());
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // MaxSize
       
   155 // -----------------------------------------------------------------------------
       
   156 TInt CXMLWorkspace::MaxSize()
       
   157 	{
       
   158 	return KMaxTInt32;
       
   159 	}
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // Size
       
   163 // -----------------------------------------------------------------------------
       
   164 TInt CXMLWorkspace::Size()
       
   165 	{
       
   166 	return iBuffer->Size();
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // Delete
       
   171 // -----------------------------------------------------------------------------
       
   172 void CXMLWorkspace::Delete( TInt aPos, TInt aLength )
       
   173 	{
       
   174 	iBuffer->Delete(aPos, aLength);
       
   175 	}