aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-15 18:19:34 +0200
committerMattias Andrée <maandree@kth.se>2016-07-15 18:22:14 +0200
commit5a07c182ff21ae4713ce05416273ad764fb02051 (patch)
tree0ce2dae9b9ede3bb45084fba6600239aaab3bf7d /src
parentImplement libcoopgamma_synchronise (diff)
downloadlibcoopgamma-5a07c182ff21ae4713ce05416273ad764fb02051.tar.gz
libcoopgamma-5a07c182ff21ae4713ce05416273ad764fb02051.tar.bz2
libcoopgamma-5a07c182ff21ae4713ce05416273ad764fb02051.tar.xz
Add synchronous functions
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/libcoopgamma.c130
-rw-r--r--src/libcoopgamma.h82
2 files changed, 209 insertions, 3 deletions
diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c
index 175828f..1f1fab7 100644
--- a/src/libcoopgamma.c
+++ b/src/libcoopgamma.c
@@ -118,6 +118,32 @@ char* argv0 __attribute__((weak)) = "libcoopgamma";
(ctx)->error.description = NULL))
+#define SYNC_CALL(send_call, recv_call, fail_return) \
+ libcoopgamma_async_context_t async; \
+ size_t _selected; \
+ if (send_call < 0) \
+ { \
+ reflush: \
+ if (errno != EINTR) \
+ return fail_return; \
+ if (libcoopgamma_flush(ctx) < 0) \
+ goto reflush; \
+ } \
+resync: \
+ switch (libcoopgamma_synchronise(ctx, &async, 1, &_selected)) \
+ { \
+ case 0: \
+ break; \
+ case -1: \
+ if (errno != EINTR) \
+ return fail_return; \
+ /* Fall through */ \
+ case -2: \
+ goto resync; \
+ } \
+ return recv_call
+
+
/**
* Initialise a `libcoopgamma_ramps8_t`, `libcoopgamma_ramps16_t`, `libcoopgamma_ramps32_t`,
@@ -1436,6 +1462,7 @@ int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx,
ctx->bad_message = 0;
ctx->have_all_headers = 0;
ctx->length = 0;
+ ctx->inbound_tail = ctx->curline;
errno = EBADMSG;
return -1;
}
@@ -1446,6 +1473,7 @@ int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx,
return 0;
}
*selected = 0;
+ ctx->inbound_tail = ctx->curline;
return -2;
}
}
@@ -1770,6 +1798,31 @@ char** libcoopgamma_get_crtcs_recv(libcoopgamma_context_t* restrict ctx,
/**
+ * List all available CRTC:s, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param ctx The state of the library, must be connected
+ * @return A `NULL`-terminated list of names. You should only free
+ * the outer pointer, inner pointers are subpointers of the
+ * outer pointer and cannot be freed. `NULL` on error, in
+ * which case `ctx->error` (rather than `errno`) is read
+ * for information about the error.
+ */
+char** libcoopgamma_get_crtcs_sync(libcoopgamma_context_t* restrict ctx)
+{
+ SYNC_CALL(libcoopgamma_get_crtcs_send(ctx, &async),
+ libcoopgamma_get_crtcs_recv(ctx, &async), NULL);
+}
+
+
+
+/**
* Retrieve information about a CRTC:s gamma ramps, send request part
*
* Cannot be used before connecting to the server
@@ -1780,7 +1833,7 @@ char** libcoopgamma_get_crtcs_recv(libcoopgamma_context_t* restrict ctx,
* identify and parse the response, is stored here
* @return Zero on success, -1 on error
*/
-int libcoopgamma_get_gamma_info_send(const char* crtc, libcoopgamma_context_t* restrict ctx,
+int libcoopgamma_get_gamma_info_send(const char* restrict crtc, libcoopgamma_context_t* restrict ctx,
libcoopgamma_async_context_t* restrict async)
{
if ((crtc == NULL) || strchr(crtc, '\n'))
@@ -1906,6 +1959,31 @@ int libcoopgamma_get_gamma_info_recv(libcoopgamma_crtc_info_t* restrict info,
/**
+ * Retrieve information about a CRTC:s gamma ramps, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param crtc The name of the CRTC
+ * @param info Output parameter for the information, must be initialised
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_get_gamma_info_sync(const char* restrict ctrc, libcoopgamma_crtc_info_t* restrict info,
+ libcoopgamma_context_t* restrict ctx)
+{
+ SYNC_CALL(libcoopgamma_get_gamma_info_send(ctrc, ctx, &async),
+ libcoopgamma_get_gamma_info_recv(info, ctx, &async), -1);
+}
+
+
+
+/**
* Retrieve the current gamma ramp adjustments, send request part
*
* Cannot be used before connecting to the server
@@ -2090,6 +2168,32 @@ int libcoopgamma_get_gamma_recv(libcoopgamma_filter_table_t* restrict table,
/**
+ * Retrieve the current gamma ramp adjustments, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param query The query to send
+ * @param table Output for the response, must be initialised
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_get_gamma_sync(libcoopgamma_filter_query_t* restrict query,
+ libcoopgamma_filter_table_t* restrict table,
+ libcoopgamma_context_t* restrict ctx)
+{
+ SYNC_CALL(libcoopgamma_get_gamma_send(query, ctx, &async),
+ libcoopgamma_get_gamma_recv(table, ctx, &async), -1);
+}
+
+
+
+/**
* Apply, update, or remove a gamma ramp adjustment, send request part
*
* Cannot be used before connecting to the server
@@ -2197,3 +2301,27 @@ int libcoopgamma_set_gamma_recv(libcoopgamma_context_t* restrict ctx,
return -1;
}
+
+/**
+ * Apply, update, or remove a gamma ramp adjustment, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param filter The filter to apply, update, or remove, gamma ramp meta-data must match the CRTC's
+ * @param depth The datatype for the stops in the gamma ramps, must match the CRTC's
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_set_gamma_sync(libcoopgamma_filter_t* restrict filter, libcoopgamma_depth_t depth,
+ libcoopgamma_context_t* restrict ctx)
+{
+ SYNC_CALL(libcoopgamma_set_gamma_send(filter, depth, ctx, &async),
+ libcoopgamma_set_gamma_recv(ctx, &async), -1);
+}
+
diff --git a/src/libcoopgamma.h b/src/libcoopgamma.h
index 4b93710..341bd1a 100644
--- a/src/libcoopgamma.h
+++ b/src/libcoopgamma.h
@@ -1311,6 +1311,26 @@ int libcoopgamma_get_crtcs_send(libcoopgamma_context_t* restrict, libcoopgamma_a
char** libcoopgamma_get_crtcs_recv(libcoopgamma_context_t* restrict, libcoopgamma_async_context_t* restrict);
/**
+ * List all available CRTC:s, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param ctx The state of the library, must be connected
+ * @return A `NULL`-terminated list of names. You should only free
+ * the outer pointer, inner pointers are subpointers of the
+ * outer pointer and cannot be freed. `NULL` on error, in
+ * which case `ctx->error` (rather than `errno`) is read
+ * for information about the error.
+ */
+char** libcoopgamma_get_crtcs_sync(libcoopgamma_context_t* restrict);
+
+
+/**
* Retrieve information about a CRTC:s gamma ramps, send request part
*
* Cannot be used before connecting to the server
@@ -1321,7 +1341,7 @@ char** libcoopgamma_get_crtcs_recv(libcoopgamma_context_t* restrict, libcoopgamm
* identify and parse the response, is stored here
* @return Zero on success, -1 on error
*/
-int libcoopgamma_get_gamma_info_send(const char*, libcoopgamma_context_t* restrict,
+int libcoopgamma_get_gamma_info_send(const char* restrict, libcoopgamma_context_t* restrict,
libcoopgamma_async_context_t* restrict);
/**
@@ -1337,6 +1357,26 @@ int libcoopgamma_get_gamma_info_recv(libcoopgamma_crtc_info_t* restrict, libcoop
libcoopgamma_async_context_t* restrict);
/**
+ * Retrieve information about a CRTC:s gamma ramps, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param crtc The name of the CRTC
+ * @param info Output parameter for the information, must be initialised
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_get_gamma_info_sync(const char* restrict, libcoopgamma_crtc_info_t* restrict,
+ libcoopgamma_context_t* restrict);
+
+
+/**
* Retrieve the current gamma ramp adjustments, send request part
*
* Cannot be used before connecting to the server
@@ -1363,6 +1403,26 @@ int libcoopgamma_get_gamma_recv(libcoopgamma_filter_table_t* restrict, libcoopga
libcoopgamma_async_context_t* restrict);
/**
+ * Retrieve the current gamma ramp adjustments, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param query The query to send
+ * @param table Output for the response, must be initialised
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_get_gamma_sync(libcoopgamma_filter_query_t* restrict, libcoopgamma_filter_table_t* restrict,
+ libcoopgamma_context_t* restrict);
+
+
+/**
* Apply, update, or remove a gamma ramp adjustment, send request part
*
* Cannot be used before connecting to the server
@@ -1377,7 +1437,6 @@ int libcoopgamma_get_gamma_recv(libcoopgamma_filter_table_t* restrict, libcoopga
int libcoopgamma_set_gamma_send(libcoopgamma_filter_t* restrict, libcoopgamma_depth_t,
libcoopgamma_context_t* restrict, libcoopgamma_async_context_t* restrict);
-
/**
* Apply, update, or remove a gamma ramp adjustment, receive response part
*
@@ -1388,6 +1447,25 @@ int libcoopgamma_set_gamma_send(libcoopgamma_filter_t* restrict, libcoopgamma_de
*/
int libcoopgamma_set_gamma_recv(libcoopgamma_context_t* restrict, libcoopgamma_async_context_t* restrict);
+/**
+ * Apply, update, or remove a gamma ramp adjustment, synchronous version
+ *
+ * This is a synchronous request function, as such,
+ * you have to ensure that communication is blocking
+ * (default), and that there are not asynchronous
+ * requests waiting, it also means that EINTR:s are
+ * silently ignored and there no wait to cancel the
+ * operation without disconnection from the server
+ *
+ * @param filter The filter to apply, update, or remove, gamma ramp meta-data must match the CRTC's
+ * @param depth The datatype for the stops in the gamma ramps, must match the CRTC's
+ * @param ctx The state of the library, must be connected
+ * @return Zero on success, -1 on error, in which case `ctx->error`
+ * (rather than `errno`) is read for information about the error
+ */
+int libcoopgamma_set_gamma_sync(libcoopgamma_filter_t* restrict, libcoopgamma_depth_t,
+ libcoopgamma_context_t* restrict);
+
#endif