bluetoothmgmt/btmgr/BTManClient/BTManClient.cpp
changeset 0 29b1cd4cb562
child 51 20ac952a623c
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 #include <btmanclient.h>
       
    17 #include <e32math.h>
       
    18 #include <utf.h>
       
    19 #include "btmanclientserver.h"
       
    20 #include "s32strm.h"
       
    21 #include <bluetooth/logger.h>
       
    22 
       
    23 #ifdef __FLOG_ACTIVE
       
    24 _LIT8(KLogComponent, LOG_COMPONENT_BT_MANAGER_CLIENT);
       
    25 #endif
       
    26 
       
    27 const TInt KServerRetries = 2;
       
    28 const TUint8 KDummyDevicePointer = 0xff;
       
    29 
       
    30 /**
       
    31 Start the btmanserver
       
    32 @return Systemwide error code
       
    33 @internalComponent
       
    34 @released
       
    35 */
       
    36 static TInt StartServer()
       
    37 	{
       
    38 	LOG_STATIC_FUNC
       
    39 
       
    40 	const TUidType serverUid(KNullUid,KNullUid,KBTManServerUid3);
       
    41 	
       
    42 #ifdef __BTMANSERVER_NO_PROCESSES__
       
    43 	//
       
    44 	// In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt
       
    45 	// which represents the real entry-point for the server thread
       
    46 	//
       
    47 	RLibrary lib;
       
    48 	TInt r=lib.Load(KBTManServerImg,serverUid);
       
    49 	if (r!=KErrNone)
       
    50 		return r;
       
    51 	TLibraryFunction ordinal1=lib.Lookup(1);
       
    52 	TThreadFunction serverFunc=reinterpret_cast<TThreadFunction>(ordinal1());
       
    53 	//
       
    54 	// To deal with the unique thread (+semaphore!) naming in EPOC, and that we may
       
    55 	// be trying to restart a server that has just exited we attempt to create a
       
    56 	// unique thread name for the server.
       
    57 	// This uses Math::Random() to generate a 32-bit random number for the name
       
    58 	//
       
    59 	TName name(KBTManServerName);
       
    60 	_LIT(KHexString, "0x");
       
    61  	name.Append(KHexString());
       
    62 	name.AppendNum(Math::Random(),EHex);
       
    63 	RThread server;
       
    64 	r=server.Create(name,serverFunc,
       
    65 					KBTManServerStackSize,
       
    66 					NULL,&lib,NULL,
       
    67 					KBTManServerInitHeapSize,KBTManServerMaxHeapSize,EOwnerProcess);
       
    68 	lib.Close();	// if successful, server thread has handle to library now
       
    69 #else
       
    70 	//
       
    71 	// EPOC and EKA2 is easy, we just create a new server process. Simultaneous
       
    72 	// launching of two such processes should be detected when the second one
       
    73 	// attempts to create the server object, failing with KErrAlreadyExists.
       
    74 	//
       
    75 	RProcess server;
       
    76 	TInt r=server.Create(KBTManServerImg,KNullDesC,serverUid);
       
    77 #endif
       
    78 
       
    79 	LOG1(_L("BTMan Server created, code %d"), r);
       
    80 
       
    81 	if (r!=KErrNone)
       
    82 		return r;
       
    83 	TRequestStatus stat;
       
    84 	server.Rendezvous(stat);
       
    85 	if (stat!=KRequestPending)
       
    86 		{
       
    87 		server.Kill(0);		// abort startup
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		server.Resume();	// logon OK - start the server
       
    92 		LOG(_L("BTMan Server Resumed"));
       
    93 		}
       
    94 		
       
    95 	User::WaitForRequest(stat);		// wait for start or death
       
    96 	// we can't use the 'exit reason' if the server panicked as this
       
    97 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    98 	// from KErrNone
       
    99 	LOG1(_L("BTMan Server started, code %d (0=>success)"), stat.Int());
       
   100 	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
   101 	
       
   102     server.Close(); 
       
   103  	LOG(_L("BTMan Server Closed"));
       
   104  	
       
   105 	return r;
       
   106 	}
       
   107 
       
   108 
       
   109 /**
       
   110 Default Constructor.
       
   111 @publishedAll
       
   112 @released
       
   113 */
       
   114 EXPORT_C RBTMan::RBTMan()
       
   115 	{
       
   116 	LOG_FUNC
       
   117 	}
       
   118 
       
   119 
       
   120 /**
       
   121 Connects to the btman server.
       
   122 @return systemwide error code
       
   123 @publishedAll
       
   124 @released
       
   125 */
       
   126 EXPORT_C TInt RBTMan::Connect()
       
   127 	{
       
   128 	LOG_FUNC
       
   129 	TInt retry=KServerRetries;
       
   130 	for (;;)
       
   131 		{
       
   132 		TInt r=CreateSession(KBTManServerName,Version());	//gives MessageSlots of -1
       
   133 																//this uses global pool rather
       
   134 																//than local pool
       
   135 		if (r!=KErrNotFound && r!=KErrServerTerminated)
       
   136 			return r;
       
   137 		if (--retry==0)
       
   138 			return r;
       
   139 		r=StartServer();
       
   140 		if (r!=KErrNone && r!=KErrAlreadyExists)
       
   141 			return r;
       
   142 		}
       
   143 	}
       
   144 
       
   145 /**
       
   146 Returns the version of the server.
       
   147 @return version of btmanserver
       
   148 */
       
   149 EXPORT_C TVersion RBTMan::Version() const
       
   150 /**
       
   151 **/
       
   152 	{
       
   153 	LOG_FUNC
       
   154 	return TVersion(KBTManServerMajorVersionNumber, 
       
   155 					KBTManServerMinorVersionNumber, 
       
   156 					KBTManServerBuildVersionNumber);
       
   157 	}
       
   158 
       
   159 
       
   160 /**
       
   161 Default constructor of base class for subsessions
       
   162 @publishedAll
       
   163 @released
       
   164 */
       
   165 EXPORT_C RBTManSubSession::RBTManSubSession()
       
   166 : iClientServerMsg()
       
   167 	{
       
   168 	LOG_FUNC
       
   169 	iClientServerMsg().iClientBusy = EFalse;
       
   170 	iClientServerMsg().iClientStatusToCancel = NULL;
       
   171 	}
       
   172 
       
   173 /**
       
   174 Cancel an outstanding request on btmanserver
       
   175 @param aStatus the status of active object that made the original request
       
   176 @publishedAll
       
   177 @released
       
   178 */
       
   179 EXPORT_C void RBTManSubSession::CancelRequest(TRequestStatus& aStatus)
       
   180 	{
       
   181 	LOG_FUNC
       
   182 	if (SubSessionHandle())
       
   183 		{
       
   184 		SendReceive(EBTManCancelRequest, TIpcArgs(&aStatus));
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		//Client has a bad handle therefore complete the call from here
       
   189 		LocalComplete(aStatus, KErrBadHandle);
       
   190 		}
       
   191 	}
       
   192 
       
   193 /**
       
   194 Completes a request locally without involving the server.
       
   195 Called when a client-side error occurs.
       
   196 @param	aStatus:	The TRequestStatus of the active object that made the request that needs to be completed.
       
   197 @param	aErr:		The reason for completion. aErr will be written into the TRequestStatus of the active object.
       
   198 @internalComponent
       
   199 @released
       
   200 **/
       
   201 void RBTManSubSession::LocalComplete(TRequestStatus& aStatus, TInt aErr)
       
   202 	{
       
   203 	LOG_FUNC
       
   204 	aStatus = KRequestPending;
       
   205 	TRequestStatus* pS = &aStatus;
       
   206 	User::RequestComplete(pS, aErr);
       
   207 	}
       
   208 
       
   209 
       
   210 TBool RBTManSubSession::IsBusy() const
       
   211 	{
       
   212 	LOG_FUNC
       
   213 	return iClientServerMsg().iClientBusy;
       
   214 	}
       
   215 
       
   216 /**
       
   217 To prevent clients using the server more than once
       
   218 Business is cleared once the server has completed the job
       
   219 @param aStatus the status of the client AO making a request on the server. this will can be used for cancelling later
       
   220 @internalComponent
       
   221 @released
       
   222 **/
       
   223 void RBTManSubSession::SetBusy(TRequestStatus& aStatus)
       
   224 	{
       
   225 	LOG_FUNC
       
   226 	iClientServerMsg().iClientBusy = ETrue;
       
   227 	iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   228 	}
       
   229 
       
   230 /**
       
   231 Default constructor of registry session
       
   232 @publishedAll
       
   233 @released
       
   234 */
       
   235 EXPORT_C RBTRegServ::RBTRegServ()
       
   236 	{
       
   237 	LOG_FUNC
       
   238 	}
       
   239 
       
   240 
       
   241 /**
       
   242 Connect to Registry Server
       
   243 @return System-wide error code
       
   244 @publishedAll
       
   245 @released
       
   246 @capability LocalServices
       
   247 */
       
   248 EXPORT_C TInt RBTRegServ::Connect()
       
   249 	{
       
   250 	LOG_FUNC
       
   251 	// we provide the standard RBTMan session for now, but the client doesnt know this!
       
   252 	TInt r=RBTMan::Connect();
       
   253 	return r;
       
   254 	}
       
   255 
       
   256 /**
       
   257 Close session on Registry Server
       
   258 @publishedAll
       
   259 @released
       
   260 */
       
   261 EXPORT_C void RBTRegServ::Close()
       
   262 	{
       
   263 	LOG_FUNC
       
   264 	RBTMan::Close();
       
   265 	}
       
   266 
       
   267 /**
       
   268 Return reference to the server session
       
   269 @return reference to btman session
       
   270 @publishedAll
       
   271 @released
       
   272 */
       
   273 EXPORT_C RBTMan& RBTRegServ::Session()
       
   274 	{
       
   275 	LOG_STATIC_FUNC
       
   276 	return static_cast<RBTMan&>(*this);
       
   277 	}
       
   278 
       
   279 #ifndef _DEBUG
       
   280 EXPORT_C TInt RBTRegServ::SetHeapFailure(TInt /*aType*/,TInt /*aRate*/)
       
   281 #else
       
   282 EXPORT_C TInt RBTRegServ::SetHeapFailure(TInt aType,TInt aRate)
       
   283 #endif
       
   284 /**
       
   285 Send a message to the server to fail memory allocations (in debug builds)
       
   286 @internalAll
       
   287 @released
       
   288 */
       
   289 	{
       
   290 	LOG_FUNC
       
   291 #ifdef _DEBUG
       
   292 	return SendReceive(EBTManSetHeapFailure,TIpcArgs(static_cast<RHeap::TAllocFail>(aType), aRate));
       
   293 #else
       
   294 	return KErrNotSupported;
       
   295 #endif
       
   296 	}
       
   297 
       
   298 
       
   299 /**
       
   300 Returns the number of open subsessions.
       
   301 This should be used by clients to do resource leakage debugging checks
       
   302 @publishedAll
       
   303 @released
       
   304 */
       
   305 EXPORT_C TInt RBTRegServ::ResourceCount()
       
   306 	{
       
   307 	LOG_FUNC
       
   308 	TInt count = 0;
       
   309 	TPckg<TInt> pckg(count);
       
   310 	SendReceive(EBTManSubSessionCount, TIpcArgs(&pckg));
       
   311 	return count;
       
   312 	}
       
   313 
       
   314 /**
       
   315 Default constructor for registry subsession
       
   316 @publishedAll
       
   317 @released
       
   318 */
       
   319 EXPORT_C RBTRegistry::RBTRegistry()
       
   320 : RBTManSubSession(), iDevicePckg(*reinterpret_cast<TBTNamelessDevice*>(KDummyDevicePointer))
       
   321 	{
       
   322 	LOG_FUNC
       
   323 	} 
       
   324 
       
   325 /**
       
   326 Open a Bluetooth device subsession.
       
   327 @param	aSession The BTManager session to which this subsession is to be attached.
       
   328 @return An error code depicting the outcome of the "open".
       
   329 @publishedAll
       
   330 @released
       
   331 @capability LocalServices
       
   332 */
       
   333 EXPORT_C TInt RBTRegistry::Open(RBTRegServ& aSession)
       
   334 	{
       
   335 	LOG_FUNC
       
   336 	iSendBuffer = NULL;
       
   337 	return CreateSubSession(aSession.Session(), EBTManCreateRegistrySubSession, TIpcArgs(NULL));
       
   338 	}
       
   339 
       
   340 /** Create a constrained view of devices on the remote device table of the registry server.
       
   341 
       
   342 This is in effect a registry search facility. 
       
   343 It is needed if the user wishes find data in the registry of uncertain size.
       
   344 For example:-
       
   345 1) a list of remote devices. 
       
   346 2) full details of a remote device including its name and/or friendly name.
       
   347 Note 1: Some methods in the API (e.g. UnpairAllInView) require a view to have been created prior to their use.
       
   348 Note 2: When a view has been generated, if details of the device(s) found are needed, these should be obtained using an instance of CBTRegistryResponse.
       
   349 Note 3: A view must be closed before a new view can be created.
       
   350 
       
   351 @see UnpairAllInView
       
   352 @see DeleteAllInView
       
   353 @see CloseView
       
   354 @see NotifyViewChange
       
   355 @see TBTRegistrySearch
       
   356 @see CBTRegistryResponse
       
   357 @param	aSearch A search struct with details of devices to be contained in the result set
       
   358 @param	aStatus TRequestStatus supplied by caller
       
   359 @return systemwide error
       
   360 @publishedAll
       
   361 @released
       
   362 @capability LocalServices
       
   363 @capability ReadDeviceData  (LocalServices only if link key is not needed)
       
   364 */
       
   365 EXPORT_C void RBTRegistry::CreateView(const TBTRegistrySearch& aSearch, TRequestStatus& aStatus)
       
   366 	{
       
   367 	LOG_FUNC
       
   368 	if (IsBusy())
       
   369 		{
       
   370 		LocalComplete(aStatus, KErrInUse);
       
   371 		}
       
   372 	else
       
   373 		{
       
   374 		if (SubSessionHandle())
       
   375 			{
       
   376 			SetBusy(aStatus);
       
   377 			iSearchPckg = aSearch;
       
   378 			SendReceive(EBTManRegistrySearch, TIpcArgs(&iSearchPckg, NULL, &iClientServerMsg), aStatus);
       
   379 			}
       
   380 		else
       
   381 			{
       
   382 			//Client has a bad handle therefore complete the call from here
       
   383 			LocalComplete(aStatus, KErrBadHandle);
       
   384 			}
       
   385 		}
       
   386 	}
       
   387 
       
   388 /**
       
   389 Close the subsession.  Removes all server side resources pertaining to this subsession
       
   390 @publishedAll
       
   391 @released
       
   392 */
       
   393 EXPORT_C void RBTRegistry::Close()
       
   394 	{
       
   395 	LOG_FUNC
       
   396 	delete iSendBuffer;
       
   397 	iSendBuffer = NULL;
       
   398 	RSubSessionBase::CloseSubSession(EBTManCloseSubSession);
       
   399 	}
       
   400 	
       
   401 
       
   402 /**
       
   403 Close a previously created view on the registry.
       
   404 Allows an app to use this subsession for other view or non-view operations
       
   405 @return Systemwide error
       
   406 @post Subsession is left open for further use - eg to create another view, or perform a viewless operation
       
   407 @publishedAll
       
   408 @released
       
   409 */
       
   410 EXPORT_C TInt RBTRegistry::CloseView()
       
   411 	{
       
   412 	LOG_FUNC
       
   413 	if (SubSessionHandle())
       
   414 		{
       
   415 		return SendReceive(EBTRegistryCloseView, TIpcArgs(NULL, NULL, NULL));	// synchronous
       
   416 		}
       
   417 	else
       
   418 		{
       
   419 		return KErrBadHandle;
       
   420 		}
       
   421 	}
       
   422 
       
   423 
       
   424 /**
       
   425 Unpair a device in the registry
       
   426 @param aAddress The device to unpair
       
   427 @param aStatus reference to client AO's TRequestStatus
       
   428 @publishedPartner
       
   429 @released
       
   430 @capability LocalServices
       
   431 @capability WriteDeviceData
       
   432 */
       
   433 EXPORT_C void RBTRegistry::UnpairDevice(const TBTDevAddr& aAddress, TRequestStatus& aStatus)
       
   434 	{
       
   435 	LOG_FUNC
       
   436 	if (IsBusy())
       
   437 		{
       
   438 		LocalComplete(aStatus, KErrInUse);
       
   439 		}
       
   440 	else
       
   441 		{
       
   442 		if (SubSessionHandle())
       
   443 			{
       
   444 			SetBusy(aStatus);
       
   445 			iAddrBuf = aAddress;
       
   446 			SendReceive(EBTRegistryDeleteLinkKey, TIpcArgs(&iAddrBuf, NULL,  &iClientServerMsg), aStatus);
       
   447 			}
       
   448 		else
       
   449 			{
       
   450 			//Client has a bad handle therefore complete the call from here
       
   451 			LocalComplete(aStatus, KErrBadHandle);
       
   452 			}
       
   453 		}
       
   454 	}
       
   455 
       
   456 /**
       
   457 Unpair all the devices in the view - useful to unbond eg all devices (create a View with search All), or eg unbond all headsets
       
   458 @param aStatus reference to client AO's TRequestStatus
       
   459 @publishedPartner
       
   460 @released
       
   461 @capability LocalServices
       
   462 @capability WriteDeviceData
       
   463 */
       
   464 EXPORT_C void RBTRegistry::UnpairAllInView(TRequestStatus& aStatus)
       
   465 	{
       
   466 	LOG_FUNC
       
   467 	if (SubSessionHandle())
       
   468 		{
       
   469 		iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   470 		SendReceive(EBTRegistryUnpairView, TIpcArgs(NULL, NULL, &iClientServerMsg), aStatus);
       
   471 		}
       
   472 	else
       
   473 		{
       
   474 		//Client has a bad handle therefore complete the call from here
       
   475 		LocalComplete(aStatus, KErrBadHandle);
       
   476 		}
       
   477 	}
       
   478 
       
   479 
       
   480 /**
       
   481 Add device to the registry
       
   482 @leave OOM
       
   483 @param aDevice reference to CBTDevice of details of device to add
       
   484 @param aStatus reference to client AO's TRequestStatus
       
   485 @publishedAll
       
   486 @released
       
   487 @capability LocalServices
       
   488 */
       
   489 EXPORT_C void RBTRegistry::AddDeviceL(const CBTDevice& aDevice, TRequestStatus& aStatus)
       
   490 	{
       
   491 	LOG_FUNC
       
   492 	if (IsBusy())
       
   493 		{
       
   494 		LocalComplete(aStatus, KErrInUse);
       
   495 		}
       
   496 	else
       
   497 		{
       
   498 		if (SubSessionHandle())
       
   499 			{
       
   500 			if (iSendBuffer)
       
   501 				{
       
   502 				delete iSendBuffer;
       
   503 				iSendBuffer = NULL;
       
   504 				}
       
   505 			// need to contiguate CBTDevice into a buffer
       
   506 			SetBusy(aStatus);
       
   507 			iSendBuffer = CBufFlat::NewL(sizeof(CBTDevice)); //granularity
       
   508 
       
   509 			RBufWriteStream stream;
       
   510 			stream.Open(*iSendBuffer);
       
   511 			CleanupClosePushL(stream);
       
   512 
       
   513 			aDevice.ExternalizeL(stream);
       
   514 			const TPtr8 ptr=iSendBuffer->Ptr(0);
       
   515 			iSendBufferPtr.Set(ptr);
       
   516 			// now we can give the buffer to BTMan
       
   517 			SendReceive(EBTRegistryAddDevice, TIpcArgs(&iSendBufferPtr, NULL,  &iClientServerMsg), aStatus);
       
   518 
       
   519 			CleanupStack::PopAndDestroy(1);	// stream
       
   520 			}
       
   521 		else
       
   522 			{
       
   523 			//Client has a bad handle therefore complete the call from here
       
   524 			LocalComplete(aStatus, KErrBadHandle);
       
   525 			}
       
   526 		}
       
   527 	}
       
   528 
       
   529 /**
       
   530 Get a *nameless* device to the registry. To retrieve a full device with names a view should be created
       
   531 @see CreateView
       
   532 @pre Clients must ensure that they do not call this method while the same operation is already outstanding on the same RBTRegistry subsession
       
   533 @param aDevice reference to TBTDevice (used as input and output). The input MUST contain the device address - this is used as the key. Once the method completes the reference will contain all other details found from the registry
       
   534 @param aStatus reference to client AO's TRequestStatus
       
   535 @publishedPartner
       
   536 @released
       
   537 @capability LocalServices
       
   538 @capability ReadDeviceData  (LocalServices only if link key is not needed) 
       
   539 */
       
   540 EXPORT_C void RBTRegistry::GetDevice(TBTNamelessDevice& aDevice, TRequestStatus& aStatus)
       
   541 	{
       
   542 	LOG_FUNC
       
   543 	if (IsBusy())
       
   544 		{
       
   545 		LocalComplete(aStatus, KErrInUse);
       
   546 		}
       
   547 	else
       
   548 		{
       
   549 		if (SubSessionHandle())
       
   550 			{
       
   551 			SetBusy(aStatus);
       
   552 			TPckg<TBTNamelessDevice> temp(aDevice);
       
   553 			iDevicePckg.Set(temp);
       
   554 			SendReceive(EBTRegistryGetNamelessDevice, TIpcArgs(&iDevicePckg, NULL,  &iClientServerMsg), aStatus);
       
   555 			}
       
   556 		else
       
   557 			{
       
   558 			//Client has a bad handle therefore complete the call from here
       
   559 			LocalComplete(aStatus, KErrBadHandle);
       
   560 			}
       
   561 		}
       
   562 	}
       
   563 
       
   564 
       
   565 /**
       
   566 Modify the friendly name of a device
       
   567 @leave OOM
       
   568 @param aAddress	The address of the device of which to change the name
       
   569 @param aName		The new name (note - not an 8bit descriptor)
       
   570 @param aStatus reference to client AO's TRequestStatus
       
   571 @publishedAll
       
   572 @released
       
   573 @capability LocalServices
       
   574 */
       
   575 EXPORT_C void RBTRegistry::ModifyFriendlyDeviceNameL(const TBTDevAddr& aAddress,
       
   576 											   		 const TDesC& aName,
       
   577 											   		 TRequestStatus& aStatus)
       
   578 	{
       
   579 	LOG_FUNC
       
   580 	if (IsBusy())
       
   581 		{
       
   582 		LocalComplete(aStatus, KErrInUse);
       
   583 		}
       
   584 	else
       
   585 		{
       
   586 		if (SubSessionHandle())
       
   587 			{
       
   588 			SetBusy(aStatus);
       
   589 			TBuf8<KMaxFriendlyNameLen> tempBuf;
       
   590 			tempBuf.Zero();
       
   591 			if (CnvUtfConverter::ConvertFromUnicodeToUtf8(tempBuf, aName) != KErrNone)
       
   592 				{
       
   593 				LocalComplete(aStatus, KErrBadName);
       
   594 				return;
       
   595 				}
       
   596 			
       
   597 			if (iSendBuffer)
       
   598 				{
       
   599 				delete iSendBuffer;
       
   600 				iSendBuffer = NULL;
       
   601 				}
       
   602 
       
   603 			iSendBuffer = CBufFlat::NewL(sizeof(TBuf8<KMaxFriendlyNameLen>)); //granularity
       
   604 
       
   605 			iSendBuffer->Reset();
       
   606 			iSendBuffer->InsertL(0, tempBuf);
       
   607 
       
   608 			const TPtr8 ptr=iSendBuffer->Ptr(0);
       
   609 			iSendBufferPtr.Set(ptr);
       
   610 			
       
   611 			iAddrBuf = aAddress;
       
   612 
       
   613 			SendReceive(EBTRegistryModifyFriendlyName,
       
   614 						TIpcArgs(&iAddrBuf, &iSendBufferPtr,  &iClientServerMsg), aStatus);
       
   615 			}
       
   616 		else
       
   617 			{
       
   618 			//Client has a bad handle therefore complete the call from here
       
   619 			LocalComplete(aStatus, KErrBadHandle);
       
   620 			}
       
   621 		}
       
   622 	}
       
   623 
       
   624 
       
   625 
       
   626 /**
       
   627 Modify the Bluetooth name of a device.  This is not used beyond the stack
       
   628 @param aAddress	The address of the device of which to change the name
       
   629 @param aName		The new name (note - this is an 8bit descriptor)
       
   630 @param aStatus reference to client AO's TRequestStatus
       
   631 @internalAll
       
   632 @released
       
   633 @capability LocalServices
       
   634 @capability WriteDeviceData (localServices only if friendly device name)
       
   635 */
       
   636 EXPORT_C void RBTRegistry::ModifyBluetoothDeviceNameL(const TBTDevAddr& aAddress,
       
   637 													  const TDesC8& aName,
       
   638 													  TRequestStatus& aStatus)
       
   639 	{
       
   640 	LOG_FUNC
       
   641 	if (IsBusy())
       
   642 		{
       
   643 		LocalComplete(aStatus, KErrInUse);
       
   644 		}
       
   645 	else
       
   646 		{
       
   647 		if (SubSessionHandle())
       
   648 			{
       
   649 			SetBusy(aStatus);
       
   650 			
       
   651 			if (iSendBuffer)
       
   652 				{
       
   653 				delete iSendBuffer;
       
   654 				iSendBuffer = NULL;
       
   655 				}
       
   656 
       
   657 			iSendBuffer = CBufFlat::NewL(sizeof(TBuf8<KMaxBluetoothNameLen>)); //granularity
       
   658 			
       
   659 			iSendBuffer->Reset();
       
   660 			iSendBuffer->InsertL(0, aName);
       
   661 
       
   662 			const TPtr8 ptr=iSendBuffer->Ptr(0);
       
   663 			iSendBufferPtr.Set(ptr);
       
   664 			
       
   665 			iAddrBuf = aAddress;
       
   666 
       
   667 			SendReceive(EBTRegistryModifyBluetoothName,
       
   668 						TIpcArgs(&iAddrBuf, &iSendBufferPtr,  &iClientServerMsg), aStatus);
       
   669 			}
       
   670 		else
       
   671 			{
       
   672 			//Client has a bad handle therefore complete the call from here
       
   673 			LocalComplete(aStatus, KErrBadHandle);
       
   674 			}
       
   675 		}
       
   676 	}
       
   677 
       
   678 
       
   679 /**
       
   680 Update details of a device - other than its names: Not used beyond stack
       
   681 @param aDeviceDetails The new details - the device address MUST be present in aDeviceDetails is used as the key
       
   682 @param aStatus reference to client AO's TRequestStatus
       
   683 @internalTechnology
       
   684 @released
       
   685 @capability LocalServices
       
   686 @capability WriteDeviceData
       
   687 */
       
   688 EXPORT_C void RBTRegistry::ModifyDevice(const TBTNamelessDevice& aDeviceDetails, TRequestStatus& aStatus)
       
   689 	{
       
   690 	LOG_FUNC
       
   691 	if (IsBusy())
       
   692 		{
       
   693 		LocalComplete(aStatus, KErrInUse);
       
   694 		}
       
   695 	else
       
   696 		{
       
   697 		if (SubSessionHandle())
       
   698 			{
       
   699 			SetBusy(aStatus);
       
   700 			TPckg<TBTNamelessDevice> temp(aDeviceDetails);
       
   701 			iDevicePckg.Set(temp);
       
   702 			SendReceive(EBTRegistryModifyNamelessDevice, TIpcArgs(&iDevicePckg, NULL,  &iClientServerMsg), aStatus);
       
   703 			}
       
   704 		else
       
   705 			{
       
   706 			//Client has a bad handle therefore complete the call from here
       
   707 			LocalComplete(aStatus, KErrBadHandle);
       
   708 			}
       
   709 		}
       
   710 	}
       
   711 
       
   712 /**
       
   713 Notifies the client when a change has been made to the registry that affects the currently open view of devices.
       
   714 @see CreateView
       
   715 @see CloseView
       
   716 @param aStatus reference to client AO's TRequestStatus
       
   717 @publishedAll
       
   718 @released
       
   719 */
       
   720 EXPORT_C void RBTRegistry::NotifyViewChange(TRequestStatus& aStatus)
       
   721 	{
       
   722 	LOG_FUNC
       
   723 	if (SubSessionHandle())
       
   724 		{
       
   725 		// We don't set the session as busy because then no other commands can be sent
       
   726 		iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   727 		SendReceive(EBTRegistryNotifyViewChange, TIpcArgs(NULL, NULL, &iClientServerMsg), aStatus);
       
   728 		}
       
   729 	else
       
   730 		{
       
   731 		//Client has a bad handle therefore complete the call from here
       
   732 		LocalComplete(aStatus, KErrBadHandle);
       
   733 		}
       
   734 	}
       
   735 
       
   736 /**
       
   737 @internalComponent
       
   738 */
       
   739 void RBTRegistry::PreLoad(TRequestStatus& aStatus)
       
   740 	{
       
   741 	LOG_FUNC
       
   742 	if (SubSessionHandle())
       
   743 		{
       
   744 		iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   745 		SendReceive(EBTManExtractRegistryDataIntoServer, TIpcArgs(NULL, NULL, &iClientServerMsg), aStatus);
       
   746 		}
       
   747 	else
       
   748 		{
       
   749 		//Client has a bad handle therefore complete the call from here
       
   750 		LocalComplete(aStatus, KErrBadHandle);
       
   751 		}
       
   752 	}
       
   753 
       
   754 
       
   755 
       
   756 /**
       
   757 @internalComponent
       
   758 **/
       
   759 void RBTRegistry::GetResults(TPtr8& aResults, TRequestStatus& aStatus)
       
   760 	{
       
   761 	LOG_FUNC
       
   762 	if (SubSessionHandle())
       
   763 		{
       
   764 		iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   765 		SendReceive(EBTManRetrieveRegistryData, TIpcArgs(&aResults, NULL, &iClientServerMsg), aStatus);
       
   766 		}
       
   767 	else
       
   768 		{
       
   769 		//Client has a bad handle therefore complete the call from here
       
   770 		LocalComplete(aStatus, KErrBadHandle);
       
   771 		}
       
   772 	}
       
   773 
       
   774 /**
       
   775 Remove all devices in the view from the Registry
       
   776 @pre View must be created first by client
       
   777 @see CreateView
       
   778 @param aStatus a TRequestStatus passed in by the caller
       
   779 @publishedPartner
       
   780 @released
       
   781 @capability LocalServices
       
   782 @capability WriteDeviceData (Only if different process than the one that created the device)
       
   783 */
       
   784 EXPORT_C void RBTRegistry::DeleteAllInView(TRequestStatus& aStatus)
       
   785 	{
       
   786 	LOG_FUNC
       
   787 	if (SubSessionHandle())
       
   788 		{
       
   789 		iClientServerMsg().iClientStatusToCancel = &aStatus;
       
   790 		SendReceive(EBTRegistryDeleteDevices, TIpcArgs(NULL, NULL, &iClientServerMsg), aStatus);
       
   791 		}
       
   792 	else
       
   793 		{
       
   794 		//Client has a bad handle therefore complete the call from here
       
   795 		LocalComplete(aStatus, KErrBadHandle);
       
   796 		}
       
   797 	}
       
   798 
       
   799 /**
       
   800 default c'tor
       
   801 @publishedAll
       
   802 @released
       
   803 */
       
   804 EXPORT_C RBTLocalDevice::RBTLocalDevice()
       
   805 :RBTManSubSession(), iLocalDevicePckg(*reinterpret_cast<TBTLocalDevice*>(KDummyDevicePointer))
       
   806 	{
       
   807 	LOG_FUNC
       
   808 	}
       
   809 
       
   810 
       
   811 /**
       
   812 Open a local device subsession on the server, used for manipulating settings about the local device
       
   813 @param aSession A server session
       
   814 @return systemwide error
       
   815 @publishedAll
       
   816 @released
       
   817 */
       
   818 EXPORT_C TInt RBTLocalDevice::Open(RBTRegServ& aSession)
       
   819 	{
       
   820 	LOG_FUNC
       
   821 	return CreateSubSession(aSession.Session(), EBTManCreateLocalDeviceSubSession, TIpcArgs(NULL));
       
   822 	}
       
   823 
       
   824 
       
   825 /**
       
   826 Close the subsession on the server
       
   827 @publishedAll
       
   828 @released
       
   829 */
       
   830 EXPORT_C void RBTLocalDevice::Close()
       
   831 	{
       
   832 	LOG_FUNC
       
   833 	RSubSessionBase::CloseSubSession(EBTManCloseSubSession);
       
   834 	}
       
   835 
       
   836 
       
   837 /**
       
   838 Retrieve the local device details. Synchronous - intended mainly for Bluetooth stack use on startup
       
   839 
       
   840 @param	aLocalDeviceResult	a reference to a TBTLocalDevice to store the results from the Registry
       
   841 @return	SystemWide error
       
   842 @publishedAll
       
   843 @released
       
   844 */
       
   845 EXPORT_C TInt RBTLocalDevice::Get(TBTLocalDevice& aLocalDeviceResult)
       
   846 	{
       
   847 	LOG_FUNC
       
   848 	if (SubSessionHandle())
       
   849 		{
       
   850 		TPckg<TBTLocalDevice> pckg(aLocalDeviceResult);
       
   851 		return SendReceive(EBTRegistryGetLocalDevice, TIpcArgs(&pckg, NULL, NULL));	// synchronous
       
   852 		}
       
   853 	else
       
   854 		{
       
   855 		//Client has a bad handle therefore complete the call from here
       
   856 		return KErrBadHandle;
       
   857 		}
       
   858 	}
       
   859 
       
   860 /**
       
   861 Update the details about the local Bluetooth device
       
   862 @param aLocalDevice New settings for local device
       
   863 @param aStatus reference Client AO's TRequestStatus
       
   864 @publishedPartner
       
   865 @released
       
   866 @capability LocalServices
       
   867 @capability WriteDeviceData
       
   868 */
       
   869 EXPORT_C void RBTLocalDevice::Modify(const TBTLocalDevice& aLocalDevice, TRequestStatus& aStatus)
       
   870 	{
       
   871 	LOG_FUNC
       
   872 	if (IsBusy())
       
   873 		{
       
   874 		LocalComplete(aStatus, KErrInUse);
       
   875 		}
       
   876 	else
       
   877 		{
       
   878 		if (SubSessionHandle())
       
   879 			{
       
   880 			SetBusy(aStatus);
       
   881 			TPckg<TBTLocalDevice> pckg(aLocalDevice);
       
   882 			iLocalDevicePckg.Set(pckg);
       
   883 			SendReceive(EBTRegistryUpdateLocalDevice, TIpcArgs(&iLocalDevicePckg, NULL, &iClientServerMsg), aStatus);
       
   884 			}
       
   885 		else
       
   886 			{
       
   887 			//Client has a bad handle therefore complete the call from here
       
   888 			LocalComplete(aStatus, KErrBadHandle);
       
   889 			}
       
   890 		}
       
   891 	}
       
   892 
       
   893 /**
       
   894 Synchronous overload of Modify (primarily for stack operations)
       
   895 @see RBTLocalDevice::Modify(const TBTLocalDevice& aLocalDevice, TRequestStatus& aStatus)
       
   896 @publishedPartner
       
   897 @released
       
   898 @capability LocalServices
       
   899 @capability WriteDeviceData
       
   900 */
       
   901 EXPORT_C TInt RBTLocalDevice::Modify(const TBTLocalDevice& aLocalDevice)
       
   902 	{
       
   903 	LOG_FUNC
       
   904 	// synchronous version for stack on close-down
       
   905 	TRequestStatus status;
       
   906 	Modify(aLocalDevice, status);
       
   907 	User::WaitForRequest(status);
       
   908 	return status.Int();
       
   909 	}
       
   910 
       
   911 
       
   912 /**
       
   913 Two-phase constructor to create a helper class to retrieve a set of results (a view) from the Registry
       
   914 @leave OOM
       
   915 @pre A non-empty view on the Registry task has been created
       
   916 @param aView the Registry subsession that has had a View created on it
       
   917 @return pointer to allocated object
       
   918 @see CreateView()
       
   919 @publishedAll
       
   920 @released
       
   921 */
       
   922 EXPORT_C CBTRegistryResponse* CBTRegistryResponse::NewL(RBTRegistry& aView)
       
   923 	{
       
   924 	LOG_STATIC_FUNC
       
   925 	return new (ELeave) CBTRegistryResponse(aView);
       
   926 	}
       
   927 
       
   928 
       
   929 /**
       
   930 Start fetching results from the Registry Server.  When the request is complete, the results can be obtained via the Results() method.
       
   931 @param aClientStatus a TRequestStatus passed in by the caller
       
   932 @publishedAll
       
   933 @released
       
   934 */
       
   935 EXPORT_C void CBTRegistryResponse::Start(TRequestStatus& aClientStatus)
       
   936 	{
       
   937 	LOG_FUNC
       
   938 	// we do late construction on the heap buffer
       
   939 	__ASSERT_DEBUG(!IsActive(), User::Panic(KBTManClientPanic, EBTManClientResultRetrieveAlreadyActive));
       
   940 
       
   941 	iClientStatus = &aClientStatus;
       
   942 	*iClientStatus = KRequestPending;
       
   943 	CActiveScheduler::Add(this);
       
   944 	DoGet();
       
   945 	}
       
   946 
       
   947 /** Get Results previously fetched from the Registry Server.
       
   948  
       
   949 @pre The method Start needs to have been called, and notification of its completion received.
       
   950 @return reference to the array of results
       
   951 @publishedAll
       
   952 @released
       
   953 */
       
   954 EXPORT_C RBTDeviceArray& CBTRegistryResponse::Results()
       
   955 	{
       
   956 	LOG_FUNC
       
   957 	return iArray;
       
   958 	}
       
   959 
       
   960 CBTRegistryResponse::CBTRegistryResponse(RBTRegistry& aView)
       
   961 : CActive(EPriorityStandard), iView(aView), iResponsePtr(NULL,0)
       
   962 	{
       
   963 	LOG_FUNC
       
   964 	}
       
   965 
       
   966 /**
       
   967 Destructor
       
   968 */
       
   969 EXPORT_C CBTRegistryResponse::~CBTRegistryResponse()
       
   970 	{
       
   971 	LOG_FUNC
       
   972 	Cancel();
       
   973 
       
   974 	iArray.ResetAndDestroy();
       
   975 	delete iResponseBuf;
       
   976 	}
       
   977 
       
   978 void CBTRegistryResponse::DoGet()
       
   979 	{
       
   980 	LOG_FUNC
       
   981 // create RPointerArray to point to n CBTDevices
       
   982 // ask server async size of result set - this causes BTMan to extract from DBMS and return size
       
   983 // we then allocate and in 2nd phase get the stuff from the server (could be synchronous
       
   984 // we could wrap all this up in a helper object for client to use: CBTRegistryResponder
       
   985 
       
   986 	iArray.ResetAndDestroy();
       
   987 	iState = EGettingSize;
       
   988 	// Get the size of the entry
       
   989 	iView.PreLoad(iStatus);
       
   990 	SetActive();
       
   991 	}
       
   992 
       
   993 void CBTRegistryResponse::DoCancel()
       
   994 	{
       
   995 	LOG_FUNC
       
   996 	//cancel the server
       
   997 	iView.CancelRequest(iStatus);
       
   998 	//notify our user
       
   999 	User::RequestComplete(iClientStatus, KErrCancel);
       
  1000 	}
       
  1001 
       
  1002 void CBTRegistryResponse::RunL()
       
  1003 	{
       
  1004 	LOG_FUNC
       
  1005 	switch (iState)
       
  1006 		{
       
  1007 		case EGettingSize:
       
  1008 			{
       
  1009 			// get the results
       
  1010 			if (iStatus.Int() >= KErrNone)
       
  1011 				{
       
  1012 				// we have a byte count of the response size
       
  1013 				iResponseBuf = HBufC8::NewMaxL(iStatus.Int());
       
  1014 				iResponsePtr.Set(iResponseBuf->Des());
       
  1015 				iView.GetResults(iResponsePtr, iStatus);
       
  1016 				iState = EGettingResults;
       
  1017 				SetActive();
       
  1018 				}
       
  1019 			else
       
  1020 				{
       
  1021 				User::Leave(iStatus.Int());
       
  1022 				}
       
  1023 			}
       
  1024 			break;
       
  1025 		case EGettingResults:
       
  1026 			{
       
  1027 			if (iStatus.Int() >= KErrNone)
       
  1028 				{
       
  1029 				// got n CBTDevices to return
       
  1030 				TInt c = iStatus.Int();
       
  1031 				RDesReadStream stream(iResponsePtr);
       
  1032 				CleanupClosePushL(stream);
       
  1033 				while (c-->0)
       
  1034 					{
       
  1035 					CBTDevice* device = CBTDevice::NewLC();
       
  1036 					device->InternalizeL(stream);
       
  1037 					// place it into the result array
       
  1038 					User::LeaveIfError(iArray.Append(device));
       
  1039 					CleanupStack::Pop();			//device - don't destroy as 'owned' by array
       
  1040 					}
       
  1041 				CleanupStack::PopAndDestroy();	//stream
       
  1042 				// free up memory:
       
  1043 				delete iResponseBuf;
       
  1044 				iResponseBuf = NULL;
       
  1045 
       
  1046 				User::RequestComplete(iClientStatus, KErrNone);
       
  1047 				} // if
       
  1048 			else
       
  1049 				{
       
  1050 				User::Leave(iStatus.Int());
       
  1051 				}
       
  1052 			break;
       
  1053 			} // case
       
  1054 		default:
       
  1055 			User::Panic(KBTManClientPanic, EBTManClientBadResultRetrieveState);
       
  1056 		}
       
  1057 
       
  1058 	}
       
  1059 
       
  1060 TInt CBTRegistryResponse::RunError(TInt aError)
       
  1061 	{
       
  1062 	LOG_FUNC
       
  1063 	//complete request if its pending
       
  1064 	if (*iClientStatus == KRequestPending)
       
  1065 		{
       
  1066 		User::RequestComplete(iClientStatus, aError);
       
  1067 		}
       
  1068 	return KErrNone;
       
  1069 	}
       
  1070 
       
  1071 /**
       
  1072 Default constructor
       
  1073 @publishedAll
       
  1074 @released
       
  1075 */
       
  1076 EXPORT_C TBTRegistrySearch::TBTRegistrySearch()
       
  1077 	{
       
  1078 	LOG_FUNC
       
  1079 	Reset();
       
  1080 	}
       
  1081 
       
  1082 /**
       
  1083 Resets the search criteria
       
  1084 @publishedAll
       
  1085 @released
       
  1086 */
       
  1087 EXPORT_C void TBTRegistrySearch::Reset()
       
  1088 	{
       
  1089 	LOG_FUNC
       
  1090 	iSearchMask =0;
       
  1091 	}
       
  1092 
       
  1093 /**	
       
  1094 Copy Constructor
       
  1095 @publishedAll
       
  1096 @released
       
  1097 */
       
  1098 EXPORT_C TBTRegistrySearch::TBTRegistrySearch(const TBTRegistrySearch& aSearch)
       
  1099 	{
       
  1100 	LOG_FUNC
       
  1101 	iSearchMask = aSearch.iSearchMask;
       
  1102 	iDeviceClass = aSearch.iDeviceClass;
       
  1103 	iDeviceAddress = aSearch.iDeviceAddress;
       
  1104 	iLastSeen = aSearch.iLastSeen;
       
  1105 	iLastUsed = aSearch.iLastUsed;
       
  1106 	iCurrentProcessSID = aSearch.iCurrentProcessSID;
       
  1107 	iBluetoothName.Set(aSearch.iBluetoothName);
       
  1108 	iFriendlyName.Set(aSearch.iFriendlyName);
       
  1109 	}
       
  1110 
       
  1111 
       
  1112 /**
       
  1113 Add search criterion for bonded devices
       
  1114 @publishedAll
       
  1115 @released
       
  1116 */
       
  1117 EXPORT_C void TBTRegistrySearch::FindBonded()
       
  1118 	{
       
  1119 	LOG_FUNC
       
  1120 	iSearchMask |= EBonded;
       
  1121 	}
       
  1122 
       
  1123 
       
  1124 /**
       
  1125 Add search criterion for trusted devices
       
  1126 @publishedAll
       
  1127 @released
       
  1128 */
       
  1129 EXPORT_C void TBTRegistrySearch::FindTrusted()
       
  1130 	{
       
  1131 	LOG_FUNC
       
  1132 	iSearchMask |= ETrusted;
       
  1133 	}
       
  1134 
       
  1135 /**
       
  1136 Add search criterion to search for specific CoD
       
  1137 @param aClass The CoD to search
       
  1138 @see TBTDeviceClass
       
  1139 @publishedAll
       
  1140 @released
       
  1141 */
       
  1142 EXPORT_C void TBTRegistrySearch::FindCoD(const TBTDeviceClass& aClass)
       
  1143 	{
       
  1144 	LOG_FUNC
       
  1145 	iDeviceClass = aClass;
       
  1146 	iSearchMask |= ECoD;
       
  1147 	}
       
  1148 
       
  1149 
       
  1150 /**
       
  1151 Add search criterion to search for certain classes of device
       
  1152 @param aClass the device class to search for
       
  1153 @param aPref describes the type of device search to perform
       
  1154 @see TBTDeviceClass
       
  1155 @see enum TBTDeviceClassSearch
       
  1156 @publishedAll
       
  1157 @released
       
  1158 */
       
  1159 EXPORT_C void TBTRegistrySearch::FindCoD(const TBTDeviceClass& aClass, TBTDeviceClassSearch aPref)
       
  1160 	{
       
  1161 	LOG_FUNC
       
  1162 	iDeviceClass = aClass;
       
  1163 	iSearchMask |= (aPref & EMajorDevice ? ECoDMajorDev : 0);
       
  1164 	iSearchMask |= (aPref & EMinorDevice ? ECoDMinorDev : 0);
       
  1165 	}
       
  1166 
       
  1167 /**
       
  1168 Add search criterion to search for given device
       
  1169 @param	aAddress address of device to search for
       
  1170 @publishedAll
       
  1171 @released
       
  1172 */
       
  1173 EXPORT_C void TBTRegistrySearch::FindAddress(const TBTDevAddr& aAddress)
       
  1174 	{
       
  1175 	LOG_FUNC
       
  1176 	iDeviceAddress = aAddress;
       
  1177 	iSearchMask |= EAddress;
       
  1178 	}
       
  1179 
       
  1180 
       
  1181 /**
       
  1182 Add search criterion to search for devices seen since given date
       
  1183 NOTE not currently implemented
       
  1184 @param	aLastSeen date from which to find devices
       
  1185 @publishedAll
       
  1186 @released
       
  1187 */
       
  1188 EXPORT_C void TBTRegistrySearch::FindSinceSeen(const TTime& aLastSeen)
       
  1189 	{
       
  1190 	LOG_FUNC
       
  1191 	iLastSeen = aLastSeen;
       
  1192 	iSearchMask |= ELastSeen;
       
  1193 	}
       
  1194 
       
  1195 /**
       
  1196 Add search criterion to search for devices used since given date
       
  1197 @param	aLastUsed date from which to find devices
       
  1198 @publishedAll
       
  1199 @released
       
  1200 */
       
  1201 EXPORT_C void TBTRegistrySearch::FindSinceUsed(const TTime& aLastUsed)
       
  1202 	{
       
  1203 	LOG_FUNC
       
  1204 	iLastUsed = aLastUsed;
       
  1205 	iSearchMask |= ELastUsed;
       
  1206 	}
       
  1207 
       
  1208 
       
  1209 
       
  1210 /**
       
  1211 Add search criterion to search for devices with some Bluetooth device name
       
  1212 @param aName device name to search for
       
  1213 @publishedAll
       
  1214 @released
       
  1215 */
       
  1216 EXPORT_C void TBTRegistrySearch::FindBluetoothName(const TDesC8& aName)
       
  1217 /**
       
  1218 	Add search criteria of specific Bluetooth name
       
  1219 */
       
  1220 	{
       
  1221 	LOG_FUNC
       
  1222 	iBluetoothName.Set(aName);
       
  1223 	iSearchMask |= EBTName;
       
  1224 	}
       
  1225 
       
  1226 /**
       
  1227 Add search criterion to search for devices with some friendly name
       
  1228 @param aName device name to search for
       
  1229 @publishedAll
       
  1230 @released
       
  1231 */
       
  1232 EXPORT_C void TBTRegistrySearch::FindFriendlyName(const TDesC& aName)
       
  1233 	{
       
  1234 	LOG_FUNC
       
  1235 	iFriendlyName.Set(aName);
       
  1236 	iSearchMask |= EFriendlyName;
       
  1237 	}
       
  1238 
       
  1239 /**
       
  1240 Add search criterion to search for finding all devices
       
  1241 @publishedAll
       
  1242 @released
       
  1243 */
       
  1244 EXPORT_C void TBTRegistrySearch::FindAll()
       
  1245 	{
       
  1246 	LOG_FUNC
       
  1247 	iSearchMask |= EAll;
       
  1248 	}
       
  1249 
       
  1250 /**
       
  1251 Add search criterion to search for devices added by the current process
       
  1252 @publishedAll
       
  1253 @released
       
  1254 */
       
  1255 EXPORT_C void TBTRegistrySearch::FindCurrentProcessOwned()
       
  1256 	{
       
  1257 	LOG_FUNC
       
  1258 	iCurrentProcessSID = User::Identity();
       
  1259 	iSearchMask |= EProcess;
       
  1260 	}
       
  1261 
       
  1262 /**
       
  1263 Add search criterion to search for devices with a particular UI Cookie value.
       
  1264 @param aUiCookie The particular UI cookie value to search on.
       
  1265 @publishedPartner
       
  1266 @released
       
  1267 */
       
  1268 EXPORT_C void TBTRegistrySearch::FindUiCookie(TUint32 aUiCookie)
       
  1269 	{
       
  1270 	LOG_FUNC
       
  1271 	static const TUint32 KAllBitsMasked = 0xffffffff;
       
  1272 	FindUiCookie(aUiCookie, KAllBitsMasked);
       
  1273 	}
       
  1274 
       
  1275 /**
       
  1276 Add search criterion to search for devices with a particular UI Cookie value.
       
  1277 @param aUiCookie The particular UI cookie value to search on.
       
  1278 @param aUiCookieMask The mask to indicate which bits of the cookie value are to be searched on.
       
  1279 @publishedPartner
       
  1280 @released
       
  1281 */
       
  1282 EXPORT_C void TBTRegistrySearch::FindUiCookie(TUint32 aUiCookie, TUint32 aUiCookieMask)
       
  1283 	{
       
  1284 	LOG_FUNC
       
  1285 	iUiCookie = aUiCookie;
       
  1286 	iUiCookieMask = aUiCookieMask;
       
  1287 	iSearchMask |= EUiCookie;
       
  1288 	}
       
  1289 
       
  1290 /**
       
  1291 Assignment operator
       
  1292 @param aSearch the search pattern to which to assign this
       
  1293 @publishedAll
       
  1294 @released
       
  1295 */
       
  1296 EXPORT_C TBTRegistrySearch& TBTRegistrySearch::operator=(const TBTRegistrySearch& aSearch)
       
  1297 	{
       
  1298 	LOG_FUNC
       
  1299 	if (this != &aSearch)
       
  1300 		{
       
  1301 		iSearchMask = aSearch.iSearchMask;
       
  1302 		iDeviceClass = aSearch.iDeviceClass;
       
  1303 		iDeviceAddress = aSearch.iDeviceAddress;
       
  1304 		iLastSeen = aSearch.iLastSeen;
       
  1305 		iLastUsed = aSearch.iLastUsed;
       
  1306 		iCurrentProcessSID = aSearch.iCurrentProcessSID;
       
  1307 		iUiCookie = aSearch.iUiCookie;
       
  1308 		iUiCookieMask = aSearch.iUiCookieMask;
       
  1309 		iBluetoothName.Set(aSearch.iBluetoothName);
       
  1310 		iFriendlyName.Set(aSearch.iFriendlyName);
       
  1311 		}
       
  1312 	return *this;
       
  1313 	}
       
  1314 
       
  1315