presencecache/presencecacheclient2/inc/presencecacheclient.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Implementation for presence cache reader and writer.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef PRESENCECACHECLIENT_H
       
    19 #define PRESENCECACHECLIENT_H
       
    20 
       
    21 #include <presencecachereader2.h>
       
    22 #include <presencecachewriter2.h>
       
    23 
       
    24 #include "presencecachedefs2.h"
       
    25 
       
    26 class MPresenceBuddyInfo2;
       
    27 class MPresenceCacheWriteHandler2;
       
    28 class MPresenceCacheReadHandler2;
       
    29 class CPresenceCacheClientNotification;
       
    30 
       
    31 //Include Cache server namespace
       
    32 using namespace NCacheSrv2;
       
    33 
       
    34 /**
       
    35  * Implementation for presence cache reader and writer. This object is 
       
    36  * instantiated either by MPresenceCacheReader2 or MPresenceCacheWriter2 using ecom framework.
       
    37  * Apart from implementing these two objects, this is also a Symbian OS client and
       
    38  * it communicates with presence cache server. Its also an active object.
       
    39  *
       
    40  * @since S60 v3.2
       
    41  */
       
    42 class CPresenceCacheClient : public CActive,
       
    43 							 public RSessionBase,
       
    44 							 public MPresenceCacheReader2,
       
    45                              public MPresenceCacheWriter2
       
    46 
       
    47     {
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Factory method to instantiate CPresenceCacheClient through the ECom. 
       
    52      *
       
    53      * @return The new CPresenceCacheClient object. Object
       
    54      *         ownership is returned to caller.
       
    55      */
       
    56     IMPORT_C static CPresenceCacheClient* NewL();
       
    57     
       
    58     /**
       
    59      * Factory method to instantiate CPresenceCacheClient through the ECom.
       
    60      * It's returns MPresenceCacheReader2
       
    61      *
       
    62      * @return The new CPresenceCacheClient object. Object
       
    63      *         ownership is returned to caller.
       
    64      */
       
    65     IMPORT_C static MPresenceCacheReader2* CreateReaderL();
       
    66     
       
    67     /**
       
    68      * Factory method to instantiate CPresenceCacheClient through the ECom.
       
    69      * It's returns MPresenceCacheWriter2
       
    70      *
       
    71      * @return The new CPresenceCacheClient object. Object
       
    72      *         ownership is returned to caller.
       
    73      */
       
    74     IMPORT_C static MPresenceCacheWriter2* CreateWriterL();
       
    75     
       
    76   
       
    77     /**
       
    78      * Public destructor.
       
    79      * Objects can be deleted through this interface.
       
    80      */
       
    81     virtual ~CPresenceCacheClient();
       
    82     
       
    83     /**
       
    84     * Start the server
       
    85     * @return TInt Error code
       
    86     */
       
    87     TInt StartServer();
       
    88     
       
    89     /**
       
    90     * Version.
       
    91     * Gets the version number.
       
    92     * @return The version.
       
    93     */
       
    94     TVersion Version() const;
       
    95         
       
    96         
       
    97 private:
       
    98 
       
    99     /**
       
   100     * C++ constructor
       
   101     */
       
   102     CPresenceCacheClient();
       
   103     
       
   104     /**
       
   105     * Symbian second phase constructor
       
   106     */
       
   107     void ConstructL();
       
   108     
       
   109     /**
       
   110     * Connect.
       
   111     * Connects to the server and create a session.
       
   112     * @return Error code.
       
   113     */
       
   114     TInt Connect();
       
   115     
       
   116     /**
       
   117     * Packs MPresenceBuddyInfo2 object into a buffer
       
   118     * 
       
   119     * @param aBuddyPresInfo, MPresenceBuddyInfo2
       
   120     * @return HBufC8* buffer
       
   121     */
       
   122     HBufC8* PackBuddyPresenceInfoLC(const MPresenceBuddyInfo2* aBuddyPresInfo);
       
   123     
       
   124     /**
       
   125     * Packs MPresenceBuddyInfo2List object into a buffer
       
   126     * 
       
   127     * @param aList, MPresenceBuddyInfo2List
       
   128     * @return HBufC8* buffer
       
   129     */
       
   130     HBufC8* PackPresenceBuddyListLC(const RPointerArray<MPresenceBuddyInfo2>& aList);  
       
   131       
       
   132     
       
   133     /**
       
   134     * Handle asynchronous call from server that buddies presence have been prepared.
       
   135     * This function does further processing and calls the client.
       
   136     * 
       
   137     * @param aError, Error came from server.
       
   138     */
       
   139     void HandlePreparedAllBuddiesPresenceL(TInt aError);
       
   140     
       
   141     /**
       
   142     * Return true if given identity is valid xsp identity
       
   143     * 
       
   144     * @param ETrue if valid xsp identity
       
   145     */
       
   146     TBool ValidateXspId(const TDesC& aXspId);
       
   147     
       
   148        
       
   149       
       
   150 public: //From MPresenceCacheReader2
       
   151 
       
   152     MPresenceBuddyInfo2* PresenceInfoLC(const TDesC& aIdentity);    
       
   153     
       
   154     TInt BuddyCountInAllServices();
       
   155     
       
   156     TInt BuddyCountInService(const TDesC& aServiceName);
       
   157     
       
   158     TInt ServicesCount();
       
   159     
       
   160     TInt CancelRead();                                        
       
   161                                                 
       
   162     TInt SubscribePresenceBuddyChangeL(const TDesC& aIdentity);
       
   163                                                 
       
   164     void UnSubscribePresenceBuddyChangeL(const TDesC& aIdentity);                             
       
   165                                                 
       
   166 
       
   167 public: //From MPresenceCacheReader2, Asynchronous methods
       
   168 
       
   169     TInt AllBuddiesPresenceInService(const TDesC& aServiceName, 
       
   170                                         MPresenceCacheReadHandler2* aHandler);
       
   171 
       
   172     TInt SetObserverForSubscribedNotifications(
       
   173                         MPresenceCacheReadHandler2* aHandler);                             
       
   174 
       
   175 public: //From MPresenceCacheWriter2
       
   176 
       
   177     TInt WritePresenceL(const MPresenceBuddyInfo2* aPresenceBuddyInfo);
       
   178     
       
   179     TInt DeleteService(const TDesC& aServiceName);
       
   180     
       
   181     TInt DeletePresenceL(const TDesC& aIdentity);
       
   182         
       
   183     MPresenceBuddyInfo2* NewBuddyPresenceInfoLC();
       
   184     
       
   185     // MPresenceBuddyInfoList* NewPresenceBuddyInfoListLC(const TDesC& aServiceName);
       
   186     
       
   187     TInt CancelWrite();
       
   188     
       
   189 
       
   190 public: //From MPresenceCacheWriter2, Asynchronous methods
       
   191 
       
   192     TInt WriteMultiplePresenceL(const RPointerArray<MPresenceBuddyInfo2>& aPresenceBuddyInfos,
       
   193                         MPresenceCacheWriteHandler2* aHandler);
       
   194                                     
       
   195 public:  //From CActive
       
   196 
       
   197     void RunL();
       
   198 
       
   199     void DoCancel();
       
   200     
       
   201 private: // Data
       
   202     
       
   203     //Not Owned
       
   204     MPresenceCacheWriteHandler2* iWriteHandler;
       
   205     
       
   206     //Not Owned
       
   207     MPresenceCacheReadHandler2* iReadHandler;
       
   208     
       
   209     //To store async request status
       
   210     NRequest::TOpAsyncCodes iAsyncReq;
       
   211           
       
   212     /**
       
   213      * Client who subscribed cache notifications
       
   214      * NOT OWN
       
   215      */
       
   216     MPresenceCacheReadHandler2* iNotifyClient;   
       
   217     
       
   218     /**
       
   219      * Handler for subscribed cache notifications
       
   220      * OWN
       
   221      */    
       
   222     CPresenceCacheClientNotification* iNotifyHandler;
       
   223     
       
   224     /**
       
   225      * Asynchronous data packet
       
   226      * OWN
       
   227      */
       
   228     HBufC8* iPresInfoPack;    
       
   229     
       
   230     /**
       
   231      * Asynchronous data packet
       
   232      * OWN
       
   233      */
       
   234     HBufC16* iPresInfoPack16;      
       
   235     
       
   236 private: // friend classes
       
   237 
       
   238 	friend class CPresenceCacheClientNotification;
       
   239 
       
   240     };
       
   241 
       
   242 #endif // PRESENCECACHECLIENT_H
       
   243 
       
   244 
       
   245