Add code for simulating a SDP server present in the host

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34330 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2009-11-28 19:26:00 +00:00
parent af10de93a4
commit e97e2846af
+23 -20
View File
@@ -91,6 +91,7 @@ bool BluetoothServer::QuitRequested(void)
/* stop the SDP server thread */ /* stop the SDP server thread */
fIsShuttingDown = true; fIsShuttingDown = true;
status_t threadReturnStatus; status_t threadReturnStatus;
wait_for_thread(fSDPThreadID, &threadReturnStatus); wait_for_thread(fSDPThreadID, &threadReturnStatus);
printf("SDP server thread exited with: %s\n", strerror(threadReturnStatus)); printf("SDP server thread exited with: %s\n", strerror(threadReturnStatus));
@@ -130,10 +131,13 @@ void BluetoothServer::ReadyToRun(void)
fSDPThreadID = spawn_thread(SDPServerThread, "SDP server thread", fSDPThreadID = spawn_thread(SDPServerThread, "SDP server thread",
B_NORMAL_PRIORITY, this); B_NORMAL_PRIORITY, this);
//#define _USE_SDP_SERVER
#ifdef _USE_SDP_SERVER
if (fSDPThreadID <= 0 || resume_thread(fSDPThreadID) != B_OK) { if (fSDPThreadID <= 0 || resume_thread(fSDPThreadID) != B_OK) {
Output::Instance()->Postf(BLACKBOARD_SDP, Output::Instance()->Postf(BLACKBOARD_SDP,
"Failed launching the SDP server thread: %x\n", fSDPThreadID); "Failed launching the SDP server thread: %x\n", fSDPThreadID);
} }
#endif
} }
@@ -266,7 +270,7 @@ BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
/* Try to find out when a ID was specified */ /* Try to find out when a ID was specified */
int index; int index;
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) { for (index = 0; index < fLocalDevicesList.CountItems(); index++) {
LocalDeviceImpl* lDeviceImpl = fLocalDevicesList.ItemAt(index); LocalDeviceImpl* lDeviceImpl = fLocalDevicesList.ItemAt(index);
if (lDeviceImpl->GetID() == hid) if (lDeviceImpl->GetID() == hid)
return lDeviceImpl; return lDeviceImpl;
@@ -302,7 +306,7 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
BLACKBOARD_KIT); BLACKBOARD_KIT);
lDeviceImpl = LocateDelegateFromMessage(message); lDeviceImpl = LocateDelegateFromMessage(message);
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size ) } else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size)
== B_OK) { == B_OK) {
/* Try to find out when the user specified the address */ /* Try to find out when the user specified the address */
Output::Instance()->Post("GetLocalDevice requested with bdaddr\n", Output::Instance()->Post("GetLocalDevice requested with bdaddr\n",
@@ -321,8 +325,8 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
// Careless, any device not performing operations will be fine // Careless, any device not performing operations will be fine
Output::Instance()->Post("GetLocalDevice plain request\n", BLACKBOARD_KIT); Output::Instance()->Post("GetLocalDevice plain request\n", BLACKBOARD_KIT);
// from last assigned till end // from last assigned till end
for ( int index = lastIndex + 1; index < fLocalDevicesList.CountItems(); index ++) { for (int index = lastIndex + 1; index < fLocalDevicesList.CountItems(); index++) {
lDeviceImpl = fLocalDevicesList.ItemAt(index); lDeviceImpl= fLocalDevicesList.ItemAt(index);
printf("Requesting local device %ld\n", lDeviceImpl->GetID()); printf("Requesting local device %ld\n", lDeviceImpl->GetID());
if (lDeviceImpl != NULL && lDeviceImpl->Available()) if (lDeviceImpl != NULL && lDeviceImpl->Available())
{ {
@@ -334,7 +338,7 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
// from starting till last assigned if not yet found // from starting till last assigned if not yet found
if (lDeviceImpl == NULL) { if (lDeviceImpl == NULL) {
for ( int index = 0; index <= lastIndex ; index ++) { for (int index = 0; index <= lastIndex ; index ++) {
lDeviceImpl = fLocalDevicesList.ItemAt(index); lDeviceImpl = fLocalDevicesList.ItemAt(index);
printf("Requesting local device %ld\n", lDeviceImpl->GetID()); printf("Requesting local device %ld\n", lDeviceImpl->GetID());
if (lDeviceImpl != NULL && lDeviceImpl->Available()) if (lDeviceImpl != NULL && lDeviceImpl->Available())
@@ -453,8 +457,7 @@ BluetoothServer::SDPServerThread(void* data)
int socketServer; int socketServer;
int client; int client;
status_t status; status_t status;
char buff[512] = ""; char buffer[512] = "";
Output::Instance()->Postf(BLACKBOARD_SDP, "SDP server thread up...\n"); Output::Instance()->Postf(BLACKBOARD_SDP, "SDP server thread up...\n");
@@ -469,7 +472,7 @@ BluetoothServer::SDPServerThread(void* data)
// bluetooth adapter // bluetooth adapter
loc_addr.l2cap_family = AF_BLUETOOTH; loc_addr.l2cap_family = AF_BLUETOOTH;
loc_addr.l2cap_bdaddr = *BDADDR_ANY; loc_addr.l2cap_bdaddr = *BDADDR_ANY;
loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1); // correct? loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1);
loc_addr.l2cap_len = sizeof(struct sockaddr_l2cap); loc_addr.l2cap_len = sizeof(struct sockaddr_l2cap);
status = bind(socketServer, (struct sockaddr *)&loc_addr, sizeof(struct sockaddr_l2cap)); status = bind(socketServer, (struct sockaddr *)&loc_addr, sizeof(struct sockaddr_l2cap));
@@ -490,7 +493,6 @@ BluetoothServer::SDPServerThread(void* data)
return status; return status;
} }
while (!server->fIsShuttingDown) { while (!server->fIsShuttingDown) {
Output::Instance()->Postf(BLACKBOARD_SDP, "Waiting connection for socket %d ...\n", socketServer); Output::Instance()->Postf(BLACKBOARD_SDP, "Waiting connection for socket %d ...\n", socketServer);
@@ -500,18 +502,20 @@ BluetoothServer::SDPServerThread(void* data)
Output::Instance()->Postf(BLACKBOARD_SDP, "Incomming connection... %ld\n", client); Output::Instance()->Postf(BLACKBOARD_SDP, "Incomming connection... %ld\n", client);
ssize_t leng = recv(client, buff, 29 , 0); ssize_t receivedSize;
if (leng == -1) {
do {
receivedSize = recv(client, buffer, 29 , 0);
if (receivedSize < 0)
Output::Instance()->Post("Error reading client socket\n", BLACKBOARD_SDP); Output::Instance()->Post("Error reading client socket\n", BLACKBOARD_SDP);
else {
} Output::Instance()->Postf(BLACKBOARD_SDP, "Received from SDP client: %ld:\n", receivedSize);
for (int i = 0; i < receivedSize ; i++)
Output::Instance()->Postf(BLACKBOARD_SDP, "Received from SDP client: %ld:\n", leng); Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buffer[i]);
for (int i = 0; i < leng ; i++)
Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buff[i]);
Output::Instance()->Post("\n", BLACKBOARD_SDP); Output::Instance()->Post("\n", BLACKBOARD_SDP);
}
} while (receivedSize >= 0);
/* fd_set fdSet; /* fd_set fdSet;
FD_ZERO(&fdSet); FD_ZERO(&fdSet);
@@ -520,13 +524,12 @@ BluetoothServer::SDPServerThread(void* data)
struct timeval timeout; struct timeval timeout;
memset(&timeout, 0, sizeof(timeout)); memset(&timeout, 0, sizeof(timeout));
// TODO initialize timeout! // TODO initialize timeout!
int ret = select(1, &fdSet, NULL, NULL, &timeout); int ret = select(1, &fdSet, NULL, NULL, &timeout);
printf("ready to read descriptors: %d\n", ret); printf("ready to read descriptors: %d\n", ret);
*/ */
snooze(5000000); snooze(5000000);
Output::Instance()->Post("Waiting for next connection...\n", BLACKBOARD_SDP); Output::Instance()->Post("\nWaiting for next connection...\n", BLACKBOARD_SDP);
} }
/* Close the socket */ /* Close the socket */