git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26199 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-07-01 19:43:37 +00:00
parent 480cccf67b
commit 291e114333
6 changed files with 857 additions and 857 deletions

View File

@ -1,26 +1,26 @@
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include "HCIControllerAccessor.h"
HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path)
{
}
status_t
HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size)
{
if (GetID() < 0)
return B_ERROR;
return B_ERROR;
}
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include "HCIControllerAccessor.h"
HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path)
{
}
status_t
HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size)
{
if (GetID() < 0)
return B_ERROR;
return B_ERROR;
}

View File

@ -1,23 +1,23 @@
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCICONTROLLER_ACCESSOR_H_
#define _HCICONTROLLER_ACCESSOR_H_
#include "HCIDelegate.h"
class HCIControllerAccessor : public HCIDelegate {
public:
HCIControllerAccessor(BPath* path);
status_t IssueCommand(raw_command* rc, size_t size);
};
#endif
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCICONTROLLER_ACCESSOR_H_
#define _HCICONTROLLER_ACCESSOR_H_
#include "HCIDelegate.h"
class HCIControllerAccessor : public HCIDelegate {
public:
HCIControllerAccessor(BPath* path);
status_t IssueCommand(raw_command* rc, size_t size);
};
#endif

View File

@ -1,65 +1,65 @@
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCIDELEGATE_H_
#define _HCIDELEGATE_H_
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <Path.h>
#include <bluetooth/HCI/btHCI_transport.h>
typedef void* raw_command;
class HCIDelegate {
public:
HCIDelegate(BPath* path)
{
status_t status;
fFD = open (path->Path(), O_RDWR);
if (fFD > 0) {
// find out which ID was assigned
status = ioctl(fFD, GET_HCI_ID, &fHID, 0);
printf("%s: hid retrieved %ld status=%ld\n", __FUNCTION__, fHID, status);
}
else {
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID);
fHID = B_ERROR;
}
}
hci_id GetID(void)
{
return fHID;
}
virtual status_t IssueCommand(raw_command rc, size_t size)
{
return B_ERROR;
}
protected:
hci_id fHID;
int fFD;
private:
};
#endif
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCIDELEGATE_H_
#define _HCIDELEGATE_H_
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <Path.h>
#include <bluetooth/HCI/btHCI_transport.h>
typedef void* raw_command;
class HCIDelegate {
public:
HCIDelegate(BPath* path)
{
status_t status;
fFD = open (path->Path(), O_RDWR);
if (fFD > 0) {
// find out which ID was assigned
status = ioctl(fFD, GET_HCI_ID, &fHID, 0);
printf("%s: hid retrieved %ld status=%ld\n", __FUNCTION__, fHID, status);
}
else {
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID);
fHID = B_ERROR;
}
}
hci_id GetID(void)
{
return fHID;
}
virtual status_t IssueCommand(raw_command rc, size_t size)
{
return B_ERROR;
}
protected:
hci_id fHID;
int fFD;
private:
};
#endif

View File

@ -1,22 +1,22 @@
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCITRANSPORT_ACCESSOR_H_
#define _HCITRANSPORT_ACCESSOR_H_
#include "HCIDelegate.h"
class HCITransportAccessor : public HCIDelegate {
public:
HCITransportAccessor(BPath* path);
status_t IssueCommand(raw_command rc, size_t size);
};
#endif
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#ifndef _HCITRANSPORT_ACCESSOR_H_
#define _HCITRANSPORT_ACCESSOR_H_
#include "HCIDelegate.h"
class HCITransportAccessor : public HCIDelegate {
public:
HCITransportAccessor(BPath* path);
status_t IssueCommand(raw_command rc, size_t size);
};
#endif

View File

@ -1,170 +1,170 @@
/*
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include "LocalDeviceHandler.h"
LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
{
fHCIDelegate = hd;
fProperties = new BMessage();
}
LocalDeviceHandler::~LocalDeviceHandler()
{
}
hci_id
LocalDeviceHandler::GetID()
{
return fHCIDelegate->GetID();
}
bool
LocalDeviceHandler::Available() {
return true;
}
void
LocalDeviceHandler::Acquire(void) {
}
bool
LocalDeviceHandler::IsPropertyAvailable(const BString& property) {
type_code typeFound;
int32 countFound;
return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK );
}
void
LocalDeviceHandler::AddWantedEvent(BMessage* msg)
{
fEventsWanted.Lock();
// TODO: review why it is neede to replicate the msg
fEventsWanted.AddMessage(msg);
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
{
fEventsWanted.Lock();
fEventsWanted.RemoveMessage(msg);
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
{
// Remove the whole petition from queue
fEventsWanted.Lock();
int16 eventFound;
int16 opcodeFound;
int32 eventIndex = 0;
// for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
printf("@ Event expected found @%ld\n", eventIndex);
if (eventFound == event) {
printf("@ Event matches %ld\n", eventIndex);
// there is an opcode specified
if (opcode != 0) {
// The opcode matches
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) &&
((uint16)opcodeFound == opcode) ) {
// this should remove only the entry
printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg);
(void)msg->RemoveData("eventExpected", eventIndex);
(void)msg->RemoveData("opcodeExpected", eventIndex);
goto bail;
}
} else {
// Event matches so far
printf("@ Removed event %d from message %p\n", event, msg);
(void)msg->RemoveData("eventExpected", eventIndex);
goto bail;
}
}
eventIndex++;
}
bail:
fEventsWanted.Unlock();
}
BMessage*
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
{
int16 eventFound;
int16 opcodeFound;
int32 eventIndex;
fEventsWanted.Lock();
// for each Petition
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
BMessage* msg = fEventsWanted.FindMessage(index);
printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
msg->PrintToStream();
eventIndex = 0;
// for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
if (eventFound == event) {
printf("Event found %ld\n", eventIndex);
// there is an opcode specified..
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
// ensure the opcode
if ((uint16)opcodeFound != opcode) {
printf("opcode does not match %d\n", opcode);
break;
}
printf("Opcdodes match %d %d \n", opcode , opcodeFound);
}
fEventsWanted.Unlock();
if (indexFound != NULL)
*indexFound = eventIndex;
return msg;
}
eventIndex++;
}
}
fEventsWanted.Unlock();
return NULL;
}
/*
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include "LocalDeviceHandler.h"
LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
{
fHCIDelegate = hd;
fProperties = new BMessage();
}
LocalDeviceHandler::~LocalDeviceHandler()
{
}
hci_id
LocalDeviceHandler::GetID()
{
return fHCIDelegate->GetID();
}
bool
LocalDeviceHandler::Available() {
return true;
}
void
LocalDeviceHandler::Acquire(void) {
}
bool
LocalDeviceHandler::IsPropertyAvailable(const BString& property) {
type_code typeFound;
int32 countFound;
return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK );
}
void
LocalDeviceHandler::AddWantedEvent(BMessage* msg)
{
fEventsWanted.Lock();
// TODO: review why it is neede to replicate the msg
fEventsWanted.AddMessage(msg);
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
{
fEventsWanted.Lock();
fEventsWanted.RemoveMessage(msg);
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
{
// Remove the whole petition from queue
fEventsWanted.Lock();
int16 eventFound;
int16 opcodeFound;
int32 eventIndex = 0;
// for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
printf("@ Event expected found @%ld\n", eventIndex);
if (eventFound == event) {
printf("@ Event matches %ld\n", eventIndex);
// there is an opcode specified
if (opcode != 0) {
// The opcode matches
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) &&
((uint16)opcodeFound == opcode) ) {
// this should remove only the entry
printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg);
(void)msg->RemoveData("eventExpected", eventIndex);
(void)msg->RemoveData("opcodeExpected", eventIndex);
goto bail;
}
} else {
// Event matches so far
printf("@ Removed event %d from message %p\n", event, msg);
(void)msg->RemoveData("eventExpected", eventIndex);
goto bail;
}
}
eventIndex++;
}
bail:
fEventsWanted.Unlock();
}
BMessage*
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
{
int16 eventFound;
int16 opcodeFound;
int32 eventIndex;
fEventsWanted.Lock();
// for each Petition
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
BMessage* msg = fEventsWanted.FindMessage(index);
printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
msg->PrintToStream();
eventIndex = 0;
// for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
if (eventFound == event) {
printf("Event found %ld\n", eventIndex);
// there is an opcode specified..
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
// ensure the opcode
if ((uint16)opcodeFound != opcode) {
printf("opcode does not match %d\n", opcode);
break;
}
printf("Opcdodes match %d %d \n", opcode , opcodeFound);
}
fEventsWanted.Unlock();
if (indexFound != NULL)
*indexFound = eventIndex;
return msg;
}
eventIndex++;
}
}
fEventsWanted.Unlock();
return NULL;
}

File diff suppressed because it is too large Load Diff