4

I'm trying to use AllJoyn for my app, but when I'm trying to use code from sample (sample 13), I can't join to session and get error BUS_BLOCKING_CALL_NOT_ALLOWED.

    bus.registerBusListener(new BusListener() {
        @Override
        public void foundAdvertisedName(String name,
                                        short transport,
                                        String namePrefix) {
            short contactPort = CONTACT_PORT;
            SessionOpts sessionOpts = new SessionOpts();
            Mutable.IntegerValue sessionId = new Mutable.IntegerValue();

            Status status = bus.joinSession("com.my.well.known.name", //here's error: status = BUS_BLOCKING_CALL_NOT_ALLOWED 
                    contactPort,
                    sessionId,
                    sessionOpts,
                    new SessionListener());
            bus.cancelAdvertiseName("com.my.well.known.name",SessionOpts.TRANSPORT_ANY);
        }
    });

This code is from sample and I have no idea what's wrong with it. Can you help me?

If necessary, here's full code: http://pastebin.com/f1sD7RtK

I'm trying to create new channel and connect to it automatically, without user's participation.

Also I'll be very grateful for any good advices or samples.

Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
uncle Lem
  • 4,954
  • 8
  • 33
  • 53

1 Answers1

5

Try calling bus.enableConcurrentCallbacks() prior to calling bus.joinSession(...) in the foundAdvertisedName method.
This will allow AllJoyn to dispatch an additional callback while the current one, foundAdvertisedName, is still executing. Here's a link to the documentation that explains what is happening.

mdub85
  • 51
  • 1
  • Now i'm getting ALLJOYN_JOINSESSION_REPLY_ALREADY_JOINED – uncle Lem Nov 15 '12 at 08:52
  • 2
    It looks like you are registering a BusListener twice, once on line 13, and again on line 83 in your full code posting. As a result, the foundAdvertisedName callback is getting triggered twice, with the second time resulting in the ALLJOYN_JOINSESSION_REPLY_ALREADY_JOINED, because you already joined the session the first time. Removing the second bus listener should fix the issue. – mdub85 Nov 15 '12 at 20:23