usbmgmt/usbmgrtest/t_ncm/src/ncmwatcher.cpp
branchRCL_3
changeset 15 f92a4f87e424
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:
       
    15 *
       
    16 */
       
    17 
       
    18 /** @file
       
    19  @internalComponent
       
    20  @test
       
    21  */
       
    22 
       
    23 #include "ncmwatcher.h"
       
    24 #include "ncmtestconsole.h"
       
    25 
       
    26 using namespace UsbNcm;
       
    27 
       
    28 //
       
    29 // CSharedStateWatcher
       
    30 //
       
    31 CSharedStateWatcher* CSharedStateWatcher::NewL(CUsbNcmConsole& aConsole)
       
    32     {
       
    33     CSharedStateWatcher* self = new (ELeave) CSharedStateWatcher(aConsole);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 CSharedStateWatcher::CSharedStateWatcher(CUsbNcmConsole& aConsole) :
       
    41     CActive(EPriorityStandard), iConsole(aConsole), iNcmStateDes(
       
    42             reinterpret_cast<TUint8*> (&iSharedState), sizeof(iSharedState),
       
    43             sizeof(iSharedState))
       
    44     {
       
    45     CActiveScheduler::Add(this);
       
    46     }
       
    47 
       
    48 CSharedStateWatcher::~CSharedStateWatcher()
       
    49     {
       
    50     Cancel();
       
    51     iProperty.Close();
       
    52     }
       
    53 
       
    54 void CSharedStateWatcher::ConstructL()
       
    55     {
       
    56     User::LeaveIfError(iProperty.Attach(KC32ExeSid, KKeyNcmConnectionEvent));
       
    57     reportState();
       
    58     iProperty.Subscribe(iStatus);
       
    59     SetActive();
       
    60     }
       
    61 
       
    62 void CSharedStateWatcher::RunL()
       
    63     {
       
    64     TInt err = iStatus.Int();
       
    65     iProperty.Subscribe(iStatus);
       
    66     SetActive();
       
    67 
       
    68     if (KErrNone == err)
       
    69         {
       
    70         reportState();
       
    71         }
       
    72     }
       
    73 
       
    74 void CSharedStateWatcher::reportState()
       
    75     {
       
    76     iProperty.Get(iNcmStateDes);
       
    77     TBuf<DISPLAY_NCM_CONNECTION_STATE> stateBuf;
       
    78     switch (iSharedState.iState)
       
    79         {
       
    80         case ENcmStateDisconnected:
       
    81             stateBuf = _L("DisConnected");
       
    82             break;
       
    83         case ENcmStateConnected:
       
    84             stateBuf = _L("Connected");
       
    85             break;
       
    86         default:
       
    87             stateBuf = _L("Unknown");
       
    88             break;
       
    89         }
       
    90     __FLOG_STATIC2(KSubSys, KLogComponent ,
       
    91             _L8("NCM state=%d, iapid=%d"), iSharedState.iState, iSharedState.iIapId);
       
    92 
       
    93     iConsole.SetLocalIapId(iSharedState.iIapId);
       
    94     iConsole.SetDisplayItem(ENcmConnectionStateItem, stateBuf);
       
    95     }
       
    96 
       
    97 /**
       
    98  Stop checking the shared state 
       
    99  */
       
   100 void CSharedStateWatcher::DoCancel()
       
   101     {
       
   102     iProperty.Cancel();
       
   103     }