mmsengine/applicationadapter/src/mmsapplicationadapter.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005 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: mmsapplicationadapter implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    "mmsapplicationadapter.h"
       
    23 #include    "mmsheaders.h"
       
    24 #include    "mmsmsventry.h" // for the TMmsMsvEntry
       
    25 #include    "mmssettings.h"
       
    26 #include	"mmsconninit.h"
       
    27 #include 	"mmsregisteredapplications.h"
       
    28 #include	<msvids.h>
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // LOCAL CONSTANTS AND MACROS
       
    41 
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 
       
    51 
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 
       
    56 
       
    57 // ============================ MEMBER FUNCTIONS ===============================
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CMmsApplicationAdapter::NewL
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CMmsApplicationAdapter* CMmsApplicationAdapter::NewL()
       
    64     {
       
    65     CMmsApplicationAdapter* self = new ( ELeave ) CMmsApplicationAdapter;
       
    66     
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMmsApplicationAdapter::~CMmsApplicationAdapter
       
    76 // -----------------------------------------------------------------------------
       
    77 //    
       
    78 // Destructor
       
    79 CMmsApplicationAdapter::~CMmsApplicationAdapter()
       
    80     {
       
    81     delete iMmsHeaders;
       
    82     delete iMmsSettings;
       
    83     delete iRegAppIds;
       
    84     delete iClientEntry;
       
    85     delete iSession;
       
    86     }
       
    87     
       
    88 // -----------------------------------------------------------------------------
       
    89 // CMmsApplicationAdapter::RegisterL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 
       
    93 EXPORT_C TInt CMmsApplicationAdapter::RegisterL(
       
    94     const TDesC& aApplicationId, TMsvId& aFolderId )
       
    95     {
       
    96     return RegisterWithNameL( aApplicationId, TPtrC(), aFolderId );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMmsApplicationAdapter::UnregisterL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 
       
   104 EXPORT_C TInt CMmsApplicationAdapter::UnregisterL(
       
   105     const TDesC& aApplicationId )
       
   106     {
       
   107         
       
   108     TInt error = KErrNone;     
       
   109     if ( RegisteredL( aApplicationId ) )
       
   110 	    {
       
   111 	    error = iRegAppIds->UnregisterL( aApplicationId );
       
   112 	    }
       
   113 	    
       
   114 	TMsvId applicationFolder = iMmsSettings->ApplicationFolder(); 
       
   115     TMsvId folderId = iMmsSettings->FolderEntryL( *iSession, applicationFolder,
       
   116         aApplicationId );
       
   117             
       
   118 	// Despite of the error, delete the folder anyway.    
       
   119 	if (  folderId != KMsvNullIndexEntryId )
       
   120 	    {
       
   121 	    error = DeleteL( folderId );	
       
   122 	    }		    
       
   123 		
       
   124 	return error;	
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CMmsApplicationAdapter::RegisteredL
       
   129 // -----------------------------------------------------------------------------
       
   130 //    
       
   131     
       
   132 EXPORT_C TBool CMmsApplicationAdapter::RegisteredL( const TDesC& aApplicationId )
       
   133 	{
       
   134 	iRegAppIds->LoadRegisteredApplicationsL();
       
   135 	return iRegAppIds->RegisteredL( aApplicationId );	
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CMmsApplicationAdapter::FolderIdL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C TMsvId CMmsApplicationAdapter::FolderIdL( const TDesC& aApplicationId )
       
   143     {
       
   144     // check if the appid is registered
       
   145     TBool registered = RegisteredL( aApplicationId );
       
   146     
       
   147     // check if folder for the appid exists
       
   148     TMsvId applicationFolder = iMmsSettings->ApplicationFolder(); 
       
   149     TMsvId folderId = iMmsSettings->FolderEntryL( *iSession, applicationFolder,
       
   150         aApplicationId );
       
   151  
       
   152     if ( registered )
       
   153 	    {
       
   154 	    if ( folderId != KMsvNullIndexEntryId )
       
   155 		    {
       
   156 		    return folderId;		    	
       
   157 		    }
       
   158 		 else
       
   159 			 {
       
   160 			 User::LeaveIfError( iMmsSettings->CreateFolderEntryL( *iSession, applicationFolder, 
       
   161         	 aApplicationId, folderId) );
       
   162         	 return folderId;	
       
   163 			 }   
       
   164 	    }
       
   165 	else // application id is not registered
       
   166 		{
       
   167 		if ( folderId != KMsvNullIndexEntryId )
       
   168 			{
       
   169 		    User::LeaveIfError( DeleteL( folderId ) ); 
       
   170 			}
       
   171 		return KMsvNullIndexEntryId;			
       
   172 		}    
       
   173                
       
   174     }
       
   175     
       
   176 // -----------------------------------------------------------------------------
       
   177 // CMmsApplicationAdapter::ApplicationIdL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 
       
   181 EXPORT_C TPtrC16 CMmsApplicationAdapter::ApplicationIdL(
       
   182     TMsvId aMmId )
       
   183     {
       
   184     iClientEntry->SetEntryL( aMmId );
       
   185     CMsvStore* store = iClientEntry->ReadStoreL();
       
   186     CleanupStack::PushL( store );
       
   187     iMmsHeaders->RestoreL( *store );
       
   188     
       
   189     TPtrC16 applicId = iMmsHeaders->ApplicId();
       
   190     CleanupStack::PopAndDestroy( store );
       
   191     return applicId;
       
   192     } 
       
   193     
       
   194 // -----------------------------------------------------------------------------
       
   195 // CMmsApplicationAdapter::SetApplicationIdL
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 
       
   199 EXPORT_C void CMmsApplicationAdapter::SetApplicationIdL(
       
   200     TMsvId aMmId,
       
   201     const TDesC& aApplicationId )
       
   202     {
       
   203     iClientEntry->SetEntryL( aMmId );
       
   204     
       
   205     CMsvStore* store = iClientEntry->EditStoreL();
       
   206     CleanupStack::PushL( store );
       
   207     iMmsHeaders->RestoreL( *store );
       
   208 
       
   209     iMmsHeaders->SetApplicIdL( aApplicationId );
       
   210 
       
   211     // The headers changed, save them. 
       
   212     iMmsHeaders->StoreL( *store );
       
   213     store->CommitL();
       
   214     CleanupStack::PopAndDestroy( store );
       
   215     
       
   216     }
       
   217     
       
   218 // -----------------------------------------------------------------------------
       
   219 // CMmsApplicationAdapter::ReplyToApplicationIdL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 
       
   223 EXPORT_C TPtrC16 CMmsApplicationAdapter::ReplyToApplicationIdL(
       
   224     TMsvId aMmId )
       
   225     {
       
   226     iClientEntry->SetEntryL( aMmId );
       
   227     
       
   228     CMsvStore* store = iClientEntry->ReadStoreL();
       
   229     CleanupStack::PushL( store );
       
   230     iMmsHeaders->RestoreL( *store );
       
   231     TPtrC16 replyToApplicId = iMmsHeaders->ReplyApplicId();
       
   232     CleanupStack::PopAndDestroy( store );
       
   233     
       
   234     return replyToApplicId;
       
   235     } 
       
   236     
       
   237 // -----------------------------------------------------------------------------
       
   238 // CMmsApplicationAdapter::SetReplyToApplicationIdL
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 
       
   242 EXPORT_C void CMmsApplicationAdapter::SetReplyToApplicationIdL(
       
   243     TMsvId aMmId,
       
   244     const TDesC& aApplicationId )
       
   245     {
       
   246     iClientEntry->SetEntryL( aMmId );
       
   247     
       
   248     CMsvStore* store = iClientEntry->EditStoreL();
       
   249     CleanupStack::PushL( store );
       
   250     iMmsHeaders->RestoreL( *store );
       
   251 
       
   252     iMmsHeaders->SetReplyApplicIdL( aApplicationId );
       
   253 
       
   254     // The headers changed, save them. 
       
   255     iMmsHeaders->StoreL( *store );
       
   256     store->CommitL();
       
   257     CleanupStack::PopAndDestroy( store );
       
   258     
       
   259     }
       
   260     
       
   261 // -----------------------------------------------------------------------------
       
   262 // CMmsApplicationAdapter::DeleteL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 
       
   266 EXPORT_C TInt CMmsApplicationAdapter::DeleteL(
       
   267     TMsvId aMmId )
       
   268     {    
       
   269     TInt error = KErrNone;
       
   270     TRAP ( error,
       
   271     {
       
   272     iClientEntry->SetEntryL( aMmId );
       
   273     TMsvEntry tEntry = iClientEntry->Entry();
       
   274     iClientEntry->SetEntryL( tEntry.Parent() );
       
   275     iClientEntry->DeleteL( aMmId );
       
   276     } )
       
   277     
       
   278     if ( error == KErrNotFound )
       
   279         {
       
   280         error = KErrNone;
       
   281         }
       
   282     return error;    
       
   283     } 
       
   284         
       
   285 // -----------------------------------------------------------------------------
       
   286 // CMmsApplicationAdapter::MmscUrlL
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 EXPORT_C TInt CMmsApplicationAdapter::MmscUrlL( HBufC*& aServerUri )
       
   290 	{
       
   291 	TUint32 accessPointLink = 0;
       
   292     TUint32 accessPoint = 0;
       
   293     TBool proxyUsed = EFalse;
       
   294     HBufC8* proxyAddress = NULL;
       
   295     
       
   296     iMmsSettings->LoadSettingsL();
       
   297     
       
   298     TInt accessPointCount = iMmsSettings->AccessPointCount();
       
   299    
       
   300     if ( accessPointCount > 0 )
       
   301         {
       
   302         accessPointLink = iMmsSettings->AccessPoint( 0 );
       
   303         }
       
   304     else
       
   305 	    {
       
   306 	    return KErrNotFound;	
       
   307 	    } 
       
   308 	    
       
   309     CMmsConnectionInitiator::GetParametersL( accessPointLink, accessPoint, 
       
   310 	aServerUri, proxyUsed, proxyAddress); 
       
   311 	
       
   312 	delete proxyAddress;
       
   313 	proxyAddress = NULL;
       
   314 	
       
   315 	if ( accessPoint == 0 )
       
   316 		{
       
   317 		// something is gone wrong.
       
   318 		return KErrGeneral;	
       
   319 		}	           
       
   320 	return KErrNone;	
       
   321 	}
       
   322 	
       
   323 // -----------------------------------------------------------------------------
       
   324 // 
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 EXPORT_C const CDesCArray& CMmsApplicationAdapter::RegisteredApplicationList() const
       
   328     {
       
   329     // Leaves only if runs out of memory
       
   330     TRAP_IGNORE( iRegAppIds->LoadRegisteredApplicationsL() ); 
       
   331     // Return what we got.
       
   332     // The list always exists, but may not be up to date if we run out of memory
       
   333 	return iRegAppIds->RegisteredApplicationList();
       
   334     }
       
   335     
       
   336 // -----------------------------------------------------------------------------
       
   337 // 
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 EXPORT_C TInt CMmsApplicationAdapter::RegisterWithNameL(
       
   341     const TDesC& aApplicationId,
       
   342     const TDesC& aUserFriendlyName,
       
   343     TMsvId& aFolderId )
       
   344     {
       
   345     aFolderId = KMsvNullIndexEntryId;
       
   346     TInt error = KErrNone;
       
   347 	iRegAppIds->LoadRegisteredApplicationsL();
       
   348 	
       
   349 	// iRegAppIds checks if the application id is already registered.
       
   350 	// User friendly name can be added afterwards even if the id
       
   351 	// is already registered, so we let CMmsRegisteredApplications class
       
   352 	// do the checking.
       
   353 	// CMmsRegisteredApplications also checks if the length of the
       
   354 	// strings is too long to fit into registry. 
       
   355     error = iRegAppIds->RegisterL( aApplicationId, aUserFriendlyName );	    
       
   356 	    
       
   357 	if ( error == KErrNone || error == KErrAlreadyExists )
       
   358 		{
       
   359 		TMsvId applicationFolder = iMmsSettings->ApplicationFolder();
       
   360 		error =  iMmsSettings->CreateFolderEntryL( *iSession, applicationFolder, 
       
   361     	aApplicationId, aFolderId);	
       
   362     	if ( error == KErrAlreadyExists )
       
   363 	    	{
       
   364 	    	error = KErrNone;	    		
       
   365 	    	}
       
   366 		}
       
   367 		   
       
   368 	return error;	    
       
   369     }
       
   370     
       
   371 // -----------------------------------------------------------------------------
       
   372 // 
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 EXPORT_C TPtrC CMmsApplicationAdapter::UserFriendlyName( const TDesC& aApplicationId )
       
   376     {
       
   377     // Leaves only if out of memory
       
   378     TRAPD( error, iRegAppIds->LoadRegisteredApplicationsL() );
       
   379     if ( error == KErrNone )
       
   380         {
       
   381     	return iRegAppIds->UserFriendlyName( aApplicationId );	
       
   382         }
       
   383     else
       
   384         {
       
   385         // if out of memory, no user friendly name
       
   386         return TPtrC();
       
   387         }
       
   388     }
       
   389     
       
   390 // -----------------------------------------------------------------------------
       
   391 // CMmsApplicationAdapter::HandleSessionEventL
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CMmsApplicationAdapter::HandleSessionEventL( TMsvSessionEvent  /* aEvent */, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   395     {
       
   396      
       
   397     }  
       
   398     
       
   399 // -----------------------------------------------------------------------------
       
   400 // CMmsApplicationAdapter::CMmsApplicationAdapter
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 CMmsApplicationAdapter::CMmsApplicationAdapter()
       
   404     {     
       
   405     }
       
   406     
       
   407     
       
   408 // -----------------------------------------------------------------------------
       
   409 // CMmsApplicationAdapter::ConstructL
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CMmsApplicationAdapter::ConstructL()
       
   413     {
       
   414           
       
   415     iSession = CMsvSession::OpenSyncL( *this );
       
   416     
       
   417     iClientEntry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
   418    
       
   419     // First loading settings
       
   420     iMmsSettings = CMmsSettings::NewL(); 
       
   421     iMmsSettings->LoadSettingsL();   
       
   422     
       
   423     iRegAppIds = CMmsRegisteredApplications::NewL();
       
   424         
       
   425     iMmsHeaders = CMmsHeaders::NewL( iMmsSettings->MmsVersion() );
       
   426     
       
   427     }
       
   428     
       
   429 
       
   430 
       
   431 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   432 
       
   433 //  End of File