kerneltest/f32test/shostmassstorage/msman/src/cusbotgwatcher.cpp
changeset 0 a41df078684a
child 297 b2826f67641f
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32cmn.h>
       
    17 #include <e32base.h>
       
    18 #include <e32property.h>
       
    19 #include <d32otgdi.h>
       
    20 #include <e32debug.h>
       
    21 
       
    22 #include "cusbotg.h"
       
    23 #include "cusbotgwatcher.h"
       
    24 
       
    25 #include "tmslog.h"
       
    26 #include "debug.h"
       
    27 
       
    28 
       
    29 CUsbOtgBaseWatcher::CUsbOtgBaseWatcher(RUsbOtgDriver& aLdd)
       
    30 :   CActive(CActive::EPriorityStandard),
       
    31     iLdd(aLdd)
       
    32 	{
       
    33     __MSFNLOG
       
    34 	CActiveScheduler::Add(this);
       
    35 	}
       
    36 
       
    37 
       
    38 CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher()
       
    39 	{
       
    40     __MSFNLOG
       
    41 	Cancel();
       
    42 	}
       
    43 
       
    44 void CUsbOtgBaseWatcher::Start()
       
    45 	{
       
    46     __MSFNLOG
       
    47 	Post();
       
    48 	}
       
    49 
       
    50 
       
    51 
       
    52 CRequestSessionWatcher* CRequestSessionWatcher::NewL(MUsbRequestSessionObserver& aObserver)
       
    53     {
       
    54     __MSFNSLOG
       
    55     CRequestSessionWatcher* r = new (ELeave) CRequestSessionWatcher(aObserver);
       
    56     r->ConstructL();
       
    57     return r;
       
    58     }
       
    59 
       
    60 CRequestSessionWatcher::CRequestSessionWatcher(MUsbRequestSessionObserver& aObserver)
       
    61 :   CActive(EPriorityStandard),
       
    62     iObserver(aObserver)
       
    63     {
       
    64     __MSFNLOG
       
    65     }
       
    66 
       
    67 void CRequestSessionWatcher::ConstructL()
       
    68     {
       
    69     __MSFNLOG
       
    70     User::LeaveIfError(iProperty.Define(KUidUsbManCategory, KUsbRequestSessionProperty, RProperty::EInt));
       
    71     User::LeaveIfError(iProperty.Attach(KUidUsbManCategory, KUsbRequestSessionProperty));
       
    72     CActiveScheduler::Add(this);
       
    73 
       
    74     // initial subscription and process current property value
       
    75 	RunL();
       
    76     }
       
    77 
       
    78 
       
    79 void CRequestSessionWatcher::DoCancel()
       
    80 	{
       
    81     __MSFNLOG
       
    82 	iProperty.Cancel();
       
    83 	}
       
    84 
       
    85 
       
    86 CRequestSessionWatcher::~CRequestSessionWatcher()
       
    87     {
       
    88     __MSFNLOG
       
    89     Cancel();
       
    90     iProperty.Close();
       
    91     iProperty.Delete(KUidUsbManCategory, KUsbRequestSessionProperty);
       
    92     }
       
    93 
       
    94 
       
    95 void CRequestSessionWatcher::RunL()
       
    96     {
       
    97     __MSFNLOG
       
    98 	// resubscribe before processing new value to prevent missing updates
       
    99 	iProperty.Subscribe(iStatus);
       
   100 	SetActive();
       
   101     TInt val;
       
   102     User::LeaveIfError(iProperty.Get(KUidUsbManCategory, KUsbRequestSessionProperty, val));
       
   103     __USBOTGPRINT1(_L(">> CUsbRequestSessionWatcher[%d]"), val);
       
   104 
       
   105     switch(val)
       
   106         {
       
   107         case KUsbManSessionOpen:
       
   108             {
       
   109             iObserver.BusRequestL();
       
   110             }
       
   111             break;
       
   112         default:
       
   113             __USBOTGPRINT(_L("Event ignored"));
       
   114             break;
       
   115         }
       
   116     }
       
   117 
       
   118 TInt CRequestSessionWatcher::RunError(TInt aError)
       
   119     {
       
   120     __MSFNLOG
       
   121     __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
       
   122     return KErrNone;
       
   123     }
       
   124 
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 
       
   130 
       
   131 
       
   132 
       
   133 CUsbOtgEventWatcher* CUsbOtgEventWatcher::NewL(RUsbOtgDriver& aLdd,
       
   134                                                CUsbOtg& aUsbOtg)
       
   135     {
       
   136     __MSFNSLOG
       
   137     CUsbOtgEventWatcher* r = new (ELeave) CUsbOtgEventWatcher(aLdd, aUsbOtg);
       
   138     r->ConstructL();
       
   139     return r;
       
   140     }
       
   141 
       
   142 CUsbOtgEventWatcher::CUsbOtgEventWatcher(RUsbOtgDriver& aLdd,
       
   143                                          CUsbOtg& aUsbOtg)
       
   144 :   CUsbOtgBaseWatcher(aLdd),
       
   145     iUsbOtg(aUsbOtg)
       
   146     {
       
   147     __MSFNLOG
       
   148     }
       
   149 
       
   150 
       
   151 void CUsbOtgEventWatcher::ConstructL()
       
   152     {
       
   153     __MSFNLOG
       
   154     }
       
   155 
       
   156 
       
   157 void CUsbOtgEventWatcher::DoCancel()
       
   158 	{
       
   159     __MSFNLOG
       
   160     iLdd.CancelOtgEventRequest();
       
   161 	}
       
   162 
       
   163 
       
   164 CUsbOtgEventWatcher::~CUsbOtgEventWatcher()
       
   165     {
       
   166     __MSFNLOG
       
   167     }
       
   168 
       
   169 
       
   170 void CUsbOtgEventWatcher::Post()
       
   171     {
       
   172     __MSFNLOG
       
   173     iLdd.QueueOtgEventRequest(iEvent, iStatus);
       
   174     SetActive();
       
   175     }
       
   176 
       
   177 void CUsbOtgEventWatcher::RunL()
       
   178     {
       
   179     __MSFNLOG
       
   180 
       
   181     TInt r = iStatus.Int();
       
   182     User::LeaveIfError(r);
       
   183 
       
   184     __USBOTGPRINT1(_L(">> CUsbOtgEventWatcher[%x]"), iEvent);
       
   185     User::LeaveIfError(r);
       
   186 
       
   187     iUsbOtg.HandleUsbOtgEvent(iEvent);
       
   188     Start();
       
   189     }
       
   190 
       
   191 TInt CUsbOtgEventWatcher::RunError(TInt aError)
       
   192     {
       
   193     __MSFNLOG
       
   194     __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
       
   195     return KErrNone;
       
   196     }