usbmgmt/usbmgrtest/t_charging_emu/src/activepropertysubscribercharging.cpp
changeset 0 c9bc50fca66e
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /*
       
     2 * Copyright (c) 2008-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 /**
       
    19  @file
       
    20  @internalComponent
       
    21  @prototype
       
    22 */
       
    23 
       
    24 #include "activepropertysubscribercharging.h"
       
    25 #include"tbatterychargingdefinitions.h"
       
    26 
       
    27 CActivePropertyWriteRepository::CActivePropertyWriteRepository(MPropertyWriteRepositoryObserver& aObserver)
       
    28 :	CActive(CActive::EPriorityStandard),
       
    29 	iObserver(aObserver)
       
    30 	{
       
    31 	CActiveScheduler::Add(this);
       
    32 	}
       
    33 
       
    34 CActivePropertyWriteRepository::~CActivePropertyWriteRepository()
       
    35 	{
       
    36 	
       
    37 	Cancel();
       
    38 	iPropertyWriteToRepository.Close();
       
    39 	}
       
    40 
       
    41 CActivePropertyWriteRepository* CActivePropertyWriteRepository::NewL(MPropertyWriteRepositoryObserver& aObserver)
       
    42 	{
       
    43 	
       
    44 	CActivePropertyWriteRepository* self = new(ELeave) CActivePropertyWriteRepository(aObserver);
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL();
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 void CActivePropertyWriteRepository::ConstructL()
       
    52 	{
       
    53 	// Assumes the property has already been defined by the driving test code.
       
    54 	User::LeaveIfError(iPropertyWriteToRepository.Attach(TUid::Uid(KBattChargWriteRepositoryUid), KBattChargWriteRepositoryKey));
       
    55 	}
       
    56 
       
    57 void CActivePropertyWriteRepository::Request()
       
    58 	{
       
    59 	iPropertyWriteToRepository.Subscribe(iStatus);
       
    60 	SetActive();
       
    61 	}
       
    62 
       
    63 void CActivePropertyWriteRepository::RunL()
       
    64 	{
       
    65 	
       
    66 	if ( iStatus.Int() == KErrNone )
       
    67 		{
       
    68 		TInt value;
       
    69 		TInt err = iPropertyWriteToRepository.Get(value);
       
    70 		ASSERT(!err);
       
    71 		iObserver.MpsoPropertyWriteChanged(value);
       
    72 		}
       
    73 
       
    74 	Request();
       
    75 	}
       
    76 
       
    77 void CActivePropertyWriteRepository::DoCancel()
       
    78 	{
       
    79 	
       
    80 	iPropertyWriteToRepository.Cancel();
       
    81 	}
       
    82 
       
    83 
       
    84 // this is to read the property for current charging
       
    85 CActivePropertyReadChargingCurrent::CActivePropertyReadChargingCurrent(MPropertyReadBatteryChargingCurrentObserver& aObserver)
       
    86 :	CActive(CActive::EPriorityStandard),
       
    87 	iObserver(aObserver)
       
    88 	{
       
    89 	CActiveScheduler::Add(this);
       
    90 	}
       
    91 
       
    92 CActivePropertyReadChargingCurrent::~CActivePropertyReadChargingCurrent()
       
    93 	{
       
    94 	
       
    95 	Cancel();
       
    96 	iPropertyReadChargingCurrent.Close();
       
    97 	}
       
    98 
       
    99 CActivePropertyReadChargingCurrent* CActivePropertyReadChargingCurrent::NewL(MPropertyReadBatteryChargingCurrentObserver& aObserver)
       
   100 	{
       
   101 	
       
   102 	CActivePropertyReadChargingCurrent* self = new(ELeave) CActivePropertyReadChargingCurrent(aObserver);
       
   103 	CleanupStack::PushL(self);
       
   104 	self->ConstructL();
       
   105 	CleanupStack::Pop(self);
       
   106 	return self;
       
   107 	}
       
   108 
       
   109 void CActivePropertyReadChargingCurrent::ConstructL()
       
   110 	{
       
   111 	// Assumes the property has already been defined by the driving test code.
       
   112 	User::LeaveIfError(iPropertyReadChargingCurrent.Attach(TUid::Uid(KBattChargReadPropertyCurrentUid), KBattChargReadCurrentChargingKey));
       
   113 	}
       
   114 
       
   115 void CActivePropertyReadChargingCurrent::Request()
       
   116 	{
       
   117 	iPropertyReadChargingCurrent.Subscribe(iStatus);
       
   118 	SetActive();
       
   119 	}
       
   120 
       
   121 void CActivePropertyReadChargingCurrent::RunL()
       
   122 	{
       
   123 	
       
   124 	if ( iStatus.Int() == KErrNone )
       
   125 		{
       
   126 		//not interested in the value of the property but just by the fact that it was triggered
       
   127 		iObserver.MpsoPropertyReadChanged();
       
   128 		}
       
   129 
       
   130 	Request();
       
   131 	}
       
   132 
       
   133 void CActivePropertyReadChargingCurrent::DoCancel()
       
   134 	{
       
   135 	
       
   136 	iPropertyReadChargingCurrent.Cancel();
       
   137 	}
       
   138 
       
   139 
       
   140 
       
   141 
       
   142