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