mtpdataproviders/mtppictbridgedp/pictbridgeengine/inc/dpsstatemachine.h
author hgs
Fri, 23 Jul 2010 18:35:35 +0800
changeset 35 c4c427c00f31
parent 29 3ae5cb0b4c02
permissions -rw-r--r--
201029_04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     1
/*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     2
* Copyright (c) 2006, 2007 Nokia Corporation and/or its subsidiary(-ies).
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     3
* All rights reserved.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     8
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
     9
* Initial Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    11
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    12
* Contributors:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    13
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    14
* Description:  This class defines the dps state machine. 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    15
*
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    16
*/
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    17
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    18
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    19
#ifndef DPSSTATEMACHINE_H
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    20
#define DPSSTATEMACHINE_H
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    21
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    22
#include "dpsconst.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    23
#include "dpsdefs.h"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    24
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    25
class CDpsTransaction;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    26
class CDpsEngine;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    27
class CDpsScriptReceiver;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    28
class MDpsState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    29
class TMDpsOperation;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    30
class CDpsScriptSender;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    31
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    32
/**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    33
*   This class defines the dps state machine using the state design pattern
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    34
*/
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    35
NONSHARABLE_CLASS(CDpsStateMachine) : public CBase
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    36
    {
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    37
	    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    38
    public:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    39
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    40
        *   Two phase constructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    41
        *   @param aEngine a pointer to dps engine object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    42
        *   @return the CDpsOperator instance
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    43
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    44
        static CDpsStateMachine* NewL(CDpsEngine *aEngine);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    45
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    46
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    47
        *   Destructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    48
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    49
        ~CDpsStateMachine();   
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    50
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    51
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    52
        *   Creates the dps transaction. It further calls CreateRequest()
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    53
        *   to create dps device request script.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    54
        *   @param aParam the dps operation object, passed from UI
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    55
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    56
        void StartTransactionL(TMDpsOperation* aOperation);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    57
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    58
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    59
        *   Initializes the state machine
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    60
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    61
        void Initialize();
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    62
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    63
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    64
        *   Handles errors
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    65
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    66
        inline void Error(TInt err);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    67
                
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    68
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    69
        *   Notifies script sent
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    70
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    71
        inline void ScriptSentNotifyL(TBool aReply);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    72
            
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    73
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    74
        *   Notifies script received
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    75
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    76
        inline void ScriptReceivedNotifyL(TBool aReply);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    77
         
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    78
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    79
        *   Sets the current state
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    80
        *   @param aState the state to be set
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    81
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    82
        inline void SetState(MDpsState* aState);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    83
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    84
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    85
        *   Gets the idle state
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    86
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    87
        inline MDpsState* IdleState() const; 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    88
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    89
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    90
        *   @return the sending request state object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    91
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    92
        inline MDpsState* SendingReqState() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    93
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    94
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    95
        *   @return the waiting for reply state object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    96
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    97
        inline MDpsState* WaitingRepState() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    98
             
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
    99
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   100
        *   @return the sending reply state object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   101
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   102
        inline MDpsState* SendingRepState() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   103
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   104
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   105
        *   @return the CDpsScriptReceiver object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   106
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   107
        inline CDpsScriptReceiver* ScriptReceiver() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   108
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   109
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   110
        *   @return CDpsScriptSender pointer 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   111
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   112
        inline CDpsScriptSender* ScriptSender() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   113
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   114
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   115
        *   @return the CDpsTransaction object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   116
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   117
        inline CDpsTransaction* Trader() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   118
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   119
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   120
        *   @return the current Dps operation enum 
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   121
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   122
        inline TDpsOperation Operation() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   123
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   124
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   125
        *   Sets the current Dps operation enum
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   126
        *   @param aOp the Dps operation enum to be set
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   127
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   128
        inline void SetOperation(TDpsOperation aOp);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   129
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   130
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   131
        *   @return the Dps operation object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   132
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   133
        inline TMDpsOperation* MOperation() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   134
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   135
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   136
        *   @return the Dps event enum
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   137
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   138
        inline TDpsEvent Event() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   139
          
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   140
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   141
        *   Sets the current Dps event
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   142
        *   @param aEvent the Dps event to be set
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   143
        */    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   144
        inline void SetEvent(TDpsEvent aEvent);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   145
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   146
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   147
        *   @return the current state.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   148
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   149
        inline MDpsState* CurState() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   150
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   151
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   152
        *   @return the dps engine object.
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   153
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   154
        inline CDpsEngine* DpsEngine() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   155
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   156
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   157
        *
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   158
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   159
        inline TInt CurError() const;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   160
            
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   161
    private:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   162
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   163
        *   Default constructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   164
        *   @param aEngine a pointer to dps engine object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   165
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   166
        CDpsStateMachine(CDpsEngine* aEngine);
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   167
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   168
        /**
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   169
        *   Two phase constructor. The functions which called in constructor
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   170
        *   and might leave should be called here
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   171
        */
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   172
        void ConstructL();     
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   173
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   174
                                    
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   175
    private:
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   176
        // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   177
        MDpsState* iIdleState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   178
        // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   179
        MDpsState* iSendingReqState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   180
        // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   181
        MDpsState* iWaitingRepState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   182
        // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   183
        MDpsState* iSendingRepState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   184
        // pointer to the current state object
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   185
        MDpsState* iCurState;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   186
        // not owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   187
        TMDpsOperation* iMOperation;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   188
     
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   189
        // not owned by this class  
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   190
        CDpsEngine  *iEngine;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   191
        // the current dps operation, can be empty
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   192
        TDpsOperation iOperation;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   193
        // the current dps event, can be empty
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   194
        TDpsEvent iEvent;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   195
        // the pointer to dps operation object, which takes
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   196
        // care of creating and parsing dps script
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   197
         // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   198
        CDpsTransaction *iTrader;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   199
        // the pointer to dps script receiving notifier
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   200
        // owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   201
        CDpsScriptReceiver* iScriptReceiver;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   202
        
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   203
        // the pointer to script sender object, owned by this class
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   204
        CDpsScriptSender* iScriptSender;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   205
        TInt iCurError;
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   206
    };
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   207
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   208
#include "dpsstatemachine.inl"
3ae5cb0b4c02 201025_07
hgs
parents:
diff changeset
   209
#endif