aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-registry/slave.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mds-registry/slave.h')
-rw-r--r--src/mds-registry/slave.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/mds-registry/slave.h b/src/mds-registry/slave.h
new file mode 100644
index 0000000..ae8ae09
--- /dev/null
+++ b/src/mds-registry/slave.h
@@ -0,0 +1,160 @@
+/**
+ * mds — A micro-display server
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef MDS_MDS_REGISTRY_SLAVE_H
+#define MDS_MDS_REGISTRY_SLAVE_H
+
+
+#include <libmdsserver/hash-table.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <pthread.h>
+
+
+
+#define SLAVE_T_VERSION 0
+
+/**
+ * Slave information, a thread waiting for protocols to become available
+ */
+typedef struct slave /* TODO: add time-to-live */
+{
+ /**
+ * Set of protocols for which to wait that they become available
+ */
+ hash_table_t* wait_set;
+
+ /**
+ * The ID of the waiting client
+ */
+ uint64_t client;
+
+ /**
+ * The ID of the waiting client
+ */
+ char* client_id;
+
+ /**
+ * The ID of the message that triggered the waiting
+ */
+ char* message_id;
+
+ /**
+ * The slave's node in the linked list of slaves
+ */
+ ssize_t node;
+
+ /**
+ * Whether the client has been closed
+ */
+ volatile int closed;
+
+ /**
+ * The slave thread
+ */
+ pthread_t thread;
+
+} slave_t;
+
+
+
+/**
+ * Start a slave thread
+ *
+ * @param wait_set Set of protocols for which to wait that they become available
+ * @param recv_client_id The ID of the waiting client
+ * @param recv_message_id The ID of the message that triggered the waiting
+ * @return Non-zero on error
+ */
+int start_slave(hash_table_t* restrict wait_set, const char* restrict recv_client_id, const char* restrict recv_message_id);
+
+/**
+ * Close all slaves associated with a client
+ *
+ * @param client The client's ID
+ */
+void close_slaves(uint64_t client);
+
+/**
+ * Notify slaves that a protocol has become available
+ *
+ * @param command The protocol
+ * @return Non-zero on error, `ernno`will be set accordingly
+ */
+int advance_slaves(char* command);
+
+/**
+ * Create a slave
+ *
+ * @return The slave
+ */
+slave_t* slave_create(hash_table_t* restrict wait_set, const char* restrict recv_client_id, const char* restrict recv_message_id);
+
+
+/**
+ * Initialise a slave
+ *
+ * @param this Memory slot in which to store the new slave information
+ */
+void slave_initialise(slave_t* restrict this);
+
+/**
+ * Release all resources assoicated with a slave
+ *
+ * @param this The slave information
+ */
+void slave_destroy(slave_t* restrict this);
+
+/**
+ * Calculate the buffer size need to marshal slave information
+ *
+ * @param this The slave information
+ * @return The number of bytes to allocate to the output buffer
+ */
+size_t slave_marshal_size(const slave_t* restrict this) __attribute__((pure));
+
+/**
+ * Marshals slave information
+ *
+ * @param this The slave information
+ * @param data Output buffer for the marshalled data
+ * @return The number of bytes that have been written (everything will be written)
+ */
+size_t slave_marshal(const slave_t* restrict this, char* restrict data);
+
+/**
+ * Unmarshals slave information
+ *
+ * @param this Memory slot in which to store the new slave information
+ * @param data In buffer with the marshalled data
+ * @return Zero on error, errno will be set accordingly, otherwise the number of read bytes.
+ * Destroy the slave information on error.
+ */
+size_t slave_unmarshal(slave_t* restrict this, char* restrict data);
+
+/**
+ * Pretend to unmarshal slave information
+ *
+ * @param data In buffer with the marshalled data
+ * @return The number of read bytes
+ */
+size_t slave_unmarshal_skip(char* restrict data) __attribute__((pure));
+
+
+#endif
+