applicationmanagement/omascomoadapter/src/nsmldmiapmatcher.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     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:  Implementation of applicationmanagement components
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // ------------------------------------------------------------------------------------------------
       
    20 // Includes
       
    21 // ------------------------------------------------------------------------------------------------
       
    22 
       
    23 #include <utf.h>
       
    24 #include "nsmldmiapmatcher.h"
       
    25 #include <smldmadapter.h>
       
    26 #include <featmgr.h>
       
    27 
       
    28 // ------------------------------------------------------------------------------------------------
       
    29 // CNSmlDMIAPMatcher* CNSmlDMIAPMatcher::NewL( MSmlDmCallback* aDmCallback )
       
    30 // ------------------------------------------------------------------------------------------------
       
    31 CNSmlDMIAPMatcher* CNSmlDMIAPMatcher::NewL( 
       
    32 	MSmlDmCallback* aDmCallback )
       
    33     {
       
    34     CNSmlDMIAPMatcher* self = CNSmlDMIAPMatcher::NewLC( aDmCallback );	
       
    35     CleanupStack::Pop();
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ------------------------------------------------------------------------------------------------
       
    40 // CNSmlDMIAPMatcher* CNSmlDMIAPMatcher::NewLC( MSmlDmCallback* aDmCallback )
       
    41 // ------------------------------------------------------------------------------------------------
       
    42 CNSmlDMIAPMatcher* CNSmlDMIAPMatcher::NewLC(
       
    43 	MSmlDmCallback* aDmCallback )
       
    44     {
       
    45     CNSmlDMIAPMatcher* self = new( ELeave ) CNSmlDMIAPMatcher;
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL( aDmCallback );
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ------------------------------------------------------------------------------------------------
       
    52 // void CNSmlDMIAPMatcher::ConstructL( MSmlDmCallback* aDmCallback )
       
    53 // ------------------------------------------------------------------------------------------------
       
    54 void CNSmlDMIAPMatcher::ConstructL( MSmlDmCallback* aDmCallback )
       
    55     {
       
    56     iCallback = aDmCallback;
       
    57     FeatureManager::InitializeLibL();
       
    58     iFeatMgrInitialized = ETrue;
       
    59     }
       
    60 
       
    61 // ------------------------------------------------------------------------------------------------
       
    62 // CNSmlDMIAPMatcher::~CNSmlDMIAPMatcher()
       
    63 // ------------------------------------------------------------------------------------------------
       
    64 CNSmlDMIAPMatcher::~CNSmlDMIAPMatcher()
       
    65     {
       
    66     	if(iFeatMgrInitialized)
       
    67     		{
       
    68     			FeatureManager::UnInitializeLib();
       
    69     		}
       
    70     }
       
    71 
       
    72 // ------------------------------------------------------------------------------------------------
       
    73 // TInt CNSmlDMIAPMatcher::IAPIdFromURIL( const TDesC8& aURI )
       
    74 // ------------------------------------------------------------------------------------------------
       
    75 TInt CNSmlDMIAPMatcher::IAPIdFromURIL( const TDesC8& aURI )
       
    76     {
       
    77     TInt iapId(KErrNotFound);
       
    78 
       
    79 	MSmlDmAdapter::TError status;
       
    80 	CBufBase* allIAPs = CBufFlat::NewL(16);
       
    81 	CleanupStack::PushL(allIAPs);
       
    82 	iCallback->FetchLinkL( GetConRef(), *allIAPs, status );
       
    83 	TPtrC8 uri = RemoveDotSlash(aURI);
       
    84 
       
    85     if( status == MSmlDmAdapter::EOk &&
       
    86         uri.Find(GetConRef()) == 0 &&
       
    87         allIAPs->Ptr(0).Find(LastURISeg(uri))>=0)
       
    88         {
       
    89         HBufC8* luid = iCallback->GetLuidAllocL( uri ); 
       
    90 
       
    91         if ( luid->Length() )
       
    92             {
       
    93             iapId = DesToInt(*luid);
       
    94             } 
       
    95         delete luid;
       
    96         }
       
    97 
       
    98     CleanupStack::PopAndDestroy(allIAPs);
       
    99     
       
   100     return iapId;
       
   101     }
       
   102 
       
   103 // ------------------------------------------------------------------------------------------------
       
   104 // HBufC8* CNSmlDMIAPMatcher::URIFromIAPIdL( TInt aIAPId )
       
   105 // ------------------------------------------------------------------------------------------------
       
   106 HBufC8* CNSmlDMIAPMatcher::URIFromIAPIdL( TInt aIAPId )
       
   107     {
       
   108     CBufBase *allIAPs = CBufFlat::NewL(16);
       
   109 	CleanupStack::PushL(allIAPs);
       
   110     MSmlDmAdapter::TError status;
       
   111 
       
   112     iCallback->FetchLinkL( GetConRef(), *allIAPs, status );
       
   113 
       
   114     if ( status == MSmlDmAdapter::EOk )
       
   115         {   
       
   116         TInt index(0);
       
   117         TInt segStart(0);
       
   118 
       
   119         while ( index != KErrNotFound)
       
   120             {                
       
   121             TPtrC8 allIAPsptr = allIAPs->Ptr(segStart).Mid(0);
       
   122             index = allIAPsptr.Locate('/');
       
   123             HBufC8* uriSeg = 0;
       
   124 
       
   125             if ( index == KErrNotFound )
       
   126                 {
       
   127                 TPtrC8 uriSeg8Ptr = allIAPs->Ptr(segStart);
       
   128                 uriSeg = uriSeg8Ptr.AllocLC();
       
   129                 }
       
   130             else
       
   131                 {
       
   132                 TPtrC8 uriSeg8Ptr = allIAPs->Ptr(segStart).Mid( 0, index );
       
   133                 uriSeg = uriSeg8Ptr.AllocLC();
       
   134                 }
       
   135 
       
   136             HBufC8* uri = HBufC8::NewLC( GetConRef().Length() + 1 +
       
   137             	uriSeg->Length() );
       
   138             	
       
   139 			TPtr8 uriPtr = uri->Des();
       
   140 			uriPtr.Format( GetConRef());
       
   141 			uriPtr.Append( KNSmlDMSeparator8 );
       
   142 			uriPtr.Append( *uriSeg );
       
   143 			HBufC8* luid = iCallback->GetLuidAllocL( uriPtr );
       
   144 			CleanupStack::PushL(luid);
       
   145 
       
   146 			if ( luid->Length() > 0 )
       
   147 				{				
       
   148 				TInt iapId = DesToInt(luid->Des());
       
   149 				if ( iapId == aIAPId )
       
   150 					{
       
   151 		            CleanupStack::PopAndDestroy();  //luid
       
   152 		            CleanupStack::Pop();  //uri
       
   153 		            CleanupStack::PopAndDestroy(2);  //uriSeg, allIAPs
       
   154 		            return uri;
       
   155 					}
       
   156 				}
       
   157             CleanupStack::PopAndDestroy(3); // luid, uri, uriSeg
       
   158 
       
   159             segStart += index + 1;
       
   160             }        
       
   161         }
       
   162 
       
   163     CleanupStack::PopAndDestroy(); // allIAPs
       
   164 
       
   165     return 0;
       
   166     }
       
   167 
       
   168 // ------------------------------------------------------------------------------------------------
       
   169 // TInt CNSmlDMIAPMatcher::DesToInt(const TDesC& aLuid)
       
   170 // ------------------------------------------------------------------------------------------------
       
   171 TInt CNSmlDMIAPMatcher::DesToInt(const TDesC8& aLuid) const
       
   172 	{
       
   173 	TLex8 lex(aLuid);
       
   174 	TInt value = 0;
       
   175 	lex.Val(value);
       
   176 	return value;
       
   177 	}
       
   178 
       
   179 // ------------------------------------------------------------------------------------------------
       
   180 // TPtrC8 CNSmlDMIAPMatcher::RemoveDotSlash(const TDesC8& aURI) const
       
   181 // ------------------------------------------------------------------------------------------------
       
   182 TPtrC8 CNSmlDMIAPMatcher::RemoveDotSlash(const TDesC8& aURI) const
       
   183 	{
       
   184 	if(aURI.Find(KNSmlDMIAPUriDotSlash)==0)
       
   185 		{
       
   186 		return aURI.Right( aURI.Length()-KNSmlDMIAPUriDotSlash().Length() );
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		return aURI;
       
   191 		}
       
   192 	}
       
   193 
       
   194 // ------------------------------------------------------------------------------------------------
       
   195 // CNSmlDMIAPMatcher::TPtrC8 LastURISeg(const TDesC8& aURI)
       
   196 // Returns only the last uri segemnt
       
   197 // ------------------------------------------------------------------------------------------------
       
   198 TPtrC8 CNSmlDMIAPMatcher::LastURISeg(const TDesC8& aURI) const
       
   199 	{
       
   200 	TInt i;
       
   201 	for(i=aURI.Length()-1;i>=0;i--)
       
   202 		{
       
   203 		if(aURI[i]==KNSmlDMSlash)
       
   204 			{
       
   205 			break;
       
   206 			}
       
   207 		}
       
   208 	if(i==0)
       
   209 		{
       
   210 		return aURI;
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		return aURI.Mid(i+1);
       
   215 		}
       
   216 	}
       
   217 	
       
   218 // ------------------------------------------------------------------------------------------------
       
   219 // CNSmlDMIAPMatcher::const TDesC8& GetConRef()
       
   220 // Returns the connection reference
       
   221 // ------------------------------------------------------------------------------------------------
       
   222 const TDesC8& CNSmlDMIAPMatcher::GetConRef()
       
   223 	{
       
   224 	if(FeatureManager::FeatureSupported(KFeatureIdFfDmConnmoAdapter))
       
   225 		{
       
   226 			return KNSmlDMConnMOIAPUri();
       
   227 		}
       
   228 	else
       
   229 		{
       
   230 			return KNSmlDMIAPUri();
       
   231 		}	
       
   232   }
       
   233   
       
   234 
       
   235