uiservicetab/vimpststorage/src/cvimpststoragemanager.cpp
branchRCL_3
changeset 14 9fdee5e1da30
parent 0 5e5d6b214f4f
equal deleted inserted replaced
13:796276a1bdcc 14:9fdee5e1da30
    22 
    22 
    23 #include <e32std.h>
    23 #include <e32std.h>
    24 
    24 
    25 #include "cvimpststoragemanager.h"
    25 #include "cvimpststoragemanager.h"
    26 #include "tvimpststoragepanics.h"
    26 #include "tvimpststoragepanics.h"
    27 #include "vimpstdebugtrace.h"
    27 #include "uiservicetabtracer.h"
    28 
    28 
    29 
    29 
    30 // ============================ MEMBER FUNCTIONS ===============================
    30 // ============================ MEMBER FUNCTIONS ===============================
    31 
    31 
    32 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    34 // Factory method that create the singleton instance of the storage manager
    34 // Factory method that create the singleton instance of the storage manager
    35 // -----------------------------------------------------------------------------
    35 // -----------------------------------------------------------------------------
    36 //
    36 //
    37 void CVIMPSTStorageManager::InitialiseLibraryL()
    37 void CVIMPSTStorageManager::InitialiseLibraryL()
    38     {
    38     {
    39     TRACE( T_LIT("CVIMPSTStorageManager::InitialiseLibraryL() begin") );
    39 	TRACER_AUTO;
    40     //see whether there is an instance in the TLS
    40     //see whether there is an instance in the TLS
    41     //if not create the instance and set the same in TLS
    41     //if not create the instance and set the same in TLS
    42     CVIMPSTStorageManager *sm = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    42     CVIMPSTStorageManager *sm = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    43     if ( ! sm )
    43     if ( ! sm )
    44         {
    44         {
    47         sm = manager;
    47         sm = manager;
    48         CleanupStack::PushL( manager );
    48         CleanupStack::PushL( manager );
    49         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( sm ) ) );
    49         User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( sm ) ) );
    50         CleanupStack::Pop( manager );
    50         CleanupStack::Pop( manager );
    51         }
    51         }
    52     TRACE( T_LIT("CVIMPSTStorageManager::InitialiseLibraryL() end") );
       
    53     }
    52     }
    54 
    53 
    55 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    56 // CVIMPSTStorageManager::Release
    55 // CVIMPSTStorageManager::Release
    57 // Factory method to release the singleton instance of the storage manager
    56 // Factory method to release the singleton instance of the storage manager
    58 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    59 //
    58 //
    60 TInt CVIMPSTStorageManager::Release()
    59 TInt CVIMPSTStorageManager::Release()
    61     {
    60     {
    62     TRACE( T_LIT("CVIMPSTStorageManager::Release() begin") );
    61 	TRACER_AUTO;
    63     //if any instance in TLS get the same and delete it    
    62     //if any instance in TLS get the same and delete it    
    64     CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    63     CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    65     if ( storage )
    64     if ( storage )
    66         {
    65         {
    67         delete storage;
    66         delete storage;
    68         Dll::SetTls( NULL );
    67         Dll::SetTls( NULL );
    69         }
    68         }
    70     TRACE( T_LIT("CVIMPSTStorageManager::Release() end") );
       
    71     return KErrNone;
    69     return KErrNone;
    72     }
    70     }
    73 
    71 
    74 
    72 
    75 
    73 
    77 // CVIMPSTStorageManager::Instance()
    75 // CVIMPSTStorageManager::Instance()
    78 // -----------------------------------------------------------------------------
    76 // -----------------------------------------------------------------------------
    79 //
    77 //
    80 CVIMPSTStorageManager& CVIMPSTStorageManager::Instance()
    78 CVIMPSTStorageManager& CVIMPSTStorageManager::Instance()
    81     {
    79     {
       
    80 	TRACER_AUTO;
    82     //get the instance frm TLS and return the same
    81     //get the instance frm TLS and return the same
    83     TRACE( T_LIT("CVIMPSTStorageManager::Instance() begin") );
       
    84     CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    82     CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() );
    85     
    83     
    86     __ASSERT_ALWAYS( storage,
    84     __ASSERT_ALWAYS( storage,
    87         User::Panic( KPanicCategory, KLIBNOTINITIALIZED ) );
    85         User::Panic( KPanicCategory, KLIBNOTINITIALIZED ) );
    88 	TRACE( T_LIT("CVIMPSTStorageManager::Instance() end") );
       
    89     return *storage;
    86     return *storage;
    90     }    
    87     }    
    91     
    88     
    92     
    89     
    93 
    90 
    95 // CVIMPSTStorageManager::NewL
    92 // CVIMPSTStorageManager::NewL
    96 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
    97 //
    94 //
    98  CVIMPSTStorageManager* CVIMPSTStorageManager::NewL()
    95  CVIMPSTStorageManager* CVIMPSTStorageManager::NewL()
    99     {
    96     {
   100     TRACE( T_LIT("CVIMPSTStorageManager::NewL() begin") );
    97 		TRACER_AUTO;
   101     //creates the instance
    98     //creates the instance
   102     CVIMPSTStorageManager* self = new( ELeave ) CVIMPSTStorageManager;
    99     CVIMPSTStorageManager* self = new( ELeave ) CVIMPSTStorageManager;
   103     CleanupStack::PushL( self );
   100     CleanupStack::PushL( self );
   104     self->ConstructL();
   101     self->ConstructL();
   105     CleanupStack::Pop( self );
   102     CleanupStack::Pop( self );
   106     TRACE( T_LIT("CVIMPSTStorageManager::NewL() end") );
       
   107     return self;
   103     return self;
   108     }
   104     }
   109     
   105     
   110 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   111 // CVIMPSTStorageManager::ConstructL
   107 // CVIMPSTStorageManager::ConstructL
   112 // Two-phased constructor.
   108 // Two-phased constructor.
   113 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   114 //
   110 //
   115 void CVIMPSTStorageManager::ConstructL()
   111 void CVIMPSTStorageManager::ConstructL()
   116 	{
   112 	{
   117     TRACE( T_LIT("CVIMPSTStorageManager::ConstructL() begin") );
   113 	TRACER_AUTO;
   118     TRACE( T_LIT("CVIMPSTStorageManager::ConstructL() end") );
       
   119     }
   114     }
   120     
   115     
   121     
   116     
   122 // -----------------------------------------------------------------------------
   117 // -----------------------------------------------------------------------------
   123 // CVIMPSTStorageManager::~CVIMPSTStorageManager
   118 // CVIMPSTStorageManager::~CVIMPSTStorageManager
   124 // -----------------------------------------------------------------------------
   119 // -----------------------------------------------------------------------------
   125 // 
   120 // 
   126  CVIMPSTStorageManager::~CVIMPSTStorageManager()
   121  CVIMPSTStorageManager::~CVIMPSTStorageManager()
   127     {
   122     {
   128     TRACE( T_LIT("CVIMPSTStorageManager::~CVIMPSTStorageManager() begin") );
   123 		TRACER_AUTO;
   129     //release  all the existing views
   124     //release  all the existing views
   130 	iServiceViewList.ResetAndDestroy();	
   125 	iServiceViewList.ResetAndDestroy();	
   131     TRACE( T_LIT("CVIMPSTStorageManager::~CVIMPSTStorageManager() end") );
       
   132     }
   126     }
   133     
   127     
   134 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
   135 // CVIMPSTStorageManager::CreateServiceViewL
   129 // CVIMPSTStorageManager::CreateServiceViewL
   136 // -----------------------------------------------------------------------------
   130 // -----------------------------------------------------------------------------
   137 //
   131 //
   138 CVIMPSTStorageServiceView* CVIMPSTStorageManager::CreateServiceViewL( TUint32 aServiceId,
   132 CVIMPSTStorageServiceView* CVIMPSTStorageManager::CreateServiceViewL( TUint32 aServiceId,
   139 											const TDesC& aStoreName,
   133 											const TDesC& aStoreName,
   140 											const TDesC& aServiceName )
   134 											const TDesC& aServiceName )
   141 	{
   135 	{
   142 	TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() begin") );
   136 	TRACER_AUTO;
   143 	//creates a new view based on the service id.
   137 	//creates a new view based on the service id.
   144 	TInt index = KErrNotFound;
   138 	TInt index = KErrNotFound;
   145 	CVIMPSTStorageServiceView* serviceView = NULL;
   139 	CVIMPSTStorageServiceView* serviceView = NULL;
   146 	
   140 	
   147 	//check if the view already exists in the viewlist
   141 	//check if the view already exists in the viewlist
   148 	index = FindServiceView(aServiceId);
   142 	index = FindServiceView(aServiceId);
   149 	if( KErrNotFound == index )
   143 	if( KErrNotFound == index )
   150 		{
   144 		{
   151 		TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() service does not exit") );
   145 	TRACE( "service does not exit" );
   152 		// service view is not found 
   146 		// service view is not found 
   153 		// check if store name is valid create a service view for aServiceId
   147 		// check if store name is valid create a service view for aServiceId
   154 		if( aStoreName.Length() )
   148 		if( aStoreName.Length() )
   155 			{
   149 			{
   156 			TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() store name is valid") );
   150 		TRACE(" store name is valid" );
   157 			serviceView = CVIMPSTStorageServiceView::NewL(aServiceId,
   151 			serviceView = CVIMPSTStorageServiceView::NewL(aServiceId,
   158 	    										aStoreName, aServiceName);	
   152 	    										aStoreName, aServiceName);	
   159 			iServiceViewList.Append(serviceView); 
   153 			iServiceViewList.Append(serviceView); 
   160 			TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() new view created for serviceId = %d"),aServiceId );
   154 			TRACE( "new view created for serviceId = %d",aServiceId );
   161 			}
   155 			}
   162 		// if store name is not valid ,return NULL
   156 		// if store name is not valid ,return NULL
   163 		}
   157 		}
   164     else
   158     else
   165 	    {
   159 	    {
   166 	    TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() service already exist = %d"),aServiceId );
   160     TRACE( " service already exist = %d",aServiceId );
   167 	    serviceView = iServiceViewList[ FindServiceView(aServiceId)];
   161 	    serviceView = iServiceViewList[ FindServiceView(aServiceId)];
   168 	    }
   162 	    }
   169     //return the extisting view from the viewlist
   163     //return the extisting view from the viewlist
   170     TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() end") );
       
   171 	return serviceView;
   164 	return serviceView;
   172 	}
   165 	}
   173 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   174 // CVIMPSTStorageManager::FindServiceView
   167 // CVIMPSTStorageManager::FindServiceView
   175 // -----------------------------------------------------------------------------
   168 // -----------------------------------------------------------------------------
   176 //
   169 //
   177 TInt CVIMPSTStorageManager::FindServiceView( TUint32 aServiceId)
   170 TInt CVIMPSTStorageManager::FindServiceView( TUint32 aServiceId)
   178 	{
   171 	{
   179 	TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() begin") );
   172 	TRACER_AUTO;
   180 	//search whether the view exists in the view list.
   173 	//search whether the view exists in the view list.
   181 	TInt index = KErrNotFound;
   174 	TInt index = KErrNotFound;
   182     TInt count = iServiceViewList.Count();
   175     TInt count = iServiceViewList.Count();
   183     for(TInt i = 0; i < count; i++ )
   176     for(TInt i = 0; i < count; i++ )
   184 	    {
   177 	    {
   185     	if( aServiceId == iServiceViewList[ i ]->GetServiceId() )
   178     	if( aServiceId == iServiceViewList[ i ]->GetServiceId() )
   186 			{
   179 			{
   187 			TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() aServiceId found = %d") ,aServiceId ); 
   180 			TRACE( "aServiceId found = %d" ,aServiceId ); 
   188 			index = i;
   181 			index = i;
   189 			break;
   182 			break;
   190 			}
   183 			}
   191 		}
   184 		}
   192 	TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() end") );	
       
   193 	return index;
   185 	return index;
   194 	}
   186 	}
   195 	
   187 	
   196 	
   188 	
   197 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   198 // CVIMPSTStorageManager::RemoveServiceView
   190 // CVIMPSTStorageManager::RemoveServiceView
   199 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   200 //
   192 //
   201 void  CVIMPSTStorageManager::RemoveServiceView( TUint32 aServiceId)
   193 void  CVIMPSTStorageManager::RemoveServiceView( TUint32 aServiceId)
   202 	{
   194 	{
   203 	TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() begin") );
   195 	TRACER_AUTO;
   204 	//searches and removes the view from the view list.
   196 	//searches and removes the view from the view list.
   205     TInt index = FindServiceView(aServiceId);
   197     TInt index = FindServiceView(aServiceId);
   206 	if( index >= 0 )
   198 	if( index >= 0 )
   207 		{
   199 		{
   208 		TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() aServiceId found = %d") ,aServiceId ); 
   200 		TRACE( "aServiceId found = %d" ,aServiceId ); 
   209 		//view exists, so delete and remove the same
   201 		//view exists, so delete and remove the same
   210 		CVIMPSTStorageServiceView* serviceView = iServiceViewList[ index ];
   202 		CVIMPSTStorageServiceView* serviceView = iServiceViewList[ index ];
   211 		iServiceViewList.Remove( index ); 
   203 		iServiceViewList.Remove( index ); 
   212 		delete serviceView;
   204 		delete serviceView;
   213 		iServiceViewList.Compress();     
   205 		iServiceViewList.Compress();     
   214 		}
   206 		}
   215 	TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() end") );   
       
   216 	}
   207 	}
   217 
   208 
   218 //  End of File
   209 //  End of File