qstmgesturelib/qstmstatemachine_v2.h
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 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 #ifndef QSTMSTATEMACHINE_V2_H_
       
    20 #define QSTMSTATEMACHINE_V2_H_
       
    21 
       
    22 namespace qstmUiEventEngine
       
    23 {
       
    24 /**
       
    25  * the next templates define the static callbacks required to pass the this object to the member function
       
    26  * There are two definitions, one for the TBool is*() method checking the message,
       
    27  * the other one returning void for entry, event and action methods.
       
    28  */
       
    29 template<class T, bool (T::*F)()>
       
    30 bool isF(void *p)
       
    31 {
       
    32     return ((reinterpret_cast<T*>(p))->*F)();
       
    33 }
       
    34 
       
    35 template<class T, void (T::*F)()>
       
    36 void aF(void *p)
       
    37 {
       
    38     ((reinterpret_cast<T*>(p))->*F)();
       
    39 }
       
    40 
       
    41 /////////////////////////////////////////////////////////////////////////////////////
       
    42 // We define the state machine in C fashion so that we get the initialized state table
       
    43 // already at compilation phase.  The message checking methods, event methods  and action methods are
       
    44 // then passed to the C++ object to be processed.
       
    45 // The currently defined states are the following, at the same time they are used as the index to the array of states.
       
    46 enum QStm_StateMachineState {Eignore, EInit, EDispatch, EInTouchTime, EInHoldTime_U, EInHoldTime_D, EInTouchArea, ESuppress_D} ;
       
    47 // Using these kind of functions the state machine is of course single threaded
       
    48 // the necessary parameters need to be passed in the member variables
       
    49 typedef bool  (*condition_t)(void* ) ;
       
    50 typedef void  (*action_t)(void*) ;
       
    51 
       
    52 /*
       
    53  * The possible events to the state machine.  The pointer and timer events are possible.
       
    54  */
       
    55 enum QStm_StateMachineEvent {EDown, EDrag, ECapacitiveUP, EResistiveUP, ETouchTimer, EHoldTimer, ESuppressTimer} ;
       
    56 /*!
       
    57  * STATE_ELEMENT defines one line in the state/event instance.
       
    58  * It contains three fields: ConditionFunction, ActionFunction and NextState.
       
    59  * The generic state machine will call the ConditionFunction (if it is != NULL)
       
    60  * and if the result is true, it will call ActionFunction (if it is != NULL).
       
    61  * Then it will continue to NextState.
       
    62  * If NextState is Eignore, it will try the next line of state/event.
       
    63  */
       
    64 typedef struct _STATE_ELEMENT {
       
    65     /*!
       
    66      * Condition function contains the pointer to the method used to check some condition.
       
    67      * If the pointer is non-NULL the state machine will call the function and based on the result
       
    68      * (if true) calls the ActionFunction.
       
    69      */
       
    70     const condition_t conditionFunction ;
       
    71     /*!
       
    72      * ActionFunction contains a pointer to a method performing some action.  The state machine
       
    73      * will call the method if the pointer is non-NULL.
       
    74      */
       
    75     const action_t    actionFunction ;
       
    76     /*!
       
    77      * NextState contains either the next state or Eignore.  The state machine will process state elements
       
    78      * until the NextState != Eignroe is found.
       
    79      */
       
    80     const QStm_StateMachineState  nextState ;
       
    81 } STATE_ELEMENT ;
       
    82 
       
    83 /*!
       
    84  * Each state contains an array defining the possible event and the state elements
       
    85  * that are processed if the event happens.
       
    86  */
       
    87 typedef struct _STATE {
       
    88     /*!
       
    89      * The event defines the pointer event or timer event being processed
       
    90      */
       
    91     const QStm_StateMachineEvent    theEvent ;        //
       
    92     /*!
       
    93      * StateElements points to the array of STATE_ELEMENT entries which define the
       
    94      * condition and action functions to be processed and the resulting nesxt state.
       
    95      */
       
    96     const STATE_ELEMENT* const   stateElements ;
       
    97 } STATE ;
       
    98 
       
    99 } // namespace
       
   100 
       
   101 #endif /* QSTMSTATEMACHINE_V2_H_ */