mtpdataproviders/mtppictbridgedp/pictbridgeengine/src/dpsptpnotifier.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 functions of setting personality to 
       
    15 *                MTP. 
       
    16 *  Version     : %version: 1 % 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <e32debug.h>
       
    22 #include "dpsptpnotifier.h"
       
    23 #include "dpsusbnotifier.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 CDpsPtpNotifier* CDpsPtpNotifier::NewL(CDpsUsbNotifier* aParent)
       
    37     {
       
    38     IF_DEBUG(Print(_L("CDpsPtpNotifier::NewL")));
       
    39     CDpsPtpNotifier* self = new(ELeave) CDpsPtpNotifier(aParent);
       
    40     return self;	    
       
    41     }
       
    42     
       
    43 // ---------------------------------------------------------------------------
       
    44 // 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CDpsPtpNotifier::CDpsPtpNotifier(CDpsUsbNotifier* aParent) :
       
    48     CActive(EPriorityNormal), iNotifier(aParent)
       
    49     {
       
    50     IF_DEBUG(Print(_L(">>>CDpsPtpNotifier::Ctor")));    
       
    51     CActiveScheduler::Add(this);
       
    52     IF_DEBUG(Print(_L("<<<CDpsPtpNotifier::Ctor")));    
       
    53     }    
       
    54     
       
    55 // ---------------------------------------------------------------------------
       
    56 // 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CDpsPtpNotifier::~CDpsPtpNotifier()
       
    60     {
       
    61     IF_DEBUG(Print(_L(">>>CDpsPtpNotifier::")));        
       
    62     Cancel();
       
    63     IF_DEBUG(Print(_L("<<<CDpsPtpNotifier::~")));        
       
    64     }
       
    65     
       
    66 // ---------------------------------------------------------------------------
       
    67 // 
       
    68 // ---------------------------------------------------------------------------
       
    69 //    
       
    70 void CDpsPtpNotifier::ChangePtpPersonality()    
       
    71     {
       
    72     IF_DEBUG(Print(_L(">>>CDpsPtpNotifier::ChangePtpPersonality")));            
       
    73     if (!IsActive())
       
    74         {
       
    75         TInt personalityId = KUsbPersonalityIdMTP;
       
    76         iNotifier->iUsbM.GetCurrentPersonalityId(personalityId);
       
    77         IF_DEBUG(Print(_L("CDpsPtpNotifier::ChangePtpPersonality, current personality= %d"), personalityId));
       
    78         if(KUsbPersonalityIdPCSuiteMTP == personalityId)
       
    79             {
       
    80             TRequestStatus* statusPtr = &iStatus;
       
    81             User::RequestComplete(statusPtr, KErrNone);
       
    82             SetActive();            
       
    83             }
       
    84         else                
       
    85             {
       
    86             iNotifier->iUsbW.SetPersonality(iStatus, KUsbPersonalityIdMTP, ETrue);
       
    87             SetActive();
       
    88             }
       
    89         }
       
    90     IF_DEBUG(Print(_L("<<<CDpsPtpNotifier::ChangePtpPersonality")));        
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // 
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 void CDpsPtpNotifier::RunL()
       
    98     {
       
    99     IF_DEBUG(Print(_L(">>>CDpsPtpNotifier::RunL %d"), iStatus.Int()));            
       
   100     if (KErrNone == iStatus.Int())
       
   101         {
       
   102         iNotifier->iPersonality = KUsbPersonalityIdMTP;
       
   103         TInt ret = iNotifier->ConnectState();
       
   104         if (ret != KErrNone)
       
   105             {
       
   106             IF_DEBUG(Print(_L("error happened %d"), ret));
       
   107             }
       
   108         }
       
   109     iNotifier->PtpNotify(iStatus.Int());        
       
   110     IF_DEBUG(Print(_L("<<<CDpsPtpNotifier::RunL")));
       
   111     }
       
   112     
       
   113 // ---------------------------------------------------------------------------
       
   114 // 
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CDpsPtpNotifier::DoCancel()
       
   118     {
       
   119     IF_DEBUG(Print(_L(">>>CDpsPtpNotifier::DoCancel")));                
       
   120     iNotifier->iUsbW.CancelSetPersonality();
       
   121     IF_DEBUG(Print(_L("<<<CDpsPtpNotifier::DoCancel")));                
       
   122     }
       
   123     
       
   124 // ---------------------------------------------------------------------------
       
   125 // 
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CDpsPtpNotifier::RunError(TInt aErr)
       
   129     {
       
   130     IF_DEBUG(Print(_L("CDpsPtpNotifier::RunError")));                    
       
   131     return aErr;
       
   132     }