xml/libxml2libs/src/xmlengineutils/xmlengxmlengine.cpp
changeset 0 e35f40988205
equal deleted inserted replaced
-1:000000000000 0:e35f40988205
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file contains methods that to add/remove XmlEngine user
       
    15 //
       
    16 
       
    17 #include "libxml2_globals_private.h"
       
    18 #include <stdapis/libxml2/libxml2_parser.h>
       
    19 #include <stdapis/libxml2/libxml2_xpath.h>
       
    20 #include <xml/utils/xmlengxestd.h>
       
    21 #include <xml/utils/xmlengmem.h>
       
    22 
       
    23 EXPORT_C void XmlEngLeaveL(TInt aCode)
       
    24 {
       
    25     User::Leave(aCode);
       
    26 }   
       
    27 
       
    28 EXPORT_C void XmlEngineCleanup(TAny* aParserContext)
       
    29     {
       
    30     xmlGlobalStatePtr gs = xeGetTLS();
       
    31     if (!gs)
       
    32         return; // Note: This should not happen in normal conditions!
       
    33     if (aParserContext)
       
    34         {
       
    35         xmlParserCtxtPtr ctxt = reinterpret_cast<xmlParserCtxtPtr>(aParserContext);
       
    36         if(ctxt->myDoc)                     
       
    37             {
       
    38             xmlFreeDoc(ctxt->myDoc); 
       
    39             }
       
    40         xmlFreeParserCtxt(ctxt);
       
    41         }
       
    42 
       
    43 #undef xeUserCount
       
    44     if(gs->xeUserCount > 1)
       
    45         {
       
    46         gs->xeUserCount--;
       
    47         return;
       
    48         }
       
    49 
       
    50     xmlCleanupGlobalData();
       
    51     }
       
    52 
       
    53 
       
    54 EXPORT_C void XmlEngineAttachL()
       
    55     {
       
    56     xmlGlobalStatePtr gs = xeGetTLS();
       
    57     if(!gs)
       
    58         {
       
    59         gs = xmlCreateAndInitializeGlobalState();
       
    60         if(!gs)
       
    61             {
       
    62             OOM_HAPPENED;
       
    63             }
       
    64         }
       
    65 #undef xeUserCount
       
    66     gs->xeUserCount++;
       
    67     }
       
    68 
       
    69 // ------------------------------------------------------------------------------
       
    70 //  This function should have matching call to XmlEnginePopAndClose()
       
    71 //  (which is CleanupStack::PopAndDestroy() so far but may become more complex)
       
    72 // ------------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C void XmlEnginePushL()
       
    75     {
       
    76     XmlEngineAttachL();
       
    77     CleanupStack::PushL(TCleanupItem(XmlEngineCleanup, NULL));
       
    78     }
       
    79 
       
    80 
       
    81 EXPORT_C void XmlEnginePopAndClose()
       
    82     {
       
    83     CleanupStack::PopAndDestroy();
       
    84     }