Пример #1
0
static void object_lost(const void* context, alljoyn_proxybusobject_ref proxyref)
{
    alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);
    printf("[listener] Door %s:%s no longer exists.\n\tLast known state for lost object:\n",
           alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));
    print_door_state(proxy);
}
Пример #2
0
static void AJ_CALL object_discovered(const void* context, alljoyn_proxybusobject_ref proxyref)
{
    QStatus status;

    struct _listener_ctx* ctx = (struct _listener_ctx*) context;
    alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);

    printf("[listener] Door %s:%s has just been discovered.\n",
           alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));

    alljoyn_busattachment_enableconcurrentcallbacks(ctx->bus);

    status = alljoyn_proxybusobject_registerpropertieschangedlistener(proxy, INTF_NAME,
                                                                      door_intf_props, 3,
                                                                      properties_changed,
                                                                      &listener_ctx);
    if (status != ER_OK) {
        fprintf(stderr, "Could not register properties changed listener\n");
    }

    alljoyn_proxybusobject_enablepropertycaching(proxy);

    print_door_state(proxy);
}
Пример #3
0
static void AJ_CALL properties_changed(alljoyn_proxybusobject proxy, const char* intf, const alljoyn_msgarg changed, const alljoyn_msgarg invalidated, void* context)
{
    QStatus status;
    size_t nelem;
    alljoyn_msgarg elems;
    char* location = NULL;
    struct _listener_ctx* ctx = (struct _listener_ctx*) context;
    QCC_UNUSED(intf);
    printf("[listener] Door %s:%s has changed some properties.\n",
           alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));

    alljoyn_busattachment_enableconcurrentcallbacks(ctx->bus);
    status = proxy_get_location(proxy, &location);
    if (status == ER_OK) {
        printf("\tThat's actually the door at location %s.\n", (location != NULL) ? location : "<unknown>");
        free(location);
    }

    if (ER_OK == status) {
        status = alljoyn_msgarg_get(changed, "a{sv}", &nelem, &elems);
    }
    if (ER_OK == status) {
        size_t i;
        for (i = 0; i < nelem; ++i) {
            const char* prop;
            alljoyn_msgarg val;
            status = alljoyn_msgarg_get(alljoyn_msgarg_array_element(elems, i), "{sv}", &prop, &val);
            if (ER_OK == status) {
                if (!strcmp(prop, "Location")) {
                    char* newloc;
                    status = alljoyn_msgarg_get_string(val, &newloc);
                    if (ER_OK == status) {
                        printf("->  location: %s\n", newloc);
                    }
                } else if (!strcmp(prop, "IsOpen")) {
                    QCC_BOOL isopen = QCC_FALSE;
                    status = alljoyn_msgarg_get_bool(val, &isopen);
                    if (ER_OK == status) {
                        printf("->   is open: %s\n", isopen ? "yes" : "no");
                    }
                }
            } else {
                break;
            }
        }
    }

    if (ER_OK == status) {
        status = alljoyn_msgarg_get(invalidated, "as", &nelem, &elems);
    }
    if (ER_OK == status) {
        size_t i;
        for (i = 0; i < nelem; ++i) {
            char* prop;
            status = alljoyn_msgarg_get(alljoyn_msgarg_array_element(elems, i), "s", &prop);
            if (status == ER_OK) {
                printf("  invalidated %s\n", prop);
            }
        }
    }

    printf("> ");
    fflush(stdout);
}
Пример #4
0
/** returns a reference that must be decref'ed by the application */
static alljoyn_proxybusobject_ref get_door_at_location(alljoyn_busattachment bus, alljoyn_observer observer, const char* find_location)
{
    alljoyn_proxybusobject_ref proxyref;
    QCC_UNUSED(bus);
    for (proxyref = alljoyn_observer_getfirst(observer); proxyref; proxyref = alljoyn_observer_getnext(observer, proxyref)) {
        char* location;
        alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);
        QStatus status = proxy_get_location(proxy, &location);
        if (ER_OK != status) {
            fprintf(stderr, "Could not get Location property for object %s:%s.\n", alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));
            continue;
        }
        if (location != NULL && !strcmp(find_location, location)) {
            free(location);
            return proxyref;
        }
        free(location);
    }
    return NULL;
}
Пример #5
0
static void list_doors(alljoyn_busattachment bus, alljoyn_observer observer)
{
    alljoyn_proxybusobject_ref proxyref;
    QCC_UNUSED(bus);
    for (proxyref = alljoyn_observer_getfirst(observer); proxyref; proxyref = alljoyn_observer_getnext(observer, proxyref)) {
        char* location;
        QCC_BOOL isOpen;
        alljoyn_proxybusobject proxy = alljoyn_proxybusobject_ref_get(proxyref);

        QStatus status = proxy_get_isopen(proxy, &isOpen);
        if (ER_OK != status) {
            fprintf(stderr, "Could not get IsOpen property for object %s:%s.\n", alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));
            continue;
        }
        status = proxy_get_location(proxy, &location);
        if (ER_OK != status) {
            fprintf(stderr, "Could not get Location property for object %s:%s.\n", alljoyn_proxybusobject_getuniquename(proxy), alljoyn_proxybusobject_getpath(proxy));
            continue;
        }
        printf("Door location: %s open: %s\n", (location != NULL) ? location : "<unknown>", isOpen ? "yes" : "no");
        free(location);
    }
}