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