omadmadapters/connmoadapter/src/AddBuffer.cpp
changeset 45 0f9fc722d255
parent 44 137912d1a556
child 62 03849bd79877
equal deleted inserted replaced
44:137912d1a556 45:0f9fc722d255
       
     1 /*
       
     2  * ==============================================================================
       
     3  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4  * All rights reserved.
       
     5  * This component and the accompanying materials are made available
       
     6  * under the terms of "Eclipse Public License v1.0"
       
     7  * which accompanies this distribution, and is available
       
     8  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9  *
       
    10  * Initial Contributors:
       
    11  * Nokia Corporation - initial contribution.
       
    12  *
       
    13  * Contributors:
       
    14  * 
       
    15  * Description:
       
    16  * 
       
    17  * ==============================================================================
       
    18  */
       
    19 
       
    20 #include <e32base.h>
       
    21 
       
    22 #include "AddBuffer.h"
       
    23 #include "Utils.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "AddBufferTraces.h"
       
    27 #endif
       
    28 
       
    29 _LIT8( KChildNodeWildCardPattern, "/*" );
       
    30 _LIT8( KNodeSeparator, "/" );
       
    31 
       
    32 // ======== LOCAL FUNCTIONS =========
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 //------------------------------------------------------------------------------
       
    36 // CConnMoNodeElement::CConnMoNodeElement()
       
    37 //------------------------------------------------------------------------------
       
    38 CConnMoNodeElement::CConnMoNodeElement() 
       
    39     {
       
    40     OstTraceFunctionEntry0( CCONNMONODEELEMENT_CCONNMONODEELEMENT_ENTRY );
       
    41     
       
    42     OstTraceFunctionExit0( CCONNMONODEELEMENT_CCONNMONODEELEMENT_EXIT );
       
    43     }
       
    44 
       
    45 //------------------------------------------------------------------------------
       
    46 // CAddBuffer::~CAddBuffer()
       
    47 //------------------------------------------------------------------------------
       
    48 CConnMoNodeElement::~CConnMoNodeElement()
       
    49     {
       
    50     OstTraceFunctionEntry0( CCONNMONODEELEMENT_DELETE_ENTRY );
       
    51     
       
    52     OstTraceFunctionExit0( CCONNMONODEELEMENT_DELETE_EXIT );
       
    53     }
       
    54 
       
    55 //-----------------------------------------------------------------------------
       
    56 // CAddBuffer* CAddBuffer::NewL( )
       
    57 //-----------------------------------------------------------------------------
       
    58 CAddBuffer* CAddBuffer::NewL()
       
    59     {
       
    60     OstTraceFunctionEntry0( CADDBUFFER_NEWL_ENTRY );
       
    61     
       
    62     CAddBuffer* self = new ( ELeave ) CAddBuffer();
       
    63     CleanupStack::PushL( self );
       
    64     
       
    65     self->ConstructL();
       
    66     
       
    67     CleanupStack::Pop( self );
       
    68 
       
    69     OstTraceFunctionExit1( CADDBUFFER_NEWL_EXIT, ( TUint )( self ) );
       
    70     return self;
       
    71     }
       
    72 
       
    73 //------------------------------------------------------------------------------
       
    74 // CAddBuffer::CAddBuffer()
       
    75 //------------------------------------------------------------------------------
       
    76 CAddBuffer::CAddBuffer() 
       
    77     {
       
    78     OstTraceFunctionEntry0( CADDBUFFER_CADDBUFFER_ENTRY );
       
    79     
       
    80     OstTraceFunctionExit0( CADDBUFFER_CADDBUFFER_EXIT );
       
    81     }
       
    82 
       
    83 //------------------------------------------------------------------------------
       
    84 // CAddBuffer::~CAddBuffer()
       
    85 //------------------------------------------------------------------------------
       
    86 CAddBuffer::~CAddBuffer()
       
    87     {
       
    88     OstTraceFunctionEntry0( CADDBUFFER_DELETE_ENTRY );
       
    89     
       
    90     iBuffer.ResetAndDestroy();
       
    91     
       
    92     OstTraceFunctionExit0( CADDBUFFER_DELETE_EXIT );
       
    93     }
       
    94 
       
    95 //------------------------------------------------------------------------------
       
    96 // CAddBuffer::CAddBuffer()
       
    97 //------------------------------------------------------------------------------
       
    98 void CAddBuffer::ConstructL() 
       
    99     {
       
   100     OstTraceFunctionEntry0( CADDBUFFER_CONSTRUCTL_ENTRY );
       
   101     
       
   102     OstTraceFunctionExit0( CADDBUFFER_CONSTRUCTL_EXIT );
       
   103     }
       
   104 
       
   105 //------------------------------------------------------------------------------
       
   106 // CAddBuffer::AddNodeToBuffer()
       
   107 //------------------------------------------------------------------------------
       
   108 void CAddBuffer::AddNodeToBufferL( const TDesC8& aUri, 
       
   109                                    const TDesC8& aParentLUID,
       
   110                                    const TInt    aStatusRef )
       
   111     {
       
   112     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_ADDNODETOBUFFERL_ENTRY, "ENTRY: CAddBuffer::AddNodeToBufferL;aUri=%s", aUri );
       
   113     
       
   114     CConnMoNodeElement* newNode = new (ELeave) CConnMoNodeElement();
       
   115     
       
   116     newNode->iUri.Copy( aUri );
       
   117     newNode->iParentLUID.Copy( aParentLUID );
       
   118     newNode->iStatusRef = aStatusRef;
       
   119     newNode->iProcessed = EFalse;
       
   120     newNode->iLeaf = EFalse;
       
   121     
       
   122     iBuffer.AppendL( newNode );
       
   123     OstTrace0( TRACE_NORMAL, CADDBUFFER_ADDNODETOBUFFERL_EXIT, "EXIT: CAddBuffer::AddNodeToBufferL");
       
   124     }
       
   125 
       
   126 //------------------------------------------------------------------------------
       
   127 // CAddBuffer::AddNodeToBuffer()
       
   128 //------------------------------------------------------------------------------
       
   129 void CAddBuffer::AddNodeToBufferL( const TDesC8& aUri, 
       
   130                                    const TDesC8& aLUID,
       
   131                                    const TDesC8& aObject,
       
   132                                    const TInt    aStatusRef )
       
   133     {
       
   134     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_ADDNODETOBUFFERL_LEAF_ENTRY, "ENTRY: CAddBuffer::AddNodeToBufferL;aUri=%s", aUri );
       
   135     
       
   136     CConnMoNodeElement* newNode = new (ELeave) CConnMoNodeElement();
       
   137     
       
   138     newNode->iUri.Copy( aUri );
       
   139     newNode->iParentLUID.Copy( aLUID );
       
   140     newNode->iObject.Copy( aObject );
       
   141     newNode->iStatusRef = aStatusRef;
       
   142     newNode->iProcessed = EFalse;
       
   143     newNode->iLeaf = ETrue;
       
   144     
       
   145     iBuffer.AppendL( newNode );
       
   146     OstTrace0( TRACE_NORMAL, CADDBUFFER_ADDNODETOBUFFERL_LEAF_EXIT, "EXIT: CAddBuffer::AddNodeToBufferL");
       
   147     }
       
   148 
       
   149 //------------------------------------------------------------------------------
       
   150 // CAddBuffer::FindDynamicNode
       
   151 //------------------------------------------------------------------------------
       
   152 CConnMoNodeElement* CAddBuffer::FindDynamicNode( const TDesC8& aUri )
       
   153     {
       
   154     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_FINDDYNAMICNODE_ENTRY, "ENTRY: CAddBuffer::FindDynamicNode;aUri=%s", aUri );
       
   155 
       
   156     CConnMoNodeElement* resultNode = NULL;
       
   157 
       
   158     for ( TInt i = 0; i < iBuffer.Count(); ++i )
       
   159         {
       
   160         if ( iBuffer[i]->iUri.Match(aUri) != KErrNotFound )
       
   161             {
       
   162             // 
       
   163             TBuf8<KMaxFieldLength> dynamicNodeChildUri(aUri);
       
   164             dynamicNodeChildUri.Append( KChildNodeWildCardPattern );
       
   165             
       
   166             if ( iBuffer[i]->iUri.Match( dynamicNodeChildUri ) == KErrNotFound )
       
   167                 {
       
   168                 // Correct dynamic node found.
       
   169                 OstTrace0( TRACE_NORMAL, 
       
   170                            CADDBUFFER_FINDDYNAMICNODE_MATCH_FOUND, 
       
   171                            "CAddBuffer::FindDynamicNode;Matching node found.");
       
   172                 resultNode = iBuffer[i];
       
   173                 break;
       
   174                 }
       
   175             }
       
   176         }
       
   177 	if ( resultNode != NULL )
       
   178 	    {
       
   179         OstTraceExt1( TRACE_NORMAL, 
       
   180                   CADDBUFFER_FINDDYNAMICNODE_EXIT, 
       
   181                   "EXIT: CAddBuffer::FindDynamicNode;resultNode=%s", 
       
   182                   resultNode->iUri );
       
   183 	    }
       
   184     
       
   185     return resultNode;
       
   186     }
       
   187     
       
   188 
       
   189 //------------------------------------------------------------------------------
       
   190 // CAddBuffer::Find
       
   191 //------------------------------------------------------------------------------
       
   192 CConnMoNodeElement* CAddBuffer::CacheFind( const TDesC8& aUri )
       
   193     {
       
   194     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_CACHEFIND_ENTRY, "ENTRY: CAddBuffer::CacheFind;aUri=%s", aUri );
       
   195     
       
   196     CConnMoNodeElement* resultNode = NULL;
       
   197 
       
   198     for ( TInt i = 0; i < iCache.Count(); ++i )
       
   199         {
       
   200         if ( iCache[i]->iUri.Match( aUri ) != KErrNotFound )
       
   201             {
       
   202             OstTrace0( TRACE_NORMAL, CADDBUFFER_CACHEFIND_MATCH_FOUND, "CAddBuffer::CacheFind; Matching URI found.");
       
   203             resultNode = iCache[i];
       
   204             
       
   205             OstTraceExt1( TRACE_NORMAL, 
       
   206                           CADDBUFFER_CACHEFIND_RESULT_NODE, 
       
   207                           "CAddBuffer::CacheFind; resultNode=%s", 
       
   208                           resultNode->iUri );
       
   209             break;
       
   210             }
       
   211         }
       
   212     
       
   213     OstTrace0( TRACE_NORMAL, CADDBUFFER_CACHEFIND_EXIT, "EXIT: CAddBuffer::CacheFind");
       
   214     return resultNode;
       
   215     }
       
   216 
       
   217 //------------------------------------------------------------------------------
       
   218 // CAddBuffer::FindDynamicNode
       
   219 //------------------------------------------------------------------------------
       
   220 CConnMoNodeElement* CAddBuffer::CacheFindDynamicNode( const TDesC8& aUri )
       
   221     {
       
   222     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_CACHEFINDDYNAMICNODE_ENTRY, "ENTRY: CAddBuffer::CacheFindDynamicNode;aUri=%s", aUri );
       
   223     
       
   224     CConnMoNodeElement* resultNode = NULL;
       
   225 
       
   226     for ( TInt i = 0; i < iCache.Count(); ++i )
       
   227         {
       
   228         if ( iCache[i]->iUri.Match( aUri ) != KErrNotFound )
       
   229             {
       
   230             // 
       
   231             TBuf8<KMaxFieldLength> dynamicNodeChildUri( aUri );
       
   232             dynamicNodeChildUri.Append( KChildNodeWildCardPattern );
       
   233             
       
   234             if ( iCache[i]->iUri.Match(dynamicNodeChildUri) == KErrNotFound )
       
   235                 {
       
   236                 // Correct dynamic node found.
       
   237                 OstTrace0( TRACE_NORMAL, 
       
   238                            CADDBUFFER_CACHEFINDDYNAMICNODE_MATCH_FOUND, 
       
   239                            "CAddBuffer::CacheFindDynamicNode; Matching node found.");
       
   240                           
       
   241                 resultNode = iCache[i];
       
   242                 break;
       
   243                 }
       
   244             }
       
   245         }
       
   246     if ( resultNode != NULL )
       
   247         {
       
   248         OstTraceExt1( TRACE_NORMAL, 
       
   249                   CADDBUFFER_CACHEFINDDYNAMICNODE_EXIT, 
       
   250                   "EXIT: CAddBuffer::CacheFindDynamicNode;resultNode=%s", 
       
   251                   resultNode->iUri );
       
   252         }
       
   253     
       
   254     return resultNode;
       
   255     }
       
   256 //------------------------------------------------------------------------------
       
   257 // CAddBuffer::AddNodeToBuffer()
       
   258 //------------------------------------------------------------------------------
       
   259 TInt CAddBuffer::GetGroup( const TDesC8& aRoot, RPointerArray<CConnMoNodeElement>* aGroup )
       
   260     {
       
   261     OstTraceExt1( TRACE_NORMAL, CADDBUFFER_GETGROUP_ENTRY, "ENTRY: CAddBuffer::GetGroup;aRoot=%s", aRoot );
       
   262 
       
   263     iCache.Reset();
       
   264     TInt retval( KErrNotFound );
       
   265     TBool first = ETrue;
       
   266     TBuf8<KSmlMaxURISegLen> groupTag;
       
   267     groupTag.Copy( aRoot );
       
   268     groupTag.Append( KChildNodeWildCardPattern );
       
   269 
       
   270     for ( TInt i = 0; i < iBuffer.Count(); ++i )
       
   271         {
       
   272         if ( iBuffer[i]->iUri.Match( groupTag ) != KErrNotFound
       
   273              && !iBuffer[i]->iProcessed )
       
   274             {
       
   275             if ( first )
       
   276                 {
       
   277                 groupTag.Insert( aRoot.Length(), KNodeSeparator );
       
   278                 groupTag.Insert( aRoot.Length() + 1, CUtils::GetSecondURISeg( iBuffer[i]->iUri ) );
       
   279                 first = EFalse;
       
   280                 retval = 0;
       
   281                 }
       
   282             aGroup->Append(iBuffer[i]);
       
   283             iCache.Append(iBuffer[i]);
       
   284             retval++;
       
   285             }
       
   286         }
       
   287     OstTrace1( TRACE_NORMAL, CADDBUFFER_GETGROUP_EXIT, "EXIT: CAddBuffer::GetGroup;retval=%d", retval );
       
   288 
       
   289     return retval;
       
   290     }
       
   291 //------------------------------------------------------------------------------
       
   292 // CAddBuffer::~CAddBuffer()
       
   293 //------------------------------------------------------------------------------
       
   294 void CAddBuffer::Reset()
       
   295     {
       
   296     OstTraceFunctionEntry0( CADDBUFFER_Reset_ENTRY );
       
   297     
       
   298     iBuffer.ResetAndDestroy();
       
   299     
       
   300     OstTraceFunctionExit0( CADDBUFFER_Reset_EXIT );
       
   301     }
       
   302