how to call 'ajn::SessionListener::SessionMemberAdded' ??

asked 2015-03-08 20:24:14 -0700

Lewis gravatar image

I override the method 'ajn::SessionListener::SessionMemberAdded' in Service implementation. when a client was added, i thought it'd be called automatically . But it's not true.Instead, NameOwnerChanged() was called.

so here's problem.I want SessionMemberAdded() to be called as soon as the client enters. How should i do that ? Please give me some advice.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-03-09 23:39:22 -0700

praveenb gravatar image

updated 2015-03-12 13:00:29 -0700

As can be seen from the C++ API documentation, ajn::SessionListener is a class implemented by AllJoyn applications and called by AllJoyn to inform applications of session-related events. Further, ajn::SessionListener::SessionMemberAdded is called by the bus to inform the application that a member has been added to multi-point session (a session with multiple participants).

Hence, here are the things to check:

  • Is/Are your app(s) doing the necessary things to host a session and join a session? The necessary things would be for one end to host a session via ajn::BusAttachment::BindSessionPort and another end to join the session via ajn::BusAttachment::JoinSession.
  • If hosting a session, have you ensured that you are hosting a session with multi-point option enabled? That means to call ajn::BusAttachment::BindSessionPort with ajn::SessionOpts where isMultiPoint is set to true.

ajn::BusListener::NameOwnerChanged is invoked when Apps (more precisely, names) come and go. This callback is independent of a session and can be invoked even if the application is not hosting / joining a session.

In theory, it is possible to communicate with another application without using a session. However, it is not recommended. A session provides contextual communication via SessionId. It is a lot easier to manage communication with sessions, than to do without them.

Needless to add, a callback can only be invoked by AllJoyn only when a Listener has been registered. In your case, SessionMemberAdded can only be inovked when a SessionListener is registered.

There are two ends for every session (whether point-to-point or multi-point). One end that is hosting the session (service in your case) and another that is joining the session (client in your case). One way the joining side registers a SessionListener is by passing the Listener as an argument to JoinSession API. The hosting side can register a SessionListener via SetSessionListener API.

Thus, if you want a callback on the service end, you should register a listener using SetSessionListener API. Please check if you are doing this or not. An example of using SetSessionListener API is can be found in allseen/core/alljoyn/alljoyn_core/test/bbservice.cc test application.

edit flag offensive delete publish link more


thank you for explain. Should the method ajn::SessionListener::SessionMemberRemoved or SessionMemberadded be called by client end or service end ? I thought it'd be called in service end, but it actually was called in client end. Seems no sense.Then how shoud i immediately know a client exited ?

Lewis ( 2015-03-10 01:10:24 -0700 )edit

I have updated the answer to address your question. See if that helps.

praveenb ( 2015-03-13 15:46:41 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-03-08 20:24:14 -0700

Seen: 130 times

Last updated: Mar 12 '15