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