applicationinterworkingfw/ServiceHandler/src/AiwResolver.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2003-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:     Implementation of Custom ECom Resolver for AIW.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "AiwResolver.h"
       
    22 
       
    23 const TInt KMaxDataItemSize = 150;
       
    24 _LIT8(KContentTag, "<CONTENT>");
       
    25 _LIT8(KOpaqueTag, "<OPAQUE>");
       
    26 
       
    27 
       
    28 CAiwResolver* CAiwResolver::NewL(MPublicRegistry& aRegistry)
       
    29     {
       
    30     return new (ELeave) CAiwResolver(aRegistry);
       
    31     }
       
    32 
       
    33 
       
    34 CAiwResolver::CAiwResolver(MPublicRegistry& aRegistry) : CResolver(aRegistry)
       
    35     {
       
    36     // Nothing to do.
       
    37     }
       
    38 
       
    39 
       
    40 CAiwResolver::~CAiwResolver()
       
    41     {
       
    42     if (iImplementationInfoArray)
       
    43         {
       
    44         iImplementationInfoArray->Reset();  
       
    45         delete iImplementationInfoArray;
       
    46         }
       
    47     }
       
    48 
       
    49 
       
    50 
       
    51 TUid CAiwResolver::IdentifyImplementationL(TUid aInterfaceUid, 
       
    52     const TEComResolverParams& aAdditionalParameters) const
       
    53     {
       
    54     RImplInfoArray& implementationsInfo = iRegistry.ListImplementationsL(aInterfaceUid);
       
    55     TUid found = KNullUid;
       
    56 
       
    57     if(implementationsInfo.Count())
       
    58         {
       
    59         found = Resolve(implementationsInfo, aAdditionalParameters);
       
    60         }
       
    61 
       
    62     return found;
       
    63     }
       
    64 
       
    65 
       
    66 
       
    67 RImplInfoArray* CAiwResolver::ListAllL(TUid aInterfaceUid, 
       
    68     const TEComResolverParams& aAdditionalParameters) const
       
    69     {
       
    70     // Use the member var to create the array so that we get proper cleanup behaviour
       
    71     delete iImplementationInfoArray;
       
    72     iImplementationInfoArray = NULL;
       
    73     iImplementationInfoArray = new (ELeave) RImplInfoArray;
       
    74     RImplInfoArray* retList = iImplementationInfoArray;
       
    75 
       
    76     RImplInfoArray& fullList = iRegistry.ListImplementationsL(aInterfaceUid);
       
    77 
       
    78     const TBool useWildcards = aAdditionalParameters.IsWildcardMatch();
       
    79     TBuf8<KMaxDataItemSize> content;
       
    80     TBuf8<KMaxDataItemSize> opaque;
       
    81 
       
    82     ParseInput(aAdditionalParameters.DataType(), content, opaque);
       
    83     const TInt numImps = fullList.Count();
       
    84 
       
    85     for (TInt index = 0; index < numImps; ++index)
       
    86         {
       
    87         if (Match(fullList[index]->DataType(), content, useWildcards) &&
       
    88             MatchServiceCmd(fullList[index]->OpaqueData(), opaque))
       
    89             {
       
    90             User::LeaveIfError(retList->Append(fullList[index]));
       
    91             }
       
    92         }
       
    93 
       
    94     // Reset the member variable because we are passing ownership back
       
    95     iImplementationInfoArray = NULL;
       
    96 
       
    97     return retList;
       
    98     }
       
    99 
       
   100 
       
   101 
       
   102 void CAiwResolver::ParseInput(const TDesC8& aParam, TDes8& aContent, TDes8& aOpaque) const
       
   103     {
       
   104     TInt cind = aParam.Find(KContentTag);
       
   105     TInt oind = aParam.Find(KOpaqueTag);
       
   106         
       
   107     if (cind != KErrNotFound)
       
   108         {
       
   109         if (oind != KErrNotFound)
       
   110             {
       
   111             aContent.Copy(aParam.Mid(cind + (&KContentTag)->Length(), 
       
   112                                      oind - (cind + (&KContentTag)->Length())));
       
   113             }
       
   114         else
       
   115             {
       
   116             aContent.Copy(aParam.Mid(cind + (&KContentTag)->Length()));
       
   117             }
       
   118         }
       
   119 
       
   120     if (oind != KErrNotFound)
       
   121         {
       
   122         aOpaque.Copy(aParam.Mid(oind + (&KOpaqueTag)->Length()));
       
   123         }
       
   124     }
       
   125 
       
   126 
       
   127 
       
   128 TUid CAiwResolver::Resolve(const RImplInfoArray& aImplementationsInfo, 
       
   129     const TEComResolverParams& aAdditionalParameters) const
       
   130     {
       
   131     // Loop through the implementations matching on type
       
   132     const TInt count = aImplementationsInfo.Count();
       
   133 
       
   134     for (TInt index = 0; index < count; ++index)
       
   135         {
       
   136         const CImplementationInformation& impData = *aImplementationsInfo[index];
       
   137         // As soon as we get a match on the datatype then return uid of the
       
   138         // implementation found.
       
   139         if (Match(impData.DataType(),                   // The Datatype of this implementation
       
   140             aAdditionalParameters.DataType(),           // The type we are trying to find
       
   141             aAdditionalParameters.IsWildcardMatch()))   // If wildcards should be used
       
   142             {
       
   143             return impData.ImplementationUid();
       
   144             }
       
   145         }
       
   146 
       
   147     return KNullUid;
       
   148     }
       
   149 
       
   150 
       
   151 TBool CAiwResolver::Match(const TDesC8& aImplementationType, const TDesC8& aMatchType, 
       
   152     TBool aUseWildcards) const
       
   153     {
       
   154     TInt matchPos = KErrNotFound;
       
   155 
       
   156     _LIT8(dataSeparator, "||");
       
   157     const TInt separatorLength = dataSeparator().Length();
       
   158 
       
   159     // Look for the section separator marker '||'
       
   160     TInt separatorPos = aImplementationType.Find(dataSeparator);
       
   161 
       
   162     if (separatorPos == KErrNotFound)
       
   163         {
       
   164         // Match against the whole string
       
   165         if (aUseWildcards)
       
   166             {
       
   167             matchPos = aImplementationType.Match(aMatchType);
       
   168             }
       
   169         else
       
   170             {
       
   171             if (aImplementationType.Compare(aMatchType) == 0)
       
   172                 {
       
   173                 matchPos = KErrNone;    
       
   174                 }
       
   175             }
       
   176         }
       
   177     else
       
   178         {
       
   179         // Find the first section, up to the separator
       
   180         TPtrC8 dataSection = aImplementationType.Left(separatorPos);
       
   181         TPtrC8 remainingData = aImplementationType.Mid(separatorPos + separatorLength);
       
   182 
       
   183         // Match against each section in turn
       
   184         while (separatorPos != KErrNotFound)
       
   185             {
       
   186             // Search this section
       
   187             if (aUseWildcards)
       
   188                 {          
       
   189                 matchPos = dataSection.Match(aMatchType);
       
   190                 }
       
   191             else
       
   192                 {
       
   193                 if (dataSection.Compare(aMatchType) == 0)
       
   194                     {
       
   195                     matchPos = KErrNone;
       
   196                     }
       
   197                 }
       
   198 
       
   199             // If we found it then no need to continue, so return
       
   200             if (matchPos != KErrNotFound)
       
   201                 {
       
   202                 return ETrue;
       
   203                 }
       
   204 
       
   205             // Move on to the next section
       
   206             separatorPos = remainingData.Find(dataSeparator);
       
   207 
       
   208             if (separatorPos != KErrNotFound)
       
   209                 {
       
   210                 dataSection.Set(remainingData.Left(separatorPos));
       
   211                 remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
       
   212                 }
       
   213             else
       
   214                 {
       
   215                 dataSection.Set(remainingData);
       
   216                 }   
       
   217             }
       
   218 
       
   219         // Check the final part
       
   220         if (aUseWildcards)
       
   221             {
       
   222             matchPos = dataSection.Match(aMatchType);
       
   223             }
       
   224         else
       
   225             {
       
   226             if (dataSection.Compare(aMatchType) == 0)
       
   227                 {
       
   228                 matchPos = KErrNone;
       
   229                 }
       
   230             }
       
   231         }
       
   232 
       
   233     return matchPos != KErrNotFound;
       
   234     }
       
   235 
       
   236 
       
   237 
       
   238 
       
   239 TBool CAiwResolver::MatchServiceCmd(const TDesC8& aOpaqueData, const TDesC8& aServiceCmd) const
       
   240     {
       
   241     _LIT8(dataSeparator, "||");
       
   242     const TInt separatorLength = dataSeparator().Length();
       
   243 
       
   244     // Look for the section separator marker '||'
       
   245     TInt separatorPos = aOpaqueData.Find(dataSeparator);
       
   246 
       
   247     if (separatorPos == KErrNotFound)
       
   248         {
       
   249          if (aServiceCmd.Compare(aOpaqueData) == 0)
       
   250             {
       
   251             return ETrue;   
       
   252             }
       
   253         }
       
   254     else
       
   255         {
       
   256          // Find the first section, up to the separator
       
   257         TPtrC8 dataSection = aOpaqueData.Left(separatorPos);
       
   258         TPtrC8 remainingData = aOpaqueData.Mid(separatorPos + separatorLength);
       
   259 
       
   260         // Match against each section in turn
       
   261         while (separatorPos != KErrNotFound)
       
   262             {
       
   263             if (dataSection.Compare(aServiceCmd) == 0)
       
   264                 {
       
   265                 return ETrue;
       
   266                 }
       
   267 
       
   268             // Move on to the next section
       
   269             separatorPos = remainingData.Find(dataSeparator);
       
   270 
       
   271             if (separatorPos != KErrNotFound)
       
   272                 {
       
   273                 dataSection.Set(remainingData.Left(separatorPos));
       
   274                 remainingData.Set(remainingData.Mid(separatorPos + separatorLength));
       
   275                 }
       
   276             else
       
   277                 {
       
   278                 dataSection.Set(remainingData);
       
   279                 }   
       
   280             }
       
   281 
       
   282         if (dataSection.Compare(aServiceCmd) == 0)
       
   283             {
       
   284             return ETrue;   
       
   285             }       
       
   286         }
       
   287 
       
   288     return EFalse;
       
   289     }
       
   290 
       
   291 
       
   292 // Map the interface UIDs
       
   293 const TImplementationProxy ImplementationTable[] =
       
   294     {
       
   295     IMPLEMENTATION_PROXY_ENTRY(KAiwResolverImplUidValue, CAiwResolver::NewL)
       
   296     };
       
   297 
       
   298 // Exported proxy for instantiation method resolution
       
   299 // ---------------------------------------------------------
       
   300 //
       
   301 //
       
   302 // ---------------------------------------------------------
       
   303 //
       
   304 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
   305     {
       
   306     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   307     return ImplementationTable;
       
   308     }
       
   309 
       
   310 // End of file
       
   311