contentpublishingsrv/contentpublishingserver/cpserver/src/cpactiondatacache.cpp
branchRCL_3
changeset 19 edd621764147
parent 15 a0713522ab97
equal deleted inserted replaced
16:b276298d5729 19:edd621764147
    18 
    18 
    19 
    19 
    20 #include <liwcommon.h>
    20 #include <liwcommon.h>
    21 #include <liwvariant.h>
    21 #include <liwvariant.h>
    22 #include <s32mem.h>
    22 #include <s32mem.h>
       
    23 #include <escapeutils.h>
    23 
    24 
    24 #include "cpactiondatacache.h"
    25 #include "cpactiondatacache.h"
    25 #include "cpglobals.h"
    26 #include "cpglobals.h"
    26 
    27 
    27 using namespace LIW;
    28 using namespace LIW;
    28 
    29 
    29 _LIT8(KCachedMap, "cached_map");
    30 _LIT8(KCachedMap, "cached_map");
    30 
    31 
    31 static const int KMaxCacheItems = 6; 
    32 static const int KMaxCacheItems = 18; 
    32 
    33 
    33 
    34 
    34 // ======== MEMBER FUNCTIONS ========
    35 // ======== MEMBER FUNCTIONS ========
    35 
    36 
    36 
    37 
   111 
   112 
   112     if (param && param->Value().TypeId() == EVariantTypeMap)
   113     if (param && param->Value().TypeId() == EVariantTypeMap)
   113         {
   114         {
   114         const CLiwMap* inputMap = param->Value().AsMap();
   115         const CLiwMap* inputMap = param->Value().AsMap();
   115         CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
   116         CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
   117         CopyVariantL(KType, inputMap, map);
   116         CopyVariantL(KId, inputMap, map);
   118         CopyVariantL(KId, inputMap, map);
   117         CopyVariantL(KPublisherId, inputMap, map);
   119         CopyVariantL(KPublisherId, inputMap, map);
   118         CopyVariantL(KContentType, inputMap, map);
   120         CopyVariantL(KContentType, inputMap, map);
   119         CopyVariantL(KContentId, inputMap, map);
   121         CopyVariantL(KContentId, inputMap, map);
   120         map->InsertL(KCachedMap, TLiwVariant(inputMap));
   122         map->InsertL(KCachedMap, TLiwVariant(inputMap));
   130 
   132 
   131 // ---------------------------------------------------------------------------
   133 // ---------------------------------------------------------------------------
   132 // 
   134 // 
   133 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   134 //
   136 //
       
   137 void CCPActionDataCache::AppendEmptyL( const CLiwMap* aIdsMap )
       
   138     {
       
   139     CLiwDefaultMap* map = CLiwDefaultMap::NewLC();
       
   140     CopyVariantL(KType, aIdsMap, map);
       
   141     CopyVariantL(KId, aIdsMap, map);
       
   142     CopyVariantL(KPublisherId, aIdsMap, map);
       
   143     CopyVariantL(KContentType, aIdsMap, map);
       
   144     CopyVariantL(KContentId, aIdsMap, map);
       
   145     iInternalList->AppendL(TLiwVariant(map));
       
   146     CleanupStack::PopAndDestroy(map);
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // 
       
   151 // ---------------------------------------------------------------------------
       
   152 //
   135 TBool CCPActionDataCache::IsCacheableL(const CLiwMap* aMap)
   153 TBool CCPActionDataCache::IsCacheableL(const CLiwMap* aMap)
   136     {
   154     {
   137     TBool result(EFalse);
   155     TBool result(EFalse);
   138     TLiwVariant value;
   156     TLiwVariant value;
   139     value.PushL();
   157     value.PushL();
   201     {
   219     {
   202     TBool idMatch(EFalse);
   220     TBool idMatch(EFalse);
   203     TLiwVariant l, r;
   221     TLiwVariant l, r;
   204     l.PushL();
   222     l.PushL();
   205     r.PushL();
   223     r.PushL();
   206     if (aCachedMap->FindL(KId, l) && aInputMap->FindL(KId, r) && l.AsTInt32()
   224     if (TypesMatchL(aCachedMap,aInputMap))
   207             == r.AsTInt32())
   225         {
   208         {
   226         if (aCachedMap->FindL(KId, l) && aInputMap->FindL(KId, r) && l.AsTInt32()
   209         idMatch = ETrue;
   227                 == r.AsTInt32())
   210         }
       
   211     if (!idMatch)
       
   212         {
       
   213         if (MatchL(aCachedMap, aInputMap, KPublisherId) && MatchL(aCachedMap,
       
   214                 aInputMap, KContentType) && MatchL(aCachedMap, aInputMap,
       
   215                 KContentId))
       
   216             {
   228             {
   217             idMatch = ETrue;
   229             idMatch = ETrue;
   218             }
   230             }
   219         }
   231         if (!idMatch)
   220 
   232             {
       
   233             if (MatchL(aCachedMap, aInputMap, KPublisherId) && MatchL(aCachedMap,
       
   234                     aInputMap, KContentType) && MatchL(aCachedMap, aInputMap,
       
   235                     KContentId))
       
   236                 {
       
   237                 idMatch = ETrue;
       
   238                 }
       
   239             }
       
   240         }
   221     CleanupStack::PopAndDestroy(&r);
   241     CleanupStack::PopAndDestroy(&r);
   222     CleanupStack::PopAndDestroy(&l);
   242     CleanupStack::PopAndDestroy(&l);
   223     return idMatch;
   243     return idMatch;
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // 
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 TBool CCPActionDataCache::TypesMatchL(const CLiwMap* aCachedMap,
       
   251         const CLiwMap* aInputMap)
       
   252     {
       
   253     TBool typesMatch(EFalse);
       
   254     TLiwVariant cacheVariant;
       
   255     TLiwVariant inputVariant;
       
   256     cacheVariant.PushL();
       
   257     inputVariant.PushL();
       
   258     if (aCachedMap->FindL(KType, cacheVariant) && aInputMap->FindL(KType,
       
   259             inputVariant))
       
   260         {
       
   261         RBuf typeCache;
       
   262         RBuf typeInput;
       
   263         CleanupClosePushL(typeCache);
       
   264         CleanupClosePushL(typeInput);
       
   265         ExtractRBufL(cacheVariant, typeCache);
       
   266         ExtractRBufL(inputVariant, typeInput);
       
   267         if (typeCache.Compare(typeInput)==0)
       
   268             {
       
   269             typesMatch = ETrue;
       
   270             }
       
   271         CleanupStack::PopAndDestroy( &typeInput );
       
   272         CleanupStack::PopAndDestroy( &typeCache );
       
   273         }
       
   274     CleanupStack::PopAndDestroy(&inputVariant);
       
   275     CleanupStack::PopAndDestroy(&cacheVariant);
       
   276     return typesMatch;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // 
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CCPActionDataCache::ExtractRBufL(const TLiwVariant& aVariant, RBuf& aBuf)
       
   284     {
       
   285     TPtrC type( KNullDesC );
       
   286     if( !aVariant.Get( type ) )
       
   287         {
       
   288         TPtrC8 type8( KNullDesC8 );
       
   289         if( !aVariant.Get( type8 ) )
       
   290             {
       
   291             User::Leave( KErrBadName );
       
   292             }
       
   293         aBuf.Assign( EscapeUtils::ConvertToUnicodeFromUtf8L( type8 ) );
       
   294         }
       
   295     else
       
   296         {
       
   297         aBuf.CreateL( type );
       
   298         }
   224     }
   299     }
   225 
   300 
   226 // ---------------------------------------------------------------------------
   301 // ---------------------------------------------------------------------------
   227 // 
   302 // 
   228 // ---------------------------------------------------------------------------
   303 // ---------------------------------------------------------------------------