webservices/wsfragment/src/rsendocument.cpp
changeset 0 62f9d29f7211
child 23 a1df79fa35b4
child 36 c5fabff9b552
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2009 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:      
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include "RSenDocument.h"
       
    24 #include <xmlengxestd.h>
       
    25 #include <xmlengdomimplementation.h>
       
    26 
       
    27 LOCAL_C void CleanupRSenDocument(TAny* aDocumentData)
       
    28 	{
       
    29 	TSenDocumentData* pData = 
       
    30 		REINTERPRET_CAST(TSenDocumentData*, aDocumentData);
       
    31     if ( *pData->ipOpenDocuments <= 1)
       
    32         {
       
    33         RSenDocument document;
       
    34     	document.ipData = pData;
       
    35     	document.Close();
       
    36         }
       
    37     else
       
    38         {
       
    39         *pData->ipOpenDocuments = *pData->ipOpenDocuments-1;
       
    40         }
       
    41 	}
       
    42 
       
    43 EXPORT_C RSenDocument RSenDocument::NewL()
       
    44     {
       
    45     RSenDocument self = RSenDocument::NewLC();
       
    46     CleanupStack::Pop();
       
    47     return self;
       
    48     }
       
    49 
       
    50 EXPORT_C RSenDocument RSenDocument::NewLC()
       
    51     {
       
    52 	TBool* pDisabled = (TBool*)Dll::Tls();
       
    53 	if ( !pDisabled )
       
    54 	    {
       
    55         XmlEngineAttachL();
       
    56 	    }
       
    57     RXmlEngDOMImplementation domImpl;
       
    58     domImpl.OpenL();
       
    59     RXmlEngDocument doc;
       
    60     doc.OpenL(domImpl);
       
    61     RSenDocument document;
       
    62     document.ipData = new (ELeave) TSenDocumentData;
       
    63     document.iInternal =
       
    64         (reinterpret_cast<RSenDocument*>(const_cast<RXmlEngDocument*>(&doc)))->iInternal;
       
    65     document.ipData->iInternal = document.iInternal;
       
    66     document.ipData->ipOpenDocuments = new (ELeave) TInt(1);
       
    67     document.ipData->iDomImpl = domImpl;
       
    68     TCleanupItem cleanup(CleanupRSenDocument, document.ipData);
       
    69     CleanupStack::PushL(cleanup);
       
    70     return document;
       
    71     }
       
    72 
       
    73 EXPORT_C RSenDocument RSenDocument::NewL(void* aInternal)
       
    74     {
       
    75     RSenDocument self = RSenDocument::NewLC(aInternal);
       
    76     CleanupStack::Pop();
       
    77     return self;
       
    78     }
       
    79 
       
    80 EXPORT_C RSenDocument RSenDocument::NewLC(void* aInternal)
       
    81     {
       
    82 	TBool* pDisabled = (TBool*)Dll::Tls();
       
    83 	if ( !pDisabled ) // NOTE: when enabled, pointer does NOT EXIST in TLS!
       
    84 	    {
       
    85         XmlEngineAttachL();
       
    86 	    }
       
    87     RXmlEngDOMImplementation domImpl;
       
    88     domImpl.OpenL();
       
    89     RXmlEngDocument doc;
       
    90     doc.OpenL(domImpl, aInternal);
       
    91     RSenDocument document;
       
    92     document.ipData = new (ELeave) TSenDocumentData;
       
    93     document.iInternal =
       
    94         (reinterpret_cast<RSenDocument*>(const_cast<RXmlEngDocument*>(&doc)))->iInternal;
       
    95     document.ipData->iInternal = document.iInternal;
       
    96     document.ipData->ipOpenDocuments = new (ELeave) TInt(1);
       
    97     document.ipData->iDomImpl = domImpl;
       
    98     TCleanupItem cleanup(CleanupRSenDocument, document.ipData);
       
    99     CleanupStack::PushL(cleanup);
       
   100     return document;
       
   101     }
       
   102 
       
   103 EXPORT_C RSenDocument RSenDocument::Copy()
       
   104     {
       
   105     *ipData->ipOpenDocuments = *ipData->ipOpenDocuments + 1;
       
   106     return *this;
       
   107     }
       
   108 
       
   109 EXPORT_C void RSenDocument::Close()
       
   110     {
       
   111     *ipData->ipOpenDocuments = *ipData->ipOpenDocuments - 1;
       
   112     if ( !*ipData->ipOpenDocuments )
       
   113         {
       
   114         RXmlEngDOMImplementation domImpl = ipData->iDomImpl;
       
   115         iInternal = ipData->iInternal;
       
   116         delete ipData->ipOpenDocuments;
       
   117         delete ipData;
       
   118         RXmlEngDocument::Close();
       
   119         domImpl.Close();
       
   120     	TBool* pDisabled = (TBool*)Dll::Tls();
       
   121     	if ( !pDisabled )
       
   122     	    {
       
   123             XmlEngineCleanup();
       
   124     	    }
       
   125         }
       
   126     else
       
   127         {
       
   128         iInternal = NULL;
       
   129         }
       
   130        
       
   131     }
       
   132 
       
   133 EXPORT_C void RSenDocument::Destroy()
       
   134     {
       
   135     RSenDocument::Close();
       
   136     /*        
       
   137     *ipData->ipOpenDocuments = *ipData->ipOpenDocuments - 1;
       
   138     if ( !*ipData->ipOpenDocuments )
       
   139         {
       
   140         RXmlEngDOMImplementation domImpl = ipData->ipDomImpl;            
       
   141         delete ipData->ipOpenDocuments;
       
   142         delete ipData;
       
   143         ipData = NULL;
       
   144         RXmlEngDocument::Destroy();
       
   145         domImpl.Close();        
       
   146     	TBool* pDisabled = (TBool*)Dll::Tls();
       
   147     	if ( !pDisabled )
       
   148     	    {
       
   149             XmlEngineCleanup();
       
   150     	    }
       
   151         }
       
   152     else
       
   153         {
       
   154         iInternal = NULL;
       
   155         }
       
   156     */        
       
   157     }
       
   158     
       
   159 EXPORT_C TInt RSenDocument::ManualXmlEngineTlsAttachL()
       
   160     {
       
   161 	TBool* pDisabled = (TBool*)Dll::Tls();
       
   162 		
       
   163 	if ( !pDisabled )
       
   164   		{
       
   165   		pDisabled = new (ELeave) TBool();
       
   166         if ( pDisabled )
       
   167             {
       
   168       		Dll::SetTls(pDisabled);
       
   169             }
       
   170         else
       
   171             {
       
   172             return KErrUnknown;
       
   173             }
       
   174   	    }
       
   175   	else
       
   176   	    {
       
   177   	    return KErrAlreadyExists;
       
   178   	    }
       
   179   	
       
   180     XmlEngineAttachL();
       
   181     
       
   182   	return KErrNone;
       
   183     }
       
   184 
       
   185 EXPORT_C TInt RSenDocument::ManualXmlEngineTlsCleanup()
       
   186     {
       
   187 	TBool* pDisabled = (TBool*)Dll::Tls();
       
   188 	if ( pDisabled )
       
   189   		{
       
   190         delete pDisabled;
       
   191         Dll::FreeTls();	            
       
   192   	    }
       
   193   	else
       
   194   	    {
       
   195   	    return KErrNotFound;
       
   196   	    }
       
   197 
       
   198     XmlEngineCleanup();
       
   199   	
       
   200   	return KErrNone;
       
   201     }
       
   202     
       
   203 // End of File
       
   204 
       
   205 
       
   206