From b56efd6e9f5375bb84c2a643e7733460fb14b337 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 28 Jul 2014 02:48:35 +0200 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/client-list.h | 125 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/libmdsserver/client-list.h (limited to 'src/libmdsserver/client-list.h') 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 . + */ +#ifndef MDS_LIBMDSSERVER_CLIENT_LIST_H +#define MDS_LIBMDSSERVER_CLIENT_LIST_H + + +#include +#include +#include + + + +#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 + -- cgit v1.2.3-70-g09d2