loadgen/engine/inc/loadgen_messages.h
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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 LOADGEN_MESSAGES_H
       
    20 #define LOADGEN_MESSAGES_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 
       
    26 #include "loadgen_loadbase.h"
       
    27 #include "loadgen_loadattributes.h"
       
    28 
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CSmsHandler;
       
    32 class CMmsHandler;
       
    33 
       
    34 const TInt EMaxMessageLength = 512;
       
    35 
       
    36 // CLASS DECLARATIONS
       
    37 
       
    38 class CMessages : public CLoadBase
       
    39     {
       
    40 public:
       
    41     static CMessages* NewL( TMessageAttributes& aAttributes, TInt aReferenceNumber );
       
    42     virtual ~CMessages();
       
    43         
       
    44 private: // Constructors
       
    45     CMessages( TMessageAttributes& aAttributes, TInt aReferenceNumber );
       
    46     void ConstructL();  
       
    47 
       
    48 public:  // New methods
       
    49     virtual void Resume();
       
    50     virtual void Suspend();
       
    51     virtual void SetPriority();
       
    52     virtual void Close();
       
    53     virtual TPtrC Description();
       
    54     inline TMessageAttributes& Attributes() { return iAttributes; }
       
    55 	inline void SetAttributes(TMessageAttributes aAttributes) { iAttributes = aAttributes; }
       
    56 
       
    57 public:  // New static methods
       
    58     static TInt ThreadFunction( TAny* aThreadArg );
       
    59 
       
    60 private:  // New static methods
       
    61     static void GenerateLoad( TMessageAttributes& aAttributes );
       
    62 
       
    63 private: // Data
       
    64     TMessageAttributes            iAttributes;    
       
    65     RThread                     iThread;
       
    66 
       
    67     };
       
    68 
       
    69 
       
    70 class CMessageManager : public CActive
       
    71     { 
       
    72 private:
       
    73     enum TState
       
    74         {
       
    75         EStateIdle = 0,
       
    76         EStateSend,
       
    77         EStateSending        
       
    78         };
       
    79 public:
       
    80     static CMessageManager* NewL( TMessageAttributes& aAttributes );
       
    81     virtual ~CMessageManager();
       
    82 
       
    83 
       
    84 private:
       
    85     CMessageManager( TMessageAttributes& aAttributes );
       
    86     void ConstructL();
       
    87 
       
    88 private:
       
    89     void RunL();
       
    90     void DoCancel();
       
    91 
       
    92 private:
       
    93     static TInt PeriodicTimerCallBack( TAny* aAny );
       
    94     void HandleMessageSending();
       
    95     void DoDial();
       
    96     void DoHangup();
       
    97     void CreateMessage();    
       
    98 
       
    99 public:
       
   100     inline CPeriodic* PeriodicTimer() { return iPeriodicTimer; }
       
   101     void HandleStatus( TInt aErr );
       
   102 
       
   103 private:
       
   104     TMessageAttributes&                   iAttributes;
       
   105     CPeriodic*                          iPeriodicTimer;
       
   106     TInt                                iState;
       
   107     CSmsHandler*                        iSmsHandler;
       
   108     CMmsHandler*                        iMmsHandler;
       
   109     TInt                                iMessageCounter;
       
   110     HBufC*                                iMessage;
       
   111     }; 
       
   112 
       
   113 //  INCLUDES
       
   114 #include <e32base.h>
       
   115 #include <msvapi.h>
       
   116 #include <mtuireg.h>
       
   117 #include <txtrich.h>
       
   118 // CONSTANTS
       
   119 const TInt KBfrLength = 20;
       
   120 const TInt KTelephoneNumberMaxLength = 100;
       
   121  
       
   122 // FORWARD DECLARATIONS
       
   123 class CSmsAppUi;
       
   124 class CClientMtmRegistry;
       
   125 class CSmsClientMtm;
       
   126  
       
   127 // CLASS DECLARATION
       
   128 /**
       
   129 * CSmsHandler application engine class.
       
   130 * Takes care of sending and receiveing SMS messages using the SMS client MTM.
       
   131 * Interacts with the application UI class.
       
   132 */
       
   133 class CSmsHandler : public CActive, public MMsvSessionObserver
       
   134     {
       
   135     public: // Constructors and destructor
       
   136  
       
   137         /**
       
   138         * NewL.
       
   139         * Two-phased constructor.
       
   140         * @param aSmsAppUi Pointer to AppUi instance.
       
   141         * @return Pointer to the created instance of CSmsHandler.
       
   142         */
       
   143         static CSmsHandler* NewL( CMessageManager& aManager );
       
   144  
       
   145         /**
       
   146         * NewLC.
       
   147         * Two-phased constructor.
       
   148         * @param aSmsAppUi Pointer to AppUi instance.
       
   149         * @return Pointer to the created instance of CSmsHandler.
       
   150         */
       
   151         static CSmsHandler* NewLC( CMessageManager& aManager );
       
   152  
       
   153         /**
       
   154         * ~CSmsHandler
       
   155         * Destructor.
       
   156         */
       
   157         virtual ~CSmsHandler();
       
   158  
       
   159     public: // New functions
       
   160         /**
       
   161         * SendL.
       
   162         * Starts the process of creating and sending an SMS message.
       
   163         * @param aRecipientNumber The number of the recipent.
       
   164         * @param aMessageText The message text.
       
   165         * @return ETrue if successful, EFalse if not.
       
   166         */
       
   167        TBool SendL( const TDesC& aRecipientNumber,
       
   168                     const TDesC& aMessageText );
       
   169  
       
   170     public: // Functions from base classes
       
   171  
       
   172         /**
       
   173         * From MMsvSessionObserver, HandleSessionEventL.
       
   174         * Handles notifications of events from the Message Server.
       
   175         * @param aEvent The event that has taken place
       
   176         * @param aArg1 Event type-specific argument value
       
   177         * @param aArg2 Event type-specific argument value
       
   178         * @param aArg3 Event type-specific argument value
       
   179         */
       
   180         void HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1,
       
   181                                   TAny* aArg2, TAny* aArg3 );
       
   182  
       
   183     protected: // Functions from base classes
       
   184  
       
   185         /**
       
   186         * From CActive, DoCancel.
       
   187         * Cancels any outstanding requests.
       
   188         */
       
   189         void DoCancel();
       
   190  
       
   191         /**
       
   192         * From CActive, RunL.
       
   193         * Handles an active object’s request completion event.
       
   194         */
       
   195         void RunL();
       
   196  
       
   197     private: // Constructors
       
   198  
       
   199         /**
       
   200         * CSmsHandler.
       
   201         * C++ default constructor.
       
   202         * @param aSmsAppUi Pointer to AppUi instance.
       
   203         */
       
   204         CSmsHandler( CMessageManager& aManager );
       
   205  
       
   206         /**
       
   207         * ConstructL.
       
   208         * 2nd phase constructor.
       
   209         */
       
   210         void ConstructL();
       
   211  
       
   212     private: // New functions
       
   213  
       
   214         /**
       
   215         * AccessMtmL.
       
   216         * Access the MTM Registry and create an SMS specific Client MTM instance.
       
   217         */
       
   218         void AccessMtmL();
       
   219  
       
   220         /**
       
   221         * CreateMsgL.
       
   222         * Create an SMS message.
       
   223         * @return ETrue if successful, EFalse is unsuccessful.
       
   224         */
       
   225         TBool CreateMsgL();
       
   226  
       
   227         /**
       
   228         * ScheduleL.
       
   229         * Schedule an SMS message for sending.
       
   230         */
       
   231         void ScheduleL();
       
   232  
       
   233         /**
       
   234         * ValidateL.
       
   235         * Validate an SMS message.
       
   236         * @return ETrue if successful, EFalse is unsuccessful.
       
   237         */
       
   238         TBool ValidateL();
       
   239  
       
   240     private: // Enumeration
       
   241  
       
   242         /**
       
   243         * TState, enumeration for the state of the handler, used by RunL().
       
   244         */
       
   245         enum TState
       
   246             {
       
   247             EWaitingForMoving = 1,
       
   248             EWaitingForScheduling
       
   249             };
       
   250  
       
   251     private: // Data
       
   252  
       
   253         /**
       
   254         * iState, the state of the handler.
       
   255         */
       
   256         TState iState;
       
   257  
       
   258         /**
       
   259         * iSession, the contact database.
       
   260         * Owned by CSmsHandler object.
       
   261         */
       
   262         CMsvSession* iSession;
       
   263  
       
   264         /**
       
   265         * iMtmRegistry, client MTM registry.
       
   266         * Owned by CSmsHandler object.
       
   267         */
       
   268         CClientMtmRegistry* iMtmRegistry;
       
   269  
       
   270         /**
       
   271         * iSmsMtm, SMS specific Client MTM.
       
   272         * Owned by CSmsHandler object.
       
   273         */
       
   274         CSmsClientMtm* iSmsMtm;
       
   275  
       
   276         /**
       
   277         * iOperation, the current message server operation.
       
   278         * Owned by CSmsHandler object.
       
   279         */
       
   280         CMsvOperation* iOperation;
       
   281  
       
   282         /**
       
   283         * iRecipientNumber, telephone number of the recipient.
       
   284         */
       
   285         TBuf<KTelephoneNumberMaxLength> iRecipientNumber;
       
   286  
       
   287         /**
       
   288         * iMessageText, SMS message text.
       
   289         */
       
   290         TBuf<EMaxMessageLength> iMessageText;
       
   291 
       
   292  
       
   293         /**
       
   294         * iSmsAppUi, application UI
       
   295         * Not owned by CSmsHandler object.
       
   296         */
       
   297         CSmsAppUi* iSmsAppUi;
       
   298  
       
   299         /**
       
   300         * iMtmUiRegistry, User Interface MTM Registry.
       
   301         * Owned by CSmsHandler object.
       
   302         */
       
   303         CMtmUiRegistry* iMtmUiRegistry;
       
   304         
       
   305         CMessageManager& iManager;
       
   306  
       
   307     };
       
   308 
       
   309 
       
   310 // INCLUDES
       
   311 #include <msvapi.h>                         // for MMsvSessionObserver 
       
   312 #include <mmsclient.h>                      // for CMmsClientMtm
       
   313 #include <coecntrl.h>
       
   314 
       
   315 // Forward declarations
       
   316 class CClientMtmRegistry;
       
   317 class CMsvSession;
       
   318 
       
   319 //
       
   320 // Container class to draw text on screen
       
   321 //
       
   322 class CMmsHandler : public CBase, public MMsvSessionObserver
       
   323     {
       
   324 public: // Constructors and destructor
       
   325 
       
   326     /**
       
   327     * NewL.
       
   328     * Two-phased constructor.
       
   329     * @param aSmsAppUi Pointer to AppUi instance.
       
   330     * @return Pointer to the created instance of CSmsHandler.
       
   331     */
       
   332     static CMmsHandler* NewL( CMessageManager& aManager );
       
   333 
       
   334     /**
       
   335     * NewLC.
       
   336     * Two-phased constructor.
       
   337     * @param aSmsAppUi Pointer to AppUi instance.
       
   338     * @return Pointer to the created instance of CSmsHandler.
       
   339     */
       
   340     static CMmsHandler* NewLC( CMessageManager& aManager );
       
   341 
       
   342     /**
       
   343     * ~CSmsHandler
       
   344     * Destructor.
       
   345     */
       
   346     virtual ~CMmsHandler();
       
   347 
       
   348 private: // Constructors
       
   349 
       
   350     /**
       
   351     * CSmsHandler.
       
   352     * C++ default constructor.
       
   353     * @param aSmsAppUi Pointer to AppUi instance.
       
   354     */
       
   355     CMmsHandler( CMessageManager& aManager );
       
   356 
       
   357     /**
       
   358     * ConstructL.
       
   359     * 2nd phase constructor.
       
   360     */
       
   361     void ConstructL();
       
   362 
       
   363 public: // New functions
       
   364     
       
   365     /*
       
   366      * Creates client MTM registry when session is ready for use. 
       
   367      * This completes model construction and is called after 'server
       
   368      * ready' event is received after async opening of CMsvSession.
       
   369      */ 
       
   370     void CompleteConstructL();
       
   371        
       
   372     /*
       
   373      * CMmsHandler::CreateNewMessageL()
       
   374      * Creates a new message server entry and set up default values.
       
   375      * In case the attachment file does not found method return EFalse
       
   376      * otherwise ETrue.
       
   377      * There are differenses how to add attachment file between 2nd and 3rd edition.
       
   378      */  
       
   379      TBool CreateMsgL();
       
   380 
       
   381     /**
       
   382      * Send the message.
       
   383      * Return values: ETrue or EFalse
       
   384      */
       
   385     TBool SendMessageL();
       
   386         
       
   387      /**
       
   388       * SendL.
       
   389       * Starts the process of creating and sending an SMS message.
       
   390       * @param aRecipientNumber The number of the recipent.
       
   391       * @param aMessageText The message text.
       
   392       * @return ETrue if successful, EFalse if not.
       
   393       */
       
   394      TBool SendL( const TDesC& aRecipientNumber,
       
   395                  const TDesC& aMessageText );     
       
   396            
       
   397 private:    
       
   398     // from MMsvSessionObserver
       
   399     void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
       
   400   
       
   401     void SetMessageBodyL();
       
   402 
       
   403 private:
       
   404 
       
   405     CMsvSession* iSession;          // Client session on the message server
       
   406     CMmsClientMtm* iMmsMtm;         // Message Type Module (MMS)
       
   407     CClientMtmRegistry* iMtmReg;    // Mtm client registry for creating new mtms
       
   408 
       
   409     /**
       
   410     * iRecipientNumber, telephone number of the recipient.
       
   411     */
       
   412     TBuf<KTelephoneNumberMaxLength> iRecipientNumber;
       
   413 
       
   414     /**
       
   415     * iMessageText, SMS message text.
       
   416     */
       
   417     TBuf<EMaxMessageLength> iMessageText;
       
   418     
       
   419     CMessageManager& iManager;
       
   420     
       
   421     };
       
   422 #endif // LOADGEN_MESSAGES_H