commsfwsupport/commselements/testing/dummystatelibrary/inc/dummystates.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef DUMMYSTATES_H
       
    17 #define DUMMYSTATES_H
       
    18 
       
    19 #include "dummynode.h"
       
    20 #include "dummymessages.h"
       
    21 #include <elements/mm_context.h>
       
    22 #include <elements/mm_states.h>
       
    23 #include <elements/mm_mutexpolicies.h>
       
    24 #include <elements/nm_messages_peer.h>
       
    25 #include <elements/nm_messages_child.h>
       
    26 
       
    27 /*
       
    28 IMPORTANT NOTES ABOUT STATES, FORKS & TRANSITIONS
       
    29 
       
    30 1)
       
    31 Please make all of your transitions that you place
       
    32 in a state libraries atomic.
       
    33 If you couple two or more transitions into one, you
       
    34 must have a good reason for that and you should not
       
    35 put them into the state library.
       
    36 Coupled transitions usually reside with the specialised
       
    37 activities using them.
       
    38 We have given some examplea of a coupled transition below.
       
    39 The usual reasons for using aggregated transitions are the
       
    40 same also for conditional transitions, please see below.
       
    41 
       
    42 2)
       
    43 Conditional transitions are only justified when they contribute
       
    44 to a significant complexity decrease resulting from use of so called
       
    45 "single triple" activities.
       
    46 A single triple activity that needs conditional routing can not
       
    47 use forks since it does not have the activity object and must finish
       
    48 in "one shot".
       
    49 Conditional transitions are not acceptable in any other scenarios
       
    50 since in every other scenario a fork should be used for activity routing.
       
    51 */
       
    52 
       
    53 
       
    54 namespace DummyStates
       
    55 {
       
    56 
       
    57 typedef MeshMachine::TNodeContext<Dummy::CTestNodeBase, MeshMachine::TContext> TContext;
       
    58 
       
    59 //-=========================================================
       
    60 //
       
    61 //Dummy transition ids 0..1000
       
    62 //
       
    63 //-=========================================================
       
    64 const TUint KNoPeer            = 1;
       
    65 const TUint KStarting          = 2;
       
    66 const TUint KStopping          = 3;
       
    67 const TUint KStarted           = 4;
       
    68 const TUint KNoServiceProvider = 5;
       
    69 
       
    70 //-=========================================================
       
    71 //
       
    72 //States
       
    73 //
       
    74 //-=========================================================
       
    75 typedef MeshMachine::TAwaitingMessageState<Dummy::TStartProtocol::TStart> TAwaitingStart;
       
    76 typedef MeshMachine::TAwaitingMessageState<Dummy::TBindProtocol::TClientJoiningRequest> TAwaitingClientJoiningRequest;
       
    77 typedef MeshMachine::TAwaitingMessageState<Dummy::TBindProtocol::TJoinComplete> TAwaitingJoinComplete;
       
    78 typedef MeshMachine::TAwaitingMessageState<Dummy::TBindProtocol::TFactoryObjectCreated> TAwaitingFactoryObjectCreated;
       
    79 
       
    80 DECLARE_SMELEMENT_HEADER( TAwaitingStop, MeshMachine::TState<TContext>, NetStateMachine::MState, TContext )
       
    81 	virtual TBool Accept();
       
    82 DECLARE_SMELEMENT_FOOTER( TAwaitingStop )
       
    83 
       
    84 DECLARE_SMELEMENT_HEADER( TAwaitingStarted, MeshMachine::TState<TContext>, NetStateMachine::MState, TContext )
       
    85 	virtual TBool Accept();
       
    86 DECLARE_SMELEMENT_FOOTER( TAwaitingStart )
       
    87 
       
    88 DECLARE_SMELEMENT_HEADER( TAwaitingStopped, MeshMachine::TState<TContext>, NetStateMachine::MState, TContext )
       
    89 	virtual TBool Accept();
       
    90 DECLARE_SMELEMENT_FOOTER( TAwaitingStopped )
       
    91 
       
    92 DECLARE_SMELEMENT_HEADER( TAwaitingDestroy, MeshMachine::TState<TContext>, NetStateMachine::MState, TContext )
       
    93 	virtual TBool Accept();
       
    94 DECLARE_SMELEMENT_FOOTER( TAwaitingDestroy )
       
    95 
       
    96 //-=========================================================
       
    97 //
       
    98 //Stateforks
       
    99 //
       
   100 //-=========================================================
       
   101 DECLARE_SMELEMENT_HEADER( TNoTagOrStartedOrNoServiceProvider, MeshMachine::TStateFork<TContext>, NetStateMachine::MStateFork, TContext )
       
   102 	virtual TInt TransitionTag();
       
   103 DECLARE_SMELEMENT_FOOTER( TNoTagOrStartedOrNoServiceProvider )
       
   104 
       
   105 DECLARE_SMELEMENT_HEADER( TNoTagOrNoServiceProvider, MeshMachine::TStateFork<TContext>, NetStateMachine::MStateFork, TContext )
       
   106 	virtual TInt TransitionTag();
       
   107 DECLARE_SMELEMENT_FOOTER( TNoTagOrNoServiceProvider )
       
   108 
       
   109 DECLARE_SMELEMENT_HEADER( TNoTagBackwardsOrNoServiceProvider, MeshMachine::TStateFork<TContext>, NetStateMachine::MStateFork, TContext )
       
   110 	virtual TInt TransitionTag();
       
   111 DECLARE_SMELEMENT_FOOTER( TNoTagBackwardsOrNoServiceProvider )
       
   112 
       
   113 //We use serialised states (and not serialised transitions) as the
       
   114 //subsequent activity flow must be decided only after the activity
       
   115 //is woken up again.
       
   116 DECLARE_SERIALIZABLE_STATE(
       
   117 	TNoTagOrStartedOrNoServiceProviderBlockedByStart,
       
   118 	MeshMachine::TActivityIdMutex<Dummy::EActivityStart>,
       
   119 	DummyStates::TNoTagOrStartedOrNoServiceProvider
       
   120 	)
       
   121 
       
   122 DECLARE_SERIALIZABLE_STATE(
       
   123 	TNoTagOrStartedOrNoServiceProviderBlockedByStop,
       
   124 	MeshMachine::TActivityIdMutex<Dummy::EActivityStop>,
       
   125 	DummyStates::TNoTagOrStartedOrNoServiceProvider
       
   126 	)
       
   127 
       
   128 //-=========================================================
       
   129 //
       
   130 //State Transitions
       
   131 //
       
   132 //-=========================================================
       
   133 
       
   134 //Send Started setting the EActive flag on the Client(s)
       
   135 typedef MeshMachine::TPostMessageToOriginators<Dummy::TStartProtocol::TStarted, Dummy::TDummyClientType::EActive> TPostStarted;
       
   136 //Send Stopped clearing the EActive flag on the Client(s)
       
   137 typedef MeshMachine::TPostMessageToOriginators<Dummy::TStopProtocol::TStopped, 0, Dummy::TDummyClientType::EActive> TPostStopped;
       
   138 
       
   139 DECLARE_SMELEMENT_HEADER( TPostStart, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   140 	virtual void DoL();
       
   141 DECLARE_SMELEMENT_FOOTER( TPostStart )
       
   142 
       
   143 DECLARE_SMELEMENT_HEADER( TPostStop, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   144 	virtual void DoL();
       
   145 DECLARE_SMELEMENT_FOOTER( TPostStop )
       
   146 
       
   147 DECLARE_SMELEMENT_HEADER( TCreateServiceProvider, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   148 	virtual void DoL();
       
   149 DECLARE_SMELEMENT_FOOTER( TCreateServiceProvider )
       
   150 
       
   151 DECLARE_SMELEMENT_HEADER( TAddClient, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   152 	virtual void DoL();
       
   153 	virtual void Error(TInt aError); //This transition will post TDestroy on error
       
   154 DECLARE_SMELEMENT_FOOTER( TAddClient )
       
   155 
       
   156 DECLARE_SMELEMENT_HEADER( TAddServiceProvider, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   157 	virtual void DoL();
       
   158 	virtual void Error(TInt aError); //This transition will post TDestroy on error
       
   159 DECLARE_SMELEMENT_FOOTER( TAddServiceProvider )
       
   160 
       
   161 DECLARE_SMELEMENT_HEADER( TPostClientJoiningRequest, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   162 	virtual void DoL();
       
   163 DECLARE_SMELEMENT_FOOTER( TPostClientJoiningRequest )
       
   164 
       
   165 DECLARE_SMELEMENT_HEADER( TPostClientLeavingRequest, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   166 	virtual void DoL();
       
   167 DECLARE_SMELEMENT_FOOTER( TPostClientLeavingRequest )
       
   168 
       
   169 DECLARE_SMELEMENT_HEADER( TCommenceJoin, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   170 	virtual void DoL();
       
   171 DECLARE_SMELEMENT_FOOTER( TCommenceJoin )
       
   172 
       
   173 DECLARE_SMELEMENT_HEADER( TPostDestroyToSelfIfLastClient, MeshMachine::TStateTransition<TContext>, NetStateMachine::MStateTransition, TContext )
       
   174 	virtual void DoL();
       
   175 DECLARE_SMELEMENT_FOOTER( TPostDestroyToSelfIfLastClient )
       
   176 
       
   177 //Aggregated transitions are used to combine 2 or more separate transitions into one.
       
   178 DECLARE_AGGREGATED_TRANSITION3(
       
   179 	TCommenceJoinAndAddClientAndPostJoinComplete,
       
   180 	DummyStates::TCommenceJoin,
       
   181 	DummyStates::TAddClient,
       
   182 	MeshMachine::TPostMessageToSender<Dummy::TBindProtocol::TJoinComplete>
       
   183 	)
       
   184 
       
   185 DECLARE_AGGREGATED_TRANSITION3(
       
   186 	TPostLeaveCompleteAndRemoveClientAndPostDestroyIfLast,
       
   187 	MeshMachine::TPostMessageToSender<Messages::TEPeer::TLeaveComplete>,
       
   188 	MeshMachine::TRemoveClient,
       
   189 	DummyStates::TPostDestroyToSelfIfLastClient
       
   190 	)
       
   191 
       
   192 DECLARE_AGGREGATED_TRANSITION2(
       
   193 	TAddServiceProviderAndPostStart,
       
   194 	DummyStates::TAddServiceProvider,
       
   195 	DummyStates::TPostStart
       
   196 	)
       
   197 
       
   198 } //namespace DummyStates
       
   199 
       
   200 
       
   201 #endif
       
   202 //DUMMYSTATES_H
       
   203 
       
   204