aboutsummaryrefslogtreecommitdiffstats
path: root/src/crtc-server/server.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-17 19:01:54 +0200
committerMattias Andrée <maandree@kth.se>2016-07-17 19:01:54 +0200
commitae1870e0a650cf299acc758aca9704a8e552cc09 (patch)
tree68edb40d6a542b3f58c8243328867acb0f513832 /src/crtc-server/server.c
parentContinue restructure (diff)
downloadcoopgammad-ae1870e0a650cf299acc758aca9704a8e552cc09.tar.gz
coopgammad-ae1870e0a650cf299acc758aca9704a8e552cc09.tar.bz2
coopgammad-ae1870e0a650cf299acc758aca9704a8e552cc09.tar.xz
Continued refactoring
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/crtc-server/server.c')
-rw-r--r--src/crtc-server/server.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/crtc-server/server.c b/src/crtc-server/server.c
index 6ce6560..6c524e5 100644
--- a/src/crtc-server/server.c
+++ b/src/crtc-server/server.c
@@ -19,6 +19,7 @@
#include "../state.h"
#include "../communication.h"
+#include <errno.h>
#include <string.h>
@@ -86,3 +87,43 @@ char* get_crtc_name(const libgamma_crtc_information_t* restrict info,
}
}
+
+/**
+ * Get partitions and CRTC:s
+ *
+ * @return Zero on success, -1 on error
+ */
+int initialise_crtcs(void)
+{
+ size_t i, j, n, n0;
+ int gerror;
+
+ /* Get partitions */
+ if (site.partitions_available)
+ if (!(partitions = calloc(site.partitions_available, sizeof(*partitions))))
+ goto fail;
+ for (i = 0; i < site.partitions_available; i++)
+ {
+ if ((gerror = libgamma_partition_initialise(partitions + i, &site, i)))
+ goto fail_libgamma;
+ outputs_n += partitions[i].crtcs_available;
+ }
+
+ /* Get CRTC:s */
+ if (outputs_n)
+ if (!(crtcs = calloc(outputs_n, sizeof(*crtcs))))
+ goto fail;
+ for (i = 0, j = n = 0; i < site.partitions_available; i++)
+ for (n0 = n, n += partitions[i].crtcs_available; j < n; j++)
+ if ((gerror = libgamma_crtc_initialise(crtcs + j, partitions + i, j - n0)))
+ goto fail_libgamma;
+
+ return 0;
+
+ fail_libgamma:
+ libgamma_perror(argv0, gerror);
+ errno = 0;
+ fail:
+ return -1;
+}
+