--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetoothengine/headsetsimulator/core/src/Tools/hsdevicediscoverer.cpp Wed Sep 15 15:59:44 2010 +0200
@@ -0,0 +1,134 @@
+/*
+ * Component Name: Headset Simulator
+ * Author: Comarch S.A.
+ * Version: 1.0
+ * Copyright (c) 2010 Comarch S.A.
+ *
+ * This Software is submitted by Comarch S.A. to Symbian Foundation Limited on
+ * the basis of the Member Contribution Agreement entered between Comarch S.A.
+ * and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be
+ * used only in accordance with the terms and conditions of the Agreement.
+ * Any other usage, duplication or redistribution of this Software is not
+ * allowed without written permission of Comarch S.A.
+ *
+ */
+
+#include "debug.h"
+#include "hstools.h"
+
+CHsDeviceDiscoverer* CHsDeviceDiscoverer::NewL(
+ MHsDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSocketServ )
+ {
+ CHsDeviceDiscoverer *self = CHsDeviceDiscoverer::NewLC( aDeviceObserver,
+ aSocketServ );
+ CleanupStack::Pop( self );
+ return self;
+ }
+
+CHsDeviceDiscoverer* CHsDeviceDiscoverer::NewLC(
+ MHsDeviceDiscovererObserver* aDeviceObserver, RSocketServ& aSocketServ )
+ {
+ CHsDeviceDiscoverer *self = new ( ELeave ) CHsDeviceDiscoverer(
+ aDeviceObserver, aSocketServ );
+ CleanupStack::PushL( self );
+ self->ConstructL();
+ return self;
+ }
+
+CHsDeviceDiscoverer::CHsDeviceDiscoverer(
+ MHsDeviceDiscovererObserver* aDeviceObserver,
+ RSocketServ& aSocketServ ) : CActive( EPriorityNormal ),
+ iSocketServ( aSocketServ ), iDeviceObserver(
+ aDeviceObserver )
+ {
+ CActiveScheduler::Add( this );
+ iSearching = EFalse;
+ }
+
+CHsDeviceDiscoverer::~CHsDeviceDiscoverer()
+ {
+ TRACE_FUNC_ENTRY
+ Cancel();
+ iHostResolver.Close();
+ TRACE_FUNC_EXIT
+ }
+
+void CHsDeviceDiscoverer::ConstructL()
+ {
+ }
+
+void CHsDeviceDiscoverer::DeviceSearchL()
+ {
+ TRACE_FUNC_ENTRY
+ Cancel();
+
+ ConnectHostResolverL();
+ iSearching = ETrue;
+ iHostResolver.GetByAddress( iSockAddr, iEntry, iStatus );
+ SetActive();
+
+ TRACE_FUNC_EXIT
+ }
+
+void CHsDeviceDiscoverer::ConnectHostResolverL()
+ {
+ TRACE_FUNC_ENTRY
+ TProtocolDesc protDesc;
+ TProtocolName protName( KHsProtocolName );
+
+ User::LeaveIfError( iSocketServ.FindProtocol( protName, protDesc ) );
+ User::LeaveIfError( iHostResolver.Open( iSocketServ, protDesc.iAddrFamily,
+ protDesc.iProtocol ) );
+ iSockAddr.SetIAC( KGIAC );
+ iSockAddr.SetAction( KHostResInquiry | KHostResName );
+
+ TRACE_FUNC_EXIT
+ }
+
+void CHsDeviceDiscoverer::RunL()
+ {
+ TRACE_FUNC_ENTRY
+
+ TRACE_INFO( (_L("Status value = %d"), iStatus.Int() ) )
+ if ( iStatus.Int() == KErrNone )
+ {
+
+ TInquirySockAddr& sa = TInquirySockAddr::Cast( iEntry().iAddr );
+ TBuf <KDevAddrLength> devAddrBuf;
+ sa.BTAddr().GetReadable( devAddrBuf );
+ TBuf8 <KDevAddrLength> devAddrBuf8;
+ devAddrBuf8.Copy( devAddrBuf );
+
+ TBuf8 <KMaxBluetoothNameLen> devNameBuf;
+ devNameBuf.Copy( iEntry().iName );
+ iDeviceObserver->HandleDeviceFindSuccessL( devAddrBuf8, devNameBuf,
+ sa.MajorServiceClass(), sa.MajorClassOfDevice(),
+ sa.MinorClassOfDevice() );
+ // Get next device if no previous errors
+ iHostResolver.Next( iEntry, iStatus );
+ SetActive();
+ }
+ else
+ {
+ Cancel();
+ iHostResolver.Close();
+ iSearching = EFalse;
+ if ( iDeviceObserver )
+ {
+ iDeviceObserver->HandleDeviceFindFailed( iStatus.Int() );
+ }
+ }
+ TRACE_FUNC_EXIT
+ }
+
+void CHsDeviceDiscoverer::DoCancel()
+ {
+ TRACE_FUNC_ENTRY
+ if ( iSearching )
+ {
+ iHostResolver.Cancel();
+ iHostResolver.Close();
+ }
+ TRACE_FUNC_EXIT
+
+ }