2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Channel condition object
19 #ifndef SENSRVCHANNELCONDITION_H
20 #define SENSRVCHANNELCONDITION_H
25 // FORWARD DECLARATIONS
27 class CSensrvChannelCondition;
32 * RPointerArray based channel condition list
34 typedef RPointerArray<CSensrvChannelCondition> RSensrvChannelConditionList;
37 * Defines condition type.
39 * Conditions can be standalone conditions or a part of a two-part condition.
41 * - ESensrvLimitCondition is a standalone condition which has a limit. This kind of condition
42 * is met when the observed value exceeds or equals the condition value, depending on the
43 * operator used in the condition.
44 * - ESensrvRangeConditionLowerLimit is the first part of a two-part range condition. This kind
45 * of condition is met when the observed value is between specified lower and upper limits or
46 * beyond specified range, depending on the operators used in the two conditions that make up
48 * A condition set that contains ESensrvRangeConditionLowerLimit condition must also contain
49 * ESensrvRangeConditionUpperLimit condition using the same index. Both lower and upper limit
50 * operators must have different direction, i.e. if lower limit has "less than" operator, then
51 * upper limit must have "greater than" operator, and vice versa. ESensrvOperatorEquals operator
52 * is not valid for range condition.
53 * - ESensrvRangeConditionUpperLimit is the second part of a two-part range condition.
54 * - ESensrvBinaryCondition is used for channels that provide bitmask values (typically event
55 * channels). ESensrvOperatorBinaryXxx operations can only be used with this condition type.
57 * @see CSensrvChannelCondition
58 * @see TSensrvConditionOperator
60 enum TSensrvConditionType
62 /** Standalone condition which has a limit */
63 ESensrvSingleLimitCondition = 0,
64 /** 1st part of a two-part range condition. 2nd part is ESensrvRangeConditionUpperLimit */
65 ESensrvRangeConditionLowerLimit,
66 /** 2nd part of a two-part range condition. 1st part is ESensrvRangeConditionLowerLimit */
67 ESensrvRangeConditionUpperLimit,
68 /** Standalone condition for binary operations */
69 ESensrvBinaryCondition
73 * Defines condition operator
75 * For a range condition a ConditionSet must contain 2 Conditions each with an operator in a
76 * different direction. i.e. There must be matching greater than and less than pair. Also the pair
77 * of conditions must have the same index in the ConditionSet.
79 * - ESensrvOperatorEquals checks if the value got from the sensor is equal to the set value. This is
80 * not a valid operator for a range condition.
81 * - ESensrvOperatorGreaterThan checks if the value got from the sensor is greater than the set limit.
82 * This is not a valid operator for a binary condition.
83 * - ESensrvOperatorGreaterThanOrEquals checks if the value got from the sensor is greater than or equal
84 * to the set limit. This is not a valid operator for a binary condition.
85 * - ESensrvOperatorLessThan checks if the value got from the sensor is less than the set limit. This is
86 * not a valid operator for a binary condition.
87 * - ESensrvOperatorLessThanOrEquals checks if the value got from the sensor is less than or equal to the
88 * set limit. This is not a valid operator for a binary condition.
89 * - ESensrvOperatorBinaryAnd checks if a bitmask data value got from the sensor has set at least one of
90 * the bits set in the condition value. In other words, if result of datavalue & conditionvalue != 0,
91 * there is a match. This is not a valid operator for a single limit or range conditions.
94 * Condition value: 01101101
95 * Data value: 10001010
96 * Resulting value: 00001000 -> Non-zero, which indicates a match.
97 * - ESensrvOperatorBinaryAll checks if a bitmask data value got from the sensor has set all of the bits
98 * set in the condition value. The rest of the data value bits are ignored. In other words, if
99 * datavalue & conditionvalue == conditionvalue, there is a match. Not a valid operator for a single limit
100 * or range conditions.
102 * Condition value: 01101101
103 * Data value: 10001010
104 * Resulting value: 00001000 -> Not equal to condition value -> Not a match.
106 * @see CSensrvChannelCondition
107 * @see TSensrvConditionType
109 enum TSensrvConditionOperator
111 ESensrvOperatorEquals = 0,
112 ESensrvOperatorGreaterThan,
113 ESensrvOperatorGreaterThanOrEquals,
114 ESensrvOperatorLessThan,
115 ESensrvOperatorLessThanOrEquals,
116 ESensrvOperatorBinaryAnd,
117 ESensrvOperatorBinaryAll
123 * CSensrvChannelCondition represents a channel condition item. Channel conditions are added to a channel
124 * condition set. A channel condition set is met when all channel conditions are met at the same time, if it
125 * is AND-type set, or when single condition is met if it is OR-type set. Only one channel condition can be
126 * set for each data item in single channel condition set. Certain condition types (range conditions) require
127 * two condition objects (upper and lower limit) in a condition set for the set to be valid. The pair of
128 * conditions must both have the same index in the condition set and they are considered a single channel
131 * Each Condition has an ItemIndex associated with it. When a Condition is added to a Condition Set using
132 * CSensrvChannelConditionSet::AddChannelConditionL() this index must be different to all other conditions
133 * added to the set with the exception of range conditions as described above. If the index supplied already
134 * exists and the condition is not part of a range condition then
135 * CSensrvChannelConditionSet::AddChannelConditionL() leaves with KErrArgument.
137 * @see CSensrvChannelConditionSet
138 * @see TSensrvConditionType
139 * @see TSensrvConditionOperator
140 * @lib sensrvutil.lib
143 NONSHARABLE_CLASS( CSensrvChannelCondition ): public CBase
147 * Two-phase constructor
149 * @param aConditionType Defines the type of the condition
150 * @param aConditionOperator Defines the operator used in the condition
151 * @param aItemIndex Item index to be used in the condition evaluation
152 * @param aValue Value to be used in condition evaluation. By default this should be a packaged data
153 * object of the channel. See the channel specific headers in \epoc32\include\sensors\channels.
154 * If the channel type requires a different type of value, that must be indicated clearly in
155 * the channel specific header defining the channel.
156 * @return Pointer to created object
157 * @leave KErrNoMemory
158 * @leave KErrArgument if parameters are invalid or are less than 0
159 * @leave One of the system-wide error codes
161 IMPORT_C static CSensrvChannelCondition* NewL
162 ( TInt aConditionType,
163 TInt aConditionOperator,
168 * Two-phase constructor
170 * @param aConditionType Defines the type of the condition
171 * @param aConditionOperator Defines the operator used in the condition
172 * @param aItemIndex Item index to be used in the condition evaluation
173 * @param aValue Value to be used in condition evaluation. By default this should be a packaged data
174 * object of the channel. See the channel specific headers in \epoc32\include\sensors\channels.
175 * If the channel type requires a different type of value, that must be indicated clearly in
176 * the channel specific header defining the channel.
177 * @return Pointer to created object
178 * @leave KErrNoMemory
179 * @leave KErrArgument if parameters are invalid or are less than 0
180 * @leave One of the system-wide error codes
182 IMPORT_C static CSensrvChannelCondition* NewLC
183 ( TInt aConditionType,
184 TInt aConditionOperator,
192 * @return Condition Type
194 virtual TInt ConditionType() const = 0;
197 * Get condition operator
199 * @return TInt Condition operator
201 virtual TInt ConditionOperator() const = 0;
204 * Get condition item index
206 * @return TInt Condition item index
208 virtual TInt ConditionItemIndex() const = 0;
211 * Get condition value.
213 * @param aValue Value of the condition is copied to the supplied descriptor
214 * @return KErrOverflow if aData is the wrong size for data item or one of the system-wide error codes
216 virtual TInt GetConditionValue( TDes8& aValue ) const = 0;
219 * Get condition value as reference.
221 * @return Reference to condition value descriptor.
223 virtual const TDesC8& ConditionValue() const = 0;
227 * Default constructor.
229 CSensrvChannelCondition();
232 #endif //SENSRVCHANNELCONDITION_H