examples/ForumNokia/Symbian_OS_End-to-End_Sockets_API_Example/SocketTaskManager_S60/inc/TaskManagerEngine.h

00001 /*
00002 * ============================================================================
00003 *  Name     : CTaskManagerEngine from TaskManagerEngine.h
00004 *  Part of  : TaskManager
00005 *  Created  : 15/03/2006 by Forum Nokia
00006 *  Version  : 1.2
00007 *  Copyright: Nokia Corporation
00008 * ============================================================================
00009 */
00010 
00011 #ifndef __TASKMANAGERENGINE_H
00012 #define __TASKMANAGERENGINE_H
00013 
00014 // INCLUDE FILES
00015 #include "TaskManager.hrh"
00016 #include "TaskManagerEngineReader.h"
00017 #include "timeouttimer.h"
00018 #include "request.h"
00019 
00020 #include <in_sock.h>                                            //TInetAddr
00021 #include <msvapi.h>                                                     //MMsvSessionObserver
00022 #include <cdblen.h>                                                     //KCommsDbSvrMaxFieldLength
00023 #include <es_sock.h>                                            //TSockXfrLength
00024 
00025 // FORWARD DECLARATIONS
00026 class CSecureSocket;
00027 class CResponse;
00028 
00029 // CLASS DECLARATION
00030 
00034 class MTransactionObserver
00035         {
00036 public:
00040         virtual void OpeningConnectionL() = 0;
00041         
00046         virtual void SuccessL(const CResponse& aResponse) = 0;
00047         
00052         virtual void FailedL(const TInt& aError) = 0;
00053         
00058         virtual void ConnectingToServerL(const TBool& aLoadingTasks) = 0;
00059         
00063         virtual void CancelledL() = 0;
00064         
00070         virtual void ErrorL(const TDesC& aErrorMsg) = 0;
00071         };
00072 
00073 // CLASS DECLARATION
00074 
00078 class TIap
00079         {
00080 public:
00081         TUint32 iId;
00082         TBuf<KCommsDbSvrMaxFieldLength> iName;
00083         };
00084         
00085 
00086 // CLASS DECLARATION
00087 
00093 class CTaskManagerEngine :      public CActive,
00094                                                         public MMsvSessionObserver,
00095                                                         public MEngineNotifier,
00096                                                         public MTimeoutNotifier
00097         {
00098 public: // Constructors and destructor
00099 
00103         static CTaskManagerEngine* NewL(MTransactionObserver& aObserver);
00104 
00108         ~CTaskManagerEngine();
00109         
00110 protected: // from CActive
00111 
00115    void DoCancel();
00116 
00120    void RunL();
00121    
00125    TInt RunError( TInt aError );
00126         
00127 public: // Main interface for engine logic
00128         
00136         void SetConnectionSettings(const TDesC& aServerName, 
00137                                                                 const TInt& aPort,
00138                                                                 const TDesC& aUsername, 
00139                                                                 const TDesC& aPassword);
00140                                                                 
00145         void FetchTasksL();
00146         
00151         void MarkTaskDoneL(const TInt& aTaskId);
00152 
00156         void CheckRefreshL();
00157 
00158 public: // from MEngineNotifier
00159 
00164     TBool PackageReceivedL( const TDesC8& aData );
00165 
00166 public: // MTimeoutNotifier
00167 
00171     void TimerExpired();
00172 
00173 public: // New functions
00174 
00179         void SetIap(const TUint32& aId);
00180         
00184         void CancelTransaction();
00185         
00190         TBool IapSet() const;
00191         
00196         RArray<TIap>& Iaps();
00197 
00203     void SetAutomaticUpdateL(const TBool& aOn);
00204         
00205 private: // Functions from base classes
00206 
00210         void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
00211                 
00212 private: // New functions
00213 
00217         void LoadIapsL();
00218         
00222         void ConnectL();
00223         
00228         void ConnectL( TUint32 aAddr );
00229         
00235         TBool CheckAndReportErrorsL();
00236         
00240         void GPRSConnectL();
00241         
00245         void EndConnection();
00246         
00247 private:
00248 
00252         CTaskManagerEngine(MTransactionObserver& aObserver);
00253         void ConstructL();
00254         
00255         enum TEngineState
00256                 {
00257                 // Connection enums
00258                 ENotConnected = 1,
00259                 EStartingGPRS,
00260         ELookingUp,
00261                 EConnecting,
00262                 ESSLConnecting,
00263                 EConnected,
00264                 
00265                 // Transmission enums
00266                 EWriting,
00267                 EReading
00268                 };
00269         
00270 private: // Data members
00271 
00272     // Timeout-constant, defined in .cpp
00273     static const TInt           KTimeOut;
00274 
00275     // Socket handles and variables
00276         RSocketServ                                     iSocketServer;
00277         RSocket                                         iSocket;
00278         RConnection                                     iConnection;
00279         CSecureSocket*              iSecureSocket;
00280         TInetAddr                                       iAddress;
00281 
00282     // State of engine
00283         TEngineState                            iState;
00284         
00285     // Timeout timer
00286         CTimeOutTimer*              iTimer;
00287         
00288         // Which operation is being performed
00289         TRequest::TOperationType        iOperation;
00290         
00291         // If the operation is "mark task", the id of
00292         // the task is stored here.
00293         TBuf<5>                                         iMarkId;
00294         
00295         // DNS resolver
00296         RHostResolver                           iResolver;
00297 
00298         // Result from DNS resolver
00299         TNameEntry                                      iNameEntry;
00300         TNameRecord                             iNameRecord;
00301 
00302     // Message server observation
00303         CMsvSession*                            iMsvSession;
00304         CMsvEntry*                                      iMsvEntry;
00305 
00306     // Handle to inform view
00307         MTransactionObserver&           iTransactionObserver;
00308         
00309         // User variables
00310         TBuf<KMaxUsernameLength>        iUsername;
00311         TBuf<KMaxPasswordLength>        iPassword;
00312         TBuf<KMaxServerNameLength>      iServer;
00313         TInt                                            iPort;
00314         
00315         // Write message buffer
00316         TBuf8<KMaxWriteBufferSize>      iWriteBuffer;
00317         
00318         // Active object for reading inbound streams
00319     CTaskManagerEngineReader*   iReader;
00320     
00321         // Parser class, hides the structure of messages from the engine
00322         CResponse*                  iResponse;
00323         
00324         // The amount of data read is stored here
00325         TSockXfrLength                          iDummyLength;
00326         
00327         TBool                                           iRunning;
00328         TBool                                           iDoRefresh;
00329         TBool                       iOpeningConnection;
00330         RArray<TIap>                            iIAPs;
00331         TUint32                                         iIap;
00332         TBool                                           iAutomaticUpdate;
00333         };
00334 
00335 #endif
00336 
00337 // End of file
00338 
00339 
00340 

Generated by  doxygen 1.6.2