aboutsummaryrefslogtreecommitdiffstats
path: root/src/cg-base.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-22 17:58:19 +0200
committerMattias Andrée <maandree@kth.se>2016-07-22 17:58:19 +0200
commite0713613079946f30e03cdbb1ddd9c9e4e378070 (patch)
tree55f9989320bf29775f79d16c53eed26a8e50c827 /src/cg-base.c
parentList available methods (diff)
downloadcg-tools-e0713613079946f30e03cdbb1ddd9c9e4e378070.tar.gz
cg-tools-e0713613079946f30e03cdbb1ddd9c9e4e378070.tar.bz2
cg-tools-e0713613079946f30e03cdbb1ddd9c9e4e378070.tar.xz
List CRTC:s
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/cg-base.c')
-rw-r--r--src/cg-base.c46
1 files changed, 44 insertions, 2 deletions
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 <libcoopgamma.h>
+#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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;
}