bluetoothmgmt/btmgr/Inc/BTManServer.h
changeset 0 29b1cd4cb562
child 11 20fda83a6398
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  @file
       
    18  @internalAll
       
    19 */
       
    20 
       
    21 #ifndef BTManServer_H
       
    22 #define BTManServer_H
       
    23 
       
    24 #include <bt_subscribe.h>
       
    25 #include "BTRegistryDB.h"
       
    26 #include "btmanclientserver.h"
       
    27 
       
    28 #if KMaxBluetoothNameLen > KMaxFriendlyNameLen
       
    29 #define KLongestName KMaxBluetoothNameLen
       
    30 #else
       
    31 #define KLongestName KMaxFriendlyNameLen
       
    32 #endif
       
    33 
       
    34 class CBTSecMan;
       
    35 class CBTRegistryHelper;
       
    36 class CBTManSession;
       
    37 class CBTManSubSession;
       
    38 
       
    39 /**
       
    40 BTMan Server Shutdown Timer.
       
    41 Closes the BTMan server after a preset delay. Activated before the first client connects
       
    42 and after the last client disconnects.
       
    43 **/
       
    44 NONSHARABLE_CLASS(CBTManServerShutdown) : public CTimer
       
    45 	{
       
    46 	enum {KBTManServerShutdownDelay=5000000};	// 5s
       
    47 public:
       
    48 	inline CBTManServerShutdown();
       
    49 	inline void ConstructL();
       
    50 	inline void Start();
       
    51 private:
       
    52 	void RunL();
       
    53 	};
       
    54 
       
    55 void PanicServer(TInt aPanic);
       
    56 void PanicClient(const RMessage2& aMessage, TInt aPanic, CBTManSession* aSession);
       
    57 
       
    58 //**********************************
       
    59 //MBTManHelper
       
    60 //**********************************
       
    61 /**
       
    62 Helper interface class.
       
    63 Defines interface to allow CBTManMessage to use SecMan helper objects.
       
    64 **/
       
    65 class MBTManHelper
       
    66 	{
       
    67 public:
       
    68 	virtual void Delete() = 0;
       
    69 	virtual const RMessage2& Message() = 0;
       
    70 	};
       
    71 
       
    72 //**********************************
       
    73 //CBTManMessage
       
    74 //**********************************
       
    75 /**
       
    76 RMessage2 container class.
       
    77 Ties together client requests and helper objects dealing with them.
       
    78 Messages must be completed via this class.
       
    79 **/
       
    80 NONSHARABLE_CLASS(CBTManMessage) : public CBase
       
    81 	{
       
    82 public:
       
    83 	static CBTManMessage* NewL(const RMessage2& aMessage);
       
    84 	~CBTManMessage();
       
    85 	void SetHelper(MBTManHelper* aHelper);
       
    86 	void RemoveHelper();
       
    87 	void Complete(TInt aReason);
       
    88 	const RMessage2& Message();
       
    89 	const TAny* CancelPtr();
       
    90 	MBTManHelper* Helper();
       
    91 	TBool operator==(CBTManMessage& aMessage) const;
       
    92 private:
       
    93 	CBTManMessage(const RMessage2& aMessage);
       
    94 	void ConstructL();
       
    95 private:
       
    96 	RMessage2	iMessage;	//<The message to be completed
       
    97 	const TAny* iCancelPtr;	//<Address of the TRequestStatus of the client-side active object - used for cancelling purposes
       
    98 	MBTManHelper* iHelper;	//<The helper associated with the message
       
    99 	};
       
   100 
       
   101 
       
   102 //**********************************
       
   103 //CBTManServer
       
   104 //**********************************
       
   105 /**
       
   106 The BTMan Server.
       
   107 **/
       
   108 NONSHARABLE_CLASS(CBTManServer) : public CPolicyServer
       
   109 	{
       
   110 public:
       
   111 	//construct / destruct
       
   112 	static CServer2* NewLC();
       
   113 	~CBTManServer();
       
   114 
       
   115 	void AddSession();
       
   116 	void DropSession();
       
   117 
       
   118 	inline TInt MaxSessionCount() const;
       
   119 	inline TInt SessionCount() const;
       
   120 	
       
   121 	//return an object container. Will produce containers with unique ids within the server
       
   122 	CObjectCon* NewContainerL();
       
   123 	void DeleteContainer(CObjectCon* aCon);
       
   124 
       
   125 	inline CBTRegistry& Registry() const;
       
   126 
       
   127 	void Publish(TUint aKey, TInt aValue); // only publish ints for now, ignore error
       
   128 	void NotifyViewChange(CBTManSubSession& aSubSessionViewOwner, const TDesC& aViewDescriptor);
       
   129 
       
   130 private:
       
   131 	CBTManServer();
       
   132 	void ConstructL();
       
   133 	//open/close a session
       
   134 	CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
       
   135 
       
   136 private:
       
   137 	TInt					iMaxSessionCount;
       
   138 	TInt					iSessionCount;	//<The number of sessions
       
   139 	CBTManServerShutdown	iShutdown;//<A timer used to shut the server down after all clients have exited.
       
   140 	CObjectConIx*			iContainerIndex;//<The server has an onject container index which creates an object container for each session
       
   141 	CBTRegistry*			iRegistry;
       
   142 	RProperty				iProperty;	// so that subsessions can publish change info
       
   143 	};
       
   144 
       
   145 inline TInt CBTManServer::MaxSessionCount() const {return iMaxSessionCount;}
       
   146 inline TInt CBTManServer::SessionCount() const {return iSessionCount;}
       
   147 inline CBTRegistry& CBTManServer::Registry() const {return *iRegistry;}
       
   148 
       
   149 //
       
   150 //**********************************
       
   151 //CBTManSession
       
   152 //**********************************
       
   153 /**
       
   154 BTMan Server Session.
       
   155 General purpose session used to create functionally specific subsessions.
       
   156 **/
       
   157 NONSHARABLE_CLASS(CBTManSession) : public CSession2
       
   158 	{
       
   159 private:
       
   160 	enum TSubSessionType{EHostResolver, ERegistry, ELocalDevice, ECommPortSettings,ESecuritySettingsB};
       
   161 public:
       
   162 	CBTManSession(CBTRegistry& aRegistry, const RMessage2& aMessage);
       
   163 	void CreateL();
       
   164 	void ConstructL();
       
   165 	~CBTManSession();
       
   166 
       
   167 	//Create/delete subsession
       
   168 	void NewSubSessionL(TSubSessionType aType, const RMessage2 &aMessage);
       
   169 	void CloseSubSession(const RMessage2 &aMessage);
       
   170 	void DeleteSubsession(TInt aHandle, const RMessage2 &aMessage); //can't fail - can panic client
       
   171 	CBTManSubSession* SubSessionFromHandle(TInt aHandle);
       
   172 	CBTManServer& Server();
       
   173 
       
   174 	void ServiceL(const RMessage2 &aMessage);
       
   175 	TInt HandleError(TInt aError, const RMessage2 &aMessage);
       
   176 	TBool DispatchSessMessageL(const RMessage2 &aMessage);
       
   177 	void DispatchSubSessMessageL(const RMessage2 &aMessage);
       
   178 
       
   179 	void CompleteMessage(const RMessage2& aMessage, TInt aReason);
       
   180 	void CompleteMessage(MBTManHelper* aHelper, TInt aReason);
       
   181 	void CreateBTManMessageL(const RMessage2& aMessage);
       
   182 	CBTManMessage* FindMessage(const RMessage2& aMessage);
       
   183 	CBTManMessage* FindMessage(MBTManHelper* aHelper);
       
   184 	void DeleteMessage(CBTManMessage* aMessage);
       
   185 
       
   186 	void CancelRequest(const RMessage2& aMessage);
       
   187 
       
   188 	TBool SubSessionHasOverlappingView(CBTManSubSession& aSubSessionViewOwner, const TDesC& aViewDescriptor);
       
   189 
       
   190 private:
       
   191 	void DoCompleteMessage(CBTManMessage& aMessage, TInt aReason);
       
   192 	void CompleteOutstandingMessages();
       
   193 	void ClientRegChangeNotification(TAny* aPtr1);
       
   194 
       
   195 private:
       
   196 	CObjectCon*					iContainer;		//<object container for this session
       
   197 	CObjectIx*					iSubSessions;	//<object index which stores subsessions
       
   198 	TInt						iResourceCount;		//<total number of resources allocated
       
   199 	CBTRegistry&				iRegistry;
       
   200 
       
   201 	CArrayPtr<CBTManMessage>*	iMessageArray;	//array of outstanding messages
       
   202 	RMessage2 iCurrentMessage;
       
   203 	TBool	  					iClientPanic;   //Flag to indicate if ClientPanic'd when session closed
       
   204 
       
   205 	};
       
   206 
       
   207 
       
   208 //**********************************
       
   209 // CBTManSubSession
       
   210 //**********************************
       
   211 /**
       
   212 BTMan Subsession base class.
       
   213 **/
       
   214 NONSHARABLE_CLASS(CBTManSubSession) : public CObject
       
   215 	{
       
   216 public:
       
   217 	virtual void Cleanup(TInt aError)=0;
       
   218 	virtual TBool IsOverlappingView(const TDesC& aViewDescriptor);
       
   219 	virtual void SetViewChangeNotificationMessage(const RMessage2& aMessage);
       
   220 
       
   221 protected:
       
   222 	CBTManSubSession(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   223 	void NotifyChange(TUint aTableChanged);
       
   224 	void NotifyChange(TUint aTableChanged, CBTManSubSession& aSubSessionViewOwner, const TDesC& aViewDescriptor);
       
   225 
       
   226 protected:
       
   227 	CBTManSession&	iSession;	// session owning us
       
   228 	CBTRegistry&	iRegistry;	// the class that shields us from DBMS
       
   229 
       
   230 	RMessage2       iViewChangeNotificationMessage; // not all subsession types may use this
       
   231 	};
       
   232 
       
   233 //**********************************
       
   234 // CBTRegistrySubSession
       
   235 //**********************************
       
   236 /**
       
   237 Registry Subsession.
       
   238 Represents (server-side) remote Bluetooth devices
       
   239 **/
       
   240 NONSHARABLE_CLASS(CBTRegistrySubSession): public CBTManSubSession
       
   241 	{
       
   242 public:
       
   243 	static CBTRegistrySubSession* NewL(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   244 	~CBTRegistrySubSession();
       
   245 
       
   246 	void PreLoadL(const RMessage2& aMessage);
       
   247 	void GetDeviceL(const TBTNamelessDevice& aDevice, const RMessage2& aMessage);
       
   248 	void AddDeviceL(const CBTDevice& aDetails, const RMessage2& aMessage);
       
   249 	void ModifyL(const CBTDevice& aDetails, const RMessage2& aMessage);
       
   250 	void ModifyL(const TBTNamelessDevice& aNewDetails, const RMessage2& aMessage);
       
   251 	void ModifyNameL(const TBTDevAddr& aAddress, const RMessage2& aMessage);
       
   252 	void OpenViewL(const TBTRegistrySearch& aSearch, const RMessage2& aMessage);
       
   253 	void UnpairL(const TBTDevAddr& aAddress, const RMessage2& aMessage);
       
   254 	void UnpairViewL(const RMessage2& aMessage);
       
   255 	void RetrieveL(const RMessage2& aMessage);
       
   256 	void DeleteViewL(const RMessage2& aMessage);
       
   257 	void CloseView(const RMessage2& aMessage);
       
   258 	void Cleanup(TInt aError);
       
   259 
       
   260 private:
       
   261 	void ConstructL();
       
   262 	CBTRegistrySubSession(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   263 	void DoCloseView();
       
   264 	void NotifyChange(CBTManSubSession& aSubSessionViewOwner, const TDesC& aViewDescriptor);
       
   265 
       
   266 	virtual TBool IsOverlappingView(const TDesC& aViewDescriptor);
       
   267 	virtual void SetViewChangeNotificationMessage(const RMessage2& aMessage);
       
   268 
       
   269 private:
       
   270 	RDbView*		iDBView;
       
   271 	TInt			iViewCount;
       
   272 	TDbBookmark		iBookmark;	// we look after our bookmark for registry to zip back to
       
   273 	CBufFlat*		iResultBuffer; // for communicating back to client
       
   274 	TInt			iNumDevicesInBuffer;
       
   275 
       
   276 	// Each Registry subsession keeps one of these to then use for view spoil notifications.
       
   277 	// When the server sees a subsession perform a writeable view operation it will give the changed 
       
   278 	// subsession's precompiled query to all other subsessions, each of which will be asked to run 
       
   279 	// the precompiled query against its own rowset row by row.
       
   280 	// Any Match will be reported back and tells the server that a spoil has occurred
       
   281 	
       
   282 	HBufC* iUnderlyingSearch;
       
   283 
       
   284 	};
       
   285 
       
   286 
       
   287 
       
   288 //**********************************
       
   289 // CBTLocalDeviceSubSession
       
   290 //**********************************
       
   291 /**
       
   292 Registry Subsession.
       
   293 Represents (server-side) local device details
       
   294 **/
       
   295 NONSHARABLE_CLASS(CBTLocalDeviceSubSession): public CBTManSubSession
       
   296 	{
       
   297 public:
       
   298 	static CBTLocalDeviceSubSession* NewL(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   299 	~CBTLocalDeviceSubSession();
       
   300 
       
   301 	void GetL(const RMessage2& aMessage);
       
   302 	void UpdateL(const TBTLocalDevice& aLocalDevice, const RMessage2& aMessage);
       
   303 	void Cleanup(TInt aError);
       
   304 private:
       
   305 	CBTLocalDeviceSubSession(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   306 	void ConstructL();
       
   307 	};
       
   308 
       
   309 //**********************************
       
   310 // CBTCommPortSettingsSubSession
       
   311 //**********************************
       
   312 /**
       
   313 Registry Subsession.
       
   314 Represents (server-side) settings for virtual serial ports
       
   315 **/
       
   316 NONSHARABLE_CLASS(CBTCommPortSettingsSubSession): public CBTManSubSession
       
   317 	{
       
   318 public:
       
   319 	static CBTCommPortSettingsSubSession* NewL(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   320 	~CBTCommPortSettingsSubSession();
       
   321 
       
   322 	void GetL(const TBTCommPortSettings& aLocalDevice, const RMessage2& aMessage);
       
   323 	void UpdateL(const TBTCommPortSettings& aLocalDevice, const RMessage2& aMessage);
       
   324 	void DeleteL(const TBTCommPortSettings& aLocalDevice, const RMessage2& aMessage);
       
   325 	void Cleanup(TInt aError);
       
   326 private:
       
   327 	CBTCommPortSettingsSubSession(CBTManSession& aSession, CBTRegistry& aRegistry);
       
   328 	void ConstructL();	
       
   329 	};
       
   330 
       
   331 
       
   332 /*
       
   333 * Panic definitions
       
   334 */
       
   335 _LIT(KBTManPanic,"BTManServer");
       
   336 // reasons for server panic
       
   337 enum TBTManServerPanic
       
   338 	{
       
   339 	EBTManBadRequest,
       
   340 	EBTManBadDescriptor,
       
   341 	EBTManBadSubSessionHandle,
       
   342 	EBTManBadSubSessionRemove,
       
   343 	EBTManBadSubSessionType,
       
   344 	EBTManBadHelper,
       
   345 	EBTManBadBTManMessage,
       
   346 	EBTManBadServiceArray,
       
   347 	EBTManBadNotifierArray,
       
   348 	EBTManBadHCIRequestRequest,
       
   349 	EBTManTooManyDevicesInView,
       
   350 	EBTManUnknownSeverity,
       
   351 	EBTManClientShouldBeBusy,
       
   352 	EBTManBadState,
       
   353 	EBTManUnexpectedDbError,
       
   354 	};
       
   355 
       
   356 
       
   357 
       
   358 #endif
       
   359