btobexprofiles/obexsendservices/obexservicesendutils/inc/BTServiceStarter.h
changeset 32 19bd632b5100
child 40 997690c3397a
child 42 b72428996822
equal deleted inserted replaced
31:a0ea99b6fa53 32:19bd632b5100
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Service starter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef BT_SERVICE_STARTER_H
       
    21 #define BT_SERVICE_STARTER_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "BTServiceAPI.h"
       
    25 #include "BTServiceUtils.h"
       
    26 #include "BTServiceParameterList.h"
       
    27 
       
    28 #include <btengdiscovery.h>
       
    29 #include <btengsettings.h>
       
    30 #include <obexutilsdialog.h>
       
    31 #include <msvapi.h>
       
    32 #include <hbdevicedialogsymbian.h>
       
    33 #include <hb/hbwidgets/hbdeviceprogressdialogsymbian.h>
       
    34 #include <hbsymbianvariant.h>
       
    35 
       
    36 // DATA TYPES
       
    37 
       
    38 enum TBTServiceProfile
       
    39     {
       
    40     EBTSNone,
       
    41     EBTSBPP,
       
    42     EBTSOPP,
       
    43     EBTSBIP
       
    44     };
       
    45 
       
    46 enum TBTActiveNotifier
       
    47     {
       
    48     ENoneQuery = 0,
       
    49     EOfflineQuery,
       
    50     ENameQuery
       
    51     };
       
    52 
       
    53 // FORWARD DECLARATIONS
       
    54 class CObexUtilsUiLayer;
       
    55 class MBTServiceProgressGetter;
       
    56 class CBTSController;
       
    57 class CBTSProgressTimer;
       
    58 
       
    59 
       
    60 const TUint KBTSdpObjectPush            = 0x1105;
       
    61 const TUint KBTSdpBasicImaging          = 0x111b;
       
    62 const TUint KBTSdpBasicPrinting         = 0x1120;
       
    63 
       
    64 
       
    65 // CLASS DECLARATION
       
    66 
       
    67 /**
       
    68 *  An observer interface for service controllers.
       
    69 */
       
    70 class MBTServiceObserver
       
    71     {
       
    72     public: // New functions
       
    73 
       
    74         /**
       
    75         * Informs the observer that the handler has completed its tasks.
       
    76         * @param aStatus The the completion status of the handler.
       
    77         * @return None.
       
    78         */
       
    79         virtual void ControllerComplete( TInt aStatus ) = 0;
       
    80 
       
    81         /**
       
    82         * Informs the observer that a progress note should be shown.
       
    83         * @param aGetter A pointer to a progess status getter object.
       
    84         * @return None.
       
    85         */
       
    86         virtual void LaunchProgressNoteL( MBTServiceProgressGetter* aGetter, TInt aTotalSize, TInt aFileCount ) = 0;
       
    87         
       
    88         
       
    89         /**
       
    90         * Informs the observer that a progress note should be shown.
       
    91         * @param aGetter A pointer to a progess status getter object.
       
    92         * @return None.
       
    93         */
       
    94         virtual void UpdateProgressNoteL(TInt aFileSize,TInt aFileIndex, const TDesC& aFileName ) = 0;
       
    95         
       
    96 
       
    97         /**
       
    98         * Informs the observer that a progress note should be shown.
       
    99         * @param aGetter A pointer to a progess status getter object.
       
   100         * @return None.
       
   101         */
       
   102         virtual void UpdateProgressInfoL() = 0;
       
   103         
       
   104         
       
   105         /**
       
   106         *  Informs the observer that a confirmation query for sending
       
   107         *  should be shouwn for BIP sendign
       
   108         *  @return
       
   109         */ 
       
   110         virtual TInt LaunchConfirmationQuery(TInt aResouceId)=0;        
       
   111         
       
   112         /**
       
   113         *  Informs the observer that a connect is timedout        
       
   114         *  @return
       
   115         */ 
       
   116         virtual void ConnectTimedOut()=0;
       
   117        
       
   118     };
       
   119 
       
   120 
       
   121 /**
       
   122 *  A starter class for Bluetooth services.
       
   123 */
       
   124 NONSHARABLE_CLASS (CBTServiceStarter) : public CActive,
       
   125                           public MBTServiceObserver,
       
   126                           public MObexUtilsDialogObserver,
       
   127                           public MObexUtilsProgressObserver,
       
   128                           public MBTEngSdpResultReceiver,
       
   129                           public MBTEngSettingsObserver,
       
   130                           public MHbDeviceProgressDialogObserver,
       
   131 						  public MHbDeviceDialogObserver 
       
   132     {
       
   133     public:  // Constructors and destructor
       
   134         
       
   135         /**
       
   136         * Two-phased constructor.
       
   137         */
       
   138         static CBTServiceStarter* NewL();
       
   139         
       
   140         /**
       
   141         * Destructor.
       
   142         */
       
   143         virtual ~CBTServiceStarter();
       
   144 
       
   145     public: // New functions
       
   146         
       
   147         /**
       
   148         * Starts the given service.
       
   149         * @param aService The service to be started.
       
   150         * @param aList Parameters for the service.
       
   151         * @param aWaiter A pointer to a waiter object.
       
   152         * @return None.
       
   153         */
       
   154         void StartServiceL( TBTServiceType aService, 
       
   155                             CBTServiceParameterList* aList,
       
   156                             CActiveSchedulerWait* aWaiter = NULL );
       
   157 
       
   158     private: // Functions from base classes
       
   159 
       
   160 
       
   161 
       
   162         /**
       
   163         * From MBTServiceObserver A controller has completed.
       
   164         * @param aStatus The completion status of the controller.
       
   165         * @return None.
       
   166         */
       
   167         void ControllerComplete( TInt aStatus );
       
   168 
       
   169         /**
       
   170         * From MBTServiceObserver A progress note should be shown.
       
   171         * @param aGetter A pointer to a progess status getter object.
       
   172         * @param aTotalSize Max size of the progress bar.
       
   173         * @return None.
       
   174         */
       
   175         void LaunchProgressNoteL( MBTServiceProgressGetter* aGetter, TInt aTotalSize, TInt aFileCount );
       
   176         
       
   177         
       
   178         /**
       
   179         * From MBTServiceObserver Updating progress note when multiple files are sent.
       
   180         * @param aFileSize Size of the file to be send.
       
   181         * @param aFileIndex index of the file to be send.
       
   182         * @param aFileName name of the file to be send.
       
   183         * @return None.
       
   184         */
       
   185         void UpdateProgressNoteL(TInt aFileSize,TInt aFileIndex, const TDesC& aFileName );
       
   186 		
       
   187       /**
       
   188         * From MBTServiceObserver Updating progress note info about the progress percentage
       
   189         * @return None.
       
   190         */
       
   191          void UpdateProgressInfoL();
       
   192 
       
   193         /**
       
   194         * From MObexUtilsWaitDialogObserver The wait note has been dismissed.
       
   195         * @param aButtonId The button id that was used to dismiss the dialog.
       
   196         * @return None.
       
   197         */
       
   198         void DialogDismissed( TInt aButtonId );
       
   199         
       
   200         /**
       
   201 		* From MHbDeviceProgressDialogObserver
       
   202 		*
       
   203 		*/
       
   204         void ProgressDialogCancelled(const CHbDeviceProgressDialogSymbian *  aDialog);
       
   205         
       
   206 	  /**
       
   207 		* From MHbDeviceProgressDialogObserver
       
   208 		*
       
   209 		*/
       
   210         void ProgressDialogClosed(const CHbDeviceProgressDialogSymbian *  aDialog )  ; 
       
   211 
       
   212         /**
       
   213         * From MObexUtilsProgressObserver request for number of bytes sent
       
   214         * @Param None.
       
   215         * @return Number of bytes sent.
       
   216         */
       
   217         TInt GetProgressStatus();
       
   218         
       
   219         /**
       
   220         *  From MBTServiceObserver A confirmation query for BIP
       
   221         *  profile  should be shown.
       
   222         *  @return key
       
   223         */ 
       
   224         TInt LaunchConfirmationQuery(TInt aResourceId); 
       
   225         
       
   226         /**
       
   227         *  From MBTServiceObserver a connect request is timedout        
       
   228         *  @return
       
   229         */ 
       
   230         void ConnectTimedOut();
       
   231         
       
   232         
       
   233         /**
       
   234         * Provides notification of the result of a service search that matches 
       
   235         * the requested UUID (through CBTEngDiscovery::RemoteSdpQuery).
       
   236         * This method indicates that the search has completed, and returns 
       
   237         * all the results to the caller at once.
       
   238         *
       
   239         * @since S60 v3.2
       
   240         * @param aResult Array of record handles that match the requested UUID.
       
   241         *                Note: the array will not be available anymore after 
       
   242         *                this method returns.
       
   243         * @param aTotalRecordsCount The total number of records returned.
       
   244         * @param aErr Error code of the service search operation; KErrNone if 
       
   245         *             sucessful, KErrEof if no record matched the requested UUID, 
       
   246         *             KErrCouldNotConnect and KErrCouldDisconnected in case of 
       
   247         *             Bluetooth connection errors; otherwise one of the 
       
   248         *             system-wide error codes.
       
   249         */
       
   250         void ServiceSearchComplete( const RSdpRecHandleArray& aResult, 
       
   251                                     TUint aTotalRecordsCount, TInt aErr );
       
   252 
       
   253         /**
       
   254         * Provides notification of the result of an attribute search that matches 
       
   255         * the requested attribute (through CBTEngDiscovery::RemoteSdpQuery).
       
   256         * This method indicates that the search has completed, and returns 
       
   257         * all the results to the caller at once.
       
   258         *
       
   259         * @since S60 v3.2
       
   260         * @param aHandle Record handle of the service record containing the result.
       
   261         * @param aAttr Array containing the attribute that matches the 
       
   262         *              requested attribute.
       
   263         *              Note: the array will not be available anymore after 
       
   264         *              this method returns.
       
   265         * @param aErr Error code of the service search operation; KErrNone if 
       
   266         *             sucessful, KErrEof if the requested attribute was not 
       
   267         *             contained in the specified service record, 
       
   268         *             KErrCouldNotConnect and KErrCouldDisconnected in case of 
       
   269         *             Bluetooth connection errors; otherwise one of the 
       
   270         *             system-wide error codes.
       
   271         */
       
   272         void AttributeSearchComplete( TSdpServRecordHandle aHandle, 
       
   273                                            const RSdpResultArray& aAttr, 
       
   274                                            TInt aErr );
       
   275 
       
   276         /**
       
   277         * Provides notification of the result of an combination of a service 
       
   278         * and attribute search (through CBTEngDiscovery::RemoteSdpQuery).
       
   279         * This method is called for each service and attribute combination for 
       
   280         * which a match was found. The last result (which could be empty if no 
       
   281         * match was found) contain error code KErrEof to indicate that the 
       
   282         * search has completed.
       
   283         *
       
   284         * @since S60 v3.2
       
   285         * @param aHandle Record handle of the service record containing the result.
       
   286         * @param aAttr Array containing the attribute that matches the 
       
   287         *              requested attribute.
       
   288         *              Note: the array will not be available anymore after 
       
   289         *              this method returns.
       
   290         * @param aErr Error code of the service search operation; KErrNone if 
       
   291         *             sucessful and more results follow, KErrEof indicates that 
       
   292         *             this is the last result (which could be empty if no match 
       
   293         *             was found), KErrCouldNotConnect and KErrCouldDisconnected 
       
   294         *             in case of Bluetooth connection errors; otherwise one of 
       
   295         *             the system-wide error codes.
       
   296         */
       
   297         void ServiceAttributeSearchComplete( TSdpServRecordHandle aHandle, 
       
   298                                                       const RSdpResultArray& aAttr, 
       
   299                                                       TInt aErr );
       
   300 
       
   301         /**
       
   302         * Provides notification of the result of the discovery of nearby 
       
   303         * Bluetooth devices.
       
   304         *
       
   305         * @since S60 v3.2
       
   306         * @param aDevice The data structure encapsulates all information 
       
   307         *                about the selected device. Ownership of the data 
       
   308         *                structure has not been transfered and is still with
       
   309         *                the API client.
       
   310         * @param aErr Error code of the device search operation; KErrNone if 
       
   311         *             sucessful, KErrCancel if the user cancelled the 
       
   312         *             dialog, KErrCancel if CBTEngDiscovery::CancelSearchRemoteDevice
       
   313         *             was called; otherwise one of the system-wide error codes.
       
   314         */
       
   315         void DeviceSearchComplete( CBTDevice* aDevice, TInt aErr );
       
   316     
       
   317         /**
       
   318          * From MBTEngSettingsObserver.
       
   319          * Provides notification of changes in the power state 
       
   320          * of the Bluetooth hardware.
       
   321          *
       
   322          * @since S60 v3.2
       
   323          * @param aState EBTPowerOff if the BT hardware has been turned off, 
       
   324          *               EBTPowerOn if it has been turned off.
       
   325          */
       
   326         void PowerStateChanged( TBTPowerStateValue aState );
       
   327 
       
   328         /**
       
   329          * From MBTEngSettingsObserver.
       
   330          * Provides notification of changes in the discoverability 
       
   331          * mode of the Bluetooth hardware.
       
   332          *
       
   333          * @since S60 v3.2
       
   334          * @param aState EBTDiscModeHidden if the BT hardware is in hidden mode, 
       
   335          *               EBTDiscModeGeneral if it is in visible mode.
       
   336          */
       
   337         void VisibilityModeChanged( TBTVisibilityMode aState );
       
   338 
       
   339         /**
       
   340          * From CActive.
       
   341          * Called by the active scheduler when the request has been cancelled.
       
   342          * 
       
   343          * @since S60 v3.2
       
   344          */
       
   345         void DoCancel();
       
   346 
       
   347         /**
       
   348          * From CActive.
       
   349          * Called by the active scheduler when the request has been completed.
       
   350          * 
       
   351          * @since S60 v3.2
       
   352          */
       
   353         void RunL();
       
   354 
       
   355         /**
       
   356          * From CActive.
       
   357          * Called by the active scheduler when an error in RunL has occurred.
       
   358          * 
       
   359          * @since S60 v3.2
       
   360          */
       
   361         TInt RunError( TInt aError );
       
   362 
       
   363     private:
       
   364 
       
   365         /**
       
   366         * C++ default constructor.
       
   367         */
       
   368         CBTServiceStarter();
       
   369 
       
   370         /**
       
   371         * By default Symbian 2nd phase constructor is private.
       
   372         */
       
   373         void ConstructL();
       
   374 
       
   375         /**
       
   376         * Check that the parameters are valid for a given service.
       
   377         * @param aService The requested service.
       
   378         * @param aList Parameters for the service.        
       
   379         * @return None.
       
   380         */
       
   381         TBool ValidParameters( TBTServiceType aService, 
       
   382                                const CBTServiceParameterList* aList) const;
       
   383 
       
   384         /**
       
   385         * Starts finding a Bluetooth profile suitable for requested service.
       
   386         * @param aService The requested service.
       
   387         * @return None.
       
   388         */
       
   389         void StartProfileSelectL( TBTServiceType aService );
       
   390 
       
   391         /**
       
   392         * Start a controller for the given Bluetooth profile.
       
   393         * @param aProfile The profile to be started.
       
   394         * @return None.
       
   395         */
       
   396         void StartProfileL( TBTServiceProfile aProfile );
       
   397 
       
   398         /**
       
   399         * Launches a connecting wait note
       
   400         * @param None.
       
   401         * @return None.
       
   402         */
       
   403         void LaunchWaitNoteL();
       
   404         
       
   405         /**
       
   406         * Cancel connecting wait note
       
   407         * @param None.
       
   408         * @return None.
       
   409         */
       
   410         void CancelWaitNote();
       
   411 
       
   412         /**
       
   413         * Show a note with given error value
       
   414         * @param aReason Error value
       
   415         * @return None.
       
   416         */
       
   417         void ShowNote( TInt aReason ) const;
       
   418 
       
   419         /**
       
   420         * Cancel progress note
       
   421         * @param None.
       
   422         * @return None.
       
   423         */
       
   424         void CancelProgressNote();
       
   425         
       
   426         /**
       
   427         * StopTransfer and show information note
       
   428         * @param aError Error code if error exist.
       
   429         * @return None.
       
   430         */
       
   431         void StopTransfer( TInt aError );
       
   432 
       
   433         /**
       
   434          * Check if phone is in offline mode, and ask the user if it is..
       
   435          * @return ETrue if the phone is in offline mode, otherwise EFalse.
       
   436          */
       
   437         TBool CheckOfflineModeL();
       
   438 
       
   439         /**
       
   440         * Start BT device discovery.
       
   441         * @return None.
       
   442         */
       
   443         void StartDiscoveryL();
       
   444 
       
   445         /**
       
   446          * Turn BT power on.
       
   447          * @param aState The current BT power state.
       
   448          * @return None.
       
   449          */
       
   450         void TurnBTPowerOnL( const TBTPowerStateValue aState );
       
   451         
       
   452         void DataReceived(CHbSymbianVariantMap& aData);
       
   453        
       
   454         void DeviceDialogClosed(TInt aCompletionCode);
       
   455     private:    // Data definitions
       
   456 
       
   457         enum TBTServiceStarterState
       
   458             {
       
   459             EBTSStarterIdle,
       
   460             EBTSStarterFindingBPP,
       
   461             EBTSStarterFindingOPP,
       
   462             EBTSStarterFindingBIP,
       
   463             EBTSStarterStoppingService
       
   464             };
       
   465 
       
   466     private:    // Data
       
   467 
       
   468         CBTDevice*                  iDevice;
       
   469         CBTEngDiscovery*            iBTEngDiscovery;
       
   470         CBTServiceParameterList*    iList;
       
   471  //       CObexUtilsDialog*           iDialog;
       
   472         CBTSController*       iController;
       
   473 
       
   474         TBTServiceType              iService;
       
   475         TInt                        iClientChannel;
       
   476         TBTServiceStarterState      iState;
       
   477         TBool                       iServiceStarted;
       
   478         TMsvId                      iMessageServerIndex;
       
   479         
       
   480         MBTServiceProgressGetter*   iProgressGetter;
       
   481         CActiveSchedulerWait*       iWaiter;
       
   482         TBool                       iAllSend;                     
       
   483         TInt						iBytesSendWithBIP;        
       
   484         TBool						iProgressDialogActive;        
       
   485         TBool                       iUserCancel;
       
   486         CBTEngSettings*             iBTEngSettings;
       
   487         TBool                       iWaitingForBTPower;
       
   488         RNotifier                   iNotifier;  // Handle to the generic notifier.
       
   489         TPckgBuf<TBool>             iOffline;
       
   490         TPckgBuf<TBool>             iName;
       
   491         TBool                       iSendToBIPOnlyDevice;
       
   492         TBTActiveNotifier           iActiveNotifier;
       
   493         TBool                       iFeatureManagerInitialized;
       
   494         TBool                       iTriedBIP;
       
   495         TBool                       iTriedOPP;
       
   496         CHbDeviceDialogSymbian *iDeviceDialog;
       
   497         CHbDeviceProgressDialogSymbian *iProgressDialog;
       
   498         TInt                        iFileCount;
       
   499         TInt                        iFileIndex;
       
   500         CBTSProgressTimer *iProgressTimer;
       
   501     };
       
   502 
       
   503 #endif      // BT_SERVICE_CONTROLLER_H
       
   504             
       
   505 // End of File
       
   506