bluetoothengine/btserviceutil/inc/btdevrepositoryimpl.h
changeset 19 43824b19ee35
child 31 a0ea99b6fa53
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
       
     1 /*
       
     2 * Copyright (c) 2010 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:  The repository of remote devices from BT registry
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef BTDEVICEREPOSITORYIMPL_H
       
    19 #define BTDEVICEREPOSITORYIMPL_H
       
    20 
       
    21 #include <bttypes.h>
       
    22 #include <bt_sock.h>
       
    23 #include <btmanclient.h>
       
    24 #include <e32property.h>
       
    25 #include <btengconnman.h>
       
    26 #include <btservices/btsimpleactive.h>
       
    27 #include <btservices/btdevextension.h>
       
    28 
       
    29 class MBtDevRepositoryObserver;
       
    30 
       
    31 /**
       
    32  *  Class CBtDevRepositoryImpl
       
    33  *
       
    34  *  This class keep a storage of remote device information.
       
    35  *
       
    36  */
       
    37 NONSHARABLE_CLASS( CBtDevRepositoryImpl ) : 
       
    38     public CBase, 
       
    39     public MBtSimpleActiveObserver,
       
    40     public MBTEngConnObserver
       
    41     {
       
    42 public:
       
    43 
       
    44     /**
       
    45      * Two-phase constructor
       
    46      */
       
    47     static CBtDevRepositoryImpl* NewL();
       
    48 
       
    49     /**
       
    50      * Destructor
       
    51      */
       
    52     ~CBtDevRepositoryImpl();
       
    53 
       
    54     /**
       
    55      * Add an observer to this reposity for receivng repository update
       
    56      * events.
       
    57      * @param aObserver the observer to be added.
       
    58      */
       
    59     void AddObserverL( MBtDevRepositoryObserver* aObserver );
       
    60 
       
    61     /**
       
    62      * Remove an observer from this repository.
       
    63      * @param aObserver the observer to be removed.
       
    64      */
       
    65     void RemoveObserver( MBtDevRepositoryObserver* aObserver );
       
    66     
       
    67     /**
       
    68      * Tells if this repository has finished the initialization.
       
    69      * Initialization completion means the repository has retieved all
       
    70      * Bluetooth devices from BT registry, and it is subscribing to
       
    71      * registry update events.
       
    72      */
       
    73     TBool IsInitialized() const;
       
    74     
       
    75     /**
       
    76      * Gets all devices in this repository.
       
    77      * @return the device list.
       
    78      */
       
    79     const RDevExtensionArray& AllDevices() const;
       
    80     
       
    81     /**
       
    82      * Get a specific device by the given address.
       
    83      * @param aAddr the address of the device to be retrieved
       
    84      * @return the device pointer, NULL if the device is unavailable.
       
    85      */
       
    86     const CBtDevExtension* Device( const TBTDevAddr& aAddr ) const;
       
    87     
       
    88     /**
       
    89      * Returns the service (limited to services managed in bteng scope)
       
    90      * level connection status of the specified device.
       
    91      *
       
    92      * @param aAddr the address of the device
       
    93      * @return one of TBTEngConnectionStatus enums
       
    94      */
       
    95     //TBTEngConnectionStatus IsDeviceConnected( const TBTDevAddr& aAddr );
       
    96     
       
    97 private:
       
    98     
       
    99     // from MBtSimpleActiveObserver
       
   100     
       
   101     /**
       
   102      * Callback from RunL() to notify that an outstanding request has completed.
       
   103      *
       
   104      * @since Symbian^4
       
   105      * @param aActive Pointer to the active object that completed.
       
   106      * @param aStatus The status of the completed request.
       
   107      */
       
   108     void RequestCompletedL( CBtSimpleActive* aActive, TInt aStatus );
       
   109 
       
   110     /**
       
   111      * Callback from Docancel() for handling cancelation of an outstanding request.
       
   112      *
       
   113      * @since Symbian^4
       
   114      * @param aId The ID that identifies the outstanding request.
       
   115      */
       
   116     void CancelRequest( TInt aRequestId );
       
   117 
       
   118     /**
       
   119      * Callback from RunError() to notify that an error has occurred in RunL.
       
   120      *
       
   121      * @since Symbian^4
       
   122      * @param aActive Pointer to the active object that completed.
       
   123      * @param aError The error occurred in RunL.
       
   124      */
       
   125     void HandleError( CBtSimpleActive* aActive, TInt aError );
       
   126 
       
   127     // From MBTEngConnObserver
       
   128     
       
   129     /**
       
   130      * Indicates to the caller that a service-level connection has completed.
       
   131      * This function is called for both incoming and outgoing connections. 
       
   132      * This function is also called when an outgoing connection request fails, 
       
   133      * e.g. with error code KErrCouldNotConnect.
       
   134      * When this function is called, new commands can be issued to the 
       
   135      * CBTEngConnMan API immediately.
       
   136      * @param  aAddr The address of the remote device.
       
   137      * @param  aErr Status information of the connection. KErrNone if the
       
   138      *              connection succeeded, otherwise the error code with 
       
   139      *              which the outgoing connection failed. KErrAlreadyExists 
       
   140      *              is returned if there already is an existing connection 
       
   141      *              for the selected profile(s), or otherwise e.g. 
       
   142      *              KErrCouldNotConnect or KErrDisconnected for indicating 
       
   143      *              connection problems.
       
   144      * @param  aConflicts If there already is a connection for the selected 
       
   145      *                    profile(s) of an outgoing connection request (the 
       
   146      *                    selection is performed by BTEng), then this array 
       
   147      *                    contains the bluetooth device addresses of the 
       
   148      *                    remote devices for those connections.
       
   149      */
       
   150     void ConnectComplete( TBTDevAddr& aAddr, TInt aErr, 
       
   151                           RBTDevAddrArray* aConflicts = NULL );
       
   152 
       
   153     /**
       
   154      * Indicates to the caller that a service-level connection has disconnected.
       
   155      * When this function is called, new commands can be issued to the 
       
   156      * CBTEngConnMan API immediately.
       
   157      * 
       
   158      * @param  aAddr The address of the remote device.
       
   159      * @param  aErr The error code with which the disconnection occured. 
       
   160      *              KErrNone for a normal disconnection, 
       
   161      *              or e.g. KErrDisconnected if the connection was lost.
       
   162      */
       
   163     void DisconnectComplete( TBTDevAddr& aAddr, TInt aErr );
       
   164     
       
   165 private:
       
   166     
       
   167     /**
       
   168      * C++ default constructor
       
   169      */
       
   170     CBtDevRepositoryImpl();
       
   171     
       
   172     /**
       
   173      * Symbian 2nd-phase constructor
       
   174      */
       
   175     void ConstructL();
       
   176     
       
   177     /**
       
   178      * Creates a registry view which shall contain all remote devices.
       
   179      */    
       
   180     void CreateRemoteDeviceView();
       
   181     
       
   182     /**
       
   183      * retrieves remote devices from registry.
       
   184      */
       
   185     void GetRemoteDevicesL();
       
   186     
       
   187     /**
       
   188      * handles the completion of paired device view creation
       
   189      */
       
   190     void HandleCreateRemoteDeviceViewCompletedL( TInt aStatus);
       
   191     
       
   192     /**
       
   193      * handles the completion of getting paired devices
       
   194      */
       
   195     void HandleGetRemoteDevicesCompletedL( TInt aStatus );
       
   196     
       
   197     /**
       
   198      * Copy the remote devices to internal array storage.
       
   199      */
       
   200     void UpdateRemoteDeviceRepositoryL();
       
   201     
       
   202 private:
       
   203     
       
   204     /**
       
   205      * The observers
       
   206      * do not own them.
       
   207      */
       
   208     RPointerArray<MBtDevRepositoryObserver> iObservers;
       
   209     
       
   210     /**
       
   211      * Registry sub session for remote device db.
       
   212      * not own
       
   213      */
       
   214     RBTRegistry iBTRegistry;
       
   215     
       
   216     // own.
       
   217     RBTRegServ iBTRegServ;
       
   218     
       
   219     /**
       
   220      * AO for registry operations
       
   221      * own.
       
   222      */
       
   223     CBtSimpleActive* iRegistryActive;    
       
   224     
       
   225     /**
       
   226      * the counter of not handled registry events.
       
   227      */
       
   228     TInt iNotHandledRegEventCounter;
       
   229     
       
   230     /**
       
   231      * temporary instance to retrieve paired devices.
       
   232      * own.
       
   233      */
       
   234     CBTRegistryResponse* iRegRespRemoteDevices;
       
   235 
       
   236     /**
       
   237      * Property containing the BT registry change monitoring key
       
   238      * own.
       
   239      */
       
   240     RProperty iBtRegistryKey;
       
   241      
       
   242     /**
       
   243      * AO for subscribing registry PubSub key
       
   244      * own.
       
   245      */
       
   246     CBtSimpleActive* iRegistryKeyActive;  
       
   247     
       
   248     /**
       
   249      * For connection status
       
   250      */
       
   251     CBTEngConnMan* iBtengConn;
       
   252     
       
   253     /**
       
   254      * contains the list of all devices.
       
   255      * own.
       
   256      */
       
   257     RDevExtensionArray iDevices;
       
   258 
       
   259     TInt iInitialized;
       
   260     
       
   261     };
       
   262 
       
   263 #endif /*BTDEVICEREPOSITORYIMPL_H*/