bluetooth/btsdp/server/epocsvr.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1999-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 #ifndef EPOCSVR_H
       
    18 #define EPOCSVR_H
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <btdevice.h>
       
    22 #include <bluetooth/eirpublisher.h>
       
    23 #include "SDPDatabase.h"
       
    24 
       
    25 class CSdpServSession;
       
    26 class CSdpDatabaseSubSession;
       
    27 class CSdpUuidManager;
       
    28 
       
    29 /**
       
    30 SDP Server Shutdown Timer.
       
    31 Closes the SDP server after a preset delay. Activated before the first client connects
       
    32 and after the last client disconnects.
       
    33 **/
       
    34 NONSHARABLE_CLASS(CSdpServerShutdown) : public CTimer
       
    35 	{
       
    36 	enum {KSdpServerShutdownDelay=5000000};	// approx 5s
       
    37 public:
       
    38 	inline CSdpServerShutdown();
       
    39 	inline void ConstructL();
       
    40 	inline void Start();
       
    41 private:
       
    42 	void RunL();
       
    43 	};
       
    44 
       
    45 _LIT(KSdpServerPanic,"SdpServInternal");
       
    46 enum TSdpServerPanic
       
    47 	{
       
    48 	ESdpStoredAttrValNotEncoded = 0,
       
    49 	ESdpAttributeEncodingFailed = 1,
       
    50 	ESdpBadState = 2,
       
    51 	ESdpReadAlreadyOutstanding = 3,
       
    52 	ESdpOutstandingOperation = 4,
       
    53 	};
       
    54 
       
    55 void PanicServer(TSdpServerPanic aPanic);
       
    56 void PanicClient(const RMessage2& aMessage, TSdpClientPanic aPanic);
       
    57 
       
    58 /**
       
    59    The EPOC SDP Server.
       
    60    This is the start of the EPOC client/server
       
    61    class hierarchy
       
    62 **/
       
    63 NONSHARABLE_CLASS(CSdpServer) : public CPolicyServer
       
    64 	{
       
    65 public:
       
    66 	//construct / destruct
       
    67 	static CSdpServer* NewLC();
       
    68 	CSdpDatabase* Database();
       
    69 	void BuildRecordZeroL();
       
    70 	~CSdpServer();
       
    71 
       
    72 	void AddSession();
       
    73 	void DropSession();
       
    74 
       
    75 	inline CSdpListener& Listener() const;
       
    76 
       
    77 	TInt RunError(TInt aError);
       
    78 	
       
    79 	//database operations
       
    80 	CSdpServRecord* CreateServiceRecordL(const RMessage2& aMessage);
       
    81 	CSdpServRecord* FindAndCheckServiceRecordForDeletion(const RMessage2& aMessage);
       
    82 	void UpdateAttributeL(const RMessage2& aMessage);
       
    83 	void DeleteAttribute(const RMessage2& aMessage);
       
    84 	void DeleteServiceRecord(CSdpServRecord* aServiceRecord);
       
    85 	
       
    86 private:
       
    87 	CSdpServer();
       
    88 	void ConstructL();
       
    89 	//open/close a session
       
    90 	CSession2* NewSessionL(const TVersion &aVersion) const;
       
    91 	CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
       
    92 
       
    93 	void CheckAllowedL(const RMessage2& aMessage, const CSdpServRecord& aRecord);
       
    94 	TBool Allowed(const RMessage2& aMessage, const CSdpServRecord& aRecord);
       
    95 	
       
    96 	CSdpServRecord* FindRecordByHandle(const TSdpServRecordHandle aHandle);
       
    97 	CSdpAttr* FindAttributeByID(CSdpServRecord& aRecord, const TSdpAttributeID aAttrId);
       
    98 
       
    99 	void UpdateOrCreateAtributeL(CSdpServRecord& aRecord, TSdpAttributeID aAttrId, const TDesC8& aPtr);
       
   100 	void DatabaseStateChange();
       
   101 
       
   102 private:
       
   103 	TInt iMaxSessionCount;
       
   104 	TInt iSessionCount;
       
   105 
       
   106 	CSdpServerShutdown		iShutdown;
       
   107 	
       
   108 	RSocketServ				iSocketServ;
       
   109 	CSdpListener*			iSdpListener;
       
   110 	CSdpDatabase*			iSdpDatabase;
       
   111 
       
   112 	CSdpServRecord*			iRecZero;
       
   113 	CSdpAttrValueUint*		iDbState;			// This value is used to update a state attribute whenever a record is 
       
   114 												// added or removed to facilitate caching by remotes
       
   115 	CAttrEncoderVisitor*	iEncoderVisitor;	// We maintain a pre-alloced encoder visitor so we can update 
       
   116 												// attributes without having to allocate memory.
       
   117 	RBuf8					iEncodeBuf;			// Used by the encoder to encode into
       
   118 	CSdpUuidManager*		iUuidManager;
       
   119 	};
       
   120 
       
   121 
       
   122 /**
       
   123    SDP Server Session.
       
   124    General purpose session used to create functionally specific subsessions.
       
   125 **/
       
   126 NONSHARABLE_CLASS(CSdpServSession) : public CSession2
       
   127 	{
       
   128 private:
       
   129 	enum TSubSessionType{ESdpAgent, ESdpDatabase}; /*however sdpagent is still 
       
   130 												     part of esock and may never
       
   131 													 be moved here*/
       
   132 
       
   133 public:
       
   134 	CSdpServSession(const RMessage2& aMessage);
       
   135 	~CSdpServSession();
       
   136 
       
   137 	void ServiceL(const RMessage2 &aMessage);
       
   138 
       
   139 	//Create/delete subsession
       
   140 	void NewSubSessionL(TSubSessionType aType, const RMessage2& aMessage);
       
   141 	void CloseSubSession(const RMessage2& aMessage); //can't fail - can panic client
       
   142 
       
   143 	//resource counting
       
   144 	void NumResourcesL(const RMessage2& aMessage);
       
   145 	TInt CountResources();
       
   146 
       
   147 	CSdpServer& Server();
       
   148 	void CreateL(const CServer2& aServer);
       
   149 
       
   150 private:
       
   151 	void ConstructL();
       
   152 	void CreateL();
       
   153 
       
   154 	void DeleteSubsession(TUint aHandle, const RMessage2& aMessage);
       
   155 	void RemoveSessionRecords();
       
   156 	
       
   157 private:
       
   158 	TUint iSubSessionCount;
       
   159 	RPointerArray<CSdpServRecord> iSessionRecords;
       
   160 	};
       
   161 
       
   162 
       
   163 //**********************************
       
   164 // CEirPublisherSdpUuidBase
       
   165 //**********************************
       
   166 /**
       
   167 CEirPublisherSdpUuidBase provides base class for Sdp Uuid Eir Publisher.
       
   168 **/
       
   169 NONSHARABLE_CLASS(CEirPublisherSdpUuidBase) : public CBase, public MEirPublisherNotifier
       
   170 	{
       
   171 public:
       
   172 	static CEirPublisherSdpUuidBase* NewL(CSdpUuidManager& aSdpUuidManager, TEirTag aTag);
       
   173 
       
   174 	~CEirPublisherSdpUuidBase();
       
   175 	void UpdateUuids(TInt aLength);
       
   176 
       
   177 protected:
       
   178 	CEirPublisherSdpUuidBase(CSdpUuidManager& aSdpUuidManager, TEirTag aTag);
       
   179 	void ConstructL();
       
   180 
       
   181 protected:
       
   182 	CSdpUuidManager& iParent;
       
   183 	CEirPublisher* iPublisher; 
       
   184 	TEirTag iTag;
       
   185 	};
       
   186 
       
   187 //**********************************
       
   188 // CEirPublisherSdpUuid16
       
   189 //**********************************
       
   190 /**
       
   191 Provides functionality to publish 16 bit UUIDs to EIR.
       
   192 **/
       
   193 NONSHARABLE_CLASS(CEirPublisherSdpUuid16) : public CEirPublisherSdpUuidBase
       
   194 	{
       
   195 public:
       
   196 	static CEirPublisherSdpUuid16* NewL(CSdpUuidManager& aSdpDatabase);
       
   197 	~CEirPublisherSdpUuid16();
       
   198 
       
   199 private:
       
   200 	CEirPublisherSdpUuid16(CSdpUuidManager& aSdpDatabase);
       
   201 
       
   202 	// From MEirPublisherNotifier
       
   203 	void MepnSpaceAvailable(TUint aBytesAvailable);
       
   204 	void MepnSetDataError(TInt aResult);
       
   205 
       
   206 private:
       
   207 	HBufC8* iExtracted;
       
   208 	};
       
   209 
       
   210 //**********************************
       
   211 // CEirPublisherSdpUuid128
       
   212 //**********************************
       
   213 /**
       
   214 Provides functionality to publish 128 bit UUIDs to EIR.
       
   215 **/
       
   216 NONSHARABLE_CLASS(CEirPublisherSdpUuid128) : public CEirPublisherSdpUuidBase
       
   217 	{
       
   218 public:
       
   219 	static CEirPublisherSdpUuid128* NewL(CSdpUuidManager& aSdpDatabase);
       
   220 	~CEirPublisherSdpUuid128();
       
   221 
       
   222 private:
       
   223 	CEirPublisherSdpUuid128(CSdpUuidManager& aSdpDatabase);
       
   224 
       
   225 	// From MEirPublisherNotifier
       
   226 	void MepnSpaceAvailable(TUint aBytesAvailable);
       
   227 	void MepnSetDataError(TInt aResult);
       
   228 
       
   229 private:
       
   230 	HBufC8* iExtracted;
       
   231 	};
       
   232 
       
   233 
       
   234 //**********************************
       
   235 // CSdpUuidManager
       
   236 //**********************************
       
   237 /**
       
   238 Retrieve UUIDs from CSdpDatabase and then store them in 16 or 128 bit Eir Uuid PublishersUUIDs
       
   239 **/
       
   240 NONSHARABLE_CLASS(CSdpUuidManager) : public CBase
       
   241 	{
       
   242 public:
       
   243 	static CSdpUuidManager* NewL(CSdpDatabase& aSdpDatabase);
       
   244 	~CSdpUuidManager();
       
   245 	
       
   246 	void NotifySdpRecordChange();
       
   247 	void AddUuid(TUUID aUuid);
       
   248 	void ResetUuids();
       
   249 	HBufC8* GetAll16BitUUIDs(TInt aBytesAvailable, TBool& aPartial);
       
   250 	HBufC8* GetAll128BitUUIDs(TInt aBytesAvailable, TBool& aPartial);
       
   251 
       
   252 private:
       
   253 	CSdpUuidManager(CSdpDatabase& aSdpDatabase);
       
   254 	void ConstructL();
       
   255 
       
   256 private:
       
   257 	CSdpDatabase& 				iSdpDatabase;
       
   258 	CAttrUuidVisitor*			iUuidVisitor;
       
   259 	CEirPublisherSdpUuid16* 	iEirPublisherSdpUuid16;
       
   260 	CEirPublisherSdpUuid128*	iEirPublisherSdpUuid128;
       
   261 	RUUIDContainer				i16BitUUIDs;
       
   262 	RUUIDContainer				i128BitUUIDs;
       
   263 	};
       
   264 
       
   265 enum TSdpServerPanics
       
   266 	{
       
   267 	ESdpServerUuidFlattenBroken = 0,
       
   268 	ESdpServerDeleteServiceRecordHandleZero = 1,
       
   269 	ESdpServerUpdateAttributeRecordHandleZero = 2,
       
   270 	ESdpServerDeleteAttributeRecordHandleZero = 3
       
   271 	};
       
   272 _LIT(KSdpServerPanicName, "SdpServer");
       
   273 
       
   274 #endif