mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsscriptreceiver.cpp
changeset 47 63cf70d3ecd8
parent 28 85e0c0339cc3
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    13 *
    13 *
    14 * Description:  This class implements the dps script receiving function. 
    14 * Description:  This class implements the dps script receiving function. 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include <e32debug.h>
       
    20 #include <f32file.h>
    18 #include <f32file.h>
    21 #include "dpsscriptreceiver.h"
    19 #include "dpsscriptreceiver.h"
    22 #include "dpsstatemachine.h"
    20 #include "dpsstatemachine.h"
    23 #include "pictbridge.h"
    21 #include "pictbridge.h"
    24 #include "dpsconst.h"
    22 #include "dpsconst.h"
    25 
    23 #include "mtpdebug.h"
    26 #ifdef _DEBUG
    24 #include "OstTraceDefinitions.h"
    27 #	define IF_DEBUG(t) {RDebug::t;}
    25 #ifdef OST_TRACE_COMPILER_IN_USE
    28 #else
    26 #include "dpsscriptreceiverTraces.h"
    29 #	define IF_DEBUG(t)
       
    30 #endif
    27 #endif
    31 
    28 
    32 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    33 // 
    30 // 
    34 // ---------------------------------------------------------------------------
    31 // ---------------------------------------------------------------------------
    35 //
    32 //
    36 CDpsScriptReceiver* CDpsScriptReceiver::NewL(CDpsStateMachine* aOperator)								 	     
    33 CDpsScriptReceiver* CDpsScriptReceiver::NewL(CDpsStateMachine* aOperator)								 	     
    37     {
    34     {
    38     IF_DEBUG(Print(_L("CDpsScriptReceiver::NewL")));
       
    39     CDpsScriptReceiver* self = new(ELeave) CDpsScriptReceiver(aOperator);
    35     CDpsScriptReceiver* self = new(ELeave) CDpsScriptReceiver(aOperator);
    40     return self;	
    36     return self;	
    41     }
    37     }
    42 
    38 
    43 // ---------------------------------------------------------------------------
    39 // ---------------------------------------------------------------------------
    46 //
    42 //
    47 CDpsScriptReceiver::CDpsScriptReceiver(CDpsStateMachine* aOperator) :
    43 CDpsScriptReceiver::CDpsScriptReceiver(CDpsStateMachine* aOperator) :
    48     CActive(EPriorityNormal), iOperator(aOperator),
    44     CActive(EPriorityNormal), iOperator(aOperator),
    49     iFileNameAndPath(KDpsHostResponseFileName)
    45     iFileNameAndPath(KDpsHostResponseFileName)
    50     {
    46     {
    51     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::Ctor")));
    47     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_CDPSSCRIPTRECEIVER_CONS_ENTRY );
    52     CActiveScheduler::Add(this);  
    48     CActiveScheduler::Add(this);  
    53     WaitForReceive();
    49     WaitForReceive();
    54     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::Ctor")));
    50     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_CDPSSCRIPTRECEIVER_CONS_EXIT );
    55     }  
    51     }  
    56  
    52  
    57 // ---------------------------------------------------------------------------
    53 // ---------------------------------------------------------------------------
    58 // 
    54 // 
    59 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
    60 //	
    56 //	
    61 CDpsScriptReceiver::~CDpsScriptReceiver()
    57 CDpsScriptReceiver::~CDpsScriptReceiver()
    62     {
    58     {
    63     IF_DEBUG(Print(_L(">>>~CDpsScriptReceiver")));
    59     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_CDPSSCRIPTRECEIVER_DES_ENTRY );
    64     Cancel();
    60     Cancel();
    65     IF_DEBUG(Print(_L("<<<~CDpsScriptReceiver")));
    61     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_CDPSSCRIPTRECEIVER_DES_EXIT );
    66     }
    62     }
    67  
    63  
    68 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    69 // 
    65 // 
    70 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    71 //   
    67 //   
    72 void CDpsScriptReceiver::WaitForReceive()
    68 void CDpsScriptReceiver::WaitForReceive()
    73     {
    69     {
    74     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::WaitForReceive"))); 
    70     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_WAITFORRECEIVE_ENTRY );
    75     if (!IsActive())
    71     if (!IsActive())
    76         {	
    72         {	
    77         iOperator->DpsEngine()->Ptp().ObjectReceivedNotify(KDpsScriptFile, 
    73         iOperator->DpsEngine()->Ptp().ObjectReceivedNotify(KDpsScriptFile, 
    78             iFileNameAndPath, iStatus, EFalse);        
    74             iFileNameAndPath, iStatus, EFalse);        
    79         SetActive();		    	
    75         SetActive();		    	
    80         }
    76         }		
    81     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::WaitForReceive"))); 		
    77     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_WAITFORRECEIVE_EXIT );
    82     }
    78     }
    83 
    79 
    84 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
    85 // 
    81 // 
    86 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
   109 // 
   105 // 
   110 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   111 //	
   107 //	
   112 void CDpsScriptReceiver::RunL()
   108 void CDpsScriptReceiver::RunL()
   113     {
   109     {
   114     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::RunL %S"), &iFileNameAndPath));
   110     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_RUNL_ENTRY );
       
   111     OstTraceExt1( TRACE_NORMAL, CDPSSCRIPTRECEIVER_RUNL, "iFileNameAndPath %S", iFileNameAndPath );
   115     // in the certain error case, it is possible that the printer sending
   112     // in the certain error case, it is possible that the printer sending
   116     // the device status before the UI is ready to receive this event.
   113     // the device status before the UI is ready to receive this event.
   117     // in this case, pictbridge engine still does not get the ptp folder
   114     // in this case, pictbridge engine still does not get the ptp folder
   118     // setting from the stack. 
   115     // setting from the stack. 
   119     // if we receive script from host, the stack has started. so we check if
   116     // if we receive script from host, the stack has started. so we check if
   124             iOperator->DpsEngine()->Ptp().PtpFolder());
   121             iOperator->DpsEngine()->Ptp().PtpFolder());
   125         }
   122         }
   126     if (KErrNone == iStatus.Int())
   123     if (KErrNone == iStatus.Int())
   127         {
   124         {
   128         TFileName receive;
   125         TFileName receive;
   129         User::LeaveIfError(GetFileName(receive));
   126         LEAVEIFERROR(GetFileName(receive),
   130         IF_DEBUG(Print(_L("received file is %S"), &receive));
   127                 OstTraceExt2( TRACE_ERROR, DUP3_CDPSSCRIPTRECEIVER_RUNL, 
       
   128                         "Gets the file name from %S failed! error code %d",receive, munged_err  ));
       
   129                 
       
   130         OstTraceExt1( TRACE_NORMAL, DUP1_CDPSSCRIPTRECEIVER_RUNL, "received file is %S", receive );
   131          // reply from Host is received    
   131          // reply from Host is received    
   132         if (!receive.Compare(KDpsHostResponseFileName))
   132         if (!receive.Compare(KDpsHostResponseFileName))
   133             {
   133             {
   134             iOperator->ScriptReceivedNotifyL(ETrue);    
   134             iOperator->ScriptReceivedNotifyL(ETrue);    
   135             }
   135             }
   140             }
   140             }
   141         WaitForReceive();    
   141         WaitForReceive();    
   142         }                
   142         }                
   143     else
   143     else
   144     	{
   144     	{
   145         IF_DEBUG(Print(_L("the iStatus is wrong!!! %d"), iStatus.Int()));
   145         OstTrace1( TRACE_ERROR, DUP2_CDPSSCRIPTRECEIVER_RUNL, "the iStatus is wrong!!! %d", iStatus.Int() );
   146         iOperator->Error(iStatus.Int());
   146         iOperator->Error(iStatus.Int());
   147         }    
   147         }    
   148     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::RunL")));
   148     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_RUNL_EXIT );
   149     }
   149     }
   150  
   150  
   151 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   152 // 
   152 // 
   153 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   154 //    
   154 //    
   155 void CDpsScriptReceiver::DoCancel()
   155 void CDpsScriptReceiver::DoCancel()
   156     {
   156     {
   157     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::DoCancel")));
   157     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_DOCANCEL_ENTRY );
   158     iOperator->DpsEngine()->Ptp().CancelObjectReceivedNotify();
   158     iOperator->DpsEngine()->Ptp().CancelObjectReceivedNotify();
   159     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::DoCancel")));
   159     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_DOCANCEL_EXIT );
   160     }
   160     }
   161 
   161 
   162 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   163 // 
   163 // 
   164 // ---------------------------------------------------------------------------
   164 // ---------------------------------------------------------------------------
   165 //	
   165 //	
   166 TInt CDpsScriptReceiver::RunError(TInt aError)	
   166 TInt CDpsScriptReceiver::RunError(TInt aError)	
   167     {
   167     {
   168     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::RunError is %d"), aError));
   168     OstTraceFunctionEntry0( CDPSSCRIPTRECEIVER_RUNERROR_ENTRY );
       
   169     OstTraceDef1( OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, CDPSSCRIPTRECEIVER_RUNERROR, 
       
   170             "error code %d", aError);
   169     // if error happened cancel the outstanding request
   171     // if error happened cancel the outstanding request
   170     Cancel();
   172     Cancel();
   171     iOperator->Error(aError);
   173     iOperator->Error(aError);
   172     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::RunError")));
   174     OstTraceFunctionExit0( CDPSSCRIPTRECEIVER_RUNERROR_EXIT );
   173     return KErrNone;
   175     return KErrNone;
   174     }
   176     }