IMPSengine/engsrv/inc/impssession.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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: Classes used to describe IMSP CSP session.
       
    15 *              Major for Imps Session.
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CImpsSession_H
       
    20 #define CImpsSession_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include "impsclientsrv.h"
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class CImpsServer;
       
    28 class CImpsSubSession;
       
    29 class CImpsVariant;
       
    30 
       
    31 // CLASS DECLARATION
       
    32 
       
    33 /**
       
    34 *  Common event for all client session types
       
    35 */
       
    36 class CWvEvent : public CBase    // a notify event
       
    37     {
       
    38     public:
       
    39         CWvEvent( TImpsEventType aType );
       
    40         ~CWvEvent();
       
    41         void Destroy();
       
    42 
       
    43         TImpsEventType      iType;      // notification type, see impsconst.h
       
    44         TImpsServRequest    iRequestType;
       
    45         TImpsMessageType    iMessageType;  // response message
       
    46         TInt                iReqMesType;   // request type
       
    47         TBool               iSent;      // sent to client
       
    48         TInt                iOpCode;    // op-id
       
    49         TInt                iStatus;
       
    50         TInt                iAux;       // auxiliary for small data
       
    51         HBufC8*             iPackedMessage;
       
    52         TDblQueLink         iLink;
       
    53     };
       
    54 
       
    55 /**
       
    56 *  Common request data for all service session types
       
    57 */
       
    58 class CRequest : public CBase
       
    59     {
       
    60     public:
       
    61         CRequest(
       
    62             const TDesC& aTID,
       
    63             TInt aOpId,
       
    64             TImpsServRequest aRequestType,
       
    65             TTime aExpiry,
       
    66             TImpsMessageType aMessageType );
       
    67         ~CRequest();
       
    68         void Destroy();
       
    69 
       
    70         TBuf<KImpsMaxTID> iTID;          // CSP TID
       
    71         TInt             iOpId;
       
    72         TImpsServRequest iRequestType;
       
    73         TImpsMessageType iMessageType;
       
    74         TTime            iExpiry;
       
    75         TDblQueLink      iLink;
       
    76     };
       
    77 
       
    78 
       
    79 /**
       
    80 *  SOS Client-server framework session for WV engine
       
    81 */
       
    82 class CImpsSession : public CSession2
       
    83     {
       
    84     public:  // Constructors and destructor
       
    85 
       
    86         /**
       
    87         * C++ default constructor.
       
    88         * @param aClient client thread
       
    89         */
       
    90         CImpsSession( RMessage2& aMsg );
       
    91 
       
    92         /**
       
    93         * Destructor.
       
    94         */
       
    95         virtual ~CImpsSession();
       
    96 
       
    97     public: // New functions
       
    98 
       
    99         /**
       
   100         * Handles a client request; tests the opcode and gives
       
   101         * service according to that. ServiceL calls this.
       
   102         * @param aMessage service request from client
       
   103         */
       
   104         void DispatchMessageL( const RMessage2& aMessage );
       
   105 
       
   106         /**
       
   107         * Search pending request using CSP transaction-id
       
   108         * @param aTid transaction-id
       
   109         * @param aOpId op-id if matching one found (OUT)
       
   110         * @param aRequestType request type if found (OUT)
       
   111         * @param aReqMsgType request CSP primitive if found (OUT)
       
   112         * @param aCSP CSP connection id
       
   113         * @return subsession handle if search match
       
   114         */
       
   115         TUint CheckRequests(
       
   116             const TDesC& aTid,
       
   117             TInt& aOpId,
       
   118             TImpsServRequest& aRequestType,
       
   119             TImpsMessageType& aReqMsgType,
       
   120             TImpsSessIdent aCSP );
       
   121 
       
   122         /**
       
   123         * Discard expired pending requests and send error event to client
       
   124         * @param aExpiryTime expiry time interval
       
   125         * @param aServiceType service type considered
       
   126         * @param aSess CSP session entity
       
   127         */
       
   128         void DiscardRequests(
       
   129             TTime aExpiryTime,
       
   130             TImpsEventType aServiceType,
       
   131             TImpsSessIdent aCSP,
       
   132             MImpsCSPSession* aSess );
       
   133 
       
   134         /**
       
   135         * Discard expired pending requests and send error event to client
       
   136         * @param aError error code to be sent
       
   137         * @param aServiceType service type considered
       
   138         * @param aSess CSP session entity
       
   139         */
       
   140         void DiscardRequests(
       
   141             TInt aError,
       
   142             TImpsEventType aServiceType,
       
   143             TImpsSessIdent aCSP,
       
   144             MImpsCSPSession* aSess );
       
   145 
       
   146         /**
       
   147         * Discard a pending request and send an error event to client
       
   148         * @param aTid transaction-id
       
   149         * @param aServiceType service type considered
       
   150         * @param aCode error code
       
   151         * @param aSess CSP session entity
       
   152         * @return ETrue if request found and deleted
       
   153         */
       
   154         TBool DiscardRequest(
       
   155             const TDesC& aTid,
       
   156             TImpsEventType aServiceType,
       
   157             TInt aCode,
       
   158             TImpsSessIdent aCSP );
       
   159 
       
   160         /**
       
   161         * Minimum expiry time accessor
       
   162         * @return expiry time of subsession in seconds
       
   163         */
       
   164         TInt ExpiryTime();
       
   165 
       
   166 
       
   167         /**
       
   168         * Send or buffer new event to client
       
   169         * @param aFields data to be sent
       
   170         * @param aOpId corresponding op-id
       
   171         * @param aRequestType request type
       
   172         * @param aReqMsgType requesting CSP primitive starting
       
   173         *        transaction if this client has initiated it.
       
   174         * @param aHandle subsession handle
       
   175         */
       
   176         void SendEvent(
       
   177             CImpsFields* aFields,
       
   178             TInt aOpId,
       
   179             TImpsServRequest aRequestType,
       
   180             TImpsMessageType aReqMsgType,
       
   181             TUint aHandle );
       
   182 
       
   183         /**
       
   184         * Send Logout event only for Access clients (=session type)
       
   185         * @param aRespStatus response status caused this
       
   186         * @param aOpId op-id, optional
       
   187         * @param aSub subsession that is ignored.
       
   188         * @param aHandle subsession that is handled only.
       
   189         */
       
   190         void SendLogoutEvent(
       
   191             TInt aRespStatus,
       
   192             TInt aOpId,
       
   193             CImpsSubSession* aSub,
       
   194             TUint aHandle );
       
   195 
       
   196         /**
       
   197         * Send or buffer new status event to client
       
   198         * @param aStatus new status
       
   199         */
       
   200         void SendEvent(
       
   201             EImpsInternalStatus aStatus );
       
   202 
       
   203         /**
       
   204         * Check if notification should be sent when TID not given
       
   205         * This means usually SAP originated transaction.
       
   206         * @param aFields data received from SAP.
       
   207         * @param aCSP CSP connection id
       
   208         * @return ETrue if matching client found (client-id and
       
   209         * media type ok)
       
   210         */
       
   211         TBool CheckNotifications( CImpsFields* aFields, TImpsSessIdent aCSP );
       
   212 
       
   213         /**
       
   214         * Check all orphan messages from engine
       
   215         */
       
   216         void HandleAllOrphans();
       
   217 
       
   218         /**
       
   219         * Close the session
       
   220         */
       
   221         void CloseSession();
       
   222 
       
   223         /**
       
   224         * Delete all waiting client requests.
       
   225         */
       
   226         void DeleteAllRequests( );
       
   227 
       
   228         /**
       
   229         * Delete all waiting client requests.
       
   230         * @param aCSP CSP connection indetification
       
   231         */
       
   232         void DeleteAllRequests( TImpsSessIdent* aCSP );
       
   233 
       
   234         /**
       
   235         * Delete a specified client request
       
   236         * @param aOpId corresponding op-id
       
   237         * @param aSubHandle subsession handle
       
   238         */
       
   239         void DeleteRequest( TInt aOpId, TUint aSubHandle );
       
   240 
       
   241         /**
       
   242         * ApplicationId accessor
       
   243         * @return ApplicationId
       
   244         */
       
   245         TPtrC ApplicationId();
       
   246 
       
   247         /**
       
   248         * Complete the pending message and set the session status
       
   249         * @param aStatus completation status
       
   250         */
       
   251         void CompleteMe( TInt aStatus );
       
   252 
       
   253         /**
       
   254         * Reads the 8-bit data from client to the buffer
       
   255         * @param aIndex pointer to the message index
       
   256         * @param aBuffer target buffer in server memory.
       
   257         *        Buffer is reallocated if necessary.
       
   258         * @return ETrue if new buffer is allocated
       
   259         */
       
   260         TBool ReadBuffer8L(
       
   261             TInt aIndex,
       
   262             HBufC8*& aBuffer );
       
   263 
       
   264         /**
       
   265         * Delete a subsession
       
   266         * @param aHandle subsession id
       
   267         */
       
   268         void DeleteSubSession( TUint aHandle );
       
   269 
       
   270         /**
       
   271         * Check if CSP session connection matches
       
   272         * @param aCSP CSP connection indetification
       
   273         * @return aTrue if matches
       
   274         */
       
   275         TBool MatchSession( TImpsSessIdent aCSP );
       
   276 
       
   277         /**
       
   278         * Indicate that the message request has been completed
       
   279         */
       
   280         inline void SetCompleted();
       
   281 
       
   282         /**
       
   283         * Server accessor, wrapper for CSharableSession::Server()
       
   284         * @return current server instance
       
   285         */
       
   286         inline CImpsServer* CImpsSession::Server();  //lint !e1511
       
   287 
       
   288         /**
       
   289         * Get current message of this session
       
   290         * That's for CImpsServer only
       
   291         * @return last data sent by client API
       
   292         */
       
   293         inline CImpsFields* ImpsFields() const;
       
   294 
       
   295         /**
       
   296         * Get buffer for streamed message
       
   297         * @return buffer
       
   298         */
       
   299         inline HBufC8* StreamBuf() const;
       
   300 
       
   301         /**
       
   302         * Get buffer for streamed message
       
   303         * @return buffer
       
   304         */
       
   305         inline HBufC8** StreamBufAddr();
       
   306 
       
   307         /**
       
   308         * Create new data structure without deleting old one.
       
   309         * That's for a server if it has to queue current request.
       
   310         */
       
   311         void NewFieldsL();
       
   312 
       
   313         /**
       
   314         * Is this CIR watcher session
       
   315         * @return ETrue this is CIR watcher session.
       
   316         */
       
   317         inline TBool IsCIRWatcherSession() const;
       
   318 
       
   319         /**
       
   320         * Subsession (service) types of this session
       
   321         * @return event type bit mask
       
   322         */
       
   323         inline TInt Types() const;
       
   324 
       
   325         /**
       
   326         * Number of subsessions
       
   327         */
       
   328         inline TInt NbrSubs() const;
       
   329 
       
   330         /**
       
   331         * Current message
       
   332         */
       
   333         inline RMessagePtr2 Message() const;
       
   334 
       
   335         // multi:
       
   336         /**
       
   337         * user-id mutator
       
   338         * @param aId user-id
       
   339         */
       
   340         void SetUserIdL( const TDesC& aId );
       
   341 
       
   342         /**
       
   343         * Clean CSP session-id
       
   344         */
       
   345         void CleanSID();
       
   346 
       
   347         /**
       
   348         * CSP Session-id mutator
       
   349         * @param aSID session-id
       
   350         */
       
   351         void ModifySIDL( const TDesC& aSID );
       
   352 
       
   353         /**
       
   354         * CSP Session-id accessor
       
   355         * @return aId user-id
       
   356         */
       
   357         inline TPtrC SID( ) const;
       
   358 
       
   359         /**
       
   360         * client-id accessor
       
   361         * @return aId user-id
       
   362         */
       
   363         inline TPtrC UserId( ) const;
       
   364 
       
   365         /**
       
   366         * SAP mutator
       
   367         * @param aId SAP address
       
   368         */
       
   369         void SetSAPL( const TDesC& aId );
       
   370 
       
   371         /**
       
   372         * SAP accessor
       
   373         * @return aId user-id
       
   374         */
       
   375         inline TPtrC SAP( ) const;
       
   376 
       
   377         /**
       
   378         * Is this session logged in
       
   379         */
       
   380         inline TBool IsThisLogged() const;
       
   381 
       
   382 
       
   383     public: // Functions from base classes
       
   384 
       
   385         /**
       
   386          * From CSharableSession (pure virtual)
       
   387          * Handles service request messages from clients.
       
   388          * @param aMessage message from client
       
   389          */
       
   390         void ServiceL( const RMessage2& aMessage );
       
   391 
       
   392     protected:  // Functions from base classes
       
   393 
       
   394         /**
       
   395         * From CSharableSession::CreateL
       
   396         * @param aServer WV engine server core and soul
       
   397         */
       
   398         // void CreateL( const CServer& aServer );
       
   399         void CreateL();
       
   400 
       
   401     private: // New functions
       
   402 
       
   403         /**
       
   404         * New subsession creation
       
   405         * @param aType subsession type
       
   406         * @param aMessage client request
       
   407         */
       
   408         void NewSubSessionL(
       
   409             TImpsEventType aType,
       
   410             const RMessage2& aMessage );
       
   411 
       
   412         /**
       
   413         * Subsession handle accessor
       
   414         * @param aHandle 4th client-server parameter
       
   415         * @return Subsession entity
       
   416         */
       
   417         CImpsSubSession* ConnectionFromHandle( TUint aHandle );
       
   418 
       
   419         /**
       
   420         * Panics the client thread
       
   421         * @param aPanic panic reason
       
   422         */
       
   423         void PanicClient( TImpsPanic aPanic ) const;
       
   424 
       
   425         /**
       
   426         * Current service tree
       
   427         * Sends current negotiated service tree to a client thread.
       
   428         */
       
   429         void CurrentServicesL();
       
   430 
       
   431         /**
       
   432         * Push message generation
       
   433         */
       
   434         void PushMessageL();
       
   435 
       
   436         /**
       
   437         * set this client session inactive, i.e. messages should not be sent
       
   438         * Login request makes this session active again althogh creation
       
   439         * of new session is preferred way to make a new CSP login.
       
   440         */
       
   441         void SetThisInactive();
       
   442 
       
   443         /**
       
   444         * Assign the application id
       
   445         */
       
   446         void AssignIdL();
       
   447 
       
   448         // By default, prohibit copy constructor
       
   449         CImpsSession( const CImpsSession& );
       
   450         // Prohibit assigment operator
       
   451         CImpsSession& operator= ( const CImpsSession& );
       
   452 
       
   453         /**
       
   454         * Is this client session active, i.e. messages should be sent
       
   455         * @return ETrue if this is active
       
   456         */
       
   457         inline TBool IsThisActive() const;
       
   458 
       
   459         /**
       
   460         * CSP session specific client-server session counter
       
   461         * @return number of sessions
       
   462         */
       
   463         TInt NbrOfSessionsL( );
       
   464 
       
   465 
       
   466     private:    // Data
       
   467         TBool               iCanceled;
       
   468 
       
   469         HBufC*              iApplicationId;  // application id
       
   470         HBufC*              iSID;       // CSP Session-id
       
   471         HBufC*              iSAP;
       
   472         HBufC*              iUserId;    // CSP user-id
       
   473 
       
   474         TBuf<KImpsMaxTID>   iLogoutTID;
       
   475 
       
   476         HBufC8*             iStream;   // message stream between client->server
       
   477         CImpsFields*        iFields;   // current message in unpacked form
       
   478         TBool               iMessageCompleted;  // if the session is not active
       
   479 
       
   480         TBool               iCIRSess;   // Is this CIR watcher session
       
   481 
       
   482         CObjectIx*          iSubSessions; // object index which stores subsessions
       
   483         CObjectCon*         iContainer;   // object container for this session
       
   484         TInt                iResourceCount;
       
   485         TUint               iTypes; // bit mask of supported services
       
   486 
       
   487         RMessagePtr2        iMsgR;      // current client-server request
       
   488     };
       
   489 
       
   490 #include "ImpsSession.inl"
       
   491 
       
   492 #endif
       
   493 
       
   494 // End of File