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

00001 /*
00002  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef __TASKMANAGERENGINE_H
00031 #define __TASKMANAGERENGINE_H
00032 
00033 // INCLUDE FILES
00034 #include "TaskManager.hrh"
00035 #include "TaskManagerEngineReader.h"
00036 #include "timeouttimer.h"
00037 #include "request.h"
00038 
00039 #include <in_sock.h>                                            //TInetAddr
00040 #include <msvapi.h>                                                     //MMsvSessionObserver
00041 #include <cdblen.h>                                                     //KCommsDbSvrMaxFieldLength
00042 #include <es_sock.h>                                            //TSockXfrLength
00043 
00044 // FORWARD DECLARATIONS
00045 class CSecureSocket;
00046 class CResponse;
00047 
00048 // CLASS DECLARATION
00049 
00053 class MTransactionObserver
00054         {
00055 public:
00059         virtual void OpeningConnectionL() = 0;
00060         
00065         virtual void SuccessL(const CResponse& aResponse) = 0;
00066         
00071         virtual void FailedL(const TInt& aError) = 0;
00072         
00077         virtual void ConnectingToServerL(const TBool& aLoadingTasks) = 0;
00078         
00082         virtual void CancelledL() = 0;
00083         
00089         virtual void ErrorL(const TDesC& aErrorMsg) = 0;
00090         };
00091 
00092 // CLASS DECLARATION
00093 
00097 class TIap
00098         {
00099 public:
00100         TUint32 iId;
00101         TBuf<KCommsDbSvrMaxFieldLength> iName;
00102         };
00103         
00104 
00105 // CLASS DECLARATION
00106 
00112 class CTaskManagerEngine :      public CActive,
00113                                                         public MMsvSessionObserver,
00114                                                         public MEngineNotifier,
00115                                                         public MTimeoutNotifier
00116         {
00117 public: // Constructors and destructor
00118 
00122         static CTaskManagerEngine* NewL(MTransactionObserver& aObserver);
00123 
00127         ~CTaskManagerEngine();
00128         
00129 protected: // from CActive
00130 
00134    void DoCancel();
00135 
00139    void RunL();
00140    
00144    TInt RunError( TInt aError );
00145         
00146 public: // Main interface for engine logic
00147         
00155         void SetConnectionSettings(const TDesC& aServerName, 
00156                                                                 const TInt& aPort,
00157                                                                 const TDesC& aUsername, 
00158                                                                 const TDesC& aPassword);
00159                                                                 
00164         void FetchTasksL();
00165         
00170         void MarkTaskDoneL(const TInt& aTaskId);
00171 
00175         void CheckRefreshL();
00176 
00177 public: // from MEngineNotifier
00178 
00183     TBool PackageReceivedL( const TDesC8& aData );
00184 
00185 public: // MTimeoutNotifier
00186 
00190     void TimerExpired();
00191 
00192 public: // New functions
00193 
00198         void SetIap(const TUint32& aId);
00199         
00203         void CancelTransaction();
00204         
00209         TBool IapSet() const;
00210         
00215         RArray<TIap>& Iaps();
00216 
00222     void SetAutomaticUpdateL(const TBool& aOn);
00223         
00224 private: // Functions from base classes
00225 
00229         void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
00230                 
00231 private: // New functions
00232 
00236         void LoadIapsL();
00237         
00241         void ConnectL();
00242         
00247         void ConnectL( TUint32 aAddr );
00248         
00254         TBool CheckAndReportErrorsL();
00255         
00259         void GPRSConnectL();
00260         
00264         void EndConnection();
00265         
00266 private:
00267 
00271         CTaskManagerEngine(MTransactionObserver& aObserver);
00272         void ConstructL();
00273         
00274         enum TEngineState
00275                 {
00276                 // Connection enums
00277                 ENotConnected = 1,
00278                 EStartingGPRS,
00279         ELookingUp,
00280                 EConnecting,
00281                 ESSLConnecting,
00282                 EConnected,
00283                 
00284                 // Transmission enums
00285                 EWriting,
00286                 EReading
00287                 };
00288         
00289 private: // Data members
00290 
00291     // Timeout-constant, defined in .cpp
00292     static const TInt           KTimeOut;
00293 
00294     // Socket handles and variables
00295         RSocketServ                                     iSocketServer;
00296         RSocket                                         iSocket;
00297         RConnection                                     iConnection;
00298         CSecureSocket*              iSecureSocket;
00299         TInetAddr                                       iAddress;
00300 
00301     // State of engine
00302         TEngineState                            iState;
00303         
00304     // Timeout timer
00305         CTimeOutTimer*              iTimer;
00306         
00307         // Which operation is being performed
00308         TRequest::TOperationType        iOperation;
00309         
00310         // If the operation is "mark task", the id of
00311         // the task is stored here.
00312         TBuf<5>                                         iMarkId;
00313         
00314         // DNS resolver
00315         RHostResolver                           iResolver;
00316 
00317         // Result from DNS resolver
00318         TNameEntry                                      iNameEntry;
00319         TNameRecord                             iNameRecord;
00320 
00321     // Message server observation
00322         CMsvSession*                            iMsvSession;
00323         CMsvEntry*                                      iMsvEntry;
00324 
00325     // Handle to inform view
00326         MTransactionObserver&           iTransactionObserver;
00327         
00328         // User variables
00329         TBuf<KMaxUsernameLength>        iUsername;
00330         TBuf<KMaxPasswordLength>        iPassword;
00331         TBuf<KMaxServerNameLength>      iServer;
00332         TInt                                            iPort;
00333         
00334         // Write message buffer
00335         TBuf8<KMaxWriteBufferSize>      iWriteBuffer;
00336         
00337         // Active object for reading inbound streams
00338     CTaskManagerEngineReader*   iReader;
00339     
00340         // Parser class, hides the structure of messages from the engine
00341         CResponse*                  iResponse;
00342         
00343         // The amount of data read is stored here
00344         TSockXfrLength                          iDummyLength;
00345         
00346         TBool                                           iRunning;
00347         TBool                                           iDoRefresh;
00348         TBool                       iOpeningConnection;
00349         RArray<TIap>                            iIAPs;
00350         TUint32                                         iIap;
00351         TBool                                           iAutomaticUpdate;
00352         };
00353 
00354 #endif
00355 
00356 // End of file
00357 
00358 
00359 

Generated by  doxygen 1.6.2