ImagePrint/ImagePrintEngine/DeviceProtocols/btprotocol/inc/cbtchannelbase.h
branchRCL_3
changeset 21 d59c248c9d36
parent 0 d11fb78c4374
equal deleted inserted replaced
20:159fc2f68139 21:d59c248c9d36
       
     1 /*
       
     2 * Copyright (c) 2004-2007 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:  Defines the CBtChannelBase class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CBTCHANNELBASE_H
       
    20 #define CBTCHANNELBASE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include <e32math.h>
       
    25 #include <obexbase.h> 
       
    26 #include <btnotif.h>
       
    27 #include <avkon.hrh>
       
    28 
       
    29 #include "crsbtdiscoverengine.h"
       
    30 #include "tprintcapability.h"
       
    31 #include "mbtpcobserver.h"
       
    32 #include "cbtobjectserver.h"
       
    33 #include "cprintjob.h"
       
    34 #include "mconfirmationnotify.h"
       
    35 #include "cbtpasswordquery.h"
       
    36 
       
    37 class CBtSoapCodec;
       
    38 class CObexBufObject;
       
    39 class CObexClient;
       
    40 class CObexFileObject;
       
    41 
       
    42 /**
       
    43 * @class 	CBtChannelBase
       
    44 * @brief	A base class to implement CObexClient use.
       
    45 *
       
    46 *			This class implements the common methods used for connecting and
       
    47 *			communicating with device via CObexClient using either BPP job based
       
    48 *			printing or OPP simple push.
       
    49 */
       
    50 NONSHARABLE_CLASS(CBtChannelBase) : public CActive, public MObexAuthChallengeHandler, public MConfirmationNotify
       
    51 	{
       
    52 		public:
       
    53 
       
    54 			/**  		~CBtChannelBase
       
    55 			* @brief	Destructor.
       
    56 			*/
       
    57 			virtual ~CBtChannelBase();
       
    58 
       
    59 			/**  		StartL
       
    60 			* @brief	Synchronized method to start communication with device.
       
    61 			*			Method clears former connections and connects to the device given.
       
    62 			* @param	aDevice Device to connect
       
    63 			*/
       
    64 			virtual void StartL( CRsBtDevice& aDevice );
       
    65 
       
    66 			/**  		Stop
       
    67 			* @brief	Clears connection.
       
    68 			*			Device is disconnected and the channel (CObexClient) is deleted.
       
    69 			*/
       
    70 			virtual void Stop();
       
    71 
       
    72 			/**  		IsConnected
       
    73 			* @brief	Checks wether the channel is connected or not.
       
    74 			* @return	ETrue if connected, EFalse otherway.
       
    75 			*/
       
    76 			virtual TBool IsConnected();
       
    77 
       
    78 			/**  		Disconnect
       
    79 			* @brief	Method to disconnect channel.
       
    80 			*/
       
    81 			virtual void Disconnect();
       
    82 
       
    83 			/**  		FinishPrinting
       
    84 			* @brief	Finishes all printing operations started and stops the connection.
       
    85 			*/
       
    86 			virtual void FinishPrinting();
       
    87 
       
    88 			/**  		SetDevice
       
    89 			* @brief	Sets the default device.
       
    90 			* @param	aDevice Device to set as default
       
    91 			*/
       
    92 			void SetDevice( CRsBtDevice& aDevice );
       
    93 
       
    94 			/**  		Device
       
    95 			* @brief	Gets the default device.
       
    96 			* @return	Reference to default device.
       
    97 			*/
       
    98 			const CRsBtDevice& Device() const;
       
    99 
       
   100 			/**  		JobId
       
   101 			* @brief	Gets the default job id.
       
   102 			* @param	aId Job id to set as default.
       
   103 			*/
       
   104 			void SetJobId( TInt aId );
       
   105 
       
   106 			/**  		JobId
       
   107 			* @brief	Gets the default job id.
       
   108 			* @return	Default job id.
       
   109 			*/
       
   110 			TInt JobId() const;
       
   111 
       
   112        	public:
       
   113 		    /**  		GetUserPasswordL
       
   114 		    * @brief	Gets the Obex password.
       
   115 			* @return	Contain the Realm specified by the unit forcing the Authentication.
       
   116 			*/
       
   117 		    virtual void GetUserPasswordL( const TDesC &aRealm );
       
   118 		    
       
   119 		    void PasswordQueryCompleteL ( TObexPasskeyBuf aResultPckg );
       
   120 		
       
   121 		protected:
       
   122 
       
   123 			/**  		CBtChannelBase
       
   124 			* @brief	C++ constructor
       
   125 			* @param	Observer to call back about received feed back or occured errors.
       
   126 			*/
       
   127 			CBtChannelBase(MBtPCObserver& aObs);
       
   128 
       
   129 			/**  		ConstructL
       
   130 			* @brief	Symbian second phase constructor.
       
   131 			*/
       
   132 			void ConstructL();
       
   133 
       
   134 			// ===============================
       
   135 			// From CActive.
       
   136 			// ===============================
       
   137 			virtual void DoCancel();
       
   138 			virtual TInt RunError(TInt aError) = 0;
       
   139 
       
   140 			/**  		ConnectL
       
   141 			* @brief	Pure virtual method for CObexClient connection.
       
   142 			*/
       
   143 			virtual void ConnectL() = 0;
       
   144 
       
   145 			/**  		TControlState
       
   146 			* @brief	Operation states in derived classes.
       
   147 			*/
       
   148 			enum TControlState
       
   149 			{
       
   150 				EStateNone = 0,
       
   151 				
       
   152             	EStateConnecting,
       
   153             	EStateDisconnecting,
       
   154 				EStateGettingCapabilities,
       
   155 				EStateGettingPrinterState, 
       
   156 				EStateCreatingJob, 
       
   157 
       
   158 				EStateCancellingJob,
       
   159 				EStateSendingDocument,
       
   160 				EStateSendingXhtml,
       
   161 				EStateSendingOPP,
       
   162 				EStateGettingJobAttributes,
       
   163 
       
   164 				EStateGetEvent,
       
   165 				EStateGettingEvent,
       
   166 				EStateFinish
       
   167 			};
       
   168 
       
   169 
       
   170 			/**  		GetSoapResponseL
       
   171 			* @brief	Gets Soap response and parses the action name
       
   172 			* @return	Soap action ID (TBtSoapActions)
       
   173 			*/
       
   174 			virtual TInt GetSoapResponseL();
       
   175 
       
   176 			/**  		SendSoapRequestL
       
   177 			* @brief	Operates Soap Action
       
   178 			*/
       
   179 			virtual void SendSoapRequestL(const TInt aRequest, const TInt aJobId = KErrNotFound);
       
   180 			/// @brief	Overwrites SendSoapRequestL
       
   181 			virtual void SendSoapRequestL(const TInt aRequest, TRequestStatus& aStatus,
       
   182 								  		  const TInt aJobId = KErrNotFound);
       
   183 
       
   184 			/**  		CompleteRequest
       
   185 			* @brief	Completes pending request
       
   186 			*/
       
   187 			void CompleteRequest(TControlState aStateCompleted, TInt aError = KErrNone);
       
   188 
       
   189 			/**  		Activate
       
   190 			* @brief	Activates object if not already active
       
   191 			*/
       
   192 			virtual void Activate();
       
   193 
       
   194 			/**  		ClearConnection
       
   195 			* @brief	Disconnects and deletes the connection.
       
   196 			*			In case of pending request, calls Abort for CObexClient.
       
   197 			*/
       
   198 			virtual void ClearConnection();
       
   199 
       
   200 			/**  		WaitL
       
   201 			* @brief	Sets the object to wait request to complete if not already waiting.
       
   202 			*/
       
   203 			void WaitL();
       
   204 
       
   205 			/**  		StopWaiting
       
   206 			* @brief	Stops the object waiting request to complete if waiting.
       
   207 			*/
       
   208 			void StopWaiting();
       
   209 			
       
   210 			/**  		DeleteChannel
       
   211 			* @brief	Deletes the channel and initializes it.
       
   212 			*/
       
   213 			void DeleteChannel();
       
   214 
       
   215 		protected:
       
   216 
       
   217 			/** @var MBtPCObserver& iObs
       
   218 			 *  Observer to call back about received feed back or occured errors. */
       
   219 			MBtPCObserver& iObs;
       
   220 
       
   221 			/** @var TControlState iState
       
   222 			 *  Internal container for current operation state. */
       
   223 			TControlState iState;
       
   224 
       
   225 			/** @var TInt iJobId
       
   226 			 *  Current job id. */
       
   227 			TInt iJobId;
       
   228 
       
   229 			/** @var CObexClient* iChannel
       
   230 			 *  Channel to communicate with device over bluetooth. */
       
   231 			CObexClient* iChannel;
       
   232 
       
   233 			/** @var CBtSoapCodec* iSoapCodec
       
   234 			 *  Helper class to codec and manage SOAP messages. */
       
   235 			CBtSoapCodec* iSoapCodec;
       
   236 
       
   237 			/** @var CObexBufObject* iObexBufObject
       
   238 			 *  OBEX data object, type of 'buffer'. */
       
   239 			CObexBufObject* iObexBufObject;
       
   240 
       
   241 			/** @var CObexNullObject* iObexNullObject
       
   242 			 *  Empty OBEX object for connecting. */
       
   243 			CObexNullObject* iObexNullObject;
       
   244 
       
   245 			/** @var CBufBase* iObexBody
       
   246 			 *  Body of the OBEX data object. */
       
   247 			CBufBase* iObexBody;
       
   248 
       
   249 			/** @var CRsBtDevice* iDevice
       
   250 			 *  The device to communicate with. */
       
   251 			CRsBtDevice* iDevice;
       
   252 
       
   253 			/** @var CActiveSchedulerWait* iWait
       
   254 			 *  Active scheduler wait object for nested scheduler loops. */
       
   255 			CActiveSchedulerWait* iWait;
       
   256 
       
   257 			/** @var TInt iResponseError
       
   258 			 *  Member to maintain errors occured during phases of synchronized calls. */
       
   259 			TInt iResponseError;
       
   260 
       
   261 			/** @var TBool iStop
       
   262 			 *  Flag to indicate the processing shall or is about to stop. */
       
   263 			TBool iStop;
       
   264 			
       
   265 			CBtPasswordQuery* iPasswordQuery;
       
   266 			
       
   267 		    TBTObexPasskey iPckg;		// Input parameters		
       
   268 	};
       
   269 
       
   270 #endif // CBTCHANNELBASE_H
       
   271 
       
   272 //  End of File