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); }
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); }
/* Exposed concatinate method */ void cat_method(alljoyn_busobject bus, const alljoyn_interfacedescription_member* member, alljoyn_message msg) { QStatus status; alljoyn_msgarg outArg; char* str1; char* str2; /* Concatenate the two input strings and reply with the result. */ char result[256] = { 0 }; QCC_UNUSED(member); status = alljoyn_msgarg_get(alljoyn_message_getarg(msg, 0), "s", &str1); if (ER_OK != status) { printf("Ping: Error reading alljoyn_message\n"); } status = alljoyn_msgarg_get(alljoyn_message_getarg(msg, 1), "s", &str2); if (ER_OK != status) { printf("Ping: Error reading alljoyn_message\n"); } snprintf(result, sizeof(result), "%s%s", str1, str2); outArg = alljoyn_msgarg_create_and_set("s", result); status = alljoyn_busobject_methodreply_args(bus, msg, outArg, 1); if (ER_OK != status) { printf("Ping: Error sending reply\n"); } alljoyn_msgarg_destroy(outArg); }
/* 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); } }