Hello,
I am developing application which should provide sessionless signals to the bus
and I am facing the problem.
The object which implements the Interface with sessionless signal, after
registration ob the bus, is not being seen in EventsActionBrowser application
(app from samples).
If I trying to implement AllSeenIntrospectable interface I got the error
****** ERROR ALLJOYN external ..._core/src/BusObject.cc:632 |
org.allseen.Introspectable is automatically added if needed and cannot be added
manually: ER_BUS_IFACE_ALREADY_EXISTS
Here is the code:
BusInterface :
@BusInterface(name = Door.DOOR_INTF_NAME, announced = "true")
public interface Door extends LocatableBusObject{
String DOOR_INTF_NAME = "com.example.Door";
String PERSON_PASSED_THROUGH = "PersonPassedThrough";
@BusProperty(annotation = BusProperty.ANNOTATE_EMIT_CHANGED_SIGNAL)
boolean getIsOpen() throws BusException;
@BusProperty(annotation = BusProperty.ANNOTATE_EMIT_CHANGED_SIGNAL)
String getLocation() throws BusException;
@BusProperty(annotation =
BusProperty.ANNOTATE_EMIT_CHANGED_SIGNAL_INVALIDATES, signature = "u")
int getKeyCode() throws BusException;
@BusMethod(name = "Open")
void open() throws BusException;
@BusMethod(name = "Close")
void close() throws BusException;
@BusMethod(name = "KnockAndRun", annotation = BusMethod.ANNOTATE_NO_REPLY)
void knockAndRun() throws BusException;
@BusSignal(name = PERSON_PASSED_THROUGH, sessionless = true, annotation =
BusSignal.ANNOTATE_SESSIONLESS)
void personPassedThrough() throws BusException;
}
Registering object in the bus:
private void doRegisterBusObject(Object obj) {
LocatableBusObject object = (LocatableBusObject) obj;
String location = object.getBusObjectLocation();
if (!location.startsWith("/")) {
location = "/" + location;
}
// Register the object on the local bus
Status status = bus.registerBusObject(object, location);
if (Status.OK != status) {
return;
}
// Have About send a signal a new door is available.
aboutObj.announce(CONTACT_PORT, aboutData);
}
Bus object itself:
public class DoorService implements Door, Observable{
private final String introspectXML;
private boolean isOpen;
private final String location;
private int keyCode;
private final PropertyChangedEmitter pce;
private PropertyChangeRegistry callbacks = new PropertyChangeRegistry();
private Bus bus;
public DoorService(String location, Bus bus, String s) {
this.location = location;
this.introspectXML = s;
this.bus = bus;
this.pce = new PropertyChangedEmitter(DoorService.this,
BusAttachment.SESSION_ID_ALL_HOSTED, GlobalBroadcast.Off);
}
/**
* Implements the read of the IsOpen property of the door interface.
*
* @return the current state of the door. True if the door is open.
*/
@Bindable
public boolean getIsOpen() {
return isOpen;
}
/**
* Implements the read of the Location property of the door interface.
*
* @return the current location of the door.
*/
@Bindable
public String getLocation() {
return location;
}
/**
* Implements the read of the KeyCode property of the door interface.
*
* @return the current key code for this door.
*/
@Bindable
public int getKeyCode() {
return keyCode;
}
/**
* Opens the door.
*/
public void open() {
if (!isOpen) {
isOpen = true;
callbacks.notifyChange(this, BR.isOpen);
sendWorkerMessage(() -> sendDoorEvent(true));
}
}
/**
* Internal helper to. Send an property changed event to all connected
* listeners.
*
* @param b
*/
void sendDoorEvent(boolean b) {
try {
pce.PropertyChanged(DOOR_INTF_NAME, "IsOpen", new Variant(b));
} catch (BusException e) {
e.printStackTrace();
}
}
/**
* Closes the Door.
*/
public void close() {
if (isOpen) {
isOpen = false;
callbacks.notifyChange(this, BR.isOpen);
// Schedule a task to send out an event to all interested parties.
sendWorkerMessage(() -> sendDoorEvent(false));
}
}
@Override
public void knockAndRun() {
// Schedule a background task to to the knock and run behavior
sendWorkerMessage(() -> {
if (!isOpen) {
isOpen = true;
sendDoorEvent(true);
}
try {
Thread.sleep(250);
} catch (InterruptedException e) {
}
// Create a signal emitter and send out the personPassedTHrough
// signal
SignalEmitter se = new SignalEmitter(DoorService.this, 0,
GlobalBroadcast.Off);
se.setSessionlessFlag(true);
Door door = se.getInterface(Door.class);
if (door != null) {
try {
door.personPassedThrough();
} catch (BusException e) {
e.printStackTrace();
}
}
// Close the door and send an event
isOpen = false;
callbacks.notifyChange(DoorService.this, BR.isOpen);
sendDoorEvent(false);
// Invalidate the keyCode
try {
pce.PropertyChanged(DOOR_INTF_NAME, "KeyCode", new Variant(0));
} catch (BusException e) {
e.printStackTrace();
}
});
}
@Override
public void personPassedThrough() {
}
private void sendWorkerMessage(Runnable runnable) {
bus.executeRunnableTask(runnable);
}
/**
* Internal function to get the location of this door. No event is send to
UI.
*
* @return Location of the door.
*/
@Bindable
public String getInternalLocation() {
return location;
}
public void addOnPropertyChangedCallback(
OnPropertyChangedCallback callback) {
callbacks.add(callback);
}
@Override
public void removeOnPropertyChangedCallback(
OnPropertyChangedCallback callback) {
callbacks.remove(callback);
}
@Override public String getBusObjectLocation() {
return location;
}
}
Thanks for the help,
Sergey.
_______________________________________________
Allseen-core mailing list
[email protected]
https://lists.allseenalliance.org/mailman/listinfo/allseen-core