Problem with service attribute propagation and service attribute retrieval
Hi all,
I've got a problem in service with service attribte propagation and service attribute retrieval. I want to implement a service that propagates additional information about the service by using an individual service attribute.
The prppagation of the service attribute should work. I'm using the code below:
try{
//connection string: scheme, target, parameters
//... for servers: btspp://localhost:serviceuuid;name=servicename
//... for clients: btspp://00803dad2AA1:3;authenticate=true
UUID uuid = new UUID(0x0003);
notifier = (StreamConnectionNotifier)Connector.open("btspp://localhost:"+uuid.toString()+";name=Scatternet");
//modify the service record here
LocalDevice ld = LocalDevice.getLocalDevice();
ServiceRecord sr = ld.getRecord(notifier);
analyseServiceRecord(sr);
long seqno = 0;
//Construct a new seqno DataElement
DataElement seqnoDataElement = new DataElement(DataElement.U_INT_4, seqno);
//Write the new seqno DataElement
boolean successful = sr.setAttributeValue(ATTRIBUTE_ID, seqnoDataElement);
System.out.println("ReceiveManager: ServiceRecord modified successfully: " + successful);
analyseServiceRecord(sr);
//Explicitely update the ServiceRecord in the SDDB of the LocalDevice, otherwise no effect will take place.
ld.updateRecord(sr);
analyseServiceRecord(sr);
System.out.println("ServiceRecord modified. Current SeqNo = " + seqno);
} catch (BluetoothStateException bse){
bse.printStackTrace();
} catch (ServiceRegistrationException sre){
sre.printStackTrace();
} catch (IOException ioe){
ioe.printStackTrace();
}
The <code>analyseServiceRecord(sr)</code> statements produce the following output, indicating that the ServiceRecord sr has been modified:
AttribID: 256 DataType: STRING DataValue: Scatternet
AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@1a4cfaaa, javax.bluetooth.DataElement@1cb37664,
AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@f828ed68,
AttribID: 0 DataType: INT_4 DataValue: 0
ReceiveManager: ServiceRecord modified successfully: true
AttribID: 256 DataType: STRING DataValue: Scatternet
AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@ea0ef881, javax.bluetooth.DataElement@84aee8b,
AttribID: 11 DataType: U_INT_4 DataValue: 0
AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@c5c7331,
AttribID: 0 DataType: INT_4 DataValue: 0
AttribID: 256 DataType: STRING DataValue: Scatternet
AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@e938beb1, javax.bluetooth.DataElement@11eaa96,
AttribID: 11 DataType: U_INT_4 DataValue: 0
AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@15549f7c,
AttribID: 0 DataType: INT_4 DataValue: 0
ServiceRecord modified. Current SeqNo = 0
The following code shows how I'm trying to read the service record attribute (usually via another device):
int [] attrSet = {ATTRIBUTE_ID};
try{
boolean successful = servRecord[i].populateRecord(attrSet);
System.out.println("Explicitely retrieving SeqNo service attribute: " + successful);
} catch (IOException ioe){
System.out.println("servRecord[i].populateRecord(attrSet) FAILED");
ioe.printStackTrace();
}
ReceiveManager.analyseServiceRecord(servRecord[i]);
//
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
try{
dos.writeUTF(servRecord[i].getHostDevice().getBluetoothAddress());
String friendlyName;
try{
friendlyName = servRecord[i].getHostDevice().getFriendlyName(true);
} catch (IOException ioe){
friendlyName = servRecord[i].getHostDevice().getFriendlyName(false);
}
dos.writeUTF(friendlyName);//friendlyName
dos.writeInt(1);
// dos.writeLong(1);//seqno
//Get the current Attribute of the RemoteDevice from its ServiceRecord
ServiceRecord sr = servRecord[i];
//Read the seqno DataElement
int [] attrIDs = {ATTRIBUTE_ID_ID};
boolean successful = sr.populateRecord(attrIDs);
System.out.println("PiconetManager: Retrieving SeqNo from ServiceRecord successfully: " + successful);
if(successful){
DataElement seqnoDataElement = sr.getAttributeValue(ATTRIBUTE_ID);
long seqno = seqnoDataElement.getLong();
dos.writeLong(seqno);//seqno
} else {
System.out.println("PiconetManager: Could not retrieve SeqNo from ServiceRecord. (Line 103)");
return;
}
} catch (IOException ioe){
ioe.printStackTrace();
}
That produces the following output:
Searching on device No. 1 of 1 for a RFCOMM service with ATTRIBUTE_ID in its attribute set.
Service discovered
Explicitely retrieving Attribute service attribute: false
AttribID: 4 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@f3c47ffc, javax.bluetooth.DataElement@96d5985,
AttribID: 1 DataType: DATSEQ DataValue: javax.bluetooth.DataElement@1653d53f,
AttribID: 0 DataType: INT_4 DataValue: 0
Retrieving SeqNo from ServiceRecord successfully: false
Could not retrieve SeqNo from ServiceRecord. (Line 103)
Service search completed
QUESTION: Can anybody tell me why I can't retrieve the attribute?
Thanks.
Patrick
Re: Problem with service attribute propagation and service attribute retrieval
Do you mean to publish something like a string about ur server? Try to use attribitute 51. I used it before successfully to publish more date about my server. But actualy I dnt remember why.