mtpfws/mtpfw/dataproviders/dputility/src/rmtpdpsingletons.cpp
changeset 0 d0791faffa3f
child 4 60a94a45d437
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include "rmtpdpsingletons.h"
       
    17 
       
    18 #include <mtp/mmtpdataproviderframework.h>
       
    19 #include <mtp/cmtpobjectmetadata.h>
       
    20 
       
    21 
       
    22 // Class constants.
       
    23 __FLOG_STMT(_LIT8(KComponent,"DataProviderSingletons");)
       
    24 
       
    25 /**
       
    26 Constructor.
       
    27 */
       
    28 EXPORT_C RMTPDpSingletons::RMTPDpSingletons() :
       
    29     iSingletons(NULL)
       
    30     {
       
    31     }
       
    32 
       
    33 /**
       
    34 Opens the singletons reference.
       
    35 */
       
    36 EXPORT_C void RMTPDpSingletons::OpenL(MMTPDataProviderFramework& aFramework)
       
    37     {
       
    38     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    39     __FLOG(_L8("OpenL - Entry"));
       
    40     iFramework = &aFramework;
       
    41     iSingletons = &CSingletons::OpenL(aFramework);
       
    42     __FLOG(_L8("OpenL - Exit"));
       
    43     }
       
    44     
       
    45 /**
       
    46 Closes the singletons reference.
       
    47 */
       
    48 EXPORT_C void RMTPDpSingletons::Close()
       
    49     {
       
    50     __FLOG(_L8("Close - Entry"));
       
    51     if (iSingletons)
       
    52         {
       
    53         iSingletons->Close();
       
    54         iSingletons = NULL;
       
    55         }
       
    56     __FLOG(_L8("Close - Exit"));
       
    57     __FLOG_CLOSE;
       
    58     }
       
    59 
       
    60 
       
    61 /**
       
    62 This method finds the specific data provider's file system exclusion manager based on the 
       
    63 DP ID and returns it.
       
    64 @return the calling data provider's file system exclusion manager
       
    65 */	
       
    66 EXPORT_C CMTPFSExclusionMgr& RMTPDpSingletons::ExclusionMgrL() const
       
    67 	{
       
    68 	TExclusionMgrEntry entry = { 0, iFramework->DataProviderId() };
       
    69 	TInt index = iSingletons->iExclusionList.FindInOrderL(entry, TLinearOrder<TExclusionMgrEntry>(TExclusionMgrEntry::Compare));
       
    70 	return *(iSingletons->iExclusionList[index].iExclusionMgr);
       
    71 	}
       
    72 
       
    73 /**
       
    74 Inserts the calling data provider's file system exclusion manager to an ordered list 
       
    75 based on the the DP ID.
       
    76 @param aExclusionMgr a reference to a data provider's file system exclusion manager.
       
    77 */	
       
    78 EXPORT_C void RMTPDpSingletons::SetExclusionMgrL(CMTPFSExclusionMgr& aExclusionMgr)
       
    79 	{
       
    80 	TExclusionMgrEntry entry = { &aExclusionMgr, iFramework->DataProviderId() };
       
    81 	iSingletons->iExclusionList.InsertInOrderL(entry, TLinearOrder<TExclusionMgrEntry>(TExclusionMgrEntry::Compare));
       
    82 	}
       
    83 
       
    84 TInt RMTPDpSingletons::TExclusionMgrEntry::Compare(const TExclusionMgrEntry& aFirst, const TExclusionMgrEntry& aSecond)
       
    85 	{
       
    86 	return (aFirst.iDpId - aSecond.iDpId);
       
    87 	}
       
    88  
       
    89 RMTPDpSingletons::CSingletons* RMTPDpSingletons::CSingletons::NewL(MMTPDataProviderFramework& aFramework)
       
    90     {
       
    91     CSingletons* self(new(ELeave) CSingletons());
       
    92     CleanupStack::PushL(self);
       
    93     self->ConstructL(aFramework);
       
    94     CleanupStack::Pop(self);
       
    95     return self;
       
    96     }
       
    97 
       
    98 RMTPDpSingletons::CSingletons& RMTPDpSingletons::CSingletons::OpenL(MMTPDataProviderFramework& aFramework)
       
    99     {
       
   100     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("CSingletons::OpenL - Entry"));
       
   101     CSingletons* self(reinterpret_cast<CSingletons*>(Dll::Tls()));
       
   102     if (!self)
       
   103         {
       
   104         self = CSingletons::NewL(aFramework);
       
   105         Dll::SetTls(reinterpret_cast<TAny*>(self));
       
   106         }
       
   107     else
       
   108         {        
       
   109         self->Inc();
       
   110         }
       
   111     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("CSingletons::OpenL - Exit"));
       
   112     return *self;
       
   113     }
       
   114     
       
   115 void RMTPDpSingletons::CSingletons::Close()
       
   116     {
       
   117     CSingletons* self(reinterpret_cast<CSingletons*>(Dll::Tls()));
       
   118     if (self)
       
   119         {
       
   120         __FLOG(_L8("CSingletons::Close - Entry"));
       
   121         self->Dec();
       
   122         if (self->AccessCount() == 0)
       
   123             {
       
   124             __FLOG(_L8("CSingletons::Close - Exit"));
       
   125             delete self;
       
   126             Dll::SetTls(NULL);
       
   127             }
       
   128         else
       
   129             {
       
   130             __FLOG(_L8("CSingletons::Close - Exit"));
       
   131             }
       
   132         }
       
   133     }
       
   134     
       
   135 RMTPDpSingletons::CSingletons::~CSingletons()
       
   136     {
       
   137     __FLOG(_L8("CSingletons::~CSingletons - Entry"));
       
   138     iExclusionList.Close();
       
   139     iMTPUtility.Close();
       
   140     __FLOG(_L8("CSingletons::~CSingletons - Exit"));
       
   141     __FLOG_CLOSE;
       
   142     }
       
   143     
       
   144 void RMTPDpSingletons::CSingletons::ConstructL(MMTPDataProviderFramework& aFramework)
       
   145     {
       
   146     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   147     __FLOG(_L8("CSingletons::ConstructL - Entry"));
       
   148     
       
   149     iMTPUtility.OpenL(aFramework);
       
   150     
       
   151     __FLOG(_L8("CSingletons::ConstructL - Exit"));
       
   152     }
       
   153 
       
   154 EXPORT_C RMTPUtility& RMTPDpSingletons::MTPUtility() const
       
   155 	{
       
   156 	return iSingletons->iMTPUtility;
       
   157 	}