mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsfile.cpp
changeset 47 63cf70d3ecd8
parent 28 85e0c0339cc3
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    17 
    17 
    18 
    18 
    19 #include "dpsfile.h"
    19 #include "dpsfile.h"
    20 #include "dpsdefs.h"
    20 #include "dpsdefs.h"
    21 #include "dpsconst.h"
    21 #include "dpsconst.h"
    22 
    22 #include "mtpdebug.h"
    23 #ifdef _DEBUG
    23 #include "OstTraceDefinitions.h"
    24 #	define IF_DEBUG(t) {RDebug::t;}
    24 #ifdef OST_TRACE_COMPILER_IN_USE
    25 #else
    25 #include "dpsfileTraces.h"
    26 #	define IF_DEBUG(t)
       
    27 #endif
    26 #endif
    28 
    27 
    29     
    28     
    30 // --------------------------------------------------------------------------
    29 // --------------------------------------------------------------------------
    31 // 
    30 // 
    32 // --------------------------------------------------------------------------
    31 // --------------------------------------------------------------------------
    33 //
    32 //
    34 CDpsFile* CDpsFile::NewL()
    33 CDpsFile* CDpsFile::NewL()
    35 	{
    34 	{
    36 	IF_DEBUG(Print(_L("CDpsFile::NewL")));
       
    37 	CDpsFile* self = new (ELeave) CDpsFile();
    35 	CDpsFile* self = new (ELeave) CDpsFile();
    38 	CleanupStack::PushL(self);
    36 	CleanupStack::PushL(self);
    39     self->ConstructL();
    37     self->ConstructL();
    40     CleanupStack::Pop(); 
    38     CleanupStack::Pop(); 
    41 	return self;
    39 	return self;
    45 // 
    43 // 
    46 // --------------------------------------------------------------------------
    44 // --------------------------------------------------------------------------
    47 //
    45 //
    48 void CDpsFile::ConstructL()
    46 void CDpsFile::ConstructL()
    49     {
    47     {
    50     IF_DEBUG(Print(_L(">>>CDpsFile::ConstructL")));    
    48     OstTraceFunctionEntry0( CDPSFILE_CONSTRUCTL_ENTRY );  
    51 	User::LeaveIfError(iFs.Connect());
    49 	LEAVEIFERROR(iFs.Connect(),
    52     IF_DEBUG(Print(_L("<<<CDpsFile::ConstructL")));    
    50 	        OstTrace1( TRACE_ERROR, CDPSFILE_CONSTRUCTL, 
       
    51 	                "Connect to file server failed! error code %d", munged_err));
       
    52     OstTraceFunctionExit0( CDPSFILE_CONSTRUCTL_EXIT );
    53     }
    53     }
    54     
    54     
    55 // --------------------------------------------------------------------------
    55 // --------------------------------------------------------------------------
    56 // 
    56 // 
    57 // --------------------------------------------------------------------------
    57 // --------------------------------------------------------------------------
    58 //
    58 //
    59 CDpsFile::~CDpsFile()
    59 CDpsFile::~CDpsFile()
    60 	{
    60 	{
    61 	IF_DEBUG(Print(_L(">>>CDpsFile::~")));        
    61 	OstTraceFunctionEntry0( CDPSFILE_CDPSFILE_DES_ENTRY );
    62 	iFs.Close();
    62 	iFs.Close();
    63 	IF_DEBUG(Print(_L("<<<CDpsFile::~")));        
    63     OstTraceFunctionExit0( CDPSFILE_CDPSFILE_DES_EXIT );
    64     }
    64     }
    65 
    65 
    66 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    67 // 
    67 // 
    68 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
    69 //
    69 //
    70 TInt CDpsFile::CreateScriptFile(const TDesC& aFileName, const TDesC8& aScript,
    70 TInt CDpsFile::CreateScriptFile(const TDesC& aFileName, const TDesC8& aScript,
    71 								const TInt aFileSize)
    71 								const TInt aFileSize)
    72     {
    72     {
    73     IF_DEBUG(Print(_L(">>>CDpsFile::CreateScriptFile size %d"), aFileSize));            
    73     OstTraceFunctionEntry0( CDPSFILE_CREATESCRIPTFILE_ENTRY );
       
    74     OstTrace1( TRACE_NORMAL, CDPSFILE_CREATESCRIPTFILE, "File size %d", aFileSize );          
    74     RFile file;
    75     RFile file;
    75     TInt err = file.Replace(iFs, aFileName, EFileShareExclusive);
    76     TInt err = file.Replace(iFs, aFileName, EFileShareExclusive);
    76     IF_DEBUG(Print(_L("---the error is %d"), err));
    77     OstTrace1( TRACE_NORMAL, DUP1_CDPSFILE_CREATESCRIPTFILE, "---the error is %d", err );
    77     if (err != KErrNone)
    78     if (err != KErrNone)
    78         {
    79         {
       
    80         OstTraceFunctionExit0( CDPSFILE_CREATESCRIPTFILE_EXIT );
    79         return err;
    81         return err;
    80         }
    82         }
    81         
    83         
    82     TInt fileSize = aScript.Size();
    84     TInt fileSize = aScript.Size();
    83     if (!fileSize)
    85     if (!fileSize)
    91     else
    93     else
    92         {
    94         {
    93         err = file.Write(aScript, aFileSize);
    95         err = file.Write(aScript, aFileSize);
    94         }
    96         }
    95         
    97         
    96     file.Close();
    98     file.Close();     
    97     IF_DEBUG(Print(_L("<<<CDpsFile::CreateScriptFile %d"), err));            
    99     OstTrace1( TRACE_NORMAL, DUP2_CDPSFILE_CREATESCRIPTFILE, "return value %d", err );        
       
   100     OstTraceFunctionExit0( DUP1_CDPSFILE_CREATESCRIPTFILE_EXIT );
    98     return err;   
   101     return err;   
    99     }
   102     }
   100 
   103 
   101 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
   102 // 
   105 // 
   103 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   104 //
   107 //
   105 void CDpsFile::GetContentL(const TDesC& aFileName, TDes8& aScript)
   108 void CDpsFile::GetContentL(const TDesC& aFileName, TDes8& aScript)
   106     {
   109     {
   107     IF_DEBUG(Print(_L(">>>CDpsFile::GetContent %S"), &aFileName));                
   110     OstTraceFunctionEntry0( CDPSFILE_GETCONTENTL_ENTRY );
       
   111     OstTraceExt1( TRACE_NORMAL, CDPSFILE_GETCONTENTL, "File name %S", aFileName );              
   108     RFile file;
   112     RFile file;
   109     CleanupClosePushL(file);
   113     CleanupClosePushL(file);
   110     User::LeaveIfError(file.Open(iFs, aFileName, EFileRead));
   114     LEAVEIFERROR(file.Open(iFs, aFileName, EFileRead),
   111     User::LeaveIfError(file.Read(aScript));
   115             OstTraceExt2( TRACE_ERROR, DUP1_CDPSFILE_GETCONTENTL, 
   112     CleanupStack::PopAndDestroy();
   116                     "Open %S failed! error code %d", aFileName, munged_err));
   113     IF_DEBUG(Print(_L("<<<CDpsFile::GetContent")));                       
   117     LEAVEIFERROR(file.Read(aScript),
       
   118             OstTrace1( TRACE_ERROR, DUP2_CDPSFILE_GETCONTENTL, 
       
   119                     "Read from file failed! error code %d", munged_err ));
       
   120     CleanupStack::PopAndDestroy();                      
       
   121     OstTraceFunctionExit0( CDPSFILE_GETCONTENTL_EXIT );
   114     }
   122     }
   115 
   123 
   116 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   117 // 
   125 // 
   118 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   119 //    
   127 //    
   120 void CDpsFile::FileSizeL(const TDesC& aFileName, TInt& aSize)
   128 void CDpsFile::FileSizeL(const TDesC& aFileName, TInt& aSize)
   121     {
   129     {
   122     IF_DEBUG(Print(_L(">>>CDpsFile::FileSize %S"), &aFileName));       
   130     OstTraceFunctionEntry0( CDPSFILE_FILESIZEL_ENTRY );
       
   131     OstTraceExt1( TRACE_NORMAL, CDPSFILE_FILESIZEL, "File name %S", aFileName );       
   123     RFile file;
   132     RFile file;
   124     CleanupClosePushL(file);
   133     CleanupClosePushL(file);
   125     User::LeaveIfError(file.Open(iFs, aFileName, EFileRead)); 
   134     LEAVEIFERROR(file.Open(iFs, aFileName, EFileRead),
   126     User::LeaveIfError(file.Size(aSize));    
   135             OstTraceExt2( TRACE_ERROR, DUP1_CDPSFILE_FILESIZEL, 
   127     CleanupStack::PopAndDestroy();
   136                     "Open %S failed! error code %d", aFileName, munged_err));
   128     IF_DEBUG(Print(_L("<<<CDpsFile::FileSize %d"), aSize));                
   137     LEAVEIFERROR(file.Size(aSize),
       
   138             OstTrace1( TRACE_ERROR, DUP2_CDPSFILE_FILESIZEL, 
       
   139                     "Gets file size failed! error code %d", munged_err));
       
   140     CleanupStack::PopAndDestroy();    
       
   141     OstTrace1( TRACE_NORMAL, DUP3_CDPSFILE_FILESIZEL, "File size %d", aSize );    
       
   142     OstTraceFunctionExit0( CDPSFILE_FILESIZEL_EXIT );
   129     }
   143     }
   130     
   144     
   131 // ---------------------------------------------------------------------------
   145 // ---------------------------------------------------------------------------
   132 // 
   146 // 
   133 // ---------------------------------------------------------------------------
   147 // ---------------------------------------------------------------------------
   134 //    
   148 //    
   135 TInt CDpsFile::Delete(const TDesC& aFileName)
   149 TInt CDpsFile::Delete(const TDesC& aFileName)
   136     {
   150     {
   137     IF_DEBUG(Print(_L("CDpsFile::Delete")));                    
   151     OstTraceFunctionEntry0( CDPSFILE_DELETE_ENTRY );
       
   152     OstTraceFunctionExit0( CDPSFILE_DELETE_EXIT );                  
   138     return iFs.Delete(aFileName);
   153     return iFs.Delete(aFileName);
   139     }
   154     }