datacommsserver/esockserver/test/providers/dummy/src/activityTest.cpp
changeset 30 df67dc5d759e
equal deleted inserted replaced
25:e53adc4c49de 30:df67dc5d759e
       
     1 // Copyright (c) 2005-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 // TestDummy implementation file for a TierManager
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <elements/nm_messages_base.h>
       
    24 #include <comms-infras/ss_nodemessages_dataclient.h>
       
    25 #include <ss_glob.h>
       
    26 #include "activityTest.h"
       
    27 
       
    28 using namespace Messages;
       
    29 using namespace MeshMachine;
       
    30 using namespace ESock;
       
    31 
       
    32 void CActivityCancelTest::StoreRequestL(const TSignatureBase& aRequest)
       
    33     {
       
    34     TBuf8<__Align8(TSignalBase::KMaxInlineMessageSize + TSignalBase::KMaxUnstoredOverhead)> msgBuf;
       
    35     aRequest.Store(msgBuf);
       
    36     TPtrC8 messageStore(msgBuf);
       
    37     TlsGlobals::Get().VirtualCtor()->New(messageStore, iStoredRequest);
       
    38     }
       
    39 
       
    40 
       
    41 DEFINE_SMELEMENT(CActivityCancelTest::TNoTagForwardOrActiveTagBackward, NetStateMachine::MStateFork, TContext)
       
    42 TInt CActivityCancelTest::TNoTagForwardOrActiveTagBackward::TransitionTag()
       
    43     {
       
    44     if (message_cast<TEBase::TError>(&iContext.iMessage))
       
    45         {
       
    46         return KActiveTag | NetStateMachine::EBackward;
       
    47         }
       
    48     return KNoTag | NetStateMachine::EForward;
       
    49     }
       
    50 
       
    51 DEFINE_SMELEMENT(CActivityCancelTest::TBeginTest, NetStateMachine::MStateTransition, TContext)
       
    52 void CActivityCancelTest::TBeginTest::DoL()
       
    53     {
       
    54     ASSERT(iContext.iNodeActivity);
       
    55     CActivityCancelTest& act = static_cast<CActivityCancelTest&>(*iContext.iNodeActivity);
       
    56     act.StoreRequestL(iContext.iMessage);
       
    57     }
       
    58     
       
    59 DEFINE_SMELEMENT(CActivityCancelTest::TBeginLoop, NetStateMachine::MStateTransition, TContext)
       
    60 void CActivityCancelTest::TBeginLoop::DoL()
       
    61     {
       
    62     ASSERT(iContext.iNodeActivity);
       
    63     CActivityCancelTest& act = static_cast<CActivityCancelTest&>(*iContext.iNodeActivity);    
       
    64     act.PostRequestTo(iContext.Node().Id(), act.StoredRequest());  
       
    65     act.NextLoop();
       
    66     }
       
    67 
       
    68 
       
    69 DEFINE_SMELEMENT(CActivityCancelTest::TCancel, NetStateMachine::MStateTransition, TContext)
       
    70 void CActivityCancelTest::TCancel::DoL()
       
    71     {
       
    72     ASSERT(iContext.iNodeActivity);
       
    73     CActivityCancelTest& act = static_cast<CActivityCancelTest&>(*iContext.iNodeActivity);    
       
    74     act.PostRequestTo(iContext.Node().Id(), TEBase::TCancel());
       
    75     }
       
    76 
       
    77 DEFINE_SMELEMENT(CActivityCancelTest::TEndTest, NetStateMachine::MStateTransition, TContext)
       
    78 void CActivityCancelTest::TEndTest::DoL()
       
    79     {
       
    80     ASSERT(iContext.iNodeActivity);
       
    81     CActivityCancelTest& act = static_cast<CActivityCancelTest&>(*iContext.iNodeActivity);   
       
    82     act.PostToOriginators(iContext.iMessage);
       
    83     ASSERT(act.Error() != KErrNone); //if the activity has done its job, the activity have been invariably errored; 
       
    84     act.SetError(KErrNone); //No point reporting this error though.
       
    85     }
       
    86 
       
    87 
       
    88 namespace CancelTestBindToActivity
       
    89 {
       
    90 /* This is a largely generic activity written to test cancelling behaviour of another (typically 
       
    91  * production code) activity. In this case it is put on top of and to test the TBindTo 
       
    92  * activity, by the virtue of awaiting TCFDataClient::TBindTo. In principle though it can be put on
       
    93  * top of any other activity by awaiting for something else instead. CancelTestBindToActivity hijacks
       
    94  * and stores the original request (in this case TCFDataClient::TBindTo). It then goes to perform a 
       
    95  * loop:
       
    96  * { 
       
    97  * - It forwards the stored request to the overriden activity (in this case the TBindTo activity), 
       
    98  * - then follows it with a TCancel 
       
    99  * - and awaits for TError. 
       
   100  * }
       
   101  * Each loop will send the TCancel slightly later, i.e.: at consecutive ticks triggered by messages 
       
   102  * received by the local node (and subsequently resulting in AMMNodeBase::SignalActivities). 
       
   103  * If you examine CActivityCancelTest::TProgressiveCancel you will see that it is blocked 
       
   104  * (as any other synchronised activity) against gradually increasing number of ticks. It has been
       
   105  * pointed out that the tick resolution may be too small - i.e.: that we may want to tick the
       
   106  * activity with every message sent within the local thread (and thus with every even that can
       
   107  * change the state of the activity peers). This can be done by signalling CActivityCancelTest
       
   108  * from the transport upon every dispatch (or post). This is so far not done. Instead CancelTestBindToActivity
       
   109  * is put against every mm node performing bind to (CPR and SCPR).
       
   110  */
       
   111 DEFINE_CUSTOM_NODEACTIVITY(CActivityCancelTest::ECancelTestActivity, CancelBindTo, TCFDataClient::TBindTo, CActivityCancelTest::NewL)
       
   112     FIRST_NODEACTIVITY_ENTRY(CActivityCancelTest::TAwaitingMessageState<TCFDataClient::TBindTo>, MeshMachine::TNoTag)
       
   113     THROUGH_NODEACTIVITY_ENTRY(KNoTag, CActivityCancelTest::TBeginTest, MeshMachine::TTag<KActiveTag>)
       
   114     THROUGH_NODEACTIVITY_ENTRY(KActiveTag, CActivityCancelTest::TBeginLoop, MeshMachine::TNoTag)    
       
   115     NODEACTIVITY_ENTRY(KNoTag, CActivityCancelTest::TProgressiveCancel, MeshMachine::TAcceptErrorState<MeshMachine::TAwaitingMessageState<TCFDataClient::TBindToComplete>  >, CActivityCancelTest::TNoTagForwardOrActiveTagBackward)
       
   116     LAST_NODEACTIVITY_ENTRY(KNoTag, CActivityCancelTest::TEndTest)
       
   117 NODEACTIVITY_END()
       
   118 }
       
   119 
       
   120 
       
   121