为什么我需要在allJoyn中接收信号之前调用方法?

时间:2016-06-17 20:45:26

标签: java alljoyn

我正在尝试使用Java绑定在AllJoyn中实现信号处理程序。

我定义了一个BusInterface:

@BusInterface(name = "net.allplay.MediaPlayer")
public interface MediaPlayerInterface {

    @BusMethod(name = "GetPlaylist", replySignature = "a(ssssxsssa{ss}a{sv}v)ss")
    public Playlist getPlaylist() throws BusException;

    @BusProperty(name = "PlayState")
    public PlayState getPlayState() throws BusException;

    @BusSignal(name = "PlaylistChanged")
    public void onPlaylistChanged() throws BusException;

    @BusSignal(name = "PlayStateChanged")
    public void onPlayStateChanged(PlayState playState) throws BusException;

和另一个类(MediaPlayerSignalHandler)中的相应BusSignalHandler方法:

@BusSignalHandler(iface = "com.test.MediaPlayerInterface", signal = "onPlaylistChanged")
    public void onPlaylistChanged() {
        System.out.println("Play list changed");
    }

最后,我创建一个会话,获取ProxyBusObject和接口

sessionId = new Mutable.IntegerValue();
busAttachment.enableConcurrentCallbacks();
busAttachment.joinSession(busName, port, sessionId, createSessionOptions(), new SessionListener());
busAttachment.getProxyBusObject(busName, "/net/allplay/MediaPlayer", sessionId.value,
    new Class<?>[] { MediaPlayerInterface.class });
mediaPlayerInterface = allPlayObject.getInterface(MediaPlayerInterface.class);
busHandler.getBusAttachement().registerSignalHandlers(new MediaPlayerSignalHandler());

现在,即使远程设备改变其PlayState,也不会收到任何信号。 只有在远程设备上调用一次方法(例如mediaPlayerInterface.getPlaylist())后,才能正确接收所有信号。

我不认为allJoyn就是这样设计的,所以我想知道我在这里做错了什么。有什么想法吗?

0 个答案:

没有答案