コード例 #1
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL session_joined(const void* context, alljoyn_sessionport sessionPort, alljoyn_sessionid sessionId, const char* joiner)
{
    uint32_t timeout = 10;
    QStatus status = ER_OK;

    printf("Session Established: joiner=%s, sessionId=%08x\n", joiner, sessionId);

    /* Enable concurrent callbacks since some of the calls below could block */
    alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);

    status = alljoyn_busattachment_setsessionlistener(g_msgBus, sessionId, g_sessionListener);
    if (status != ER_OK) {
        printf("SetSessionListener failed with %s \n", QCC_StatusText(status));
        return;
    }

    /* Set the link timeout */
    status = alljoyn_busattachment_setlinktimeout(g_msgBus, sessionId, &timeout);
    if (status == ER_OK) {
        printf("Link timeout was successfully set to %d\n", timeout);
    } else {
        printf("SetLinkTimeout failed with %s \n", QCC_StatusText(status));
    }

    /* cancel advertisment */
    if (g_cancelAdvertise) {
        alljoyn_busattachment_canceladvertisename(g_msgBus, g_wellKnownName, alljoyn_sessionopts_get_transports(g_sessionOpts));
        if (status != ER_OK) {
            printf("CancelAdvertiseName(%s) failed with %s", g_wellKnownName, QCC_StatusText(status));
        }
    }
}
コード例 #2
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL ping(alljoyn_busobject busobject, const alljoyn_interfacedescription_member* member, alljoyn_message msg)
{

    QStatus status = ER_OK;
    char*value = NULL;
    alljoyn_msgarg outArg;

    status = alljoyn_msgarg_get(alljoyn_message_getarg(msg, 0), "s", &value);
    if (ER_OK != status) {
        printf("Ping: Error reading alljoyn_message %s\n", QCC_StatusText(status));
    } else {
        printf("Pinged with: %s\n", value);
    }

    if (alljoyn_message_isencrypted(msg) == QCC_TRUE) {
        printf("Authenticated using %s\n", alljoyn_message_getauthmechanism(msg));
    }

    outArg = alljoyn_msgarg_create_and_set("s", value);
    status = alljoyn_busobject_methodreply_args(busobject, msg, outArg, 1);
    if (ER_OK != status) {
        printf("Ping: Error sending reply %s\n", QCC_StatusText(status));
    }
    /* Destroy the msgarg */
    alljoyn_msgarg_destroy(outArg);
}
コード例 #3
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
/* ObjectRegistered callback */
void AJ_CALL busobject_object_registered(const void* context)
{
    QStatus status = ER_OK;

    /* Enable concurrent callbacks since some of the calls below could block */
    alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);

    status = alljoyn_busattachment_bindsessionport(g_msgBus, &SESSION_PORT, g_sessionOpts, g_sessionPortListener);
    if (status != ER_OK) {
        printf("BindSessionPort failed with %s. \n", QCC_StatusText(status));
    }
    /* Add rule for receiving test signals */
    status = alljoyn_busattachment_addmatch(g_msgBus, "type='signal',interface='org.alljoyn.alljoyn_test',member='my_signal'");
    if (status != ER_OK) {
        printf("Failed to register Match rule for 'org.alljoyn.alljoyn_test.my_signal' with error %s. \n", QCC_StatusText(status));
    }

    /* Request a well-known name */
    status = alljoyn_busattachment_requestname(g_msgBus, g_wellKnownName, DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE);
    if (status != ER_OK) {
        printf("RequestName(%s) failed with %s", g_wellKnownName, QCC_StatusText(status));
        return;
    }

    /* Begin Advertising the well-known name */
    /* transport mask change as per user input. */
    status = alljoyn_busattachment_advertisename(g_msgBus, g_wellKnownName, alljoyn_sessionopts_get_transports(g_sessionOpts));
    if (ER_OK != status) {
        printf("Advertise(%s) failed with %s", g_wellKnownName, QCC_StatusText(status));
        return;
    }

}
コード例 #4
0
/* FoundAdvertisedName callback */
void AJ_CALL found_advertised_name(const void* context, const char* name, alljoyn_transportmask transport, const char* namePrefix)
{
    QCC_UNUSED(context);
    printf("found_advertised_name(name=%s, prefix=%s, transport=0x%x)\n", name, namePrefix, (unsigned int)transport);

    /*
     * The access to global variable s_joinInitiated is serialized across multiple found_advertised_name callbacks
     * by accessing it only before calling alljoyn_busattachment_enableconcurrentcallbacks.
     */
    if ((QCC_FALSE == s_joinInitiated) && (0 == strcmp(name, OBJECT_NAME))) {
        /* We found a remote bus that is advertising basic service's well-known name, so connect to it */
        alljoyn_sessionopts opts = alljoyn_sessionopts_create(ALLJOYN_TRAFFIC_TYPE_MESSAGES, QCC_FALSE, ALLJOYN_PROXIMITY_ANY, ALLJOYN_TRANSPORT_ANY);

        if (NULL != opts) {
            QStatus status;
            s_joinInitiated = QCC_TRUE;

            /* alljoyn_busattachment_joinsession might block for a while, so allow other callbacks to run in parallel with it */
            alljoyn_busattachment_enableconcurrentcallbacks(s_msgBus);
            status = alljoyn_busattachment_joinsession(s_msgBus, name, SERVICE_PORT, NULL, &s_sessionId, opts);

            if (ER_OK != status) {
                printf("alljoyn_busattachment_joinsession failed (status=%s)\n", QCC_StatusText(status));
            } else {
                printf("alljoyn_busattachment_joinsession SUCCESS (Session id=%u)\n", (unsigned int)s_sessionId);
            }

            alljoyn_sessionopts_destroy(opts);
            s_joinComplete = QCC_TRUE;
        }
    }
}
コード例 #5
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL delayed_ping(alljoyn_busobject busobject, const alljoyn_interfacedescription_member* member, alljoyn_message msg)
{
    QStatus status = ER_OK;
    char*value = NULL;
    alljoyn_msgarg outArg;
    uint32_t delay = 0;

    /* Enable concurrent callbacks since some of the calls below could block */
    alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);

    status = alljoyn_msgarg_get(alljoyn_message_getarg(msg, 0), "s", &value);
    status = alljoyn_msgarg_get(alljoyn_message_getarg(msg, 1), "u", &delay);

    printf("Pinged (response delayed %ums) with: \"%s\"\n", delay, value);

    if (alljoyn_message_isencrypted(msg) == QCC_TRUE) {
        printf("Authenticated using %s\n", alljoyn_message_getauthmechanism(msg));
    }
#ifdef _WIN32
    Sleep(delay);
#else
    usleep(100 * delay);
#endif

    outArg = alljoyn_msgarg_create_and_set("s", value);
    status = alljoyn_busobject_methodreply_args(busobject, msg, outArg, 1);
    if (ER_OK != status) {
        printf("DelayedPing: Error sending reply %s\n", QCC_StatusText(status));
    }
    /* Destroy the msgarg */
    alljoyn_msgarg_destroy(outArg);
}
コード例 #6
0
void AllJoynConnection::startMessageBus()
{
    NotifyUser(MSG_STATUS, "Start the message bus.");
    /* Start the msg bus */
    if (ER_OK == status) {
        status = this->busAttachment->Start();
        if (ER_OK != status) {
            NotifyUser(MSG_ERROR, "BusAttachment::Start failed (%s)\n", QCC_StatusText(status));
        }
    }
    /* Register a bus listener */
    if (ER_OK == status) {
        // make sure the callback has been set
        this->busAttachment->RegisterBusListener(*(this->busListener));
    }
    NotifyUser(MSG_STATUS, "Registered BusListener");

    /* Get env vars */
    const char* connectSpec = getenv("BUS_ADDRESS");
    if (connectSpec == NULL) {
        connectSpec = "tcp:addr=127.0.0.1,port=9956";
        NotifyUser(MSG_STATUS, "Connect spec defaulted to %s", connectSpec);
    } else
        NotifyUser(MSG_STATUS, "Got environment BUS_ADDRESS %s", connectSpec);

    /* Connect to the local daemon */
    NotifyUser(MSG_STATUS, "Connect to the local daemon.");
    if (ER_OK == status) {
        status = this->busAttachment->Connect(connectSpec);
    }
    if (ER_OK != status) {
        NotifyUser(MSG_ERROR, "BusAttachment::Connect(%s) failed (%s)\n", connectSpec, QCC_StatusText(status));
    }
}
コード例 #7
0
void ConnectionListener::FoundAdvertisedName(const char* name, TransportMask transport, const char* namePrefix)
{

		printf("FoundAdvertisedName(name='%s', transport = 0x%x, prefix='%s')\n", name, transport, namePrefix);

		const char* convName = name + strlen(mPrefix.c_str());
		printf("Discovered chat conversation: \"%s\"\n", convName);

		/* Join the conversation */
		/* Since we are in a callback we must enable concurrent callbacks before calling a synchronous method. */
		mBus->EnableConcurrentCallbacks();
		SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, true, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
		QStatus status = mBus->JoinSession(name, mPort, this, *(mSessionUser->getSessionId()), opts);
		if (ER_OK == status) {
			printf("Joined conversation \"%s\"\n", convName);
			mSessionUser->setJoined(true);

		}
		else {
			printf("JoinSession failed (status=%s)\n", QCC_StatusText(status));
		}
		if (!mSessionUser->isJoined())
		{
		uint32_t timeout = 20;
		status = mBus->SetLinkTimeout(*(mSessionUser->getSessionId()), timeout);
		if (ER_OK == status) {
			printf("Set link timeout to %d\n", timeout);
		}
		else {
			printf("Set link timeout failed\n");
		}
	}
}
コード例 #8
0
void AllJoynConnection::bindSessionPort(SessionOpts& opts)
{
    /* Bind the session port*/
    NotifyUser(MSG_STATUS, "Bind session port.");
    if (ER_OK == status) {
        SessionPort sp = PHOTOCHAT_PORT;
        status = this->busAttachment->BindSessionPort(sp, opts, *(this->busListener));
        if (ER_OK != status) {
            NotifyUser(MSG_ERROR, "BindSessionPort failed (%s)\n", QCC_StatusText(status));
        }
    }
}
コード例 #9
0
//----------------------------------------------------------------------------------------
// AllJoynBusListener (BusListener, SessionPortListener, SessionListener )
//----------------------------------------------------------------------------------------
void AllJoynBusListener::FoundAdvertisedName(const char* name, TransportMask transport, const char* namePrefix)
{
    if (!connection->joinName.empty() && 0 == connection->sessionId) {
        const char* convName = name + strlen(NAME_PREFIX);
        SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, true, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
        QStatus status = connection->busAttachment->JoinSession(name, PHOTOCHAT_PORT, this, connection->sessionId, opts);
        if (ER_OK == status) {
            NotifyUser(MSG_STATUS, "Joined conversation \"%s\"\n", convName);
        } else {
            NotifyUser(MSG_ERROR, "JoinSession failed (status=%s)\n", QCC_StatusText(status));
        }
    }
    connection->joinComplete = true;
}
コード例 #10
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL time_ping(alljoyn_busobject busobject, const alljoyn_interfacedescription_member* member, alljoyn_message msg)
{
    QStatus status = ER_OK;
    size_t numArgs = 0;
    alljoyn_msgarg args[2];

    /* Reply with same data that was sent to us */
    alljoyn_message_getargs(msg, &numArgs, args);

    status = alljoyn_busobject_methodreply_args(busobject, msg, *args, numArgs);
    if (ER_OK != status) {
        printf("TimePing: Error sending reply %s\n", QCC_StatusText(status));
    }
}
コード例 #11
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL session_lost(const void* context, alljoyn_sessionid sessionId, alljoyn_sessionlostreason reason) {

    QStatus status = ER_OK;
    printf("SessionLost(%08x) was called\n", sessionId);

    /* Enable concurrent callbacks since some of the calls below could block */
    alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);

    /* cancel advertisment */
    if (g_cancelAdvertise) {
        alljoyn_busattachment_canceladvertisename(g_msgBus, g_wellKnownName, alljoyn_sessionopts_get_transports(g_sessionOpts));
        if (status != ER_OK) {
            printf("CancelAdvertiseName(%s) failed with %s", g_wellKnownName, QCC_StatusText(status));
        }
    }
}
コード例 #12
0
ファイル: basic_c_client.c プロジェクト: eekshs16/SIoT
/* FoundAdvertisedName callback */
void AJ_CALL found_advertised_name(const void* context, const char* name, alljoyn_transportmask transport, const char* namePrefix)
{
    printf("[Callback] found_advertised_name(name=%s, prefix=%s)\n", name, namePrefix);
    if (0 == strcmp(name, OBJECT_NAME)) {
        /* We found a remote bus that is advertising basic service's  well-known name so connect to it */
        alljoyn_sessionopts opts = alljoyn_sessionopts_create(ALLJOYN_TRAFFIC_TYPE_MESSAGES, QCC_FALSE, ALLJOYN_PROXIMITY_ANY, ALLJOYN_TRANSPORT_ANY);
        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);

        if (ER_OK != status) {
            printf("alljoyn_busattachment_joinsession failed (status=%s)\n", QCC_StatusText(status));
        } else {
            printf("alljoyn_busattachment_joinsession SUCCESS (Session id=%d)\n", s_sessionId);
        }
        alljoyn_sessionopts_destroy(opts);
    }
    s_joinComplete = QCC_TRUE;
}
コード例 #13
0
QStatus NativeAboutObject::GetAboutData(
    /* [in] */ ajn::MsgArg* msgArg,
    /* [in] */ const char* language)
{
    QStatus status = ER_FAIL;
    if (mAboutDataListenerRef != NULL) {
        AutoPtr<IMap> announceArg;
        ECode ec = mAboutDataListenerRef->GetAboutData(String(language), (IMap**)&announceArg);
        // check for ErrorReplyBusException exception
        status = CheckForThrownException(ec);
        if (ER_OK == status) {
            // Marshal the returned value
            if (Marshal("a{sv}", announceArg.Get(), msgArg) == NULL) {
                Logger::E("NativeAboutObject", "GetMsgArgAnnounce() marshaling error");
                return ER_FAIL;
            }
        }
        else {
            Logger::E("NativeAboutObject", "GetMsgArg exception with status %s", QCC_StatusText(status));
            return status;
        }
    }
    return ER_OK;
}
コード例 #14
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
void AJ_CALL security_violation(const void*context, QStatus status, const alljoyn_message msg) {
    printf("Security violation %s\n", QCC_StatusText(status));
}
コード例 #15
0
bool ChatObject::CreateInterfaces()
{
    const char* ifName = CHAT_SERVICE_INTERFACE_NAME;
    InterfaceDescription* chatIntf = NULL;

    status = ajConnection->busAttachment->CreateInterface(ifName, chatIntf);
    assert(chatIntf);
    if (ER_OK == status) {
        chatIntf->AddSignal("Chat", "s",  "str", 0);
        chatIntf->Activate();
    } else {
        NotifyUser(MSG_ERROR, "Failed to create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
        return false;
    }
    NotifyUser(MSG_SYSTEM, "Create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
    return true;
}
コード例 #16
0
static void close_door(alljoyn_busattachment bus, alljoyn_observer observer, const char* location)
{
    alljoyn_proxybusobject_ref proxyref = get_door_at_location(bus, observer, location);

    if (proxyref) {
        alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);
        alljoyn_message reply = alljoyn_message_create(bus);
        QStatus status = alljoyn_proxybusobject_methodcall(proxy, INTF_NAME, "Close", NULL, 0, reply, MAX_WAIT_MS, 0);

        if (ER_OK == status) {
            /* No error */
            printf("Closing of door succeeded\n");
        } else if (ER_BUS_REPLY_IS_ERROR_MESSAGE == status) {
            /* MethodReply Error received (an error string) */
            char errmsg[200] = { 0 };
            size_t size = sizeof(errmsg);
            const char* errname = alljoyn_message_geterrorname(reply, errmsg, &size);
            printf("Closing of door @ location %s returned an error: %s (%s).\n", location, (errname != NULL) ? errname : "<null>", errmsg);
        } else {
            /* Framework error or MethodReply error code */
            printf("Closing of door @ location %s returned an error: %s.\n", location, QCC_StatusText(status));
        }

        alljoyn_message_destroy(reply);
        alljoyn_proxybusobject_ref_decref(proxyref);
    }
}
コード例 #17
0
/** the PersonPassedThrough signal handler */
static void AJ_CALL person_passed_through(const alljoyn_interfacedescription_member* member, const char* path, alljoyn_message message)
{
    struct _listener_ctx* ctx = &listener_ctx; //alljoyn_c caveat: no way to pass a cookie into signal handlers.
    alljoyn_proxybusobject_ref proxyref = alljoyn_observer_get(ctx->observer, alljoyn_message_getsender(message), path);
    QCC_UNUSED(member);
    if (proxyref) {
        QStatus status;
        char* location = NULL;
        const char* who = NULL;
        alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);

        alljoyn_busattachment_enableconcurrentcallbacks(ctx->bus);

        status = proxy_get_location(proxy, &location);
        if (status == ER_OK) {
            status = alljoyn_message_parseargs(message, "s", &who);
        }
        if (status == ER_OK) {
            printf("[listener] %s passed through the door at location %s\n", who, (location != NULL) ? location : "<unknown>");
        } else {
            fprintf(stderr, "Something went wrong while parsing the received signal: %s\n", QCC_StatusText(status));
        }
        if (location) {
            free(location);
        }

        alljoyn_proxybusobject_ref_decref(proxyref);
    } else {
        fprintf(stderr, "Got PersonPassedThrough signal from an unknown door: %s:%s\n", alljoyn_message_getsender(message), path);
    }

    printf("> "); fflush(stdout);
}
コード例 #18
0
/** Main entry point */
int CDECL_CALL main(void)
{
    QStatus status = ER_OK;
    char* connectArgs = "unix:abstract=alljoyn";
    alljoyn_interfacedescription testIntf = NULL;
    alljoyn_busobject_callbacks busObjCbs = {
        NULL,
        NULL,
        &busobject_object_registered,
        NULL
    };
    alljoyn_busobject testObj = NULL;
    alljoyn_interfacedescription exampleIntf;
    alljoyn_interfacedescription_member cat_member;
    QCC_BOOL foundMember = QCC_FALSE;
    alljoyn_busobject_methodentry methodEntries[] = {
        { &cat_member, cat_method },
    };
    alljoyn_sessionportlistener_callbacks spl_cbs = {
        accept_session_joiner,
        NULL
    };
    alljoyn_sessionopts opts = NULL;

    if (alljoyn_init() != ER_OK) {
        return 1;
    }
#ifdef ROUTER
    if (alljoyn_routerinit() != ER_OK) {
        alljoyn_shutdown();
        return 1;
    }
#endif

    printf("AllJoyn Library version: %s\n", alljoyn_getversion());
    printf("AllJoyn Library build info: %s\n", alljoyn_getbuildinfo());

    /* Install SIGINT handler */
    signal(SIGINT, SigIntHandler);

    /* Create message bus */
    g_msgBus = alljoyn_busattachment_create("myApp", QCC_TRUE);

    if (g_msgBus != NULL) {
        /* Add org.alljoyn.Bus.method_sample interface */
        status = alljoyn_busattachment_createinterface(g_msgBus, INTERFACE_NAME, &testIntf);
        if (status == ER_OK) {
            alljoyn_interfacedescription_addmember(testIntf, ALLJOYN_MESSAGE_METHOD_CALL, "cat", "ss",  "s", "inStr1,inStr2,outStr", 0);
            alljoyn_interfacedescription_activate(testIntf);
            printf("Interface Created.\n");
        } else {
            printf("Failed to create interface 'org.alljoyn.Bus.method_sample'\n");
        }

        /* Register a bus listener */
        if (ER_OK == status) {
            /* Create a bus listener */
            alljoyn_buslistener_callbacks callbacks = {
                NULL,
                NULL,
                NULL,
                NULL,
                &name_owner_changed,
                NULL,
                NULL,
                NULL
            };
            g_busListener = alljoyn_buslistener_create(&callbacks, NULL);
            alljoyn_busattachment_registerbuslistener(g_msgBus, g_busListener);
        }

        /* Set up bus object */
        testObj = alljoyn_busobject_create(OBJECT_PATH, QCC_FALSE, &busObjCbs, NULL);
        exampleIntf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
        assert(exampleIntf);
        alljoyn_busobject_addinterface(testObj, exampleIntf);

        foundMember = alljoyn_interfacedescription_getmember(exampleIntf, "cat", &cat_member);
        assert(foundMember == QCC_TRUE);
        if (!foundMember) {
            printf("Failed to get cat member of interface\n");
        }

        status = alljoyn_busobject_addmethodhandlers(testObj, methodEntries, sizeof(methodEntries) / sizeof(methodEntries[0]));
        if (ER_OK != status) {
            printf("Failed to register method handlers for BasicSampleObject\n");
        }

        /* Start the msg bus */
        status = alljoyn_busattachment_start(g_msgBus);
        if (ER_OK == status) {
            printf("alljoyn_busattachment started.\n");
            /* Register  local objects and connect to the daemon */
            status = alljoyn_busattachment_registerbusobject(g_msgBus, testObj);

            /* Create the client-side endpoint */
            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));
                }
            }
        } else {
            printf("alljoyn_busattachment_start failed\n");
        }

        /*
         * Advertise this service on the bus
         * There are three steps to advertising this service on the bus
         * 1) Request a well-known name that will be used by the client to discover
         *    this service
         * 2) Create a session
         * 3) Advertise the well-known name
         */
        /* Request name */
        if (ER_OK == status) {
            uint32_t flags = DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE;
            QStatus status = alljoyn_busattachment_requestname(g_msgBus, OBJECT_NAME, flags);
            if (ER_OK != status) {
                printf("alljoyn_busattachment_requestname(%s) failed (status=%s)\n", OBJECT_NAME, QCC_StatusText(status));
            }
        }

        /* Create session port listener */
        s_sessionPortListener = alljoyn_sessionportlistener_create(&spl_cbs, NULL);

        /* Create session */
        opts = alljoyn_sessionopts_create(ALLJOYN_TRAFFIC_TYPE_MESSAGES, QCC_FALSE, ALLJOYN_PROXIMITY_ANY, ALLJOYN_TRANSPORT_ANY);
        if (ER_OK == status) {
            alljoyn_sessionport sp = SERVICE_PORT;
            status = alljoyn_busattachment_bindsessionport(g_msgBus, &sp, opts, s_sessionPortListener);
            if (ER_OK != status) {
                printf("alljoyn_busattachment_bindsessionport failed (%s)\n", QCC_StatusText(status));
            }
        }

        /* Advertise name */
        if (ER_OK == status) {
            status = alljoyn_busattachment_advertisename(g_msgBus, OBJECT_NAME, alljoyn_sessionopts_get_transports(opts));
            if (status != ER_OK) {
                printf("Failed to advertise name %s (%s)\n", OBJECT_NAME, QCC_StatusText(status));
            }
        }

        if (ER_OK == status) {
            while (g_interrupt == QCC_FALSE) {
    #ifdef _WIN32
                Sleep(100);
    #else
                usleep(100 * 1000);
    #endif
            }
        }
    }
    /* Deallocate sessionopts */
    if (opts) {
        alljoyn_sessionopts_destroy(opts);
    }
    /* Deallocate bus */
    if (g_msgBus) {
        alljoyn_busattachment deleteMe = g_msgBus;
        g_msgBus = NULL;
        alljoyn_busattachment_destroy(deleteMe);
    }

    /* Deallocate bus listener */
    if (g_busListener) {
        alljoyn_buslistener_destroy(g_busListener);
    }

    /* Deallocate session port listener */
    if (s_sessionPortListener) {
        alljoyn_sessionportlistener_destroy(s_sessionPortListener);
    }

    /* Deallocate the bus object */
    if (testObj) {
        alljoyn_busobject_destroy(testObj);
    }

#ifdef ROUTER
    alljoyn_routershutdown();
#endif
    alljoyn_shutdown();
    return (int) status;
}
コード例 #19
0
void ChatConnection::createMessageBus()
{
    QStatus status = ER_OK;
    NotifyUser(MSG_STATUS, "Create message bus.");
    ajn::BusAttachment* bus = new BusAttachment("chat", true);
    this->busAttachment = bus;
    this->busListener = new MyBusListener();
    this->busListener->SetListenCallback(JoinNotifier);
    this->busListener->SetConnection(this);
    /* Create org.alljoyn.bus.samples.chat interface */
    InterfaceDescription* chatIntf;
    status = bus->CreateInterface(CHAT_SERVICE_INTERFACE_NAME, chatIntf);
    if (ER_OK == status) {
        chatIntf->AddSignal("Chat", "s",  "str", 0);
        chatIntf->Activate();
    } else {
        NotifyUser(MSG_ERROR, "Failed to create interface \"%s\" (%s)\n", CHAT_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
    }
    /* Create and register the bus object that will be used to send and receive signals */
    ChatObject* chatObject = new ChatObject(*bus, CHAT_SERVICE_OBJECT_PATH);
    this->chatObject = chatObject;
    this->busAttachment->RegisterBusObject(*chatObject);
    chatObject->SetConnection(this);
}
コード例 #20
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
/* Signal handler. */
void AJ_CALL signal_handler(const alljoyn_interfacedescription_member* member, const char* srcPath, alljoyn_message msg)
{
    static uint32_t rxCounts = 0;
    QStatus status = ER_OK;

    /* Enable concurrent callbacks since some of the calls below could block */
    alljoyn_busattachment_enableconcurrentcallbacks(g_msgBus);

    if ((++rxCounts % g_reportInterval) == 0) {
        printf("RxSignal: %s - %u\n", srcPath, rxCounts);

        if (alljoyn_message_isencrypted(msg) == QCC_TRUE) {
            printf("Authenticated using %s\n", alljoyn_message_getauthmechanism(msg));
        }
    }

    if (g_echo_signal) {
        alljoyn_msgarg arg;
        uint8_t flags = 0;
        alljoyn_interfacedescription intf = NULL;
        alljoyn_interfacedescription_member my_signal_member;
        QCC_BOOL foundMember = QCC_FALSE;

        arg = alljoyn_msgarg_create_and_set("a{ys}", 0);

        if (g_compress) {
            flags |= ALLJOYN_MESSAGE_FLAG_COMPRESSED;
        }

        intf = alljoyn_busattachment_getinterface(g_msgBus, alljoyn_message_getinterface(msg));
        if (intf != NULL) {
            foundMember = alljoyn_interfacedescription_getmember(intf, "my_signal", &my_signal_member);
        }

        if (foundMember) {
            status = alljoyn_busobject_signal(g_testObj, alljoyn_message_getsender(msg), alljoyn_message_getsessionid(msg), my_signal_member, arg, 1, 0, 0, msg);
            if (status != ER_OK) {
                printf("Failed to send Signal because of %s. \n", QCC_StatusText(status));
            }
        } else {
            printf("Not able to send signal as could not find signal member. \n");
        }

        /* Destroy the msgarg */
        alljoyn_msgarg_destroy(arg);
    }

    /* ping back means make a method call when you receive a signal. */
    if (g_ping_back) {

        alljoyn_msgarg arg;
        alljoyn_interfacedescription intf = NULL;
        alljoyn_interfacedescription_member my_ping_member;
        QCC_BOOL foundMember = QCC_FALSE;

        arg = alljoyn_msgarg_create_and_set("s", "Ping back");

        intf = alljoyn_busattachment_getinterface(g_msgBus, alljoyn_message_getinterface(msg));
        if (intf != NULL) {
            foundMember = alljoyn_interfacedescription_getmember(intf, "my_ping", &my_ping_member);
            if (foundMember) {

                alljoyn_message reply = NULL;
                alljoyn_proxybusobject remoteObj = NULL;

                reply = alljoyn_message_create(g_msgBus);

                remoteObj = alljoyn_proxybusobject_create(g_msgBus, alljoyn_message_getsender(msg), OBJECT_PATH, alljoyn_message_getsessionid(msg));
                alljoyn_proxybusobject_addinterface(remoteObj, intf);
                /*
                 * Make a fire-and-forget method call. If the signal was encrypted encrypt the ping
                 */
                status = alljoyn_proxybusobject_methodcall(remoteObj, INTERFACE_NAME, "my_ping", arg, 1, reply, 5000, alljoyn_message_isencrypted(msg) ? ALLJOYN_MESSAGE_FLAG_ENCRYPTED : 0);
                if (status != ER_OK) {
                    printf("MethodCall on %s.%s failed due to %s. \n", INTERFACE_NAME, "my_ping", QCC_StatusText(status));
                }

                /* Destroy the message reply. */
                alljoyn_message_destroy(reply);
                /* Destroy the proxy bus object. */
                alljoyn_proxybusobject_destroy(remoteObj);
            }
        }
        /* Destroy the msgarg */
        alljoyn_msgarg_destroy(arg);
    }
}
コード例 #21
0
void ChatConnection::Connect()
{
    QStatus status = ER_OK;
    assert(invariants());
    createMessageBus();
    NotifyUser(MSG_STATUS, "Start the message bus.");
    /* Start the msg bus */
    if (ER_OK == status) {
        status = this->busAttachment->Start();
        if (ER_OK != status) {
            NotifyUser(MSG_ERROR, "BusAttachment::Start failed (%s)\n", QCC_StatusText(status));
        }
    }
    /* Register a bus listener */
    if (ER_OK == status) {
        // make sure the callback has been set
        this->busAttachment->RegisterBusListener(*(this->busListener));
    }
    NotifyUser(MSG_STATUS, "Registered BusListener");

    /* Connect to the local daemon */
    NotifyUser(MSG_STATUS, "Connect to the local daemon.");
    if (ER_OK == status) {
        status = this->busAttachment->Connect();
    }
    if (ER_OK != status) {
        NotifyUser(MSG_ERROR, "BusAttachment::Connect(%s) failed (%s)\n", this->busAttachment->GetConnectSpec().c_str(), QCC_StatusText(status));
    }
    if (!this->advertisedName.empty()) {
        NotifyUser(MSG_STATUS, "Request name");
        status = this->busAttachment->RequestName(this->advertisedName.c_str(), DBUS_NAME_FLAG_DO_NOT_QUEUE);
        if (ER_OK != status) {
            NotifyUser(MSG_ERROR, "RequestName(%s) failed (status=%s)\n", this->advertisedName.c_str(), QCC_StatusText(status));
            status = (status == ER_OK) ? ER_FAIL : status;
        }
        /* Bind the session port*/
        NotifyUser(MSG_STATUS, "Bind session port.");
        SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, true, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
        if (ER_OK == status) {
            SessionPort sp = CHAT_PORT;
            status = this->busAttachment->BindSessionPort(sp, opts, *(this->busListener));
            if (ER_OK != status) {
                NotifyUser(MSG_ERROR, "BindSessionPort failed (%s)\n", QCC_StatusText(status));
            }
        }

        /* Advertise same well-known name */
        if (ER_OK == status) {
            status = this->busAttachment->AdvertiseName(this->advertisedName.c_str(), opts.transports);
            if (status != ER_OK) {
                NotifyUser(MSG_ERROR, "Failed to advertise name %s (%s)\n", this->advertisedName.c_str(), QCC_StatusText(status));
            }
        }
    } else {
        /* Discover name */
        status = this->busAttachment->FindAdvertisedName(this->joinName.c_str());
        if (status != ER_OK) {
            NotifyUser(MSG_ERROR, "org.alljoyn.Bus.FindAdvertisedName failed (%s)\n", QCC_StatusText(status));
        }
        NotifyUser(MSG_STATUS, "Found Advertised Name \n");
    }
    NotifyUser(MSG_STATUS, "Ready...");
}
コード例 #22
0
/** Main entry point */
int CDECL_CALL main(void)
{
    QStatus status = ER_OK;
    alljoyn_interfacedescription testIntf = NULL;
    alljoyn_buslistener_callbacks callbacks = {
        NULL,
        NULL,
        &found_advertised_name,
        NULL,
        &name_owner_changed,
        NULL,
        NULL,
        NULL
    };
    unsigned int count = 0;

    if (alljoyn_init() != ER_OK) {
        return 1;
    }
#ifdef ROUTER
    if (alljoyn_routerinit() != ER_OK) {
        alljoyn_shutdown();
        return 1;
    }
#endif

    printf("AllJoyn Library version: %s\n", alljoyn_getversion());
    printf("AllJoyn Library build info: %s\n", alljoyn_getbuildinfo());

    /* Install SIGINT handler */
    signal(SIGINT, SigIntHandler);

    /* Create message bus */
    g_msgBus = alljoyn_busattachment_create("SRPSecurityClientC", QCC_TRUE);

    /* Add org.alljoyn.bus.samples.secure.SecureInterface interface */
    status = alljoyn_busattachment_createinterface_secure(g_msgBus, INTERFACE_NAME, &testIntf, AJ_IFC_SECURITY_REQUIRED);
    if (status == ER_OK) {
        alljoyn_interfacedescription_addmember(testIntf, ALLJOYN_MESSAGE_METHOD_CALL, "Ping", "s",  "s", "inStr1,outStr", 0);
        alljoyn_interfacedescription_activate(testIntf);
    } else {
        printf("Failed to create interface %s\n", INTERFACE_NAME);
    }

    /* Start the msg bus */
    if (ER_OK == status) {
        status = alljoyn_busattachment_start(g_msgBus);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_start failed\n");
        } else {
            printf("alljoyn_busattachment started.\n");
        }
    }

    /*
     * enable security
     * note the location of the keystore file has been specified and the
     * isShared parameter is being set to true. So this keystore file can
     * be used by multiple applications
     */
    if (ER_OK == status) {
        alljoyn_authlistener_callbacks callbacks = {
            request_credentials,
            NULL,
            NULL,
            authentication_complete
        };
        g_authListener = alljoyn_authlistener_create(&callbacks, NULL);

        /*
         * alljoyn_busattachment_enablepeersecurity function is called by
         * applications that want to use authentication and encryption. This
         * function call must be made after alljoyn_busattachment_start and
         * before calling alljoyn_busattachment_connect.
         *
         * In most situations a per-application keystore file is generated.
         * However, this code specifies the location of the keystore file and
         * the isShared parameter is being set to QCC_TRUE. The resulting
         * keystore file can be used by multiple applications.
         */
        status = alljoyn_busattachment_enablepeersecurity(g_msgBus, "ALLJOYN_SRP_KEYX", g_authListener,
                                                          "/.alljoyn_keystore/central.ks", QCC_TRUE);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_enablepeersecurity failed (%s)\n", QCC_StatusText(status));
        } else {
            printf("alljoyn_busattachment_enablepeersecurity Successful\n");
        }
    }

    /* Connect to the bus */
    if (ER_OK == status) {
        status = alljoyn_busattachment_connect(g_msgBus, NULL);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_connect() failed with status: 0x%04x\n", status);
        } else {
            printf("alljoyn_busattachment connected to \"%s\"\n", alljoyn_busattachment_getconnectspec(g_msgBus));
        }
    }

    /* Create a bus listener */
    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));
        }
    }

    /* Wait for join session to complete */
    while (!s_joinComplete && !g_interrupt) {
        if (0 == (count++ % 10)) {
            printf("Waited %u seconds for alljoyn_busattachment_joinsession completion.\n", count / 10);
        }
#ifdef _WIN32
        Sleep(100);
#else
        usleep(100 * 1000);
#endif
    }

    if (status == ER_OK && g_interrupt == QCC_FALSE) {
        alljoyn_message reply;
        alljoyn_msgarg inputs;
        size_t numArgs;

        alljoyn_proxybusobject remoteObj = alljoyn_proxybusobject_create(g_msgBus, OBJECT_NAME, OBJECT_PATH, s_sessionId);
        const alljoyn_interfacedescription alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
        QCC_ASSERT(alljoynTestIntf);
        alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);

        /*
         * Although AllJoyn will automatically try and establish a secure connection
         * when a method call is made.  It will only allow the user the amount of time
         * specified in the methodcall timeout parameter to enter user input.  For the
         * "Ping" method that is 5 seconds.  This is not a reasonable amount of time
         * for a user to see the security password and enter it.
         *
         * By calling alljoyn_proxybusobject_secureconnection the user will have
         * as much time as they need to to enter the security password to secure
         * the connection.
         */
        status = alljoyn_proxybusobject_secureconnection(remoteObj, QCC_TRUE);
        if (ER_OK == status) {
            reply = alljoyn_message_create(g_msgBus);
            inputs = alljoyn_msgarg_array_create(1);
            numArgs = 1;
            status = alljoyn_msgarg_array_set(inputs, &numArgs, "s", "ClientC says Hello AllJoyn!");

            status = alljoyn_proxybusobject_methodcall(remoteObj, INTERFACE_NAME, "Ping", inputs, 1, reply, 5000, 0);
            if (ER_OK == status) {
                char* ping_str;
                status = alljoyn_msgarg_get(alljoyn_message_getarg(reply, 0), "s", &ping_str);
                printf("%s.%s ( path=%s) returned \"%s\"\n", INTERFACE_NAME, "Ping",
                       OBJECT_PATH, ping_str);
            } else {
                printf("alljoyn_proxybusobject_methodcall on %s.%s failed\n", INTERFACE_NAME, "Ping");
            }
            alljoyn_msgarg_destroy(inputs);
            alljoyn_message_destroy(reply);
        }
        alljoyn_proxybusobject_destroy(remoteObj);
    }

    /* Deallocate bus */
    if (g_msgBus) {
        alljoyn_busattachment deleteMe = g_msgBus;
        g_msgBus = NULL;
        alljoyn_busattachment_destroy(deleteMe);
    }

    /* Deallocate bus listener */
    alljoyn_buslistener_destroy(g_busListener);

    /* Deallocate auth listener */
    alljoyn_authlistener_destroy(g_authListener);

    printf("exiting with status %d (%s)\n", status, QCC_StatusText(status));

#ifdef ROUTER
    alljoyn_routershutdown();
#endif
    alljoyn_shutdown();
    return (int) status;
}
コード例 #23
0
ファイル: MobClient.cpp プロジェクト: arcookie/mob
QStatus CMobClient::Connect()
{
	QStatus status = CAlljoynMob::Connect();

	if (ER_OK == status) {
		/* Begin discovery on the well-known name of the service to be called */
		status = m_pBus->FindAdvertisedName(m_sSvrName.data());

		if (status == ER_OK) {
			printf("org.alljoyn.Bus.FindAdvertisedName ('%s') succeeded.\n", m_sSvrName.data());
		}
		else {
			printf("org.alljoyn.Bus.FindAdvertisedName ('%s') failed (%s).\n", m_sSvrName.data(), QCC_StatusText(status));
		}
	}

	if (ER_OK == status) {
		unsigned int count = 0;

		while (!m_bJoinComplete && !s_interrupt) {
			if (0 == (count++ % 100)) {
				printf("Waited %u seconds for JoinSession completion.\n", count / 100);
			}

#ifdef _WIN32
			Sleep(10);
#else
			usleep(10 * 1000);
#endif
		}
	}

	return (m_bJoinComplete && !s_interrupt ? ER_OK : ER_ALLJOYN_JOINSESSION_REPLY_CONNECT_FAILED);
}
コード例 #24
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
/* This is similar to calling BusObject constructor. */
QStatus AJ_CALL bus_object_init() {

    QStatus status = ER_OK;
    QCC_BOOL foundMember = QCC_FALSE;
    alljoyn_interfacedescription_member my_ping_member, my_delayed_ping_member, my_time_ping_member, my_signal_member;

    alljoyn_interfacedescription intf = NULL;
    alljoyn_interfacedescription valuesintf = NULL;

    alljoyn_busobject_methodentry methodEntries[3];

    intf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
    valuesintf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_VALUE_NAME);

    if (!intf) {
        printf("ERROR - Could not fetch %s interface from the bus. \n", INTERFACE_NAME);
        return ER_FAIL;
    }

    if (!valuesintf) {
        printf("ERROR - Could not fetch %s interface from the bus. \n", INTERFACE_VALUE_NAME);
        return ER_FAIL;
    }

    /* Add interfaces to the bus object. */
    alljoyn_busobject_addinterface(g_testObj, intf);
    alljoyn_busobject_addinterface(g_testObj, valuesintf);

    /*Get the members. */
    foundMember = alljoyn_interfacedescription_getmember(intf, "my_signal", &my_signal_member);
    if (!foundMember) {
        printf("ERROR - Could not fetch %s member from %s interface. \n", "my_signal", INTERFACE_NAME);
        return ER_FAIL;
    }

    foundMember = QCC_FALSE;
    foundMember = alljoyn_interfacedescription_getmember(intf, "my_ping", &my_ping_member);
    if (!foundMember) {
        printf("ERROR - Could not fetch %s member from %s interface. \n", "my_ping", INTERFACE_NAME);
        return ER_FAIL;
    }

    foundMember = QCC_FALSE;
    foundMember = alljoyn_interfacedescription_getmember(intf, "delayed_ping", &my_delayed_ping_member);
    if (!foundMember) {
        printf("ERROR - Could not fetch %s member from %s interface. \n", "delayed_ping", INTERFACE_NAME);
        return ER_FAIL;
    }

    foundMember = QCC_FALSE;
    foundMember = alljoyn_interfacedescription_getmember(intf, "time_ping", &my_time_ping_member);
    if (!foundMember) {
        printf("ERROR - Could not fetch %s member from %s interface. \n", "time_ping", INTERFACE_NAME);
        return ER_FAIL;
    }


    /* Register a signal handler. */
    status = alljoyn_busattachment_registersignalhandler(g_msgBus, &signal_handler, my_signal_member, NULL);
    if (ER_OK != status) {
        printf("Failed to register signal handler with %s", QCC_StatusText(status));
        return status;
    }

    /* Register Method handlers. */
    methodEntries[0].member = &my_ping_member;
    methodEntries[0].method_handler = ping;

    methodEntries[1].member = &my_delayed_ping_member;
    methodEntries[1].method_handler = delayed_ping;

    methodEntries[2].member = &my_time_ping_member;
    methodEntries[2].method_handler = time_ping;


    status = alljoyn_busobject_addmethodhandlers(g_testObj, methodEntries, sizeof(methodEntries) / sizeof(methodEntries[0]));
    if (ER_OK != status) {
        printf("Failed to register method handlers because of %s\n", QCC_StatusText(status));
        return status;
    }

    return status;
}
コード例 #25
0
/** Main entry point */
int CDECL_CALL main(int argc, char** argv)
{
    QStatus status = ER_OK;
    char* connectArgs = NULL;
    alljoyn_interfacedescription testIntf = NULL;
    unsigned long timeoutMs = ULONG_MAX;
    unsigned long timeMs = 0;

    /* Create a bus listener */
    alljoyn_buslistener_callbacks callbacks = {
        NULL,
        NULL,
        &found_advertised_name,
        NULL,
        &name_owner_changed,
        NULL,
        NULL,
        NULL
    };

    if (argc == 2) {
        char* stopString = NULL;
        /* Multiply by 1000 to convert seconds to milliseconds */
        timeoutMs = strtol(argv[1], &stopString, 10) * 1000;
        if ((timeoutMs == 0) || (stopString[0] != '\0')) {
            printf("Parameter was not valid, please provide a valid integer timeout in seconds or do not provide a parameter to never time out.\n");
            return ER_BAD_ARG_1;
        }
    } else if (argc > 2) {
        printf("This app only accepts a single parameter, an integer connection timeout in seconds. For an unlimited timeout, do not provide a parameter.\n");
        return ER_BAD_ARG_COUNT;
    }


    if (alljoyn_init() != ER_OK) {
        return 1;
    }
#ifdef ROUTER
    if (alljoyn_routerinit() != ER_OK) {
        alljoyn_shutdown();
        return 1;
    }
#endif

    printf("AllJoyn Library version: %s\n", alljoyn_getversion());
    printf("AllJoyn Library build info: %s\n", alljoyn_getbuildinfo());

    /* Install SIGINT handler */
    signal(SIGINT, SigIntHandler);

    /* Create message bus */
    if (status == ER_OK) {
        g_msgBus = alljoyn_busattachment_create("myApp", QCC_TRUE);
    }

    /* Add org.alljoyn.Bus.method_sample interface */
    if (status == ER_OK) {
        status = alljoyn_busattachment_createinterface(g_msgBus, INTERFACE_NAME, &testIntf);
    }

    if (status == ER_OK) {
        printf("Interface Created.\n");
        alljoyn_interfacedescription_addmember(testIntf, ALLJOYN_MESSAGE_METHOD_CALL, "cat", "ss",  "s", "inStr1,inStr2,outStr", 0);
        alljoyn_interfacedescription_activate(testIntf);
    } else {
        printf("Failed to create interface 'org.alljoyn.Bus.method_sample'\n");
    }


    /* Start the msg bus */
    if (ER_OK == status) {
        status = alljoyn_busattachment_start(g_msgBus);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_start failed\n");
        } else {
            printf("alljoyn_busattachment started.\n");
        }
    }

    /* Connect to the bus */
    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));
        }
    }

    if (status == ER_OK) {
        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));
        }
    }

    /* Wait for join session to complete */
    while ((status == ER_OK) && (s_joinComplete == QCC_FALSE) && (g_interrupt == QCC_FALSE) && (timeMs < timeoutMs)) {
#ifdef _WIN32
        Sleep(10);
#else
        usleep(10 * 1000);
#endif
        timeMs += 10;
    }

    if (timeMs >= timeoutMs) {
        status = ER_BUS_ESTABLISH_FAILED;
        printf("Failed to connect before timeout (%s)\n", QCC_StatusText(status));
    }

    if ((status == ER_OK) && (g_interrupt == QCC_FALSE)) {
        alljoyn_message reply;
        alljoyn_msgarg inputs;
        size_t numArgs;

        alljoyn_proxybusobject remoteObj = alljoyn_proxybusobject_create(g_msgBus, OBJECT_NAME, OBJECT_PATH, s_sessionId);
        const alljoyn_interfacedescription alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
        assert(alljoynTestIntf);
        alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);

        reply = alljoyn_message_create(g_msgBus);
        inputs = alljoyn_msgarg_array_create(2);
        numArgs = 2;
        status = alljoyn_msgarg_array_set(inputs, &numArgs, "ss", "Hello ", "World!");
        if (ER_OK != status) {
            printf("Arg assignment failed: %s\n", QCC_StatusText(status));
        }
        status = alljoyn_proxybusobject_methodcall(remoteObj, INTERFACE_NAME, "cat", inputs, 2, reply, 5000, 0);
        if (ER_OK == status) {
            char* cat_str;
            status = alljoyn_msgarg_get(alljoyn_message_getarg(reply, 0), "s", &cat_str);
            printf("%s.%s ( path=%s) returned \"%s\"\n", INTERFACE_NAME, "cat", OBJECT_PATH, cat_str);
        } else {
            printf("MethodCall on %s.%s failed\n", INTERFACE_NAME, "cat");
        }

        alljoyn_proxybusobject_destroy(remoteObj);
        alljoyn_message_destroy(reply);
        alljoyn_msgarg_destroy(inputs);
    }

    /* Deallocate bus */
    if (g_msgBus) {
        alljoyn_busattachment deleteMe = g_msgBus;
        g_msgBus = NULL;
        alljoyn_busattachment_destroy(deleteMe);
    }

    /* Deallocate bus listener */
    if (g_busListener) {
        alljoyn_buslistener_destroy(g_busListener);
    }

    printf("basic client exiting with status %d (%s)\n", status, QCC_StatusText(status));

#ifdef ROUTER
    alljoyn_routershutdown();
#endif
    alljoyn_shutdown();
    return (int) status;
}
コード例 #26
0
void AllJoynConnection::Connect(char* tag, bool asAdvertiser)
{
    status = ER_OK;
    if (asAdvertiser) {
        advertisedName = NAME_PREFIX;
        advertisedName += "xfer";
        joinName = "";
        NotifyUser(MSG_STATUS, "%s is advertiser \n", advertisedName.c_str());
    } else {
        joinName = NAME_PREFIX;
        joinName += "xfer";
        advertisedName = "";
        NotifyUser(MSG_STATUS, "%s is joiner\n", joinName.c_str());
    }
    assert(invariants());
    myTag = tag;
    createMessageBus();
    startMessageBus();
    SessionOpts opts(SessionOpts::TRAFFIC_MESSAGES, true, SessionOpts::PROXIMITY_ANY, TRANSPORT_ANY);
    bindSessionPort(opts);
    if (!this->advertisedName.empty()) {
        NotifyUser(MSG_STATUS, "Request name");
        status = this->busAttachment->RequestName(this->advertisedName.c_str(), DBUS_NAME_FLAG_DO_NOT_QUEUE);
        if (ER_OK != status) {
            NotifyUser(MSG_ERROR, "RequestName(%s) failed (status=%s)\n", this->advertisedName.c_str(), QCC_StatusText(status));
            status = (status == ER_OK) ? ER_FAIL : status;
        }
        /* Advertise same well-known name */
        if (ER_OK == status) {
            status = this->busAttachment->AdvertiseName(this->advertisedName.c_str(), opts.transports);
            if (status != ER_OK) {
                NotifyUser(MSG_ERROR, "Failed to advertise name %s (%s)\n", this->advertisedName.c_str(), QCC_StatusText(status));
            }
        }
    } else {
        status = this->busAttachment->FindAdvertisedName(this->joinName.c_str());
        if (status != ER_OK) {
            NotifyUser(MSG_ERROR, "org.alljoyn.Bus.FindAdvertisedName failed (%s)\n", QCC_StatusText(status));
        }
        NotifyUser(MSG_STATUS, "Found Advertised Name \n");
    }

    createBusObjects(tag);
    m_fConnected = (ER_OK == status);
    NotifyUser(MSG_STATUS, "Ready %s ...", tag);
}
コード例 #27
0
bool ChatObject::RegisterInterfaces()
{
    /* Add the chat interface to this object */
    const InterfaceDescription* chatIntf = bus.GetInterface(CHAT_SERVICE_INTERFACE_NAME);
    assert(chatIntf);
    AddInterface(*chatIntf);
    /* Store the Chat signal member away so it can be quickly looked up when signals are sent */
    chatSignalMember = chatIntf->GetMember("Chat");
    assert(chatSignalMember);

    /* Register signal handler */
    status =  bus.RegisterSignalHandler(this,
                                        static_cast<MessageReceiver::SignalHandler>(&ChatObject::ChatSignalHandler),
                                        chatSignalMember,
                                        NULL);
    if (ER_OK != status) {
        NotifyUser(MSG_ERROR, "Failed to register signal handler for ChatObject::Chat (%s)\n", QCC_StatusText(status));
        return false;
    }
    return true;
}
コード例 #28
0
ファイル: basic_c_client.c プロジェクト: eekshs16/SIoT
/** TODO: Make this C89 compatible. */
int CDECL_CALL main(int argc, char** argv, char** envArg)
{
    QStatus status = ER_OK;
    char* connectArgs = NULL;
    //alljoyn_interfacedescription testIntf = NULL;
    /* Create a bus listener */
    alljoyn_buslistener_callbacks callbacks = {
        &registered,
        &unregistered,
        &found_advertised_name,
        &lost_advertised_name,
        &name_owner_changed,
        &stopping,
        &disconnected,
        &prop_changed
    };

    if (alljoyn_init() != ER_OK) {
        return 1;
    }
#ifdef ROUTER
    printf("Router Init\n");
    if (alljoyn_routerinit() != ER_OK) {
        alljoyn_shutdown();
        return 1;
    }
#endif

    printf("AllJoyn Library version: %s\n", alljoyn_getversion());
    printf("AllJoyn Library build info: %s\n", alljoyn_getbuildinfo());

    /* Install SIGINT handler */
    signal(SIGINT, SigIntHandler);

    /* Create message bus */
    g_msgBus = alljoyn_busattachment_create("myApp", QCC_TRUE); //Name, Allow remote message
//    g_msgBus = alljoyn_busattachment_create("myApp", QCC_FALSE); //Name, Allow remote message

    /* Add org.alljoyn.Bus.method_sample interface */
#if 0
    status = alljoyn_busattachment_createinterface(g_msgBus, INTERFACE_NAME, &testIntf);
    if (status == ER_OK) {
        printf("Interface Created.\n");
        alljoyn_interfacedescription_addmember(testIntf, ALLJOYN_MESSAGE_METHOD_CALL, "cat", "ss",  "s", "inStr1,inStr2,outStr", 0);
        alljoyn_interfacedescription_addmember(testIntf, ALLJOYN_MESSAGE_METHOD_CALL, "cat2", "ss",  "s", "inStr1,inStr2,outStr", 0);
        alljoyn_interfacedescription_activate(testIntf);
    } else {
        printf("Failed to create interface 'org.alljoyn.Bus.method_sample'\n");
    }
#endif

    /* Start the msg bus */
    if (ER_OK == status) {
        status = alljoyn_busattachment_start(g_msgBus);
        if (ER_OK != status) {
            printf("alljoyn_busattachment_start failed\n");
        } else {
            printf("alljoyn_busattachment started.\n");
        }
    }

    /* Connect to the bus */
    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));
        }
    }

    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));
        }
    }

    /* Wait for join session to complete */
    while (s_joinComplete == QCC_FALSE && g_interrupt == QCC_FALSE) {
#ifdef _WIN32
        Sleep(10);
#else
        usleep(100 * 1000);
#endif
    }

    if (status == ER_OK && g_interrupt == QCC_FALSE) {
        alljoyn_message reply;
        alljoyn_msgarg inputs;
        size_t numArgs;

        alljoyn_proxybusobject remoteObj = alljoyn_proxybusobject_create(g_msgBus, OBJECT_NAME, OBJECT_PATH, s_sessionId);

#if 1
        status = alljoyn_proxybusobject_introspectremoteobject(remoteObj);
        if (status != ER_OK) {
          printf("Failed to introspect remote object.\n");
        }
#endif

        //alljoyn_interfacedescription alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, INTERFACE_NAME);
        //assert(alljoynTestIntf);
        //alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);
        //alljoyn_proxybusobject_introspectremoteobject(remoteObj);


#if 0
        alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, "org.freedesktop.DBus.Introspectable");
        assert(alljoynTestIntf);
        alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);
        
        alljoynTestIntf = alljoyn_busattachment_getinterface(g_msgBus, "org.allseen.Introspectable");
        assert(alljoynTestIntf);
        alljoyn_proxybusobject_addinterface(remoteObj, alljoynTestIntf);
#endif

#if 1
        reply = alljoyn_message_create(g_msgBus);
        inputs = alljoyn_msgarg_array_create(2);
        numArgs = 2;
        status = alljoyn_msgarg_array_set(inputs, &numArgs, "ss", "Hello ", "World!");
        if (ER_OK != status) {
            printf("Arg assignment failed: %s\n", QCC_StatusText(status));
        }
        status = alljoyn_proxybusobject_methodcall(remoteObj, INTERFACE_NAME, "cat", inputs, 2, reply, 5000, 0);
        if (ER_OK == status) {
            char* cat_str;
            status = alljoyn_msgarg_get(alljoyn_message_getarg(reply, 0), "s", &cat_str);
            printf("%s.%s (path=%s) returned \"%s\"\n", INTERFACE_NAME, "cat", OBJECT_PATH, cat_str);
        } else {
            printf("MethodCall on %s.%s failed\n", INTERFACE_NAME, "cat");
        }
#endif
        reply = alljoyn_message_create(g_msgBus);
        inputs = alljoyn_msgarg_array_create(2);
        numArgs = 2;
        status = alljoyn_msgarg_array_set(inputs, &numArgs, "ss", "Hello ", "World!");
        if (ER_OK != status) {
            printf("Arg assignment failed: %s\n", QCC_StatusText(status));
        }
        status = alljoyn_proxybusobject_methodcall(remoteObj, INTERFACE_NAME, "cat2", inputs, 2, reply, 5000, 0);
        if (ER_OK == status) {
            char* cat_str;
            status = alljoyn_msgarg_get(alljoyn_message_getarg(reply, 0), "s", &cat_str);
            printf("%s.%s (path=%s) returned \"%s\"\n", INTERFACE_NAME, "cat2", OBJECT_PATH, cat_str);
        } else {
            printf("MethodCall on %s.%s failed\n", INTERFACE_NAME, "cat2");
        }
#if 0
        status = alljoyn_proxybusobject_methodcall(remoteObj, "org.freedesktop.DBus.Introspectable", "Introspect", NULL, 0, reply, 5000, 0);
        if (ER_OK == status) {
          char* Introspect_str;
          status = alljoyn_msgarg_get(alljoyn_message_getarg(reply, 0), "s", &Introspect_str);
          printf("%s.%s (path=%s) returned \"%s\"\n", "org.freedesktop.DBus.Introspectable", "Introspect", OBJECT_PATH, Introspect_str);
        } else {
          printf("MethodCall on %s.%s failed\n", "org.freedesktop.DBus.Introspectable", "Introspect");
        }
#endif

        alljoyn_proxybusobject_destroy(remoteObj);
        alljoyn_message_destroy(reply);
        alljoyn_msgarg_destroy(inputs);
    }

    /* Deallocate bus */
    if (g_msgBus) {
        alljoyn_busattachment deleteMe = g_msgBus;
        g_msgBus = NULL;
        alljoyn_busattachment_destroy(deleteMe);
    }

    /* Deallocate bus listener */
    alljoyn_buslistener_destroy(g_busListener);

    printf("basic client exiting with status %d (%s)\n", status, QCC_StatusText(status));

#ifdef ROUTER
    printf("Router Shutdown\n");
    alljoyn_routershutdown();
#endif
    alljoyn_shutdown();
    return (int) status;
}
コード例 #29
0
ファイル: bbcservice.c プロジェクト: octoblu/alljoyn
int main(int argc, char** argv)
{
    QStatus status = ER_OK;
    const char* keyStore = NULL;
    int i = 0;

    alljoyn_interfacedescription intf = NULL;
    alljoyn_interfacedescription intfvalue = NULL;

    /* SessionPort Listeners. */
    alljoyn_sessionportlistener_callbacks spl_cbs = {
        &accept_session_joiner,
        &session_joined
    };

    /* SessionPort Listeners. */
    alljoyn_sessionlistener_callbacks sl_cbs = {
        &session_lost, //session lost callback
        NULL, //session member added callback
        NULL //session member lost callback
    };

    /* Bus Object callbacks */
    alljoyn_busobject_callbacks busObjCbs = {
        &property_get,
        &property_set,
        &busobject_object_registered,
        &busobject_object_unregistered
    };

    /* Auth listener callbacks. */
    alljoyn_authlistenerasync_callbacks authcbs = {
        request_credentials_async,
        verify_credentials_async,
        security_violation,
        authentication_complete
    };

    alljoyn_authlistener authListener;

    printf("AllJoyn Library version: %s\n", alljoyn_getversion());
    printf("AllJoyn Library build info: %s\n", alljoyn_getbuildinfo());

    /* Install SIGINT handler */
    signal(SIGINT, SigIntHandler);

    g_wellKnownName = (char*)DEFAULT_WELLKNOWN_NAME;

    g_sessionOpts = alljoyn_sessionopts_create(ALLJOYN_TRAFFIC_TYPE_MESSAGES, QCC_FALSE, ALLJOYN_PROXIMITY_ANY, ALLJOYN_TRANSPORT_ANY);

    /* Parse command line args */
    for (i = 1; i < argc; ++i) {
        if (0 == strcmp("-h", argv[i]) || 0 == strcmp("-?", argv[i])) {
            usage();
            exit(0);
        } else if (0 == strcmp("-p", argv[i])) {
            if (g_echo_signal) {
                printf("options -e and -p are mutually exclusive\n");
                usage();
                exit(1);
            }
            g_ping_back = QCC_TRUE;
        } else if (0 == strcmp("-e", argv[i])) {
            if (g_ping_back) {
                printf("options -p and -e are mutually exclusive\n");
                usage();
                exit(1);
            }
            g_echo_signal = QCC_TRUE;;
        } else if (0 == strcmp("-x", argv[i])) {
            g_compress = QCC_TRUE;
        } else if (0 == strcmp("-i", argv[i])) {
            ++i;
            if (i == argc) {
                printf("option %s requires a parameter\n", argv[i - 1]);
                usage();
                exit(1);
            } else {
                g_reportInterval = strtoul(argv[i], NULL, 10);
            }
        } else if (0 == strcmp("-n", argv[i])) {
            ++i;
            if (i == argc) {
                printf("option %s requires a parameter\n", argv[i - 1]);
                usage();
                exit(1);
            } else {
                g_wellKnownName = argv[i];
            }
        } else if (0 == strcmp("-k", argv[i])) {
            ++i;
            if (i == argc) {
                printf("option %s requires a parameter\n", argv[i - 1]);
                usage();
                exit(1);
            } else {
                keyStore = argv[i];
            }
        } else if (0 == strcmp("-kx", argv[i])) {
            ++i;
            if (i == argc) {
                printf("option %s requires a parameter\n", argv[i - 1]);
                usage();
                exit(1);
            } else {
                g_keyExpiration = strtoul(argv[i], NULL, 10);
            }
        } else if (0 == strcmp("-m", argv[i])) {
            alljoyn_sessionopts_set_multipoint(g_sessionOpts, QCC_TRUE);
        } else if (0 == strcmp("-t", argv[i])) {
            alljoyn_sessionopts_set_transports(g_sessionOpts, ALLJOYN_TRANSPORT_TCP);
        } else if (0 == strcmp("-u", argv[i])) {
            alljoyn_sessionopts_set_transports(g_sessionOpts, ALLJOYN_TRANSPORT_UDP);
        } else if (0 == strcmp("-l", argv[i])) {
            alljoyn_sessionopts_set_transports(g_sessionOpts, ALLJOYN_TRANSPORT_LOCAL);
        } else if (0 == strcmp("-a", argv[i])) {
            g_cancelAdvertise = QCC_TRUE;
        } else {
            status = ER_FAIL;
            printf("Unknown option %s\n", argv[i]);
            usage();
            exit(1);
        }
    }

    //Create bus attachment
    g_msgBus = alljoyn_busattachment_create("bbcservice", QCC_TRUE);

    //Create and add interfaces to the bus

    status = alljoyn_busattachment_createinterface(g_msgBus, INTERFACE_NAME, &intf);
    if (status != ER_OK) {
        printf("Could not create %s interface because of %s. \n", INTERFACE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_busattachment_createinterface(g_msgBus, INTERFACE_VALUE_NAME, &intfvalue);
    if (status != ER_OK) {
        printf("Could not create %s interface because of %s. \n", INTERFACE_VALUE_NAME, QCC_StatusText(status));
        return status;
    }


    /* Activate org.alljoyn.alljoyn_test */
    status = alljoyn_interfacedescription_addmethod(intf, "my_ping", "s", "s", "i,i", 0, NULL);
    if (status != ER_OK) {
        printf("Could not add method %s to interface %s because of %s. \n", "my_ping", INTERFACE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_interfacedescription_addmethod(intf, "delayed_ping", "su", "s", "i,i", 0, NULL);
    if (status != ER_OK) {
        printf("Could not add method %s to interface %s because of %s. \n", "delayed_ping", INTERFACE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_interfacedescription_addmethod(intf, "time_ping", "uq", "uq", "i,i", 0, NULL);
    if (status != ER_OK) {
        printf("Could not add method %s to interface %s because of %s. \n", "time_ping", INTERFACE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_interfacedescription_addmember(intf, ALLJOYN_MESSAGE_SIGNAL, "my_signal", "a{ys}",  NULL, "inStr", 0);
    if (status != ER_OK) {
        printf("Could not add signal %s to interface %s because of %s. \n", "my_signal", INTERFACE_NAME, QCC_StatusText(status));
        return status;
    }



    alljoyn_interfacedescription_activate(intf);

    /*Activate org.alljoyn.alljoyn_test.values */
    status = alljoyn_interfacedescription_addproperty(intfvalue, "int_val", "i", ALLJOYN_PROP_ACCESS_RW);
    if (status != ER_OK) {
        printf("Could not add property %s to interface %s because of %s. \n", "int_val", INTERFACE_VALUE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_interfacedescription_addproperty(intfvalue, "str_val", "s", ALLJOYN_PROP_ACCESS_RW);
    if (status != ER_OK) {
        printf("Could not add method %s to interface %s because of %s. \n", "str_val", INTERFACE_VALUE_NAME, QCC_StatusText(status));
        return status;
    }

    status = alljoyn_interfacedescription_addproperty(intfvalue, "ro_str", "s", ALLJOYN_PROP_ACCESS_READ);
    if (status != ER_OK) {
        printf("Could not add method %s to interface %s because of %s. \n", "ro_str", INTERFACE_VALUE_NAME, QCC_StatusText(status));
        return status;
    }

    alljoyn_interfacedescription_activate(intfvalue);

    //Start the bus
    status = alljoyn_busattachment_start(g_msgBus);
    if (status != ER_OK) {
        printf("Could not start the bus because of %s. \n", QCC_StatusText(status));
        return status;
    }

    //Connect to the bus TODO - change the connect spec
    status = alljoyn_busattachment_connect(g_msgBus, "null:");
    if (status != ER_OK) {
        printf("Could not connect to the bus because of %s. \n", QCC_StatusText(status));
        return status;
    }

    /* SessionPort Listeners. */
    g_sessionPortListener = alljoyn_sessionportlistener_create(&spl_cbs, NULL);

    /* SessionPort Listeners. */
    g_sessionListener = alljoyn_sessionlistener_create(&sl_cbs, NULL);


    /* Bus Object call backs. */
    g_testObj = alljoyn_busobject_create(OBJECT_PATH, QCC_FALSE, &busObjCbs, NULL);
    status = bus_object_init();
    if (status != ER_OK) {
        printf("Bus object init failed because of %s. \n", QCC_StatusText(status));
        return status;
    }

    alljoyn_busattachment_registerbusobject(g_msgBus, g_testObj);

    /* Auth listener callbacks. */
    authListener = alljoyn_authlistenerasync_create(&authcbs, NULL);

    status = alljoyn_busattachment_enablepeersecurity(g_msgBus, "ALLJOYN_SRP_KEYX ALLJOYN_PIN_KEYX ALLJOYN_RSA_KEYX ALLJOYN_SRP_LOGON", authListener, keyStore, keyStore != NULL);
    if (ER_OK != status) {
        printf("enablePeerSecurity failed (%s)\n", QCC_StatusText(status));
        return status;
    }

    /* Add a logon entry. */
    alljoyn_busattachment_addlogonentry(g_msgBus, "ALLJOYN_SRP_LOGON", "sleepy", "123456");

    if (ER_OK == status) {
        printf("bbcservice %s ready to accept connections\n", g_wellKnownName);
        while (g_interrupt == QCC_FALSE) {
#ifdef _WIN32
            Sleep(100 * 10 * 300);
#else
            usleep(100 * 1000 * 10 * 300);
#endif
        }
    }

    /* Clean up. */
    alljoyn_busattachment_unregisterbusobject(g_msgBus, g_testObj);

    alljoyn_sessionopts_destroy(g_sessionOpts);
    alljoyn_authlistenerasync_destroy(authListener);
    alljoyn_busobject_destroy(g_testObj);
    alljoyn_sessionportlistener_destroy(g_sessionPortListener);
    alljoyn_sessionlistener_destroy(g_sessionListener);
    alljoyn_busattachment_destroy(g_msgBus);

    return 0;
}
コード例 #30
0
bool XferObject::CreateInterfaces()
{
    const char* ifName = XFER_SERVICE_INTERFACE_NAME;
    InterfaceDescription* xferIntf = NULL;
    status = ajConnection->busAttachment->CreateInterface(ifName, xferIntf);
    assert(xferIntf);
    if (ER_OK == status) {
        xferIntf->AddMethod("query", "si",  "i", "filename, filesize, acceptsize ", 0);
        xferIntf->AddMethod("initiate", "ii",  "i", "segmentSize, nSegs, acceptsize ", 0);
        xferIntf->AddMethod("receive", "ayii",  "i", "segment, serialNum. segSize , success ", 0);
        xferIntf->AddMethod("status", "i",  "i", "unused , status ", 0);
        xferIntf->AddMethod("close", "i",  "i", "unused , success ", 0);
        xferIntf->AddMethod("error", "i",  "i", "unused , error ", 0);
        xferIntf->Activate();
    } else {
        NotifyUser(MSG_ERROR, "Failed to create interface \"%s\" (%s)\n", XFER_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
        return false;
    }
    NotifyUser(MSG_SYSTEM, "Create interface \"%s\" (%s)\n", XFER_SERVICE_INTERFACE_NAME, QCC_StatusText(status));
    return true;
}