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