customization/DMUtils/src/TARMDmStreamAdapter.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:  $Description: $
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "TARMDmStreamAdapter.h"
       
    22 #include "debug.h"
       
    23 #include <featmgr.h>
       
    24 _LIT( KTempFilePath, "C:\\system\\temp\\" );
       
    25 
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 
       
    30 ///////////////////////////////////////////////////////////////////////////////////////////////////
       
    31 //
       
    32 // CTARMDmStreamAdapter
       
    33 //
       
    34 ///////////////////////////////////////////////////////////////////////////////////////////////////
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CTARMDmStreamAdapter::CTARMDmStreamAdapter
       
    38 // 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CTARMDmStreamAdapter::CTARMDmStreamAdapter( MSmlDmCallback* aCallback )
       
    42 	: CTARMDmAdapter( aCallback )
       
    43 	, iActionInfo( 0 )
       
    44 	{
       
    45 	RDEBUG( "CTARMDmStreamAdapter::CTARMDmStreamAdapter" );
       
    46 	if(!iFs.Connect())
       
    47 		{
       
    48 			RDEBUG( "CTARMDmStreamAdapter::CTARMDmStreamAdapter unable to connect to the fileserver" );
       
    49 		}
       
    50 	}
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CTARMDmStreamAdapter::~CTARMDmStreamAdapter
       
    54 // 
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CTARMDmStreamAdapter::~CTARMDmStreamAdapter()
       
    58 	{
       
    59 	RDEBUG( "CTARMDmStreamAdapter::~CTARMDmStreamAdapter >" );
       
    60 	ClearActionInfo();
       
    61     iFs.Close();
       
    62 	RDEBUG( "CTARMDmStreamAdapter::~CTARMDmStreamAdapter <" );
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CTARMDmStreamAdapter::
       
    67 // 
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CTARMDmStreamAdapter::UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef )
       
    71 	{
       
    72 	RDEBUG( "CTARMDmStreamAdapter::UpdateLeafObjectL >" );
       
    73 
       
    74 //#ifdef __SAP_POLICY_MANAGEMENT
       
    75 TRAPD( errf, FeatureManager::InitializeLibL() );
       
    76 	if( errf != KErrNone )
       
    77 	{
       
    78 		User::Leave(errf);
       
    79 	}
       
    80 if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement ))
       
    81 {
       
    82 	if (CheckPolicyL( aURI ) != KErrNone)
       
    83 		{
       
    84 		Callback().SetStatusL( aStatusRef, EError );
       
    85 		return;
       
    86 		}
       
    87 }
       
    88 FeatureManager::UnInitializeLib();
       
    89 
       
    90 	
       
    91 //#endif
       
    92 
       
    93 	SetActionInfoL(CTARMDmStreamAdapterBuffer::ETARMActionUpdate,
       
    94 	               aURI,
       
    95 	               aLUID,
       
    96 	               aType,
       
    97 	               aStatusRef,
       
    98 	               -1); // No result ref
       
    99 
       
   100     TInt itemSize;
       
   101     TAdapterStreamType streamType = EStreamToNone;
       
   102 	if( StreamingSupport( itemSize ) )
       
   103 	    {
       
   104 	    streamType = StreamType( aURI );
       
   105 	    }
       
   106 
       
   107     if( EStreamToNone != streamType )
       
   108         {
       
   109         if( EStreamToFile == streamType )
       
   110             {
       
   111             StreamToFileL( aStream );
       
   112             }
       
   113         else
       
   114         if( EStreamToBuffer == streamType )
       
   115             {
       
   116             StreamToBufferL( aStream );
       
   117             }
       
   118         Callback().SetStatusL( aStatusRef, EOk );  
       
   119         }
       
   120     else
       
   121         {
       
   122     	_UpdateLeafObjectL( aURI, aLUID, aStream, aType, aStatusRef );
       
   123         }
       
   124 
       
   125 	RDEBUG( "CTARMDmStreamAdapter::UpdateLeafObjectL <" );
       
   126 	}
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CTARMDmStreamAdapter::
       
   130 // 
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CTARMDmStreamAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType, TInt aStatusRef )
       
   134 	{
       
   135 	RDEBUG( "CTARMDmStreamAdapter::ExecuteCommandL (stream) >" );
       
   136 
       
   137 //#ifdef __SAP_POLICY_MANAGEMENT
       
   138 TRAPD( errf, FeatureManager::InitializeLibL() );
       
   139 	if( errf != KErrNone )
       
   140 	{
       
   141 		User::Leave(errf);
       
   142 	}
       
   143 if(FeatureManager::FeatureSupported(KFeatureIdSapPolicyManagement ))
       
   144 {
       
   145 	if (CheckPolicyL( aURI ) != KErrNone)
       
   146 		{
       
   147 		Callback().SetStatusL( aStatusRef, EError );
       
   148 		return;
       
   149 		}
       
   150 }
       
   151 FeatureManager::UnInitializeLib();
       
   152 //#endif		
       
   153 
       
   154 	SetActionInfoL(CTARMDmStreamAdapterBuffer::ETARMActionExecute,
       
   155 	               aURI,
       
   156 	               aLUID,
       
   157 	               aType,
       
   158 	               aStatusRef,
       
   159 	               -1); // no result ref
       
   160 
       
   161     TInt itemSize;
       
   162     TAdapterStreamType streamType = CTARMDmStreamAdapter::EStreamToNone;
       
   163 	if( StreamingSupport( itemSize ) )
       
   164 	    {
       
   165 	    streamType = StreamType( aURI );
       
   166 	    }
       
   167 
       
   168     if( CTARMDmStreamAdapter::EStreamToNone != streamType )
       
   169         {
       
   170         if( CTARMDmStreamAdapter::EStreamToFile == streamType )
       
   171             {
       
   172             StreamToFileL( aStream );
       
   173             }
       
   174         else
       
   175         if( CTARMDmStreamAdapter::EStreamToBuffer == streamType )
       
   176             {
       
   177             StreamToBufferL( aStream );
       
   178             }
       
   179         Callback().SetStatusL( aStatusRef, EOk ); 
       
   180         }
       
   181     else
       
   182         {
       
   183         _ExecuteCommandL( aURI, aLUID, aStream, aType, aStatusRef );
       
   184         }
       
   185 
       
   186 	RDEBUG( "CTARMDmStreamAdapter::ExecuteCommandL (stream) <" );
       
   187 	}
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CTARMDmStreamAdapter::StreamType
       
   191 // 
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 CTARMDmStreamAdapter::TAdapterStreamType CTARMDmStreamAdapter::StreamType( const TDesC8& /*aURI*/ )
       
   195     {
       
   196 	RDEBUG( "CTARMDmStreamAdapter::StreamType ><" );
       
   197     
       
   198     return CTARMDmStreamAdapter::EStreamToNone;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CTARMDmStreamAdapter::StreamToBufferL
       
   203 // 
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CTARMDmStreamAdapter::StreamToBufferL( RWriteStream*& aStream )
       
   207     {
       
   208 	RDEBUG( "CTARMDmStreamAdapter::StreamToBufferL >" );
       
   209     
       
   210     User::LeaveIfError( iWriteStream.Temp(
       
   211                     iFs,
       
   212                     KTempFilePath(),
       
   213                     iFileStoreFileName,
       
   214                     EFileWrite
       
   215                     ));
       
   216 
       
   217     aStream = &iWriteStream;
       
   218     // StreamCommittedL is called when stream is complete
       
   219     iStreamType = CTARMDmStreamAdapter::EStreamToBuffer;
       
   220 
       
   221 
       
   222 	RDEBUG( "CTARMDmStreamAdapter::StreamToBufferL <" );
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CTARMDmStreamAdapter::StreamToFileL
       
   227 // 
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 void CTARMDmStreamAdapter::StreamToFileL( RWriteStream*& aStream )
       
   231     {
       
   232 	RDEBUG( "CTARMDmStreamAdapter::StreamToFileL >" );
       
   233 
       
   234 
       
   235     User::LeaveIfError( iWriteStream.Temp(
       
   236                     iFs,
       
   237                     KTempFilePath(),
       
   238                     iFileStoreFileName,
       
   239                     EFileWrite
       
   240                     ));
       
   241 
       
   242     aStream = &iWriteStream;
       
   243     // StreamCommittedL is called when stream is complete
       
   244     iStreamType = CTARMDmStreamAdapter::EStreamToFile;
       
   245     
       
   246 
       
   247 	RDEBUG( "CTARMDmStreamAdapter::StreamToFileL <" );
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CTARMDmStreamAdapter::StreamCommittedL
       
   252 // 
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
   256 void CTARMDmStreamAdapter::StreamCommittedL( RWriteStream& /*aStream*/ )
       
   257 #else
       
   258 void CTARMDmStreamAdapter::StreamCommittedL()
       
   259 #endif	
       
   260     {
       
   261 	RDEBUG( "CTARMDmStreamAdapter::StreamCommittedL >" );
       
   262 
       
   263     TInt itemSize = 0;
       
   264     if( StreamingSupport( itemSize ) )
       
   265         {
       
   266         
       
   267         TAdapterStreamType type = iStreamType;
       
   268         iStreamType = CTARMDmStreamAdapter::EStreamToNone;
       
   269 
       
   270         if(CTARMDmStreamAdapter::EStreamToNone == type )
       
   271             {
       
   272             ClearActionInfo();
       
   273             User::Leave( KErrGeneral );
       
   274             }
       
   275 
       
   276         iWriteStream.Close();
       
   277 
       
   278         if(CTARMDmStreamAdapter::EStreamToBuffer == type )
       
   279             {           
       
   280             // Load file to memory
       
   281             RFile f;
       
   282             User::LeaveIfError( f.Open( iFs, iFileStoreFileName, EFileRead ) );
       
   283             CleanupClosePushL( f );
       
   284 
       
   285             TInt size;
       
   286             User::LeaveIfError( f.Size( size ) );
       
   287 
       
   288             HBufC8* buf = HBufC8::NewLC( size );
       
   289             TPtr8 ptr8( buf->Des() );
       
   290             User::LeaveIfError( f.Read( ptr8 ) );
       
   291 
       
   292             // Pass data as argument
       
   293             CommitActionL( ptr8 );
       
   294 
       
   295             CleanupStack::PopAndDestroy( buf );
       
   296             CleanupStack::PopAndDestroy( &f );
       
   297             }
       
   298          else
       
   299             {
       
   300             // Streamed to file, no data in arguments
       
   301             CommitActionL( KNullDesC8() );
       
   302             }
       
   303 
       
   304         iFs.Delete( iFileStoreFileName );
       
   305         
       
   306         }
       
   307 
       
   308     ClearActionInfo();
       
   309 
       
   310 	RDEBUG( "CTARMDmStreamAdapter::StreamCommittedL <" );
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CTARMDmStreamAdapter::SetActionInfoL
       
   315 // 
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CTARMDmStreamAdapter::SetActionInfoL( CTARMDmStreamAdapterBuffer::TTARMDMAction aAction,
       
   319                                      const TDesC8& aURI,
       
   320                                      const TDesC8& aLUID,
       
   321                                      const TDesC8& aType,
       
   322                                      TInt aStatusRef,
       
   323                                      TInt aResultRef )
       
   324     {
       
   325 	RDEBUG( "CTARMDmStreamAdapter::SetActionInfoL >" );
       
   326 
       
   327     ClearActionInfo();
       
   328     iActionInfo = CTARMDmStreamAdapterBuffer::NewL(
       
   329                         aURI,
       
   330                         aLUID,
       
   331                         aType,
       
   332                         aStatusRef,
       
   333                         aResultRef,
       
   334                         aAction
       
   335                         );
       
   336 
       
   337 	RDEBUG( "CTARMDmStreamAdapter::SetActionInfoL <" );
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CTARMDmStreamAdapter::ClearActionInfo
       
   342 // 
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CTARMDmStreamAdapter::ClearActionInfo()
       
   346     {
       
   347 	RDEBUG( "CTARMDmStreamAdapter::ClearActionInfo >" );
       
   348 
       
   349     delete iActionInfo;
       
   350     iActionInfo = 0;
       
   351 
       
   352 	RDEBUG( "CTARMDmStreamAdapter::ClearActionInfo <" );
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CTARMDmStreamAdapter::ActionInfoL
       
   357 // 
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 CTARMDmStreamAdapter::CTARMDmStreamAdapterBuffer& CTARMDmStreamAdapter::ActionInfoL()
       
   361     {
       
   362 	RDEBUG( "CTARMDmStreamAdapter::ActionInfoL >" );
       
   363 
       
   364     if( 0 == iActionInfo )
       
   365         {
       
   366         User::Leave( KErrNotFound );
       
   367         }
       
   368 
       
   369 	RDEBUG( "CTARMDmStreamAdapter::ActionInfoL <" );
       
   370     return *iActionInfo;
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CTARMDmStreamAdapter::CommitActionL
       
   375 // 
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CTARMDmStreamAdapter::CommitActionL( const TDesC8 &aObject )
       
   379     {
       
   380 	RDEBUG( "CTARMDmStreamAdapter::CommitActionL >" );
       
   381 
       
   382     CTARMDmStreamAdapterBuffer& action = ActionInfoL();
       
   383 
       
   384     switch( action.Action() )
       
   385         {
       
   386         case CTARMDmStreamAdapterBuffer::ETARMActionUpdate:
       
   387     	_UpdateLeafObjectL(
       
   388     	            action.URI(),
       
   389     	            action.LUID(),
       
   390     	            aObject,
       
   391     	            action.Type(),
       
   392     	            action.StatusRef()
       
   393     	            );
       
   394         break;
       
   395 
       
   396         case CTARMDmStreamAdapterBuffer::ETARMActionExecute:
       
   397         _ExecuteCommandL(
       
   398     	            action.URI(),
       
   399     	            action.LUID(),
       
   400     	            aObject,
       
   401     	            action.Type(),
       
   402     	            action.StatusRef() 
       
   403                     );
       
   404         break;
       
   405 
       
   406         default:
       
   407         User::Leave( KErrNotSupported );
       
   408         break;
       
   409         }
       
   410 
       
   411 	RDEBUG( "CTARMDmStreamAdapter::CommitActionL <" );
       
   412     }
       
   413 
       
   414 // End of File