presencecache/presencecachesymbian/presencecacheserver2/inc/presencecachesession.h
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 /*
       
     2 * Copyright (c) 2007, 2008 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:  Header file for Presence Cache Server session
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PRESENCECACHESESSION_H
       
    20 #define PRESENCECACHESESSION_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 
       
    25 #include <badesca.h>
       
    26 
       
    27 #include "presencecachedefs2.h"
       
    28 
       
    29 /**
       
    30  * Presence cache server session class.
       
    31  * @since S60 v3.2
       
    32  */
       
    33 // FORWARD DECLARATIONS
       
    34 class CPresenceCacheServer;
       
    35 class MPresenceInfo;
       
    36 class MPresenceBuddyInfo2;
       
    37 class CCacheSessionActiveHelper;
       
    38 class CPresenceCacheBuddyStore;
       
    39 class CPresenceCacheEvent;
       
    40 
       
    41 //Include Cache server namespace
       
    42 using namespace NCacheSrv2;
       
    43 
       
    44 class CPresenceCacheSession : public CSession2
       
    45     {
       
    46     friend class CCacheSessionActiveHelper;
       
    47     public: // Constructors and destructors
       
    48 
       
    49         /**
       
    50         * Two-phased constructor.
       
    51         * @param aServer The server.
       
    52         * @return Pointer to created CPresenceCacheSession object.
       
    53         */
       
    54         static CPresenceCacheSession* NewL( CPresenceCacheServer& aServer );
       
    55 
       
    56         /**
       
    57         * Two-phased constructor.
       
    58         * @param aServer The server.
       
    59         * @return Pointer to created CPresenceCacheSession object.
       
    60         */
       
    61         static CPresenceCacheSession* NewLC( CPresenceCacheServer& aServer );
       
    62 
       
    63         /**
       
    64         * ~CPresenceCacheSession.
       
    65         * Destructor.
       
    66         */
       
    67         virtual ~CPresenceCacheSession();
       
    68         
       
    69     public: // Functions from base classes
       
    70 
       
    71         /**
       
    72         * From CSession
       
    73         */
       
    74         void ServiceL( const RMessage2& aMessage );
       
    75         
       
    76     public: // own
       
    77         
       
    78         /**
       
    79         * This is called by some other session to inform this session that given
       
    80         * buddy's presence has been changed. The informing session first make
       
    81         * sure that this session has subscribed for the changes in given buddy.
       
    82         *
       
    83         *@param pointer to CPresenceBuddyInfoImp, ownership doesnt transfer.
       
    84         */
       
    85         void NotifyPresenceChangeL(const MPresenceBuddyInfo2* aPresenceBuddyInfo);             
       
    86 
       
    87     private: // Constructors and destructors
       
    88 
       
    89         /**
       
    90         * C++ default constructor.
       
    91         * @param aServer The server.
       
    92         */
       
    93         CPresenceCacheSession( CPresenceCacheServer& aServer );
       
    94 
       
    95         /**
       
    96         * Construct.
       
    97         * 2nd phase constructor
       
    98         */
       
    99 		void ConstructL();
       
   100 
       
   101     private: // New methods
       
   102 
       
   103         /**
       
   104         * Packs PresenceInfo object into a data packet.
       
   105         * @param aPresInfo PresenceInfo object.
       
   106         * @return HBufC* data packet.
       
   107         */
       
   108         HBufC8* PackPresenceInfoLC(const MPresenceBuddyInfo2& aPresInfo);        
       
   109         
       
   110         /**
       
   111         * Cancels the async request, this is called by docancel of active helper
       
   112         */
       
   113         void Cancel();
       
   114         
       
   115         /**
       
   116         * Tries writing given buddy to presence cache
       
   117         * @param aBuddyPresInfo object to write.
       
   118         * @return TInt error code
       
   119         */
       
   120         TInt TryWriteBuddyToCacheL(MPresenceBuddyInfo2* aBuddyPresInfo);
       
   121         
       
   122         
       
   123         /**
       
   124         * Removes all subscriptions stored by this session in iSubscribedStores
       
   125         */
       
   126         void RemoveMySubscriptions();
       
   127         
       
   128         /**
       
   129         * Notify to subscribers in given buddy store's presence change. This method
       
   130         * goes through all subscribed sessions and call their NotifyPresenceChangeL
       
   131         * methods. Ownership of store is not transferred.
       
   132         * 
       
   133         * @param aBuddyStore pointer to changed CPresenceCacheBuddyStore
       
   134         */
       
   135         void NotifyAllSubscribersL(CPresenceCacheBuddyStore* aBuddyStore);
       
   136         
       
   137         /**
       
   138         * Pack buddy's presence info into descriptor.
       
   139         * 
       
   140         * @param aBuddyPresInfo buddy's presence info, ownership doesnt transfer
       
   141         * @param HBufC8* packed presence info
       
   142         */
       
   143         HBufC8* PackBuddyPresenceInfoLC(
       
   144             const MPresenceBuddyInfo2* aBuddyPresInfo );
       
   145                                     // const CPresenceBuddyInfoImp* aBuddyPresInfo);
       
   146         
       
   147         void EmptyNotificationQueue();
       
   148 
       
   149         /**
       
   150          * Add into event queueu
       
   151          * @param aMsg message contect, ownership is taken in successful case
       
   152          */
       
   153         void AddIntoQueueL( HBufC8* aMsg );
       
   154 
       
   155         /**
       
   156          * Write next event into client.
       
   157          */
       
   158         void SendNextEventL( const RMessage2& aMessage );  
       
   159         
       
   160         /**
       
   161          * Complete pending notification wait in client if there is an event in the event queue.
       
   162          */
       
   163         void SendNextEventNotificationL();        
       
   164         
       
   165     
       
   166      private: // New Massage processors, these are called to process messages.
       
   167         void HandlePrepReadPresenceInfoSyncL(const RMessage2& aMessage );
       
   168         
       
   169         void HandleWritePresenceInfoSyncL(const RMessage2& aMessage ); 
       
   170         
       
   171         void HandleGetLastPreparedPacketL( const RMessage2& aMessage );
       
   172         
       
   173         void HandleGetLastPreparedAsyncPacketL( const RMessage2& aMessage );
       
   174         
       
   175         void HandleBuddyCountInAllServicesL(const RMessage2& aMessage ); 
       
   176         
       
   177         void HandleBuddyCountInServiceL(const RMessage2& aMessage );
       
   178         
       
   179         void HandleWritePresenceInfoAsyncL(const RMessage2& aMessage );
       
   180         
       
   181         void HandlePrepReadAllBuddiesPresenceInService(const RMessage2& aMessage );
       
   182                 
       
   183         void HandleGetServiceCountL(const RMessage2& aMessage );
       
   184         
       
   185         void HandleDeleteServiceL(const RMessage2& aMessage );
       
   186         
       
   187         void HandleCancel(const RMessage2& aMessage );
       
   188         
       
   189         void HandleDeletePresenceL(const RMessage2& aMessage );
       
   190         
       
   191         
       
   192         // subscribe notification related
       
   193         void HandleSubscribeBuddyPresenceChangeL(const RMessage2& aMessage );
       
   194         
       
   195         void HandleUnSubscribeBuddyPresenceChangeL(const RMessage2& aMessage );
       
   196         
       
   197         void HandleGetLastNotifiedtPacketL(const RMessage2& aMessage );
       
   198         
       
   199         void HandleWaitingForNotificationL(const RMessage2& aMessage );
       
   200         
       
   201         void HandleCancelWaitingForNotification(const RMessage2& aMessage );
       
   202         
       
   203     
       
   204     private:            
       
   205         
       
   206         /**
       
   207         * Writes Presence info async. to cache, its called on each runl cycle
       
   208         * and it takes data to write from member data holders.
       
   209         */
       
   210         void WritePresenceInfoAsyncL();
       
   211         
       
   212         /**
       
   213         * Reads all buddies presence info in given service. It takes data from 
       
   214         * stored message.
       
   215         */
       
   216         void ReadAllBuddiesPresenceInServiceL();
       
   217         
       
   218         /**
       
   219          * Get Service name from given xsp id
       
   220          * 
       
   221          * @param aXspId xsp id e.g. ovi:xyz@nokia.com
       
   222          * @return ServiceName returned here
       
   223          */
       
   224         TPtrC GetServiceName(const TDesC& aXspId);
       
   225         
       
   226         
       
   227     private: // Data
       
   228 
       
   229         /**
       
   230         * iMessage, the message exchange data with the server.
       
   231         */
       
   232         RMessage2 iMessage;
       
   233         
       
   234         /**
       
   235         * iMessage, the message holder for notification wating.
       
   236         * This is always pending when some client subscribe for notifications.
       
   237         */
       
   238         RMessage2 iMessageForNoti;
       
   239 
       
   240         /**
       
   241         * iServer, reference to the server.
       
   242         */
       
   243         CPresenceCacheServer& iServer;
       
   244         
       
   245         /**
       
   246         * Own: used for sync messages
       
   247         */
       
   248         HBufC8* iDataPack;
       
   249         
       
   250         /**
       
   251         * Own: used for async messages
       
   252         */
       
   253         HBufC8* iDataPackAsync;
       
   254         
       
   255         /**
       
   256         * Own: used for subscribe notify message
       
   257         */
       
   258         // HBufC8* iDataPackNotifier;
       
   259         
       
   260         /**
       
   261         * Own: used for ansync requests
       
   262         */
       
   263         NRequest::TOpAsyncCodes iAsyncReq;
       
   264         
       
   265         /**
       
   266         *Own
       
   267         */
       
   268         RPointerArray<MPresenceBuddyInfo2> iBuddypresInfoList;
       
   269         
       
   270         /**
       
   271         *
       
   272         */
       
   273         TInt iLastServiceCount;
       
   274         
       
   275         
       
   276         /**
       
   277         *Own
       
   278         */
       
   279         CCacheSessionActiveHelper* iActiveHelper;
       
   280         
       
   281         /**
       
   282         * Pointers not owned.
       
   283         */
       
   284         RPointerArray<CPresenceCacheBuddyStore> iSubscribedStores;
       
   285 
       
   286         /**
       
   287          * Presence notification queue
       
   288          */
       
   289         RPointerArray<CPresenceCacheEvent> iNotifyEvents;        
       
   290         
       
   291     };
       
   292 
       
   293 /**
       
   294 * This class is used by CPresenceCacheSession for dividing long running async.
       
   295 * tasks into smaller units. The CPresenceCacheSession itself was not made 
       
   296 * active, since that results in c++ ambiguousness problems in CPresenceCacheSession
       
   297 * because of inheriting twice from CBase.
       
   298 *  
       
   299 * @since S60 v3.2
       
   300 */    
       
   301 class CCacheSessionActiveHelper : public CActive
       
   302 	{
       
   303 	public: // public functions
       
   304 	
       
   305 	    /**
       
   306         * Default 1st phase factory method.
       
   307         * Creates an instance of CCacheSessionActiveHelper
       
   308         *
       
   309         * @return created instance of the CCacheSessionActiveHelper
       
   310         */
       
   311         static CCacheSessionActiveHelper* NewL(CPresenceCacheSession* aSession );
       
   312         
       
   313         /**
       
   314         * Destructor
       
   315         */
       
   316         ~CCacheSessionActiveHelper( );
       
   317         
       
   318         /**
       
   319         * Active object start
       
   320         */
       
   321 		void Start();
       
   322 	
       
   323 	private: // private functions
       
   324         
       
   325         /**
       
   326         * Constructor
       
   327         */
       
   328         CCacheSessionActiveHelper(CPresenceCacheSession* aSession);
       
   329 
       
   330         /**
       
   331         * Active object RunL
       
   332         */
       
   333 		void RunL();
       
   334 		
       
   335         /**
       
   336         * Active object DoCancel
       
   337         */
       
   338 		void DoCancel();
       
   339 		
       
   340         /**
       
   341         * ConstructL
       
   342         */
       
   343 		void ConstructL();
       
   344 		
       
   345 		TInt RunError(TInt aError);
       
   346 		
       
   347 		
       
   348         /**
       
   349         * pointer to CPresenceCacheSession doesnt own
       
   350         */
       
   351 		CPresenceCacheSession* iCacheSession;
       
   352 			
       
   353 	};
       
   354     
       
   355 #endif // PRESENCECACHESESSION_H
       
   356 
       
   357 // End of File
       
   358