- Destroy debug window as late as possible
- Delete event listener - a fake SDP server is enabled. - Checkstyled git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34995 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -76,34 +76,37 @@ BluetoothServer::BluetoothServer()
|
|||||||
(BluetoothPortListener::port_listener_func)&DispatchEvent);
|
(BluetoothPortListener::port_listener_func)&DispatchEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BluetoothServer::QuitRequested(void)
|
bool BluetoothServer::QuitRequested(void)
|
||||||
{
|
{
|
||||||
// Finish quitting
|
|
||||||
Output::Instance()->Lock();
|
|
||||||
Output::Instance()->Quit();
|
|
||||||
|
|
||||||
LocalDeviceImpl* lDeviceImpl = NULL;
|
LocalDeviceImpl* lDeviceImpl = NULL;
|
||||||
while ((lDeviceImpl = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0))
|
while ((lDeviceImpl = (LocalDeviceImpl*)
|
||||||
!= NULL)
|
fLocalDevicesList.RemoveItem((int32)0)) != NULL)
|
||||||
delete lDeviceImpl;
|
delete lDeviceImpl;
|
||||||
|
|
||||||
_RemoveDeskbarIcon();
|
_RemoveDeskbarIcon();
|
||||||
|
|
||||||
/* 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));
|
||||||
|
|
||||||
|
// Finish quitting
|
||||||
|
Output::Instance()->Lock();
|
||||||
|
Output::Instance()->Quit();
|
||||||
|
|
||||||
|
delete fEventListener2;
|
||||||
printf("Shutting down bluetooth_server.\n");
|
printf("Shutting down bluetooth_server.\n");
|
||||||
|
|
||||||
return BApplication::QuitRequested();
|
return BApplication::QuitRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BluetoothServer::ArgvReceived(int32 argc, char **argv)
|
void BluetoothServer::ArgvReceived(int32 argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc>1) {
|
if (argc > 1) {
|
||||||
if (strcmp(argv[1], "--finish") == 0)
|
if (strcmp(argv[1], "--finish") == 0)
|
||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
@@ -121,9 +124,11 @@ void BluetoothServer::ReadyToRun(void)
|
|||||||
fDeviceManager->StartMonitoringDevice("bluetooth/h5");
|
fDeviceManager->StartMonitoringDevice("bluetooth/h5");
|
||||||
|
|
||||||
if (fEventListener2->Launch() != B_OK)
|
if (fEventListener2->Launch() != B_OK)
|
||||||
Output::Instance()->Post("Bluetooth event listener failed\n", BLACKBOARD_GENERAL);
|
Output::Instance()->Post("Bluetooth event listener failed\n",
|
||||||
|
BLACKBOARD_GENERAL);
|
||||||
else
|
else
|
||||||
Output::Instance()->Post("Bluetooth event listener Ready\n", BLACKBOARD_GENERAL);
|
Output::Instance()->Post("Bluetooth event listener Ready\n",
|
||||||
|
BLACKBOARD_GENERAL);
|
||||||
|
|
||||||
_InstallDeskbarIcon();
|
_InstallDeskbarIcon();
|
||||||
|
|
||||||
@@ -131,8 +136,8 @@ 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
|
#define _USE_FAKE_SDP_SERVER
|
||||||
#ifdef _USE_SDP_SERVER
|
#ifdef _USE_FAKE_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);
|
||||||
@@ -147,30 +152,37 @@ void BluetoothServer::AppActivated(bool act)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BluetoothServer::MessageReceived(BMessage *message)
|
void BluetoothServer::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t status = B_WOULD_BLOCK; // mark somehow to do not reply anything
|
status_t status = B_WOULD_BLOCK; // mark somehow to do not reply anything
|
||||||
|
|
||||||
switch(message->what)
|
switch (message->what)
|
||||||
{
|
{
|
||||||
case BT_MSG_ADD_DEVICE:
|
case BT_MSG_ADD_DEVICE:
|
||||||
{
|
{
|
||||||
BString str;
|
BString str;
|
||||||
message->FindString("name", &str);
|
|
||||||
BPath path(str.String());
|
BPath path(str.String());
|
||||||
|
|
||||||
|
message->FindString("name", &str);
|
||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
||||||
"Requested LocalDevice %s\n", str.String());
|
"Requested LocalDevice %s\n", str.String());
|
||||||
LocalDeviceImpl* lDeviceImpl = LocalDeviceImpl::CreateTransportAccessor(&path);
|
|
||||||
|
LocalDeviceImpl* lDeviceImpl =
|
||||||
|
LocalDeviceImpl::CreateTransportAccessor(&path);
|
||||||
|
|
||||||
if (lDeviceImpl->GetID() >= 0) {
|
if (lDeviceImpl->GetID() >= 0) {
|
||||||
fLocalDevicesList.AddItem(lDeviceImpl);
|
fLocalDevicesList.AddItem(lDeviceImpl);
|
||||||
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(lDeviceImpl->GetID()));
|
|
||||||
|
Output::Instance()->AddTab("Local Device",
|
||||||
|
BLACKBOARD_LD(lDeviceImpl->GetID()));
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()),
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()),
|
||||||
"LocalDevice %s id=%x added\n", str.String(), lDeviceImpl->GetID());
|
"LocalDevice %s id=%x added\n", str.String(),
|
||||||
|
lDeviceImpl->GetID());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Output::Instance()->Post("Adding LocalDevice failed\n",
|
Output::Instance()->Post("Adding LocalDevice hci id invalid\n",
|
||||||
BLACKBOARD_GENERAL);
|
BLACKBOARD_GENERAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,11 +218,11 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
|||||||
status = HandleGetProperty(message, &reply);
|
status = HandleGetProperty(message, &reply);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Handle if the bluetooth preferences is running?? */
|
// Handle if the bluetooth preferences is running?
|
||||||
case B_SOME_APP_LAUNCHED:
|
case B_SOME_APP_LAUNCHED:
|
||||||
{
|
{
|
||||||
const char *signature;
|
const char* signature;
|
||||||
// TODO: what's this for?
|
|
||||||
if (message->FindString("be:signature", &signature) == B_OK) {
|
if (message->FindString("be:signature", &signature) == B_OK) {
|
||||||
printf("input_server : %s\n", signature);
|
printf("input_server : %s\n", signature);
|
||||||
if (strcmp(signature, "application/x-vnd.Be-TSKB") == 0) {
|
if (strcmp(signature, "application/x-vnd.Be-TSKB") == 0) {
|
||||||
@@ -239,11 +251,11 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
LocalDeviceImpl*
|
LocalDeviceImpl*
|
||||||
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
||||||
{
|
{
|
||||||
@@ -251,7 +263,7 @@ BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
|||||||
hci_id hid;
|
hci_id hid;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
||||||
/* 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 ++) {
|
||||||
lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
||||||
@@ -264,10 +276,11 @@ BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LocalDeviceImpl*
|
LocalDeviceImpl*
|
||||||
BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
|
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++) {
|
||||||
@@ -300,37 +313,39 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
|||||||
LocalDeviceImpl* lDeviceImpl = NULL;
|
LocalDeviceImpl* lDeviceImpl = NULL;
|
||||||
static int32 lastIndex = 0;
|
static int32 lastIndex = 0;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK)
|
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
||||||
{
|
|
||||||
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
||||||
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,
|
||||||
== B_OK) {
|
(const void**)&bdaddr, &size) == 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",
|
||||||
BLACKBOARD_KIT);
|
BLACKBOARD_KIT);
|
||||||
for (lastIndex = 0; lastIndex < fLocalDevicesList.CountItems(); lastIndex ++) {
|
for (lastIndex = 0; lastIndex < fLocalDevicesList.CountItems();
|
||||||
//TODO: Only possible if the property is available
|
lastIndex ++) {
|
||||||
//bdaddr_t local;
|
// TODO: Only possible if the property is available
|
||||||
//lDeviceImpl = fLocalDevicesList.ItemAt(lastIndex);
|
// bdaddr_t local;
|
||||||
//if ((lDeviceImpl->GetAddress(&local, message) == B_OK)
|
// lDeviceImpl = fLocalDevicesList.ItemAt(lastIndex);
|
||||||
// && bacmp(&local, &bdaddr)) {
|
// if ((lDeviceImpl->GetAddress(&local, message) == B_OK)
|
||||||
// break;
|
// && bacmp(&local, &bdaddr)) {
|
||||||
//}
|
// break;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// 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()) {
|
||||||
{
|
Output::Instance()->Postf(BLACKBOARD_KIT,
|
||||||
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", lDeviceImpl->GetID());
|
"Device available: %lx\n", lDeviceImpl->GetID());
|
||||||
lastIndex = index;
|
lastIndex = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -341,9 +356,9 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
|||||||
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()) {
|
||||||
{
|
Output::Instance()->Postf(BLACKBOARD_KIT,
|
||||||
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", lDeviceImpl->GetID());
|
"Device available: %lx\n", lDeviceImpl->GetID());
|
||||||
lastIndex = index;
|
lastIndex = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -351,7 +366,9 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastIndex <= fLocalDevicesList.CountItems() && lDeviceImpl != NULL && lDeviceImpl->Available()) {
|
if (lastIndex <= fLocalDevicesList.CountItems() && lDeviceImpl != NULL
|
||||||
|
&& lDeviceImpl->Available()) {
|
||||||
|
|
||||||
hid = lDeviceImpl->GetID();
|
hid = lDeviceImpl->GetID();
|
||||||
lDeviceImpl->Acquire();
|
lDeviceImpl->Acquire();
|
||||||
|
|
||||||
@@ -398,8 +415,8 @@ BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
|||||||
status_t
|
status_t
|
||||||
BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
||||||
{
|
{
|
||||||
/* User side will look for the reply in a result field
|
/* User side will look for the reply in a result field and will
|
||||||
* and will not care about status fields, therefore we return OK in all cases
|
* not care about status fields, therefore we return OK in all cases
|
||||||
*/
|
*/
|
||||||
LocalDeviceImpl* lDeviceImpl = LocateDelegateFromMessage(message);
|
LocalDeviceImpl* lDeviceImpl = LocateDelegateFromMessage(message);
|
||||||
if (lDeviceImpl == NULL) {
|
if (lDeviceImpl == NULL) {
|
||||||
@@ -411,8 +428,8 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
|||||||
// Find out if there is a property being requested,
|
// Find out if there is a property being requested,
|
||||||
if (message->FindString("property", &propertyRequested) == B_OK) {
|
if (message->FindString("property", &propertyRequested) == B_OK) {
|
||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()), "Searching %s property...\n",
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()),
|
||||||
propertyRequested);
|
"Searching %s property...\n", propertyRequested);
|
||||||
|
|
||||||
// Check if the property has been already retrieved
|
// Check if the property has been already retrieved
|
||||||
if (lDeviceImpl->IsPropertyAvailable(propertyRequested)) {
|
if (lDeviceImpl->IsPropertyAvailable(propertyRequested)) {
|
||||||
@@ -420,7 +437,8 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
|||||||
|| strcmp(propertyRequested, "lmp_version") == 0
|
|| strcmp(propertyRequested, "lmp_version") == 0
|
||||||
|| strcmp(propertyRequested, "sco_mtu") == 0) {
|
|| strcmp(propertyRequested, "sco_mtu") == 0) {
|
||||||
|
|
||||||
uint8 result = lDeviceImpl->GetPropertiesMessage()->FindInt8(propertyRequested);
|
uint8 result = lDeviceImpl->GetPropertiesMessage()->
|
||||||
|
FindInt8(propertyRequested);
|
||||||
reply->AddInt32("result", result);
|
reply->AddInt32("result", result);
|
||||||
|
|
||||||
} else if (strcmp(propertyRequested, "hci_revision") == 0
|
} else if (strcmp(propertyRequested, "hci_revision") == 0
|
||||||
@@ -430,12 +448,13 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
|||||||
|| strcmp(propertyRequested, "acl_max_pkt") == 0
|
|| strcmp(propertyRequested, "acl_max_pkt") == 0
|
||||||
|| strcmp(propertyRequested, "sco_max_pkt") == 0 ) {
|
|| strcmp(propertyRequested, "sco_max_pkt") == 0 ) {
|
||||||
|
|
||||||
uint16 result = lDeviceImpl->GetPropertiesMessage()->FindInt16(propertyRequested);
|
uint16 result = lDeviceImpl->GetPropertiesMessage()->
|
||||||
|
FindInt16(propertyRequested);
|
||||||
reply->AddInt32("result", result);
|
reply->AddInt32("result", result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()), "Property %s could not be satisfied\n",
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()),
|
||||||
propertyRequested);
|
"Property %s could not be satisfied\n", propertyRequested);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -443,6 +462,7 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#endif
|
#endif
|
||||||
@@ -450,9 +470,9 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
|||||||
int32
|
int32
|
||||||
BluetoothServer::SDPServerThread(void* data)
|
BluetoothServer::SDPServerThread(void* data)
|
||||||
{
|
{
|
||||||
const BluetoothServer *server = (BluetoothServer *)data;
|
const BluetoothServer* server = (BluetoothServer*)data;
|
||||||
|
|
||||||
/* Set up the SDP socket. */
|
// Set up the SDP socket
|
||||||
struct sockaddr_l2cap loc_addr = { 0 };
|
struct sockaddr_l2cap loc_addr = { 0 };
|
||||||
int socketServer;
|
int socketServer;
|
||||||
int client;
|
int client;
|
||||||
@@ -461,10 +481,11 @@ BluetoothServer::SDPServerThread(void* data)
|
|||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "SDP server thread up...\n");
|
Output::Instance()->Postf(BLACKBOARD_SDP, "SDP server thread up...\n");
|
||||||
|
|
||||||
socketServer = socket(PF_BLUETOOTH, SOCK_STREAM /*SOCK_SEQPACKET*/, BLUETOOTH_PROTO_L2CAP);
|
socketServer = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_L2CAP);
|
||||||
|
|
||||||
if (socketServer < 0) {
|
if (socketServer < 0) {
|
||||||
Output::Instance()->Post("Could not create server socket ...\n", BLACKBOARD_SDP);
|
Output::Instance()->Post("Could not create server socket ...\n",
|
||||||
|
BLACKBOARD_SDP);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,41 +496,48 @@ BluetoothServer::SDPServerThread(void* data)
|
|||||||
loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1);
|
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));
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Could not bind server socket %d ...\n", status);
|
Output::Instance()->Postf(BLACKBOARD_SDP,
|
||||||
|
"Could not bind server socket %d ...\n", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setsockopt(sock, SOL_L2CAP, SO_L2CAP_OMTU, &omtu, len );
|
// setsockopt(sock, SOL_L2CAP, SO_L2CAP_OMTU, &omtu, len );
|
||||||
// getsockopt(sock, SOL_L2CAP, SO_L2CAP_IMTU, &omtu, &len );
|
// getsockopt(sock, SOL_L2CAP, SO_L2CAP_IMTU, &omtu, &len );
|
||||||
|
|
||||||
/* Listen for up to 10 connections. */
|
// Listen for up to 10 connections
|
||||||
status = listen(socketServer, 10);
|
status = listen(socketServer, 10);
|
||||||
|
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Could not listen server socket %d ...\n", status);
|
Output::Instance()->Postf(BLACKBOARD_SDP,
|
||||||
|
"Could not listen server socket %d ...\n", status);
|
||||||
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);
|
||||||
|
|
||||||
uint len = sizeof(struct sockaddr_l2cap);
|
uint len = sizeof(struct sockaddr_l2cap);
|
||||||
client = accept(socketServer, (struct sockaddr *) &loc_addr, &len);
|
client = accept(socketServer, (struct sockaddr*)&loc_addr, &len);
|
||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Incomming connection... %ld\n", client);
|
Output::Instance()->Postf(BLACKBOARD_SDP,
|
||||||
|
"Incomming connection... %ld\n", client);
|
||||||
|
|
||||||
ssize_t receivedSize;
|
ssize_t receivedSize;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
receivedSize = recv(client, buffer, 29 , 0);
|
receivedSize = recv(client, buffer, 29 , 0);
|
||||||
if (receivedSize < 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 {
|
else {
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Received from SDP client: %ld:\n", receivedSize);
|
Output::Instance()->Postf(BLACKBOARD_SDP,
|
||||||
|
"Received from SDP client: %ld:\n", receivedSize);
|
||||||
for (int i = 0; i < receivedSize ; i++)
|
for (int i = 0; i < receivedSize ; i++)
|
||||||
Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buffer[i]);
|
Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buffer[i]);
|
||||||
|
|
||||||
@@ -517,22 +545,12 @@ BluetoothServer::SDPServerThread(void* data)
|
|||||||
}
|
}
|
||||||
} while (receivedSize >= 0);
|
} while (receivedSize >= 0);
|
||||||
|
|
||||||
/* fd_set fdSet;
|
|
||||||
FD_ZERO(&fdSet);
|
|
||||||
FD_SET(s, &fdSet);
|
|
||||||
|
|
||||||
struct timeval timeout;
|
|
||||||
memset(&timeout, 0, sizeof(timeout));
|
|
||||||
// TODO initialize timeout!
|
|
||||||
int ret = select(1, &fdSet, NULL, NULL, &timeout);
|
|
||||||
printf("ready to read descriptors: %d\n", ret);
|
|
||||||
*/
|
|
||||||
|
|
||||||
snooze(5000000);
|
snooze(5000000);
|
||||||
Output::Instance()->Post("\nWaiting for next connection...\n", BLACKBOARD_SDP);
|
Output::Instance()->Post("\nWaiting for next connection...\n",
|
||||||
|
BLACKBOARD_SDP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the socket */
|
// Close the socket
|
||||||
close(socketServer);
|
close(socketServer);
|
||||||
|
|
||||||
return B_NO_ERROR;
|
return B_NO_ERROR;
|
||||||
@@ -580,6 +598,7 @@ BluetoothServer::_RemoveDeskbarIcon()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user