From e0713613079946f30e03cdbb1ddd9c9e4e378070 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 22 Jul 2016 17:58:19 +0200 Subject: List CRTC:s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/cg-base.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cg-base.c b/src/cg-base.c index 52624d9..18f782e 100644 --- a/src/cg-base.c +++ b/src/cg-base.c @@ -20,6 +20,7 @@ #include +#include #include #include #include @@ -66,18 +67,59 @@ static int list_methods(void) } +static int list_crtcs(libcoopgamma_context_t* restrict cg) +{ + char** list; + size_t i; + + list = libcoopgamma_get_crtcs_sync(cg); + if (list == NULL) + return -1; + for (i = 0; list[i]; i++) + printf("%s\n", list[i]); + free(list); + if (fflush(stdout) < 0) + return -1; + + return 0; +} + + int main(int argc, char* argv[]) { + libcoopgamma_context_t cg; + int init_failed = 0; + int stage = 0; + argv0 = argv[0]; if (initialise_proc() < 0) goto fail; - list_methods(); + if (list_methods() < 0) + goto fail; + if (libcoopgamma_context_initialise(&cg) < 0) + goto fail; + stage++; + if (libcoopgamma_connect(NULL, NULL, &cg) < 0) + { + init_failed = (errno == 0); + goto fail; + } + stage++; + + if (list_crtcs(&cg) < 0) + goto fail; + libcoopgamma_context_destroy(&cg, 1); return 0; fail: - perror(argv0); + if (init_failed) + fprintf(stderr, "%s: server failed to initialise\n", argv0); + else + perror(argv0); + if (stage >= 1) + libcoopgamma_context_destroy(&cg, stage >= 2); return 1; } -- cgit v1.2.3-70-g09d2