codhandler/roapapp/src/RoapAppDocument.cpp
changeset 0 dd21522fd290
child 48 79859ed3eea9
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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: 
       
    15 *      Implementation of class CRoapAppDocument.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include <RoapEng.h>
       
    24 #include <roaptrigger.h>
       
    25 #include <AiwGenericParam.h>
       
    26 #include "RoapAppDocument.h"
       
    27 #include "RoapAppData.h"
       
    28 #include "RoapAppUi.h"
       
    29 #include "RequestCompleteCallback.h"
       
    30 #include "RoapAppLogger.h"
       
    31 #include "DrmRights.h" 
       
    32 // ================= CONSTANTS =======================
       
    33 _LIT8( KRoResponseHeader, "<roap:roResponse" );
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CRoapAppDocument::NewL()
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CRoapAppDocument* CRoapAppDocument::NewL( CEikApplication& aApp )
       
    42     {
       
    43     CRoapAppDocument* doc = new (ELeave) CRoapAppDocument( aApp );
       
    44     CleanupStack::PushL( doc );
       
    45     doc->ConstructL();
       
    46     CleanupStack::Pop( doc );
       
    47     return doc;
       
    48     }
       
    49     
       
    50 // ---------------------------------------------------------
       
    51 // CRoapAppDocument::~CRoapAppDocument()
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CRoapAppDocument::~CRoapAppDocument()
       
    55     {
       
    56     delete iData;
       
    57     delete iEngine;
       
    58     iParsedRights.ResetAndDestroy(); 
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CRoapAppDocument::Engine()
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 Roap::CRoapEng& CRoapAppDocument::Engine() const
       
    66     {
       
    67     return *iEngine;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CRoapAppDocument::Data()
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 const CRoapAppData& CRoapAppDocument::Data() const
       
    75     {
       
    76     return *iData;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------
       
    80 // CRoapAppDocument::CreateAppUiL()
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CEikAppUi* CRoapAppDocument::CreateAppUiL()
       
    84     {
       
    85     return new (ELeave) CRoapAppUi;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CRoapAppDocument::OpenFileL()
       
    90 // ---------------------------------------------------------
       
    91 //
       
    92 CFileStore* CRoapAppDocument::OpenFileL
       
    93 ( TBool aDoOpen, const TDesC& aFilename, RFs& aFs )
       
    94     {
       
    95     CLOG(( 2, _L("-> CRoapAppDocument::OpenFileL (TBool+TDesC+RFs)") ));
       
    96     CLOG(( 2, _L("   CRoapAppDocument: aDoOpen(%d) aFname<%S>"), \
       
    97         aDoOpen, &aFilename ));
       
    98     CFileStore* store( NULL );
       
    99     if ( aDoOpen )
       
   100         {
       
   101         RFile file;
       
   102         TInt err = file.Open( aFs, aFilename,
       
   103             EFileShareReadersOnly | EFileStream | EFileRead );
       
   104         if ( err == KErrInUse )
       
   105             {
       
   106             err = file.Open( aFs, aFilename,
       
   107                 EFileShareAny | EFileStream | EFileRead );
       
   108             }
       
   109         CLOG(( 2, _L("   CRoapAppDocument: RFile.Open() -> err=%d)"), err ));
       
   110         User::LeaveIfError( err );
       
   111         CleanupClosePushL<RFile>( file );
       
   112         store = OpenFileL( aFs, file );
       
   113         CleanupStack::PopAndDestroy();  // close file
       
   114         }
       
   115     CLOG(( 2, _L("<- CRoapAppDocument::OpenFileL") ));
       
   116     return store;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CRoapAppDocument::OpenFileL()
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 CFileStore* CRoapAppDocument::OpenFileL( RFs& /*aFs*/, RFile& aFile )
       
   124     {
       
   125     CLOG(( 2, _L("-> CRoapAppDocument::OpenFileL (RFs+RFile)") ));
       
   126     CFileStore* store( NULL );
       
   127     OpenFileL( store, aFile );
       
   128     CLOG(( 2, _L("<- CRoapAppDocument::OpenFileL (RFs+RFile)") ));
       
   129     return store;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // CRoapAppDocument::OpenFileL()
       
   134 // ---------------------------------------------------------
       
   135 //
       
   136 void CRoapAppDocument::OpenFileL( CFileStore*& aFileStore, RFile& aFile )
       
   137     {
       
   138     CLOG(( 2, _L("-> CRoapAppDocument::OpenFileL (CFileStore+RFile)")  ));
       
   139     if( iFileOpened )
       
   140         {
       
   141         CLOG(( 2, _L("<- CRoapAppDocument::OpenFileL: iFileOpened == ETrue") ));
       
   142         return;
       
   143         }
       
   144     if( iEngine->IsActive() )
       
   145         {
       
   146         // Busy with something else.
       
   147         // Maybe we should Cancel the ongoing operation? I don't think so.
       
   148         CLOG(( 2, _L("  leave with KErrNotReady") ));
       
   149         User::Leave( KErrNotReady );
       
   150         }
       
   151     TInt fSize;
       
   152     User::LeaveIfError( aFile.Size( fSize ) );
       
   153     HBufC8* buf = HBufC8::NewLC( fSize );
       
   154     TPtr8 bufP( buf->Des() );
       
   155     User::LeaveIfError( aFile.Read( bufP ) );
       
   156     iFileOpened = ETrue;
       
   157     // 1-Pass RO addition    
       
   158     if( buf->Find( KRoResponseHeader ) != KErrNotFound )
       
   159         {
       
   160         TInt ret = 0; 
       
   161         TRAP (ret, iEngine->HandleRoReponseL( bufP, iParsedRights ) );
       
   162         if ( ret == KErrNone && iParsedRights.Count() )
       
   163             {
       
   164             // Ro's parsed succesfully, buf can be re-used,
       
   165             CleanupStack::PopAndDestroy( buf );
       
   166             aFileStore = NULL;
       
   167             buf = NULL;
       
   168             for( TUint i = 0; i < iParsedRights.Count(); i++ )
       
   169                 {
       
   170                 iParsedRights[i]->GetContentURI( buf );
       
   171                 CleanupStack::PushL( buf );
       
   172                 iData->iContentIdList.AppendL( buf );
       
   173                 CleanupStack::Pop(); // buf
       
   174                 }               
       
   175             if( iAppUi )
       
   176                 {
       
   177                 // Show notes
       
   178                 iData->iType = Roap::ERoAcquisitionTrigger;
       
   179                 STATIC_CAST( CRoapAppUi*, iAppUi )->HandleOnePassRoL(KErrNone);
       
   180                 }     
       
   181             }
       
   182         else 
       
   183             {
       
   184             CleanupStack::PopAndDestroy( buf );
       
   185             if( iAppUi )
       
   186                 {
       
   187                 // Show notes
       
   188                 iData->iType = Roap::ERoAcquisitionTrigger;
       
   189                 STATIC_CAST( CRoapAppUi*, iAppUi )->HandleOnePassRoL(ret);
       
   190                 }     
       
   191             }  
       
   192         // close the file
       
   193         aFile.Close();  
       
   194         iFileOpened = EFalse;
       
   195         return; 
       
   196         }
       
   197         // end of 1-Pass RO addition 
       
   198     const CAiwGenericParamList* params = GetInputParameters();
       
   199     iEngine->SetTriggerL
       
   200         (
       
   201         bufP,
       
   202         params,
       
   203         iData->iType,
       
   204         iData->iContextStatus,
       
   205         iData->iDomainOperation,
       
   206         iData->iContentIdList
       
   207         );
       
   208     if ( iEngine->Trigger().iRiAlias )
       
   209         {
       
   210         iData->iRiAlias = iEngine->Trigger().iRiAlias->AllocL();
       
   211         }
       
   212     CleanupStack::PopAndDestroy( buf );
       
   213     iFileOpened = EFalse;
       
   214     aFile.Close();
       
   215 #ifdef __TEST_ROAP_APP_LOG
       
   216     CLOG(( 4, _L("  Trigger type(%d) contextStatus(%d) domainOp(%d)"), \
       
   217         iData->iType, iData->iContextStatus, iData->iDomainOperation ));
       
   218     TPtrC8 ptr;
       
   219     for ( TInt i = 0; i < iData->iContentIdList.Count(); i++ )
       
   220         {
       
   221         ptr.Set( iData->iContentIdList[i]->Des() );
       
   222         CLOG(( 4, _L8("  cid#%d:<%S>"), i, &ptr ));
       
   223         }
       
   224     if ( iData->iRiAlias )
       
   225         {
       
   226         ptr.Set( iData->iRiAlias->Des() );
       
   227         CLOG(( 4, _L8("  riAlias <%S>"), &ptr ));
       
   228         }
       
   229     else
       
   230         {
       
   231         CLOG(( 4, _L8("  riAlias NULL") ));
       
   232         }
       
   233 #endif /* def __TEST_ROAP_APP_LOG */
       
   234     if ( iAppUi )
       
   235         {
       
   236         STATIC_CAST( CRoapAppUi*, iAppUi )->HandleTriggerParsedL();
       
   237         }
       
   238     CLOG(( 2, _L("<- CRoapAppDocument::OpenFileL (CFileStore+RFile)") ));
       
   239     aFileStore = NULL;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
       
   243 // CRoapAppDocument::CRoapAppDocument()
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 CRoapAppDocument::CRoapAppDocument( CEikApplication& aApp )
       
   247 : CAiwGenericParamConsumer( aApp )
       
   248     {
       
   249     }
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // CRoapAppDocument::ConstructL()
       
   253 // ---------------------------------------------------------
       
   254 //
       
   255 void CRoapAppDocument::ConstructL()
       
   256     {
       
   257     CLOG(( 2, _L("-> CRoapAppDocument::ConstructL")  ));
       
   258     iEngine = Roap::CRoapEng::NewL();
       
   259     iData = CRoapAppData::NewL();
       
   260     CLOG(( 2, _L("<- CRoapAppDocument::ConstructL")  ));
       
   261     }