On 2015-02-10 12:09:05, Chad Versace wrote:
> > On Sun, Feb 08, 2015 at 07:50:15PM -0500, Frank Henigman wrote:
> >> I'd like to extend wflinfo so it can print platform-specific
> >> information and eventually be able to replace glxinfo, eglinfo and the
> >> like (I only know what's on linux).  There would be a new flag to
> >> request the platform-specific output in addition to the existing
> >> output.  For example on glx you'd see glx extensions, on egl you'd see
> >> egl extensions.
> >> I've started two different implementations and I'd like to know which
> >> is preferred before I go any farther.  Or if there's a better idea
> >> than either of my approaches.  I've dubbed the two approaches "native"
> >> and "core."
> >>
> >> native
> >> - all the work is done in wflinfo, no changes to waffle api
> >> - use waffle_display_get_native() to access platform-specific stuff
> >> - pro: changes limited to wflinfo, doesn't clutter up the rest of waffle
> >> - con: some duplicate code to open libraries and lookup symbols
> >> - https://github.com/fjhenigman/waffle/tree/ps_native
> >>
> >> core
> >> - add waffle_display_print_info() to waffle api
> >> - add print_info() method to each platform
> >> - pro: less code, no duplication
> >> - con (perhaps): some wflinfo functionality is now in core waffle
> >> - https://github.com/fjhenigman/waffle/tree/ps_core
> >>
> >> I'm leaning toward "core" because there is less code.  We get to
> >> leverage the platform libraries and functions already stored in waffle
> >> platform structs.  But if the consensus is it's cleaner to keep this
> >> stuff in wflinfo I'm ok with that too.
> 
> I prefer "core" too. Not for the sake of less code, but because I like
> the idea of it being available as core API.

This surprised me a bit. I wouldn't think of the waffle library
wanting to embed a bunch of strings to fulfill such an API.

Anyway... how about this:

char**
waffle_display_info_strings(struct waffle_display *self, bool verbose);

The returned array of strings could have this property:

First look for a key string pointer. If it is NULL, then you are done.
If you find non-NULL key string pointer then search for 0 or more
non-NULL value string pointers. When a NULL pointer is seen, go back
to looking for a key string pointer.

I've attached an example program that sort of emulates wflinfo...

This would allow the consumer to use comma separation and/or line
breaks as desired.

-Jordan
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

/* Prints:
 *
 * key0:
 * key1: value1
 * key2: value2.0 value2.1
 */

struct waffle_display {
    void *for_example_purposes;
};

char**
waffle_display_info_strings(struct waffle_display *self, bool verbose)
{
    static char *strings[] = {
        "key0",
        NULL, /* No value items */
        "key1",
        "value1",
        NULL, /* One value item */
        "key2",
        "value2.0",
        "value2.1",
        NULL, /* Two value items */
        NULL /* End of strings */
    };
    char **retval = malloc(sizeof strings);
    memcpy(retval, strings, sizeof strings);
    return retval;
}

void
emulate_wflinfo(struct waffle_display *dpy)
{
    char **strings, **pos;
    strings = waffle_display_info_strings(dpy, true);
    /* maybe this indicates an error? */
    if (strings == NULL)
        return;

    for (pos = strings; *pos != NULL;) {
        /* first string pointer is a key */
        printf("%s:", *pos++);
        /* followed by 0 or more value strings associated with the key */
        for (;;) {
            char *value = *pos++;
            if (value == NULL) {
                printf("\n");
                break;
            } else {
              printf(" %s", value);
            }
        }
    }

    /* the entire set of string pointers and string data can be
     * freed together
     */
    free(strings);
}

int
main(int argc, char **argv)
{
    emulate_wflinfo(NULL);
}
_______________________________________________
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle

Reply via email to