bluetooth/btsdp/database/responsesizevisitor.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #ifndef RESPONSESIZEVISITOR_H
       
    22 #define RESPONSESIZEVISITOR_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <btsdp.h>
       
    26 #include "SDPDatabase.h"
       
    27 #include "ServiceSearchVisitor.h"
       
    28 #include "ExtractorVisitor.h"
       
    29 #include "MAttributeVisitor.h"
       
    30 #include <e32base_private.h>
       
    31 
       
    32 
       
    33 class CSdpDatabase;
       
    34 class CSdpServRecord;
       
    35 class CSdpAttr;
       
    36 
       
    37 /** 
       
    38 	CAttrSizeItem
       
    39 	contains the attribute ID, the size of the attribute and a pointer to the attribute
       
    40 	This object is attached to a list (CArrayPtrFlat) contained in CHandleItem object
       
    41 **/
       
    42 NONSHARABLE_CLASS(CAttrSizeItem) // not a cbase because no benefit, just overhead
       
    43 {
       
    44 friend class CSizeAccumulator;
       
    45 public:
       
    46 	CAttrSizeItem(){};
       
    47 	~CAttrSizeItem(){iAttribute=0;};
       
    48 	CAttrSizeItem(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute):
       
    49 		iAttributeID(aAttributeID),
       
    50 		iSize(aSize),
       
    51 		iAttribute(aAttribute) {};
       
    52 	inline TSdpAttributeID AttID();
       
    53 	inline TUint Size();
       
    54 	inline CSdpAttr* Attr();
       
    55 
       
    56 private:
       
    57 	TSdpAttributeID iAttributeID;
       
    58 	TUint iSize;
       
    59 	CSdpAttr* iAttribute;
       
    60 };
       
    61 inline TSdpAttributeID CAttrSizeItem::AttID() {return iAttributeID;};
       
    62 inline TUint CAttrSizeItem::Size() {return iSize;};
       
    63 inline CSdpAttr* CAttrSizeItem::Attr() {return iAttribute;};
       
    64 
       
    65 // const TUint KSDPAttListGran = 8*(sizeof(CAttrSizeItem*)); granularity for a Seg
       
    66 const TUint KSDPAttListGran = 8; // granularity for a flat
       
    67 
       
    68 /**
       
    69 	CHandleItem
       
    70 	keeps the Service record handle and optionally manages an array of attributes
       
    71 	for that record which match the Attribute ID match list
       
    72 **/
       
    73 NONSHARABLE_CLASS(CHandleItem) : public CBase
       
    74 {
       
    75 friend class CSizeAccumulator;
       
    76 public:
       
    77 	CHandleItem(){};
       
    78 	~CHandleItem();
       
    79 	IMPORT_C static CHandleItem* NewL();
       
    80 	IMPORT_C static CHandleItem* NewLC();
       
    81 	IMPORT_C static CHandleItem* CHandleItemL(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord);
       
    82 
       
    83 //	PutRecord(TSdpServRecordHandle aHandleID, const CSdpServRecord* aRecord); // update the NULL data
       
    84 
       
    85 	void AddAttrItemL(CAttrSizeItem* aItem);
       
    86 	void AddAttrItemL(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute);
       
    87 	inline TInt Count();
       
    88 private:
       
    89 	void ConstructL();
       
    90 	TSdpServRecordHandle iHandleID;
       
    91 	CSdpServRecord* iRecord;
       
    92 	TUint iRecordSize;
       
    93 	CArrayPtrFlat<CAttrSizeItem>* iAttrSizeList; // stores the attributes found
       
    94 };
       
    95 inline TInt CHandleItem::Count() {return iAttrSizeList->Count();};
       
    96 
       
    97 // const TUint KSDPHandListGran = 8*(sizeof(CHandleItem*)); granularity for a Seg
       
    98 const TUint KSDPHandListGran = 8; // granularity for a flat
       
    99 
       
   100 NONSHARABLE_CLASS(CSizeAccumulator) : public CBase
       
   101 	{
       
   102 public:
       
   103 // these methods are used in building this object by searching the database
       
   104 	~CSizeAccumulator();
       
   105 	IMPORT_C static CSizeAccumulator* NewL();
       
   106 	IMPORT_C static CSizeAccumulator* NewLC();
       
   107 	void AddHandleL(CHandleItem* aHandleItem); // create a new array element
       
   108 //	void AddHandle(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord); // create a new array element
       
   109 //	void AddAttrib(TSdpAttributeID aAttributeID, CSdpAttr* aAttribute, TUint aSize);
       
   110 
       
   111 // these methods are used in building the server response once the search has been carried out
       
   112 	IMPORT_C TUint SizeLeft(); // can be called before or after setting the start point
       
   113 	IMPORT_C TUint16 CrcAttribs(); // CRC of the attribute values, not headers
       
   114 	IMPORT_C TBool StartAt(TUint aOffset, TUint& aPartSent, TInt& aRec, TInt& aAtt); // calculates and sets the next record and attribute
       
   115 	IMPORT_C TInt HandleCount();		// returns the count of handles in the array
       
   116 	IMPORT_C TSdpServRecordHandle HandleAt(TInt aOffset); // returns the Record handle at offset i
       
   117 	IMPORT_C TUint HandleSize(TInt aOffset);  // returns the size of the record at offset aOffset
       
   118 	IMPORT_C TInt AttrCount(TInt aOffset);	// returns the count of attributes for record at offset i
       
   119 	IMPORT_C CAttrSizeItem* AttributeOf(TInt aHandleOffset, TInt aAttOffset); // returns the attribute size object (CAttrSizeItem) at i,j
       
   120 
       
   121 private:
       
   122 	CSizeAccumulator():iFirstRec(0),iFirstAtt(0){};
       
   123 	void ConstructL();
       
   124 
       
   125 	CArrayPtrFlat<CHandleItem>* iHandleList;	// stores the records found
       
   126 	TInt iFirstRec;		// offsets for continuation
       
   127 	TInt iFirstAtt;
       
   128 	};
       
   129 
       
   130 /**
       
   131 	Class response size visitor.
       
   132 	Supply a CSizeAccumulator object which will have all the necessary sizes on return.
       
   133 	a) SizeRespSSL is called by service search to get just header list
       
   134 	b) SizeRespARL is called by Attribute request to get the list of sizes of matching attributes for the one record
       
   135 	c) SizeRespSAL is called by Service Attribute Search to get the two lists.
       
   136 	a, c carry out the same UUID search over the attribute tree as ServiceSearchVisitor::SearchDbL
       
   137 	b carries out the same selection of attributes as CAttrExtractVisitor::EncodeAttributesL
       
   138 
       
   139 **/
       
   140 class CSizeEncVisitorAdaptor;
       
   141 
       
   142 NONSHARABLE_CLASS(CResponseSizeVisitor) : public CBase, public MAttributeVisitor
       
   143 	{
       
   144 public:
       
   145     ~CResponseSizeVisitor();
       
   146 
       
   147 	IMPORT_C static void SizeRespSSL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, CSizeAccumulator& aCollector);
       
   148 	IMPORT_C static void SizeRespARL(CSdpServRecord& aRec, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector);
       
   149 	IMPORT_C static void SizeRespSAL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector);
       
   150 
       
   151 	void FoundUUIDL(const TUUID& aUUID); // needs to be public because of the encoder visitor adaptor
       
   152 
       
   153 private:
       
   154 	static CResponseSizeVisitor* NewL();
       
   155 	static CResponseSizeVisitor* NewLC();
       
   156     CResponseSizeVisitor();
       
   157 	void ConstructL();
       
   158 
       
   159 	void SearchRecordL(CSdpServRecord& aRec);
       
   160 
       
   161 	// MAttributeVisitor interface
       
   162     void VisitAttributeL(CSdpAttr &aAttribute);
       
   163     void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType);
       
   164     void StartListL(CSdpAttrValueList &aList);
       
   165     void EndListL();
       
   166 
       
   167 private:
       
   168 	CSizeEncVisitorAdaptor* iAdapter;
       
   169 	CElementParser* iParser;				// used by the encoded UUID parser
       
   170 	const CSdpSearchPattern* iSearchPattern;	// a local pointer to the UUID search list
       
   171 	CSizeAccumulator* iCollector;			// a local pointer to the size collector object supplied
       
   172 	const CSdpAttrIdMatchList* iAtMatList;		// a local pointer to the attribute match list or NULL
       
   173 	CHandleItem* iCurrentRec;				// we build the handle and attribute list and perhaps throw it away
       
   174 	CBitMapAllocator* iFoundIndex;			// a simpler match
       
   175 	TInt iSearchSize;						// how many items in search pattern
       
   176 	TBool	iUseThis;						// do we use this record ?
       
   177 	};
       
   178 
       
   179 
       
   180 #endif