bluetooth/btsdp/database/responsesizevisitor.h
changeset 51 20ac952a623c
parent 0 29b1cd4cb562
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    33 class CSdpDatabase;
    33 class CSdpDatabase;
    34 class CSdpServRecord;
    34 class CSdpServRecord;
    35 class CSdpAttr;
    35 class CSdpAttr;
    36 
    36 
    37 /** 
    37 /** 
    38 	CAttrSizeItem
    38 	TAttrSizeItem
    39 	contains the attribute ID, the size of the attribute and a pointer to the attribute
    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
    40 	This object is attached to a list (CArrayPtrFlat) contained in CHandleItem object
    41 **/
    41 **/
    42 NONSHARABLE_CLASS(CAttrSizeItem) // not a cbase because no benefit, just overhead
    42 NONSHARABLE_CLASS(TAttrSizeItem)
    43 {
    43 	{
    44 friend class CSizeAccumulator;
    44 friend class CSizeAccumulator;
    45 public:
    45 public:
    46 	CAttrSizeItem(){};
    46 	TAttrSizeItem(){};
    47 	~CAttrSizeItem(){iAttribute=0;};
    47 	TAttrSizeItem(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute):
    48 	CAttrSizeItem(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute):
       
    49 		iAttributeID(aAttributeID),
    48 		iAttributeID(aAttributeID),
    50 		iSize(aSize),
    49 		iSize(aSize),
    51 		iAttribute(aAttribute) {};
    50 		iAttribute(aAttribute) {};
    52 	inline TSdpAttributeID AttID();
    51 	inline TSdpAttributeID AttID() {return iAttributeID;}
    53 	inline TUint Size();
    52 	inline TUint Size() {return iSize;}
    54 	inline CSdpAttr* Attr();
    53 	inline CSdpAttr* Attr() {return iAttribute;}
    55 
    54 
    56 private:
    55 private:
    57 	TSdpAttributeID iAttributeID;
    56 	TSdpAttributeID iAttributeID;
    58 	TUint iSize;
    57 	TUint iSize;
    59 	CSdpAttr* iAttribute;
    58 	CSdpAttr* iAttribute;
    60 };
    59 	};
    61 inline TSdpAttributeID CAttrSizeItem::AttID() {return iAttributeID;};
       
    62 inline TUint CAttrSizeItem::Size() {return iSize;};
       
    63 inline CSdpAttr* CAttrSizeItem::Attr() {return iAttribute;};
       
    64 
    60 
    65 // const TUint KSDPAttListGran = 8*(sizeof(CAttrSizeItem*)); granularity for a Seg
    61 // const TUint KSDPAttListGran = 8*(sizeof(TAttrSizeItem*)); granularity for a Seg
    66 const TUint KSDPAttListGran = 8; // granularity for a flat
    62 const TUint KSDPAttListGran = 8; // granularity for a flat
    67 
    63 
    68 /**
    64 /**
    69 	CHandleItem
    65 	CHandleItem
    70 	keeps the Service record handle and optionally manages an array of attributes
    66 	keeps the Service record handle and optionally manages an array of attributes
    71 	for that record which match the Attribute ID match list
    67 	for that record which match the Attribute ID match list
    72 **/
    68 **/
    73 NONSHARABLE_CLASS(CHandleItem) : public CBase
    69 NONSHARABLE_CLASS(CHandleItem) : public CBase
    74 {
    70 	{
    75 friend class CSizeAccumulator;
    71 friend class CSizeAccumulator;
    76 public:
    72 public:
    77 	CHandleItem(){};
    73 	CHandleItem(){};
       
    74 	static CHandleItem* NewLC(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord);
    78 	~CHandleItem();
    75 	~CHandleItem();
    79 	IMPORT_C static CHandleItem* NewL();
    76 	
    80 	IMPORT_C static CHandleItem* NewLC();
    77 	void AddAttrItemL(TAttrSizeItem* aItem);
    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);
    78 	void AddAttrItemL(const TSdpAttributeID aAttributeID, TUint aSize, CSdpAttr* aAttribute);
    87 	inline TInt Count();
    79 	inline TInt Count() {return iAttrSizeList->Count();}
       
    80 	
    88 private:
    81 private:
       
    82 	CHandleItem(TSdpServRecordHandle aHandleID, CSdpServRecord* aRecord);
    89 	void ConstructL();
    83 	void ConstructL();
    90 	TSdpServRecordHandle iHandleID;
    84 	TSdpServRecordHandle iHandleID;
    91 	CSdpServRecord* iRecord;
    85 	CSdpServRecord* iRecord;
    92 	TUint iRecordSize;
    86 	TUint iRecordSize;
    93 	CArrayPtrFlat<CAttrSizeItem>* iAttrSizeList; // stores the attributes found
    87 	CArrayPtrFlat<TAttrSizeItem>* iAttrSizeList; // stores the attributes found
    94 };
    88 	};
    95 inline TInt CHandleItem::Count() {return iAttrSizeList->Count();};
       
    96 
    89 
    97 // const TUint KSDPHandListGran = 8*(sizeof(CHandleItem*)); granularity for a Seg
    90 // const TUint KSDPHandListGran = 8*(sizeof(CHandleItem*)); granularity for a Seg
    98 const TUint KSDPHandListGran = 8; // granularity for a flat
    91 const TUint KSDPHandListGran = 8; // granularity for a flat
    99 
    92 
   100 NONSHARABLE_CLASS(CSizeAccumulator) : public CBase
    93 NONSHARABLE_CLASS(CSizeAccumulator) : public CBase
   103 // these methods are used in building this object by searching the database
    96 // these methods are used in building this object by searching the database
   104 	~CSizeAccumulator();
    97 	~CSizeAccumulator();
   105 	IMPORT_C static CSizeAccumulator* NewL();
    98 	IMPORT_C static CSizeAccumulator* NewL();
   106 	IMPORT_C static CSizeAccumulator* NewLC();
    99 	IMPORT_C static CSizeAccumulator* NewLC();
   107 	void AddHandleL(CHandleItem* aHandleItem); // create a new array element
   100 	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 
   101 
   111 // these methods are used in building the server response once the search has been carried out
   102 // 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
   103 	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
   104 	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
   105 	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
   106 	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
   107 	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
   108 	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
   109 	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
   110 	IMPORT_C TAttrSizeItem* AttributeOf(TInt aHandleOffset, TInt aAttOffset); // returns the attribute size object (TAttrSizeItem) at i,j
   120 
   111 
   121 private:
   112 private:
   122 	CSizeAccumulator():iFirstRec(0),iFirstAtt(0){};
   113 	CSizeAccumulator():iFirstRec(0),iFirstAtt(0){};
   123 	void ConstructL();
   114 	void ConstructL();
   124 
   115 
   135 	c) SizeRespSAL is called by Service Attribute Search to get the two lists.
   126 	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
   127 	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
   128 	b carries out the same selection of attributes as CAttrExtractVisitor::EncodeAttributesL
   138 
   129 
   139 **/
   130 **/
   140 class CSizeEncVisitorAdaptor;
   131 class CResponseSizeVisitor;
       
   132 
       
   133 // need this because CResponseSizeVisitor already has start list method...
       
   134 NONSHARABLE_CLASS(TSizeEncVisitorAdaptor) : public MIgnorer
       
   135 	{
       
   136 public:
       
   137 	TSizeEncVisitorAdaptor(CResponseSizeVisitor& aVisitor);
       
   138 	MSdpElementBuilder* BuildUUIDL(const TUUID& aUUID);
       
   139 	
       
   140 private:
       
   141 	CResponseSizeVisitor& iVisitor;
       
   142 	};
   141 
   143 
   142 NONSHARABLE_CLASS(CResponseSizeVisitor) : public CBase, public MAttributeVisitor
   144 NONSHARABLE_CLASS(CResponseSizeVisitor) : public CBase, public MAttributeVisitor
   143 	{
   145 	{
       
   146 friend class TSizeEncVisitorAdaptor;
   144 public:
   147 public:
   145     ~CResponseSizeVisitor();
   148 	~CResponseSizeVisitor();
   146 
   149 	
   147 	IMPORT_C static void SizeRespSSL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, CSizeAccumulator& aCollector);
   150 	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);
   151 	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);
   152 	IMPORT_C static void SizeRespSAL(CSdpDatabase& aDb, const CSdpSearchPattern& aPattern, const CSdpAttrIdMatchList& aList, CSizeAccumulator& aCollector);
   150 
   153 	
   151 	void FoundUUIDL(const TUUID& aUUID); // needs to be public because of the encoder visitor adaptor
       
   152 
       
   153 private:
   154 private:
   154 	static CResponseSizeVisitor* NewL();
       
   155 	static CResponseSizeVisitor* NewLC();
   155 	static CResponseSizeVisitor* NewLC();
   156     CResponseSizeVisitor();
   156 	CResponseSizeVisitor();
   157 	void ConstructL();
   157 	void ConstructL();
   158 
   158 	
   159 	void SearchRecordL(CSdpServRecord& aRec);
   159 	void SearchRecordL(CSdpServRecord& aRec);
   160 
   160 	
       
   161 	void FoundUUIDL(const TUUID& aUUID);
       
   162 	
   161 	// MAttributeVisitor interface
   163 	// MAttributeVisitor interface
   162     void VisitAttributeL(CSdpAttr &aAttribute);
   164 	void VisitAttributeL(CSdpAttr &aAttribute);
   163     void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType);
   165 	void VisitAttributeValueL(CSdpAttrValue &aValue, TSdpElementType aType);
   164     void StartListL(CSdpAttrValueList &aList);
   166 	void StartListL(CSdpAttrValueList &aList);
   165     void EndListL();
   167 	void EndListL();
   166 
   168 	
   167 private:
   169 private:
   168 	CSizeEncVisitorAdaptor* iAdapter;
   170 	TSizeEncVisitorAdaptor iAdapter;
   169 	CElementParser* iParser;				// used by the encoded UUID parser
   171 	CElementParser* iParser;				// used by the encoded UUID parser
   170 	const CSdpSearchPattern* iSearchPattern;	// a local pointer to the UUID search list
   172 	const CSdpSearchPattern* iSearchPattern;	// a local pointer to the UUID search list
   171 	CSizeAccumulator* iCollector;			// a local pointer to the size collector object supplied
   173 	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
   174 	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 	CBitMapAllocator* iFoundIndex;			// a simpler match
   175 	TInt iSearchSize;						// how many items in search pattern
   176 	TInt iSearchSize;						// how many items in search pattern
   176 	TBool	iUseThis;						// do we use this record ?
   177 	TBool	iUseThis;						// do we use this record ?
   177 	};
   178 	};
   178 
   179