javaextensions/sensor/src.s60/csensorrangecondition.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Range condition implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "csensorrangecondition.h"
       
    19 #include "sensornativeconstants.h"
       
    20 #include "logger.h"
       
    21 
       
    22 CSensorRangeCondition::CSensorRangeCondition(TInt& aChannelId,
       
    23         TReal64& aLowerLimit, TReal64& aUpperLimit,
       
    24         TInt& aLowerOp, TInt& aUpperOp)
       
    25         : CSensorConditionBase(aChannelId), iLowerLimit(aLowerLimit),
       
    26         iUpperLimit(aUpperLimit), iLowerOp(aLowerOp), iUpperOp(aUpperOp)
       
    27 {
       
    28     JELOG2(ESensor);
       
    29 }
       
    30 
       
    31 CSensorRangeCondition::~CSensorRangeCondition()
       
    32 {
       
    33     JELOG2(ESensor);
       
    34 }
       
    35 
       
    36 TBool CSensorRangeCondition::Evaluate(TReal aValue, TInt aChannelId)
       
    37 {
       
    38     JELOG2(ESensor);
       
    39     if (aChannelId != iChannelId)
       
    40     {
       
    41         return EFalse;
       
    42     }
       
    43 
       
    44     TBool lowerMet = EFalse;
       
    45     switch (iLowerOp)
       
    46     {
       
    47     case INT_GREATER_THAN:
       
    48     {
       
    49         lowerMet = aValue > iLowerLimit;
       
    50         break;
       
    51     }
       
    52     case INT_GREATER_THAN_OR_EQUALS:
       
    53     {
       
    54         lowerMet = aValue >= iLowerLimit;
       
    55         break;
       
    56     }
       
    57     }
       
    58     TBool upperMet = EFalse;
       
    59     switch (iUpperOp)
       
    60     {
       
    61     case INT_LESS_THAN:
       
    62     {
       
    63         upperMet = aValue < iUpperLimit;
       
    64         break;
       
    65     }
       
    66     case INT_LESS_THAN_OR_EQUALS:
       
    67     {
       
    68         upperMet = aValue <= iUpperLimit;
       
    69         break;
       
    70     }
       
    71     }
       
    72     if (lowerMet && upperMet)
       
    73     {
       
    74         return ETrue;
       
    75     }
       
    76     return EFalse;
       
    77 }