summaryrefslogtreecommitdiffstats
path: root/ucad.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-02-17 15:52:25 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-02-17 15:52:25 +0100
commite8b3babd44971d1d4b25186f88bdbea23f7bf394 (patch)
tree6f59998cbd157df14dc444f66f302f66b85c6ec0 /ucad.c
parent9da4e6a2c7ad73a0eb4f377533179eb606a14285 (diff)
downloaduca-net-e8b3babd44971d1d4b25186f88bdbea23f7bf394.tar.gz
uca-net-e8b3babd44971d1d4b25186f88bdbea23f7bf394.tar.bz2
uca-net-e8b3babd44971d1d4b25186f88bdbea23f7bf394.tar.xz
uca-net-e8b3babd44971d1d4b25186f88bdbea23f7bf394.zip
Implement outstanding write request
Diffstat (limited to 'ucad.c')
-rw-r--r--ucad.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ucad.c b/ucad.c
index 6421c21..3c83f74 100644
--- a/ucad.c
+++ b/ucad.c
@@ -235,6 +235,42 @@ handle_grab_request (GSocketConnection *connection, UcaCamera *camera, gpointer
}
static void
+handle_write_request (GSocketConnection *connection, UcaCamera *camera, gpointer message, GError **stream_error)
+{
+ GInputStream *input;
+ UcaNetMessageWriteRequest *request;
+ UcaNetDefaultReply reply = { .type = UCA_NET_MESSAGE_WRITE };
+ gchar *buffer;
+ gsize bytes_left;
+ GError *error = NULL;
+
+ input = g_io_stream_get_input_stream (G_IO_STREAM (connection));
+ request = (UcaNetMessageWriteRequest *) message;
+ buffer = g_malloc0 (request->size);
+ bytes_left = request->size;
+
+ while (bytes_left > 0) {
+ gssize read;
+ gchar *buffer;
+
+ read = g_input_stream_read (input, &buffer[request->size - bytes_left], bytes_left, NULL, stream_error);
+
+ if (read < 0)
+ goto handle_write_request_cleanup;
+
+ bytes_left -= read;
+ }
+
+ uca_camera_write (camera, request->name, buffer, request->size, &error);
+
+ prepare_error_reply (error, &reply.error);
+ send_reply (connection, &reply, sizeof (reply), stream_error);
+
+handle_write_request_cleanup:
+ g_free (buffer);
+}
+
+static void
serve_connection (GSocketConnection *connection, UcaCamera *camera)
{
GInputStream *input;
@@ -250,6 +286,7 @@ serve_connection (GSocketConnection *connection, UcaCamera *camera)
{ UCA_NET_MESSAGE_STOP_READOUT, handle_stop_readout_request },
{ UCA_NET_MESSAGE_TRIGGER, handle_trigger_request },
{ UCA_NET_MESSAGE_GRAB, handle_grab_request },
+ { UCA_NET_MESSAGE_WRITE, handle_write_request },
{ UCA_NET_MESSAGE_INVALID, NULL }
};