/* build with:

gcc -o cspi_test `pkg-config --cflags cspi-1.0` `pkg-config --libs cspi-1.0` cspi_test.c

You'll need the at-spi-devel (or equivalent) package installed on your system.

*/

#include "cspi/spi.h"
#include <stdio.h>

int main () {
    SPI_init();
    Accessible * desktop = SPI_getDesktop(0);
    char * s;
    Accessible * a;
    long c = Accessible_getChildCount(desktop);
    int i;
    for (i = 0; 0 <= i < c; i++) {
        printf("%i", i);
        fflush(stdout);
        a = Accessible_getChildAtIndex(desktop, i);
        s = Accessible_getName(a);
        printf(" '%s'", s);
        fflush(stdout);
        SPI_freeString(s);
        s = Accessible_getRoleName(a);
        printf(" '%s'\n", s);
        SPI_freeString(s);
        Accessible_unref(a);
        a = NULL;
        if (i == c - 1) { break; }
    }
    SPI_exit();
}
