0

how to create session without the well-know name to find the IntrospectWithDescription in the router with C language

asked 2015-12-31 08:28:27 -0700

yangjun9772 gravatar image

updated 2016-01-03 09:31:11 -0700

Hi All, The question is in the followed answer line.

edit retag flag offensive close merge delete

Comments

Kindly reformat your question and clearly state what you are looking for. It is very difficult to follow the question as it stands currently. If you have long pieces of code, provide a link to them. Use code snippets to illustrate a problem you are having with a portion of code (for eg. 100 lines).

praveenb ( 2016-01-02 20:00:28 -0700 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-01-02 20:14:44 -0700

praveenb gravatar image

Note: I was unable to follow the content of the question. The following is a response to the text of the question.

Session formation needn't be done using a well-known name. In fact, usage of well-known names is gradually being reduced. Using About (Announcements and Who-Implements queries) is a better/current way of discovering remote peers. About announcement contains the following two crucial pieces of information to establish a session with the remote peer:

  • Unique Name (well-known name is simply an human-readable alias for the unique name)
  • Session Port (at which the remote peer accepts JoinSession requests)

IntrospectWithDescription method call can be made once a session is formed.

Sample applications using About can be found here.

edit flag offensive delete publish link more

Comments

Praveenb, thank you for your answer. And I'm sorry that my description is not clear. Let me describe it again at the next answer.

yangjun9772 ( 2016-01-03 08:46:22 -0700 )edit
0

answered 2016-01-03 09:24:33 -0700

yangjun9772 gravatar image

updated 2016-01-09 08:17:01 -0700

praveenb gravatar image

Firstly, I used the Dashboard_android_APP and Event_Action_Browser_APP to debug my home appliance. And my home appliance could work well with them. The Dashboard could control my home appliance, and the events and actions could be shown in the Event_Action_APP. My home appliance used the control panel service and events and actions service.

Then I wrote my code in the rout to do the work like these APPs by C. But the result was failed. With my code, I found the about function could work well. But then I created the BUS session again, it was failed(create the session failed). the code like the attachment.

static const char* INTERFACE_NAME = "me.oldpig.about";

static const char* OBJECT_NAME = "org.alljoyn.About.sl";

static const char* OBJECT_PATH = "/oldpig/server/me.oldpig.about";

static const alljoyn_sessionport SERVICE_PORT = 900;

char testAbout[100]="AAAAAAAAAAAAAAAbout!!!";

static void alljoyn_init()
{

       ....

    /* Connect to the bus and create the About session, it is succesful */
    if (ER_OK == status) {
        status = alljoyn_busattachment_connect(g_msgBus, connectArgs);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_connect(\"%s\") failed\n", (connectArgs) ? connectArgs : "NULL");
        } else {
            printf("alljoyn_busattachment connected to \"%s\"\n", alljoyn_busattachment_getconnectspec(g_msgBus));
        }
    }

    aboutlistener_cb.about_listener_announced = alljoyn_about_announced;
    alljoyn_aboutlistener aboutListener=alljoyn_aboutlistener_create(&aboutlistener_cb,testAbout);
    alljoyn_busattachment_registeraboutlistener(g_msgBus,aboutListener);

    status = alljoyn_busattachment_whoimplements_interface(g_msgBus,"org.alljoyn.About");

    if (ER_OK == status) {
        printf("WhoImplements called.\n");
    } else {
        printf("WhoImplements call FAILED with status %s\n", QCC_StatusText(status));
    }

       /*  it is failed to create the session  */
    g_busListener = alljoyn_buslistener_create(&callbacks, NULL);

    /* Register a bus listener in order to get discovery indications */
    if (ER_OK == status) {
        alljoyn_busattachment_registerbuslistener(g_msgBus, g_busListener);
        printf("alljoyn_buslistener Registered.\n");
    }

    /* Begin discovery on the well-known name of the service to be called */
    if (ER_OK == status) {
        status = alljoyn_busattachment_findadvertisedname(g_msgBus, OBJECT_NAME);
        if (status != ER_OK) {
            printf("alljoyn_busattachment_findadvertisedname failed (%s))\n", QCC_StatusText(status));
        }
    }

    return;
}

the callback function:

/* FoundAdvertisedName callback */

static void AJ_CALL found_advertised_name(const void* context, const char* name, alljoyn_transportmask transport, const char* namePrefix)
{   

    if (0 == strncmp(name, OBJECT_NAME,strlen(OBJECT_NAME))) {

        if(s_joinStart)
            return 0;
        s_joinStart= 1;

        /* We found a remote bus that is advertising basic service's  well-known name so connect to it, the result is failed */
        alljoyn_sessionopts opts = alljoyn_sessionopts_create(ALLJOYN_TRAFFIC_TYPE_MESSAGES, QCC_TRUE, ALLJOYN_PROXIMITY_ANY, ALLJOYN_TRANSPORT_ANY);
        printf("(name=%s, prefix=%s)func=%s line=%d.\n",name, namePrefix,__FUNCTION__,__LINE__);
        QStatus status;
        /* enable concurrent callbacks so joinsession can be called */
        alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);
        status = alljoyn_busattachment_joinsession(g_msgBus, name, SERVICE_PORT, NULL, &s_sessionId, opts);
        printf("(name=%s, prefix=%s)func=%s line=%d.\n",name, namePrefix,__FUNCTION__,__LINE__);

        if (ER_OK != status) {
            printf("(name=%s, prefix=%s)alljoyn_busattachment_joinsession failed (status=%s)\n",name, namePrefix, QCC_StatusText(status));
        } else {
            printf("(name=%s, prefix=%s)alljoyn_busattachment_joinsession SUCCESS (Session id=%d)\n",name, namePrefix, s_sessionId);
            QStatus status = ER_OK;
            int i = 0;
            remoteObj = alljoyn_proxybusobject_create(g_msgBus, name, OBJECT_PATH, s_sessionId);
            const alljoyn_interfacedescription alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
            assert(alljoynTestIntf);
            alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);

            ////get dev id, dev name and so on by alljoyn_aboutdata_getannouncedaboutdata??
            pthread_t tid = -1;;
            if (pthread_create(&tid, NULL, micro_demo_fetch_devinfo, NULL) != 0){
                HWF_ERR("pthread create failed");
                return;
            }
            /*if (pthread_create(&tid, NULL, micro_demo_fetch_attr, NULL) != 0){
                HWF_ERR("pthread create failed");
                return;
                }
            */
            //add signal methods
            //status = alljoyn_busattachment_addmatch(g_msgBus, "type='signal',interface='me.oldpig.about',member='ToggledSignal'");
            status = alljoyn_busattachment_addmatch(g_msgBus, "type='signal',interface='me.oldpig.about ...
(more)
edit flag offensive delete publish link more

Comments

Can you please indicate the specific error that you receive when the JoinSession API is invoked? Do you have any ER_DEBUG logs and/or packet traces when this happens?

praveenb ( 2016-01-04 21:28:51 -0700 )edit

Hi praveenb, Thank you for your help. I'm sorry I didn't have the router source code and the Logs now. This project is belong to another guy. And we had been separated for each other. I can't debug it more. But I will continue to study AllJoyn more deeper. thanks for your help again.

yangjun9772 ( 2016-01-17 19:48:12 -0700 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2015-12-31 08:28:27 -0700

Seen: 203 times

Last updated: Jan 09 '16