sensorservices/sensorserver/src/util/sensrvchannelconditionimpl.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Channel condition object implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sensrvchannelconditionimpl.h"
       
    20 #include "sensrvtrace.h"
       
    21 
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // C++ constructor
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CSensrvChannelConditionImpl::CSensrvChannelConditionImpl
       
    28         ( TInt aConditionType, 
       
    29           TInt aConditionOperator,
       
    30           TInt aItemIndex ) 
       
    31     : iType(aConditionType),
       
    32       iOperator(aConditionOperator),
       
    33       iIndex(aItemIndex)
       
    34     {
       
    35     }
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // 2nd phase of construction
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void CSensrvChannelConditionImpl::ConstructL(TDesC8& aValue)
       
    43     {
       
    44     COMPONENT_TRACE( ( _L( "Sensrv Util - CSensrvChannelConditionImpl::ConstructL()" ) ) );
       
    45     
       
    46     // Check parameters    
       
    47     // Note: Type and operator are not checked for being one of the
       
    48     //       predefined ones, as it is possible that some channels
       
    49     //       require custom condition types or operations.
       
    50     if (
       
    51         // Single limit condition cannot have binary operators        
       
    52         (   iType == ESensrvSingleLimitCondition 
       
    53          && (   iOperator == ESensrvOperatorBinaryAnd
       
    54              || iOperator == ESensrvOperatorBinaryAll ) )
       
    55         // Range conditions cannot have equals or binary operators 
       
    56         || (   (   iType == ESensrvRangeConditionLowerLimit
       
    57                 || iType == ESensrvRangeConditionUpperLimit ) 
       
    58             && (   iOperator == ESensrvOperatorEquals
       
    59                 || iOperator == ESensrvOperatorBinaryAnd
       
    60                 || iOperator == ESensrvOperatorBinaryAll ) )
       
    61         // Binary condition cannot have >, <, >= or <= operatios
       
    62         || (   (   iType == ESensrvBinaryCondition ) 
       
    63             && (   iOperator == ESensrvOperatorGreaterThan
       
    64                 || iOperator == ESensrvOperatorGreaterThanOrEquals
       
    65                 || iOperator == ESensrvOperatorLessThan
       
    66                 || iOperator == ESensrvOperatorLessThanOrEquals ) )
       
    67         // Value must not be zero length
       
    68         || !aValue.Length()
       
    69        )
       
    70         {
       
    71         User::Leave(KErrArgument);
       
    72         }
       
    73 
       
    74     iValue = aValue.AllocL();
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Destructor
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CSensrvChannelConditionImpl::~CSensrvChannelConditionImpl()
       
    83     {
       
    84     COMPONENT_TRACE( ( _L( "Sensrv Util - CSensrvChannelConditionImpl::~CSensrvChannelConditionImpl()" ) ) );
       
    85     
       
    86     delete iValue;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Return condition type
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 TInt CSensrvChannelConditionImpl::ConditionType() const
       
    94     {
       
    95     return iType;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Return condition operator
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 TInt CSensrvChannelConditionImpl::ConditionOperator() const
       
   103     {
       
   104     return iOperator;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Return condition item index
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 TInt CSensrvChannelConditionImpl::ConditionItemIndex() const
       
   112     {
       
   113     return iIndex;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Return condition value as paramater
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 TInt CSensrvChannelConditionImpl::GetConditionValue(TDes8& aValue) const
       
   121     {
       
   122     TInt err( KErrNone );
       
   123     
       
   124     if( aValue.Length() < iValue->Length() )
       
   125         {
       
   126         // aValue is too small
       
   127         err = KErrOverflow;
       
   128         }
       
   129     else
       
   130         {
       
   131         // Set return value
       
   132         TUint8* ptr = const_cast<TUint8*>( iValue->Des().Ptr() );
       
   133         aValue.Copy( ptr, iValue->Length() );
       
   134         }
       
   135     
       
   136     return err;
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // Condition value as reference
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 const TDesC8& CSensrvChannelConditionImpl::ConditionValue() const
       
   144     {
       
   145     return *iValue;
       
   146     }