multimediacommsengine/tsrc/testdriver/testclient/watcher/src/CTcWatcher.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CTcWatcher.h"
       
    19 #include "WatcherConstants.h"
       
    20 
       
    21 EXPORT_C CTcWatcher* CTcWatcher::NewL( const TDesC& aAppName, TInt aTimeout )
       
    22 	{
       
    23 	CTcWatcher* self = new( ELeave ) CTcWatcher;
       
    24 
       
    25 	CleanupStack::PushL( self );
       
    26 	self->ConstructL( aAppName, aTimeout );
       
    27 	CleanupStack::Pop();
       
    28 
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 EXPORT_C CTcWatcher::~CTcWatcher()
       
    33 	{
       
    34 	Cancel();
       
    35 	iTimer.Close();
       
    36 	iWatcher.Close();
       
    37 	}
       
    38 
       
    39 CTcWatcher::CTcWatcher()
       
    40 	: CActive( EPriorityHigh )
       
    41 	{
       
    42 	CActiveScheduler::Add( this );
       
    43 	}
       
    44 
       
    45 void CTcWatcher::ConstructL( const TDesC& aAppName, TInt aTimeout )
       
    46 	{
       
    47 	User::LeaveIfError( iTimer.CreateLocal() );
       
    48 	User::LeaveIfError( iWatcher.Connect( aAppName, aTimeout * KSecondAsMicroseconds ) );
       
    49 
       
    50 	iTimeout = aTimeout * KSecondAsMicroseconds / 2;
       
    51 	iTimer.After( iStatus, iTimeout );
       
    52 	SetActive();
       
    53 	}
       
    54 
       
    55 void CTcWatcher::DoCancel()
       
    56 	{
       
    57 	iTimer.Cancel();
       
    58 	}
       
    59 
       
    60 void CTcWatcher::RunL()
       
    61 	{
       
    62 	iWatcher.Ping();
       
    63 
       
    64 	iTimer.After( iStatus, iTimeout );
       
    65 	SetActive();
       
    66 	}