I think this is what you are looking for: void CbuddyAppView::FindDevicesL() { iInqSockAddrArray = new (ELeave) RArray<TInquirySockAddr>;
CleanupStack::PushL(iInqSockAddrArray); //Keep it KGIAC so that all the devices can be detected //who are BT enabled StartDiscoveryL(iInqSockAddrArray,KGIAC); CleanupStack::Pop();
//this function is for finding devices with BT ON void CbuddyAppView::StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray, TUint aInquiryAddr, TInt8 aMajorClass, TInt8 aMinorClass, TInt16 aServiceClass ) {
I was able to compile the code, but it finds that there are no devices in the area... I tought that it is due to the fact that StartDiscoverL requies 5 parameters, but when you call it you use 2 parameters! Is this a possible cause?
I should have passed the header file also. I am so dumb... Here's the appview header , just take the relevant function declr's
Code:
class CbuddyAppView : public CCoeControl, public MServiceDiscoObserver { public:
/*! @function NewL
@discussion Create a CbuddyAppView object, which will draw itself to aRect @param aRect the rectangle this view will be drawn to @result a pointer to the created instance of CbuddyAppView */ static CbuddyAppView* NewL(const TRect& aRect);
/*! @function NewLC
@discussion Create a CbuddyAppView object, which will draw itself to aRect @param aRect the rectangle this view will be drawn to @result a pointer to the created instance of CbuddyAppView */ static CbuddyAppView* NewLC(const TRect& aRect);
/*! @function ~CbuddyAppView
@discussion Destroy the object and release all memory */ ~CbuddyAppView();
/*! @function UserDraw
@discussion Draw this CHelloWorldAppView to the screen @param aRect the rectangle of this view that needs updating */ void UserDraw() const;
public: // from CCoeControl /*! @function Draw
@discussion Draw this CbuddyAppView to the screen @param aRect the rectangle of this view that needs updating */ void Draw(const TRect& aRect) const;
/*! @function OfferKeyEventL
@discussion Handle any user keypresses @param aKeyEvent holds the data for the event that occurred @param aType holds the type of key event that occured @result a TKeyResponse indicating if the key was consumed or not */ TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
/*! @function InputCapabilities
@discussion Return the capabilities of the OfferKeyEventL method for this class @result a TCoeInputCapabilities indicating the capabilities for this class */ TCoeInputCapabilities InputCapabilities() const; void FindServices();
@discussion Perform the second phase construction of a CbuddyAppView object @param aRect the rectangle this view will be drawn to */ void ConstructL(const TRect& aRect);
/*! @function CbuddyAppView
@discussion Perform the first phase of two phase construction */ CbuddyAppView();
I didn't tought to use the address to make a comparison, I wanted to use the name of the device!
Now I with the address...
I know this is stupid, but I'm not expert in this: I have that my address is 00:20:E0:79:56:61, how can I create a TInquirySockAddr object to make a comparison with the elemnts of the array iInqSockAddrArray?
As TInquirySockAddr class is derived from TDesC class and so you have the Match fucntion at your disposal and so comparision must be easy. Hope this helps. --Mayur.
Forum posts: 404
Bye.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
Forum posts: 404
You want to implement the discovery part silently?
Bye.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
I know the name of the device, and I want that after a silent part of discovering, if that device is present my program connects to it...
Forum posts: 404
void CbuddyAppView::FindDevicesL()
{
iInqSockAddrArray = new (ELeave) RArray<TInquirySockAddr>;
CleanupStack::PushL(iInqSockAddrArray);
//Keep it KGIAC so that all the devices can be detected
//who are BT enabled
StartDiscoveryL(iInqSockAddrArray,KGIAC);
CleanupStack::Pop();
TBuf<100> anote;
_LIT(message,"%d devices found");
anote.Format(message,iInqSockAddrArray->Count());
CAknInformationNote* informationNote;
informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(anote);
}
//this function is for finding devices with BT ON
void CbuddyAppView::StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray,
TUint aInquiryAddr,
TInt8 aMajorClass,
TInt8 aMinorClass,
TInt16 aServiceClass
)
{
#define CAST_ISA(x) (TInquirySockAddr::Cast((x)().iAddr))
RSocketServ sockServ;
RHostResolver hostResv;
TProtocolDesc protInfo;
TInquirySockAddr sockAddr;
TRequestStatus ReqStatus;
TNameEntry NameEntry;
User::LeaveIfError(sockServ.Connect());
CleanupClosePushL<RSocketServ>(sockServ);
User::LeaveIfError(sockServ.FindProtocol(_L("BTLinkManager"),
protInfo
)
);
User::LeaveIfError(hostResv.Open(sockServ,
protInfo.iAddrFamily,
protInfo.iProtocol
)
);
CleanupClosePushL<RHostResolver>(hostResv);
sockAddr.SetIAC(aInquiryAddr);
sockAddr.SetAction(KHostResInquiry);
hostResv.GetByAddress(sockAddr,NameEntry,ReqStatus);
while(User::WaitForRequest(ReqStatus),(ReqStatus == KErrNone || ReqStatus == KRequestPending)){//while starts
TInquirySockAddr &isa = CAST_ISA(NameEntry);
//add if filter matches
if((aMajorClass < 0 || aMajorClass == (TInt8)isa.MajorClassOfDevice()) &&
(aMinorClass < 0 || aMinorClass == (TInt8)isa.MinorClassOfDevice()) &&
(aServiceClass < 0 || aServiceClass == (TInt8)isa.MajorServiceClass())
){//if starts
AddToListL(NameEntry,*aInqSockAddrArray);
}//end of if
hostResv.Next(NameEntry,ReqStatus);
}//end of while
CleanupStack::PopAndDestroy(2);
}
//this function is to build a list of disvoered lists
void CbuddyAppView::AddToListL(TNameEntry& aNameEntry,
RArray<TInquirySockAddr>& aInqSockAddrEntry
)
{
TInt i;
TInquirySockAddr &isa = TInquirySockAddr::Cast(aNameEntry().iAddr);
for(i=0;i<aInqSockAddrEntry.Count();i++){
if(aInqSockAddrEntry[i].BTAddr() == isa.BTAddr()){
return;
}
}
TInquirySockAddr *isa_ptr = new (ELeave)TInquirySockAddr(isa);
CleanupStack::PushL(isa_ptr);
User::LeaveIfError(aInqSockAddrEntry.Append(*isa_ptr));
CleanupStack::Pop();
}
http://symbiangeek.blogspot.com
Forum posts: 79
How do you define: iInqSockAddrArray?
It gives me: "undecleared identifier".
Thanks!
Corben
Forum posts: 404
Sorry missed this out.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
TUint aInquiryAddr,
TInt8 aMajorClass,
TInt8 aMinorClass,
TInt16 aServiceClass
)
I was able to compile the code, but it finds that there are no devices in the area... I tought that it is due to the fact that StartDiscoverL requies 5 parameters, but when you call it you use 2 parameters! Is this a possible cause?
Thanks, Corben
Forum posts: 404
And the default values are suffice.
Bye.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
error C2660: 'StartDiscoveryL' : function does not take 2 parameters
Did I forgot something?
Forum posts: 404
I am so dumb...
Here's the appview header , just take the relevant function declr's
public MServiceDiscoObserver
{
public:
/*!
@function NewL
@discussion Create a CbuddyAppView object, which will draw itself to aRect
@param aRect the rectangle this view will be drawn to
@result a pointer to the created instance of CbuddyAppView
*/
static CbuddyAppView* NewL(const TRect& aRect);
/*!
@function NewLC
@discussion Create a CbuddyAppView object, which will draw itself to aRect
@param aRect the rectangle this view will be drawn to
@result a pointer to the created instance of CbuddyAppView
*/
static CbuddyAppView* NewLC(const TRect& aRect);
/*!
@function ~CbuddyAppView
@discussion Destroy the object and release all memory
*/
~CbuddyAppView();
/*!
@function UserDraw
@discussion Draw this CHelloWorldAppView to the screen
@param aRect the rectangle of this view that needs updating
*/
void UserDraw() const;
public: // from CCoeControl
/*!
@function Draw
@discussion Draw this CbuddyAppView to the screen
@param aRect the rectangle of this view that needs updating
*/
void Draw(const TRect& aRect) const;
/*!
@function OfferKeyEventL
@discussion Handle any user keypresses
@param aKeyEvent holds the data for the event that occurred
@param aType holds the type of key event that occured
@result a TKeyResponse indicating if the key was consumed or not
*/
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
/*!
@function InputCapabilities
@discussion Return the capabilities of the OfferKeyEventL
method for this class
@result a TCoeInputCapabilities indicating the capabilities
for this class
*/
TCoeInputCapabilities InputCapabilities() const;
void FindServices();
void FindDevicesL();
void SwitchToMode(TDevMode1 aMode);
void StartMasterAndSlaveL();
void StartServices();
void HandleServiceDiscoveryCompleteL();
private:
/*!
@function ConstructL
@discussion Perform the second phase construction of a CbuddyAppView object
@param aRect the rectangle this view will be drawn to
*/
void ConstructL(const TRect& aRect);
/*!
@function CbuddyAppView
@discussion Perform the first phase of two phase construction
*/
CbuddyAppView();
void StartDiscoveryL(RArray<TInquirySockAddr> *aInqSockAddrArray,
TUint aInquiryAddr,
TInt8 aMajorClass = -1,
TInt8 aMinorClass = -1,
TInt16 aServiceClass = -1
);
void AddToListL(TNameEntry& aNameEntry,
RArray<TInquirySockAddr>& aInqSockAddrEntry
);
RArray<TInquirySockAddr> *iInqSockAddrArray;
CTwoServiceAdvertiser *iBTA;
CDiscoverService* ServiceDiscoverer;
};
Hope this helps.
Bye.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
It works, now how can I retrieve the name of the device to make a comparison?
Thanks for the help given so far!
Corben
Forum posts: 404
I think the device address should be enough for connection.
Bye.
--Mayur.
http://symbiangeek.blogspot.com
Forum posts: 79
I didn't tought to use the address to make a comparison, I wanted to use the name of the device!
Now I with the address...
I know this is stupid, but I'm not expert in this: I have that my address is 00:20:E0:79:56:61, how can I create a TInquirySockAddr object to make a comparison with the elemnts of the array iInqSockAddrArray?
Thaks!!!
Corben
Forum posts: 404
the Match fucntion at your disposal and so comparision must be easy.
Hope this helps.
--Mayur.
http://symbiangeek.blogspot.com