aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-10 18:06:31 +0200
committerMattias Andrée <maandree@kth.se>2016-07-10 18:06:31 +0200
commitfe511a8bf9ed207c3e144ae6ca0c55fd561944ce (patch)
tree577808bd110da26a9838d400d04d080263cb611c /src
parentAdd filter.[ch] (diff)
downloadcoopgammad-fe511a8bf9ed207c3e144ae6ca0c55fd561944ce.tar.gz
coopgammad-fe511a8bf9ed207c3e144ae6ca0c55fd561944ce.tar.bz2
coopgammad-fe511a8bf9ed207c3e144ae6ca0c55fd561944ce.tar.xz
Initialise CRTC:s
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/gammad.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/gammad.c b/src/gammad.c
new file mode 100644
index 0000000..f5179bd
--- /dev/null
+++ b/src/gammad.c
@@ -0,0 +1,90 @@
+/**
+ * gammad -- Cooperative gamma server
+ * Copyright (C) 2016 Mattias Andrée (maandree@kth.se)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <libgamma.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+
+
+char* argv0;
+
+
+
+int main(int argc, char** argv)
+{
+ int method, gerror, rc = 1;
+ libgamma_site_state_t site;
+ libgamma_partition_state_t* partitions = NULL;
+ libgamma_crtc_state_t* crtcs = NULL;
+ size_t i, j, n, n0, crtcs_n = 0;
+
+ argv0 = argv[0];
+
+ memset(&site, 0, sizeof(site));
+
+ /* Get method */
+ if (libgamma_list_methods(&method, 1, 0) < 1)
+ return fprintf(stderr, "%s: no adjustment method available\n", argv0), 1;
+
+ /* Get site */
+ if ((gerror = libgamma_site_initialise(&site, method, NULL)))
+ goto fail_libgamma;
+
+ /* 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;
+ crtcs_n += partitions[i].crtcs_available;
+ }
+
+ /* Get CRTC:s */
+ if (crtcs_n)
+ if (!(crtcs = calloc(crtcs_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;
+
+ /* Done */
+ rc = 0;
+ done:
+ if (crtcs != NULL)
+ for (i = 0; i < crtcs_n; i++)
+ libgamma_crtc_destroy(crtcs + i);
+ free(crtcs);
+ if (partitions != NULL)
+ for (i = 0; i < site.partitions_available; i++)
+ libgamma_partition_destroy(partitions + i);
+ free(partitions);
+ libgamma_site_destroy(&site);
+ return rc;
+ /* Fail */
+ fail:
+ perror(argv0);
+ goto done;
+ fail_libgamma:
+ libgamma_perror(argv0, gerror);
+ goto done;
+}