tsrc/testtools/stubsrv/inc/stubber.h
branchRCL_3
changeset 92 dde4619868dc
parent 86 703a2b94c06c
child 95 55a3258355ea
equal deleted inserted replaced
86:703a2b94c06c 92:dde4619868dc
     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 #ifndef STUBBER_H
       
    19 #define STUBBER_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <apibehavior.h>
       
    23 #include <stubsrvconst.h>
       
    24 
       
    25 class RStubClient;
       
    26 
       
    27 class MApiInvoker 
       
    28 {
       
    29 public:
       
    30     virtual void InvokeApiComplete(const TApiBehavior& aBeh) = 0;
       
    31 };
       
    32 
       
    33 NONSHARABLE_CLASS(CStubber) : public CActive
       
    34     {
       
    35 public: 
       
    36 
       
    37     IMPORT_C static CStubber* NewL();
       
    38     
       
    39     IMPORT_C ~CStubber();
       
    40 
       
    41    /**
       
    42     * Queues an API behavior specification to Stub server.
       
    43     *
       
    44     * This method is called by API behavior controllers, e.g. a module test, to specify the next expected 
       
    45     * behavior of an API. When InvokeApi() is called, the first queued behavior matching
       
    46     * the lib identifier and API identifier will be extracted and returned.
       
    47     *
       
    48     * @param aApi an API behavior.
       
    49     * @param aExeDuration, specifies the execution time of InvokeApi() in microseconds.
       
    50     *            value less than 0 means never completing InvokeApi(); 
       
    51     *            value 0 means completing InvokeApi() asap;
       
    52     *            value 1000000 means InvokeApi() takes 1 sec execution time;
       
    53     *        and so on. 
       
    54     */
       
    55     IMPORT_C void EnqueBehavior(const TApiBehavior& aBeh, TInt aExeDuration = 0);
       
    56 
       
    57     /**
       
    58     * Deletes all queued behaviors of the specified API.
       
    59     *
       
    60     * @param aLib the identifier of a stub
       
    61     * @param aApi the identifier of the API
       
    62     */
       
    63     IMPORT_C void DeleteBehaviors(TUint aLib, TUint aApi);
       
    64 
       
    65     /**
       
    66     * Invokes an API.
       
    67     *
       
    68     * If there is a queued behavior for this API, Stub server will perform according to the execution setting; 
       
    69     * otherwise stub server will act according to the specified mode.
       
    70     *
       
    71     * @param aBeh contains the lib and API identifiers when passed in;
       
    72     *                 will contain the behavior at complete.
       
    73     * @param aMode the mode to be used if no queued behavior is found for the specified API;
       
    74     *              In case of ECompleteIfNoBehaviorSet mode, stub server will complete this function 
       
    75     *              immediately and return a default TApiBehavior(TUint, TUint); 
       
    76     *              stub server will keep this function call pending until a behavior is queued if the mode
       
    77     *              is ESuspendIfBehaviorSet.
       
    78     */
       
    79     IMPORT_C void InvokeApi(TApiBehavior& aBeh, TApiInvokeMode aMode = ECompleteIfNoBehaviorSet);
       
    80 	
       
    81     /**
       
    82     * asynchronous version of InvokeAPI(), MApiInvoker::InvokeApiComplete will be called when
       
    83     * this opeation is completed by stub server
       
    84     *
       
    85     * Only one InvokeApiL is allowed at a time.
       
    86     *
       
    87     * Leaves if the completion code in the behavior to be extracted is not KErrNone.
       
    88     *
       
    89     * @param aLib the identifier of a stub
       
    90     * @param aApi the identifier of the API
       
    91     * @param aMode the mode to be used if no queued behavior is found for the specified API;
       
    92     *              In case of ECompleteIfNoBehaviorSet mode, stub server will complete this function 
       
    93     *              immediately and return a default TApiBehavior(TUint, TUint); 
       
    94     *              stub server will keep this function call pending until a behavior is queued if the mode
       
    95     *              is ESuspendIfBehaviorSet.
       
    96     */
       
    97 	IMPORT_C void InvokeApiL(MApiInvoker& aInvoker, TUint aLib, TUint aApi, TApiInvokeMode aMode = ECompleteIfNoBehaviorSet);
       
    98 
       
    99     /**
       
   100     * Cancels InvokeApi()
       
   101     */
       
   102 	IMPORT_C void InvokeApiCancel();
       
   103     
       
   104 protected:
       
   105     void RunL();
       
   106     void DoCancel();
       
   107     TInt RunError(TInt aReason);
       
   108     
       
   109 protected:
       
   110     CStubber();
       
   111     
       
   112     void ConstructL();
       
   113 
       
   114 protected:
       
   115     MApiInvoker* iInvoker;
       
   116     
       
   117     TApiBehavior iBeh;
       
   118     TApiBehaviorPckg iBehPckg;
       
   119     
       
   120     RStubClient* iClient;
       
   121     };
       
   122     
       
   123 #endif // STUBBER_H
       
   124