aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver/client-list.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-07-28 02:48:35 +0200
committerMattias Andrée <maandree@operamail.com>2014-07-28 02:48:35 +0200
commitb56efd6e9f5375bb84c2a643e7733460fb14b337 (patch)
treedc2e7702bb4fe7fc62682e10cdb35fc321065276 /src/libmdsserver/client-list.h
parentm (diff)
downloadmds-b56efd6e9f5375bb84c2a643e7733460fb14b337.tar.gz
mds-b56efd6e9f5375bb84c2a643e7733460fb14b337.tar.bz2
mds-b56efd6e9f5375bb84c2a643e7733460fb14b337.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/client-list.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/libmdsserver/client-list.h b/src/libmdsserver/client-list.h
new file mode 100644
index 0000000..1894b63
--- /dev/null
+++ b/src/libmdsserver/client-list.h
@@ -0,0 +1,125 @@
+/**
+ * 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_LIBMDSSERVER_CLIENT_LIST_H
+#define MDS_LIBMDSSERVER_CLIENT_LIST_H
+
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+
+
+
+#define CLIENT_LIST_T_VERSION 0
+
+/**
+ * Dynamic array of client ID:s
+ */
+typedef struct client_list
+{
+ /**
+ * The size of the array
+ */
+ size_t capacity;
+
+ /**
+ * The index after the last used index
+ */
+ size_t size;
+
+ /**
+ * Stored client ID:s
+ */
+ uint64_t* clients;
+
+} client_list_t;
+
+
+
+/**
+ * Create a client list
+ *
+ * @param this Memory slot in which to store the new client list
+ * @param capacity The minimum initial capacity of the client list, 0 for default
+ * @return Non-zero on error, `errno` will have been set accordingly
+ */
+int client_list_create(client_list_t* restrict this, size_t capacity);
+
+/**
+ * Release all resources in a client list, should
+ * be done even if `client_list_create` fails
+ *
+ * @param this The client list
+ */
+void client_list_destroy(client_list_t* restrict this);
+
+/**
+ * Clone a client list
+ *
+ * @param this The client list to clone
+ * @param out Memory slot in which to store the new client list
+ * @return Non-zero on error, `errno` will have been set accordingly
+ */
+int client_list_clone(const client_list_t* restrict this, client_list_t* restrict out);
+
+/**
+ * Add a client to the list
+ *
+ * @param this The list
+ * @param client The client to add
+ * @return Non-zero on error, errno will be set accordingly
+ */
+int client_list_add(client_list_t* restrict this, uint64_t client);
+
+/**
+ * Remove a client from the list, once
+ *
+ * @param this The list
+ * @param client The client to remove
+ */
+void client_list_remove(client_list_t* restrict this, uint64_t client);
+
+/**
+ * Calculate the buffer size need to marshal a client list
+ *
+ * @param this The list
+ * @return The number of bytes to allocate to the output buffer
+ */
+size_t client_list_marshal_size(const client_list_t* restrict this) __attribute__((pure));
+
+/**
+ * Marshals a client list
+ *
+ * @param this The list
+ * @param data Output buffer for the marshalled data
+ */
+void client_list_marshal(const client_list_t* restrict this, char* restrict data);
+
+/**
+ * Unmarshals a client list
+ *
+ * @param this Memory slot in which to store the new client list
+ * @param data In buffer with the marshalled data
+ * @return Non-zero on error, errno will be set accordingly.
+ * Destroy the list on error.
+ */
+int client_list_unmarshal(client_list_t* restrict this, char* restrict data);
+
+
+#endif
+