commands/btservices/BtServicesEng.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // BtServicesEng.h
       
     2 // 
       
     3 // Copyright (c) 2003 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #ifndef BTSERVICESENG_H_
       
    14 #define BTSERVICESENG_H_
       
    15 
       
    16 #include <btsdp.h>
       
    17 #include <es_sock.h>
       
    18 #include <bt_sock.h>
       
    19 #include <barsread.h>
       
    20 
       
    21 #include "btserviceview.h"
       
    22 //#include <QikListBoxModel.h>
       
    23 
       
    24 enum TBtPanicCode
       
    25 	{
       
    26 	EBtEngineNotCreated = 1,
       
    27 	EBtEngineAlreadyExists = 2,
       
    28 	EBtIndentationZeroInStartList = 3,
       
    29 	EBtIndentationZeroInLineFinished = 4
       
    30 	};
       
    31 
       
    32 class CBtAttributeBuilder;
       
    33 
       
    34 class CServiceRecordItem
       
    35 	{
       
    36 public:
       
    37 	CServiceRecordItem()
       
    38 	{
       
    39 	iHandle = 0;
       
    40 	iServiceName = _L("");
       
    41 	}
       
    42 	
       
    43 	~CServiceRecordItem(){;}
       
    44 	
       
    45 	TSdpServRecordHandle iHandle;
       
    46 	TBuf<64> iServiceName;
       
    47 	
       
    48 	};
       
    49 
       
    50 /**
       
    51 This provides the main application functionality, specifically
       
    52 setting up the SDP agent and implementing the notifier interface
       
    53 to build the results into an array, displayed by the main View
       
    54 (CBtServicesListView) in the case of services, or by the attribute
       
    55 dialog in the case of attributes for a selected service.
       
    56 */
       
    57 class CBtServicesEng : public CBase, public MSdpAgentNotifier  
       
    58 	{
       
    59 public:
       
    60 	static CBtServicesEng* NewL();
       
    61 	~CBtServicesEng();
       
    62 	void SetView(CBtServiceView* apView);
       
    63 	//CDesCArrayFlat* GetTextArray() const;
       
    64 
       
    65 	// defined in MSdpAgentNotifier
       
    66 	void AttributeRequestComplete(TSdpServRecordHandle aHandle, TInt aError);
       
    67 	void AttributeRequestResult(TSdpServRecordHandle aHandle, TSdpAttributeID aAttrID, CSdpAttrValue* aAttrValue);
       
    68 	void NextRecordRequestComplete(TInt aError, TSdpServRecordHandle aHandle, TInt aTotalRecordsCount);
       
    69 
       
    70 	/////////////////////////////////////////////////////////
       
    71 	void ReportMessage(TInt aVerboseLevel, TRefByValue<const TDesC> aFmt, ...);
       
    72 	
       
    73 	void MakeTextServiceList();
       
    74 	void MakeTextUUIDList();
       
    75 	
       
    76 	TInt BluetoothReady();
       
    77 	void NewDeviceSelectedL(const TBTDevAddr& aAddress,const TBTDeviceName& aDeviceName);
       
    78 	void GetDeviceServicesL();
       
    79 
       
    80 	void GetAttributesL(TInt aIndex);
       
    81 	void GetDeviceAttributesL(const TBTDevAddr& aAddress,const TBTDeviceName& aDeviceName, TSdpServRecordHandle aHandle);
       
    82 	
       
    83 	TBool GettingAllAttributes() const;
       
    84 	void AddAttributeLineL(const TDesC& aDes);
       
    85 	void SetUUIDFilterL(TUint32 aUUID);
       
    86 	void DisplayDeviceInfoL();
       
    87 	void DisplayLocalInfoL();
       
    88 	void CancelSdpAgent();
       
    89 	void DeleteSdpAgent();
       
    90 	void AppendUUIDText(TDes& aBuf, TUUID aUUID) const;
       
    91 	
       
    92 	static void Panic(TBtPanicCode aPanicCode);
       
    93 	static TPtrC UUIDToString(TUint32 aUuidValue);
       
    94 	static TBool StringToUUID(TDesC& aString, TUint32& aUuidValue);	
       
    95 private:
       
    96 	CBtServicesEng();
       
    97 	void ConstructL();
       
    98 	void GetServiceNamesL();
       
    99 	void SdpCompletedWithError(const TInt aError);
       
   100 	void AppendErrorMessage(const TInt aError, TDes& aBuf) const;
       
   101 	void DoAttributeRequestCompleteL();
       
   102 	void DoAttributeRequestResultL(CSdpAttrValue* aAttrValue, TSdpServRecordHandle aHandle);
       
   103 	void DoNextRecordRequestCompleteL(TSdpServRecordHandle aHandle, TInt aError);
       
   104 	void ReleaseModel();
       
   105 
       
   106 private:
       
   107 	// Values of iCurrentAttributeRequest
       
   108 	enum TAttributeRequests
       
   109 		{
       
   110 		ENoOutstandingRequests,
       
   111 		EGettingNamesOnly,
       
   112 		EGettingAllAttributes
       
   113 		};
       
   114 
       
   115 	CSdpAgent* iSdpAgent;
       
   116 	CSdpSearchPattern* iSearchPattern;
       
   117 	//CDesCArrayFlat* iTextArray;
       
   118 	CDesCArrayFlat* iAttributeArray;
       
   119 	RPointerArray <CServiceRecordItem> iRecordArray;
       
   120 	CSdpAttrIdMatchList* iAttributeMatchList;
       
   121 	CBtAttributeBuilder* iAttributeBuilder;
       
   122 
       
   123 	CBtServiceView* iView; // iView is not "owned" by this
       
   124 	//CEikonEnv* iEikon;
       
   125 	
       
   126 	TInt iHandleCounter;
       
   127 	TAttributeRequests iCurrentAttributeRequest;
       
   128 	TBTDeviceName iDeviceName;	//this is taken from the caller and only be used to display
       
   129 	TBTDevAddr iDeviceAddress;	//critical for SDP
       
   130 	
       
   131 	//TBTDeviceClass iDeviceClass;//this is taken from the caller and only be used to display
       
   132 	
       
   133 	TPtrC iServiceName;
       
   134 	TUint32 iUUIDFilter;
       
   135 
       
   136 	RArray<TUUID> iUUIDs;
       
   137 	RPointerArray<HBufC> iUUIDsAsText;
       
   138 	RArray<TInt> iErrorCodes;
       
   139 	RPointerArray<HBufC> iErrorMessages;
       
   140 
       
   141 	RSocketServ iSocketServ;
       
   142 	
       
   143 	TBuf<512> iTextBuf;
       
   144 	};
       
   145 
       
   146 /**
       
   147 Receives and parses the results from an SDP Attribute Request, and builds
       
   148 them into a table (array for listbox) for displaying in
       
   149 the attributes dialog.
       
   150 */
       
   151 class CBtAttributeBuilder : public CBase, public MSdpElementBuilder
       
   152 	{
       
   153 public:
       
   154 	static CBtAttributeBuilder* NewL(CBtServicesEng& aEngine);
       
   155 	void SetHandle(TSdpServRecordHandle aHandle);
       
   156 	void Reset();
       
   157 	~CBtAttributeBuilder();
       
   158 private:
       
   159 	// defined in MSdpElementBuilder
       
   160 	MSdpElementBuilder* BuildUnknownL(TUint8 aType, TUint8 aSizeDesc, const TDesC8& aData);
       
   161 	MSdpElementBuilder* BuildNilL();
       
   162 	MSdpElementBuilder* BuildUintL(const TDesC8& aUint);
       
   163 	MSdpElementBuilder* BuildIntL(const TDesC8& aInt);
       
   164 	MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID);
       
   165 	MSdpElementBuilder* BuildBooleanL(TBool aBool);
       
   166 	MSdpElementBuilder* BuildStringL(const TDesC8& aString);
       
   167 	MSdpElementBuilder* BuildDESL();  // Must not return NULL
       
   168 	MSdpElementBuilder* BuildDEAL();  // ditto
       
   169 	MSdpElementBuilder* StartListL(); // ditto
       
   170 	MSdpElementBuilder* EndListL();
       
   171 	MSdpElementBuilder* BuildURLL(const TDesC8& aURL);
       
   172 
       
   173 private:
       
   174 	CBtAttributeBuilder(CBtServicesEng& aEngine);
       
   175 	void AppendAttrMnemonic(TDes& aBuf, TUint aAttrID) const;
       
   176 	void LineFinishedL();
       
   177 	void ConstructL();
       
   178 private:
       
   179 	enum TCurrentStatus {
       
   180 		EExpectingAttrID,
       
   181 		EExpectingAttrValue
       
   182 		};
       
   183 
       
   184 	RArray<TUint> iAttrIDs;
       
   185 	RPointerArray<HBufC> iAttrMnemonics;
       
   186 
       
   187 	CBtServicesEng& iEngine;
       
   188 	TBuf<KMaxDescriptorLength> iCurrentLine;
       
   189 	TInt iIndentation;
       
   190 	TCurrentStatus iStatus;
       
   191 	TSdpServRecordHandle iHandle;
       
   192 	};
       
   193 
       
   194 
       
   195 #endif