Resolve allocation of multiple Messengers,(Mika Lindqvist)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26449 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2008-07-16 19:04:53 +00:00
parent fe5d1557e4
commit 870ae24a6d
2 changed files with 30 additions and 23 deletions
+14 -13
View File
@@ -31,38 +31,39 @@ class RemoteDevice;
class DiscoveryAgent { class DiscoveryAgent {
public: public:
static const int GIAC = BT_GIAC; static const int GIAC = BT_GIAC;
static const int LIAC = BT_LIAC; static const int LIAC = BT_LIAC;
static const int PREKNOWN = BT_PREKNOWN; static const int PREKNOWN = BT_PREKNOWN;
static const int CACHED = BT_CACHED; static const int CACHED = BT_CACHED;
static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE;
RemoteDevicesList RetrieveDevices(int option); /* TODO */ RemoteDevicesList RetrieveDevices(int option); /* TODO */
status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */
status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs);
status_t CancelInquiry(DiscoveryListener* listener); status_t CancelInquiry(DiscoveryListener* listener);
/* /*
int searchServices(int[] attrSet, int searchServices(int[] attrSet,
UUID[] uuidSet, UUID[] uuidSet,
RemoteDevice btDev, RemoteDevice btDev,
DiscoveryListener discListener); DiscoveryListener discListener);
bool cancelServiceSearch(int transID); bool cancelServiceSearch(int transID);
BString selectService(UUID uuid, int security, boolean master); BString selectService(UUID uuid, int security, boolean master);
*/ */
private: private:
DiscoveryAgent(LocalDevice* ld); DiscoveryAgent(LocalDevice* ld);
void SetLocalDeviceOwner(LocalDevice* ld); ~DiscoveryAgent();
void SetLocalDeviceOwner(LocalDevice* ld);
DiscoveryListener* fLastUsedListener; DiscoveryListener* fLastUsedListener;
LocalDevice* fLocalDevice; LocalDevice* fLocalDevice;
BMessenger* fMessenger;
friend class LocalDevice;
friend class LocalDevice;
}; };
} }
+16 -10
View File
@@ -43,10 +43,9 @@ DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener)
status_t status_t
DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs)
{ {
BMessenger* btsm = NULL;
size_t size; size_t size;
if ((btsm = _RetrieveBluetoothMessenger()) == NULL) if (fMessenger == NULL)
return B_ERROR; return B_ERROR;
if (secs < 1 || secs > 61 ) if (secs < 1 || secs > 61 )
@@ -81,7 +80,7 @@ DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, big
request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE);
if (btsm->SendMessage(&request, listener) == B_OK) if (fMessenger->SendMessage(&request, listener) == B_OK)
{ {
return B_OK; return B_OK;
} }
@@ -94,10 +93,9 @@ DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, big
status_t status_t
DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
{ {
BMessenger* btsm = NULL; //TODO: this should be a member field
size_t size; size_t size;
if ((btsm = _RetrieveBluetoothMessenger()) == NULL) if (fMessenger == NULL)
return B_ERROR; return B_ERROR;
void* cancelInquiryCommand = NULL; void* cancelInquiryCommand = NULL;
@@ -114,11 +112,11 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL));
if (btsm->SendMessage(&request, &reply) == B_OK) { if (fMessenger->SendMessage(&request, &reply) == B_OK) {
if (reply.FindInt8("status", &bt_status ) == B_OK ) { if (reply.FindInt8("status", &bt_status ) == B_OK ) {
return bt_status; return bt_status;
} }
} }
return B_ERROR; return B_ERROR;
} }
@@ -131,7 +129,15 @@ DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld)
DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) DiscoveryAgent::DiscoveryAgent(LocalDevice* ld)
{ {
fLocalDevice = ld; fLocalDevice = ld;
fMessenger = _RetrieveBluetoothMessenger();
}
DiscoveryAgent::~DiscoveryAgent()
{
if (fMessenger)
delete fMessenger;
} }