mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsscriptreceiver.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
       
     1 /*
       
     2 * Copyright (c) 2006, 2007 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:  This class implements the dps script receiving function. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32debug.h>
       
    20 #include <f32file.h>
       
    21 #include "dpsscriptreceiver.h"
       
    22 #include "dpsstatemachine.h"
       
    23 #include "pictbridge.h"
       
    24 #include "dpsconst.h"
       
    25 
       
    26 #ifdef _DEBUG
       
    27 #	define IF_DEBUG(t) {RDebug::t;}
       
    28 #else
       
    29 #	define IF_DEBUG(t)
       
    30 #endif
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CDpsScriptReceiver* CDpsScriptReceiver::NewL(CDpsStateMachine* aOperator)								 	     
       
    37     {
       
    38     IF_DEBUG(Print(_L("CDpsScriptReceiver::NewL")));
       
    39     CDpsScriptReceiver* self = new(ELeave) CDpsScriptReceiver(aOperator);
       
    40     return self;	
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CDpsScriptReceiver::CDpsScriptReceiver(CDpsStateMachine* aOperator) :
       
    48     CActive(EPriorityNormal), iOperator(aOperator),
       
    49     iFileNameAndPath(KDpsHostResponseFileName)
       
    50     {
       
    51     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::Ctor")));
       
    52     CActiveScheduler::Add(this);  
       
    53     WaitForReceive();
       
    54     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::Ctor")));
       
    55     }  
       
    56  
       
    57 // ---------------------------------------------------------------------------
       
    58 // 
       
    59 // ---------------------------------------------------------------------------
       
    60 //	
       
    61 CDpsScriptReceiver::~CDpsScriptReceiver()
       
    62     {
       
    63     IF_DEBUG(Print(_L(">>>~CDpsScriptReceiver")));
       
    64     Cancel();
       
    65     IF_DEBUG(Print(_L("<<<~CDpsScriptReceiver")));
       
    66     }
       
    67  
       
    68 // ---------------------------------------------------------------------------
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 //   
       
    72 void CDpsScriptReceiver::WaitForReceive()
       
    73     {
       
    74     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::WaitForReceive"))); 
       
    75     if (!IsActive())
       
    76         {	
       
    77         iOperator->DpsEngine()->Ptp().ObjectReceivedNotify(KDpsScriptFile, 
       
    78             iFileNameAndPath, iStatus, EFalse);        
       
    79         SetActive();		    	
       
    80         }
       
    81     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::WaitForReceive"))); 		
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // 
       
    86 // ---------------------------------------------------------------------------
       
    87 //	
       
    88 TInt CDpsScriptReceiver::GetFileName(TDes& aFileName)
       
    89     {
       
    90     TParse p;
       
    91     TInt err = p.Set(iFileNameAndPath, NULL, NULL);
       
    92     if (KErrNone == err)
       
    93         {
       
    94         aFileName.Copy(p.NameAndExt());
       
    95         }
       
    96     return err;    
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // 
       
   101 // ---------------------------------------------------------------------------
       
   102 //	
       
   103 const TDesC& CDpsScriptReceiver::FileNameAndPath()
       
   104     {
       
   105     return iFileNameAndPath;
       
   106     }
       
   107     
       
   108 // ---------------------------------------------------------------------------
       
   109 // 
       
   110 // ---------------------------------------------------------------------------
       
   111 //	
       
   112 void CDpsScriptReceiver::RunL()
       
   113     {
       
   114     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::RunL %S"), &iFileNameAndPath));
       
   115     // 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.
       
   117     // in this case, pictbridge engine still does not get the ptp folder
       
   118     // setting from the stack. 
       
   119     // if we receive script from host, the stack has started. so we check if
       
   120     // we already get the ptp folder here.
       
   121     if (!iOperator->DpsEngine()->DpsFolder().Length())
       
   122         {
       
   123         iOperator->DpsEngine()->SetDpsFolder(
       
   124             iOperator->DpsEngine()->Ptp().PtpFolder());
       
   125         }
       
   126     if (KErrNone == iStatus.Int())
       
   127         {
       
   128         TFileName receive;
       
   129         User::LeaveIfError(GetFileName(receive));
       
   130         IF_DEBUG(Print(_L("received file is %S"), &receive));
       
   131          // reply from Host is received    
       
   132         if (!receive.Compare(KDpsHostResponseFileName))
       
   133             {
       
   134             iOperator->ScriptReceivedNotifyL(ETrue);    
       
   135             }
       
   136         // request from Host is received    
       
   137         else if (!receive.Compare(KDpsHostRequestFileName))
       
   138             {
       
   139             iOperator->ScriptReceivedNotifyL(EFalse);    
       
   140             }
       
   141         WaitForReceive();    
       
   142         }                
       
   143     else
       
   144     	{
       
   145         IF_DEBUG(Print(_L("the iStatus is wrong!!! %d"), iStatus.Int()));
       
   146         iOperator->Error(iStatus.Int());
       
   147         }    
       
   148     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::RunL")));
       
   149     }
       
   150  
       
   151 // ---------------------------------------------------------------------------
       
   152 // 
       
   153 // ---------------------------------------------------------------------------
       
   154 //    
       
   155 void CDpsScriptReceiver::DoCancel()
       
   156     {
       
   157     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::DoCancel")));
       
   158     iOperator->DpsEngine()->Ptp().CancelObjectReceivedNotify();
       
   159     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::DoCancel")));
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // 
       
   164 // ---------------------------------------------------------------------------
       
   165 //	
       
   166 TInt CDpsScriptReceiver::RunError(TInt aError)	
       
   167     {
       
   168     IF_DEBUG(Print(_L(">>>CDpsScriptReceiver::RunError is %d"), aError));
       
   169     // if error happened cancel the outstanding request
       
   170     Cancel();
       
   171     iOperator->Error(aError);
       
   172     IF_DEBUG(Print(_L("<<<CDpsScriptReceiver::RunError")));
       
   173     return KErrNone;
       
   174     }