mtpfws/mtpfw/src/rmtpframework.cpp
changeset 0 d0791faffa3f
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 "cmtpconnectionmgr.h"
       
    17 #include "cmtpdataprovidercontroller.h"
       
    18 #include "cmtpframeworkconfig.h"
       
    19 #include "cmtpobjectmgr.h"
       
    20 #include "cmtpobjectstore.h"
       
    21 #include "cmtpparserrouter.h"
       
    22 #include "cmtpstoragemgr.h"
       
    23 #include "rmtpframework.h"
       
    24 #include "cmtpdatacodegenerator.h"
       
    25 #include "cmtpservicemgr.h"
       
    26 
       
    27 // Class constants.
       
    28 __FLOG_STMT(_LIT8(KComponent,"Framework");)
       
    29 
       
    30 /**
       
    31 Constructor.
       
    32 */
       
    33 EXPORT_C RMTPFramework::RMTPFramework() :
       
    34     iSingletons(NULL)
       
    35     {
       
    36     
       
    37     }
       
    38 
       
    39 /**
       
    40 Opens the singletons reference.
       
    41 */
       
    42 EXPORT_C void RMTPFramework::OpenL()
       
    43     {
       
    44     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    45     __FLOG(_L8("OpenL - Entry"));
       
    46     iSingletons = &CSingletons::OpenL();
       
    47     iNested     = iSingletons->iConstructing;
       
    48     __FLOG(_L8("OpenL - Exit"));
       
    49     }
       
    50 
       
    51 /**
       
    52 Opens the singletons reference. The singletons reference is pushed onto the
       
    53 cleanup stack.
       
    54 */
       
    55 EXPORT_C void RMTPFramework::OpenLC()
       
    56     {
       
    57     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    58     __FLOG(_L8("OpenLC - Entry"));
       
    59     ::CleanupClosePushL(*this);
       
    60     OpenL();
       
    61     __FLOG(_L8("OpenLC - Exit"));
       
    62     }
       
    63     
       
    64 /**
       
    65 Closes the singletons reference.
       
    66 */
       
    67 EXPORT_C void RMTPFramework::Close()
       
    68     {
       
    69     __FLOG(_L8("Close - Entry"));
       
    70     if ((iSingletons) && (!iNested))
       
    71         {
       
    72         iSingletons->Close();
       
    73         iSingletons = NULL;
       
    74         }
       
    75     __FLOG(_L8("Close - Exit"));
       
    76     __FLOG_CLOSE;
       
    77     }
       
    78 
       
    79 EXPORT_C CMTPConnectionMgr& RMTPFramework::ConnectionMgr() const
       
    80     {
       
    81     __FLOG(_L8("ConnectionMgr - Entry"));
       
    82     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
    83     __ASSERT_DEBUG(iSingletons->iSingletonConnectionMgr, User::Invariant());
       
    84     __FLOG(_L8("ConnectionMgr - Exit"));
       
    85     return *(iSingletons->iSingletonConnectionMgr);
       
    86     }
       
    87     
       
    88 EXPORT_C CMTPDataProviderController& RMTPFramework::DpController() const
       
    89     {
       
    90     __FLOG(_L8("DpController - Entry"));
       
    91     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
    92     __ASSERT_DEBUG(iSingletons->iSingletonDpController, User::Invariant());
       
    93     __FLOG(_L8("DpController - Exit"));
       
    94     return *(iSingletons->iSingletonDpController);
       
    95     }
       
    96    
       
    97 EXPORT_C CMTPFrameworkConfig& RMTPFramework::FrameworkConfig() const
       
    98     {
       
    99     __FLOG(_L8("FrameworkConfig - Entry"));
       
   100     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   101     __ASSERT_DEBUG(iSingletons->iSingletonFrameworkConfig, User::Invariant());
       
   102     __FLOG(_L8("FrameworkConfig - Exit"));
       
   103     return *(iSingletons->iSingletonFrameworkConfig);
       
   104     }
       
   105 
       
   106 EXPORT_C RFs& RMTPFramework::Fs() const
       
   107     {
       
   108     __FLOG(_L8("Fs - Entry"));
       
   109     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   110     __FLOG(_L8("Fs - Exit"));
       
   111     return iSingletons->iSingletonFs;
       
   112     }
       
   113 
       
   114 EXPORT_C CMTPObjectMgr& RMTPFramework::ObjectMgr() const
       
   115     {
       
   116     __FLOG(_L8("ObjectMgr - Entry"));
       
   117     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   118     __ASSERT_DEBUG(iSingletons->iSingletonObjectMgr, User::Invariant());
       
   119     __FLOG(_L8("ObjectMgr - Exit"));
       
   120     return *(iSingletons->iSingletonObjectMgr);
       
   121     }
       
   122 
       
   123 EXPORT_C CMTPReferenceMgr& RMTPFramework::ReferenceMgr() const
       
   124     {
       
   125     __FLOG(_L8("ReferenceMgr - Entry"));
       
   126     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   127     __ASSERT_DEBUG(iSingletons->iSingletonRouter, User::Invariant());
       
   128     __FLOG(_L8("ReferenceMgr - Exit"));
       
   129     return (iSingletons->iSingletonObjectMgr->ObjectStore().ReferenceMgr());
       
   130     }
       
   131 
       
   132 EXPORT_C CMTPParserRouter& RMTPFramework::Router() const
       
   133     {
       
   134     __FLOG(_L8("Router - Entry"));
       
   135     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   136     __ASSERT_DEBUG(iSingletons->iSingletonRouter, User::Invariant());
       
   137     __FLOG(_L8("Router - Exit"));
       
   138     return *(iSingletons->iSingletonRouter);
       
   139     }
       
   140 
       
   141 EXPORT_C CMTPStorageMgr& RMTPFramework::StorageMgr() const
       
   142     {
       
   143     __FLOG(_L8("StorageMgr - Entry"));
       
   144     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   145     __ASSERT_DEBUG(iSingletons->iSingletonStorageMgr, User::Invariant());
       
   146     __FLOG(_L8("StorageMgr - Exit"));
       
   147     return *(iSingletons->iSingletonStorageMgr);
       
   148     }
       
   149 
       
   150 EXPORT_C CMTPDataCodeGenerator& RMTPFramework::DataCodeGenerator() const
       
   151     {
       
   152     __FLOG(_L8("DataCodeGenerator - Entry"));
       
   153     __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   154     __ASSERT_DEBUG(iSingletons->iSingleDataCodeGenerator, User::Invariant());
       
   155     __FLOG(_L8("DataCodeGenerator - Exit"));
       
   156     return *(iSingletons->iSingleDataCodeGenerator);
       
   157     }
       
   158 
       
   159 EXPORT_C CMTPServiceMgr& RMTPFramework::ServiceMgr() const
       
   160     {
       
   161     __FLOG(_L8("ServiceMgr - Entry"));
       
   162    __ASSERT_DEBUG(iSingletons, User::Invariant());
       
   163    __ASSERT_DEBUG(iSingletons->iSingleServiceMgr, User::Invariant());
       
   164    __FLOG(_L8("ServiceMgr - Exit"));
       
   165    return *(iSingletons->iSingleServiceMgr);
       
   166     }
       
   167 
       
   168 RMTPFramework::CSingletons& RMTPFramework::CSingletons::OpenL()
       
   169     {
       
   170     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("CSingletons::OpenL - Entry"));
       
   171     CSingletons* self(reinterpret_cast<CSingletons*>(Dll::Tls()));
       
   172     if (!self)
       
   173         {
       
   174         self = new(ELeave) CSingletons();
       
   175         Dll::SetTls(reinterpret_cast<TAny*>(self));
       
   176         self->ConstructL();
       
   177         }
       
   178     else if (!self->iConstructing)
       
   179         {        
       
   180         self->Inc();
       
   181         }
       
   182     __FLOG_STATIC(KMTPSubsystem, KComponent, _L8("CSingletons::OpenL - Exit"));
       
   183     return *self;
       
   184     }
       
   185     
       
   186 void RMTPFramework::CSingletons::Close()
       
   187     {
       
   188     CSingletons* self(reinterpret_cast<CSingletons*>(Dll::Tls()));
       
   189     if (self)
       
   190         {
       
   191         __FLOG(_L8("CSingletons::Close - Entry"));
       
   192         self->Dec();
       
   193         if (self->AccessCount() == 0)
       
   194             {
       
   195             __FLOG(_L8("CSingletons::Close - Exit"));
       
   196             delete self;
       
   197             Dll::SetTls(NULL);
       
   198             }
       
   199         else
       
   200             {
       
   201             __FLOG(_L8("CSingletons::Close - Exit"));
       
   202             }
       
   203         }
       
   204     }
       
   205     
       
   206 RMTPFramework::CSingletons::~CSingletons()
       
   207     {
       
   208     __FLOG(_L8("CSingletons::~CSingletons - Entry"));
       
   209     delete iSingletonStorageMgr;
       
   210     delete iSingletonRouter;
       
   211     delete iSingletonDpController;
       
   212     delete iSingletonObjectMgr;
       
   213     delete iSingletonFrameworkConfig;
       
   214     delete iSingletonConnectionMgr;
       
   215     delete iSingleDataCodeGenerator;
       
   216     delete iSingleServiceMgr;
       
   217     
       
   218     iSingletonFs.Close();
       
   219     __FLOG(_L8("CSingletons::~CSingletons - Exit"));
       
   220     __FLOG_CLOSE;
       
   221     }
       
   222     
       
   223 void RMTPFramework::CSingletons::ConstructL()
       
   224     {
       
   225     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   226     __FLOG(_L8("CSingletons::ConstructL - Entry"));
       
   227     iConstructing = ETrue;
       
   228     
       
   229 	User::LeaveIfError(iSingletonFs.Connect());
       
   230     iSingletonFrameworkConfig   = CMTPFrameworkConfig::NewL();
       
   231     iSingletonConnectionMgr     = CMTPConnectionMgr::NewL();
       
   232     iSingletonObjectMgr         = CMTPObjectMgr::NewL();
       
   233     iSingletonDpController      = CMTPDataProviderController::NewL();
       
   234     iSingletonRouter            = CMTPParserRouter::NewL();
       
   235     iSingletonStorageMgr        = CMTPStorageMgr::NewL();
       
   236     iSingleDataCodeGenerator    = CMTPDataCodeGenerator::NewL();
       
   237     iSingleServiceMgr           = CMTPServiceMgr::NewL();
       
   238     
       
   239     iConstructing = EFalse;
       
   240     __FLOG(_L8("CSingletons::ConstructL - Exit"));
       
   241     }