cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

proc-map.h (5036B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20
     21#ifndef _GUACD_PROC_MAP_H
     22#define _GUACD_PROC_MAP_H
     23
     24#include "config.h"
     25#include "common/list.h"
     26#include "proc.h"
     27
     28#include <guacamole/client.h>
     29
     30/**
     31 * The maximum number of concurrent connections to a single instance
     32 * of guacd.
     33 */
     34#define GUACD_CLIENT_MAX_CONNECTIONS 65536
     35
     36/**
     37 * The number of hash buckets in each process map.
     38 */
     39#define GUACD_PROC_MAP_BUCKETS GUACD_CLIENT_MAX_CONNECTIONS*2
     40
     41/**
     42 * Set of all active connections to guacd, indexed by connection ID.
     43 */
     44typedef struct guacd_proc_map {
     45
     46    /**
     47     * Internal hash buckets. Each bucket is a linked list containing all
     48     * guac_client instances which hash to this bucket location.
     49     */
     50    guac_common_list* __buckets[GUACD_PROC_MAP_BUCKETS];
     51
     52    /**
     53     * All processes present in the map. For internal use only. To operate on these
     54     * keys, use guacd_proc_map_foreach().
     55     */
     56    guac_common_list* processes;
     57
     58} guacd_proc_map;
     59
     60/**
     61 * Allocates a new client process map. There is intended to be exactly one
     62 * process map instance, which persists for the life of guacd.
     63 *
     64 * @return
     65 *     A newly-allocated client process map.
     66 */
     67guacd_proc_map* guacd_proc_map_alloc();
     68
     69/**
     70 * Free all resources allocated for the provided map. Note that this function
     71 * will _not_ clean up the processes contained within the map, only the map
     72 * itself.
     73 *
     74 * @param map
     75 *    The guacd proc map to free.
     76 */
     77void guacd_proc_map_free(guacd_proc_map* map);
     78
     79/**
     80 * Adds the given process to the client process map. On success, zero is
     81 * returned. If adding the client fails (due to lack of space, or duplicate
     82 * ID), a non-zero value is returned instead. The client process is stored by
     83 * the connection ID of the underlying guac_client.
     84 *
     85 * @param map
     86 *     The map in which the given client process should be stored.
     87 *
     88 * @param proc
     89 *     The client process to store in the given map.
     90 *
     91 * @return
     92 *     Zero if the process was successfully stored in the map, or non-zero if
     93 *     storing the process fails for any reason.
     94 */
     95int guacd_proc_map_add(guacd_proc_map* map, guacd_proc* proc);
     96
     97/**
     98 * Retrieves the client process having the client with the given ID, or NULL if
     99 * no such process is stored.
    100 *
    101 * @param map
    102 *     The map from which to retrieve the process associated with the client
    103 *     having the given ID.
    104 *
    105 * @param id
    106 *     The ID of the client whose process should be retrieved.
    107 *
    108 * @return
    109 *     The process associated with the client having the given ID, or NULL if
    110 *     no such process exists.
    111 */
    112guacd_proc* guacd_proc_map_retrieve(guacd_proc_map* map, const char* id);
    113
    114/**
    115 * Removes the client process having the client with the given ID, returning
    116 * the corresponding process. If no such process exists, NULL is returned.
    117 *
    118 * @param map
    119 *     The map from which to remove the process associated with the client
    120 *     having the given ID.
    121 *
    122 * @param id
    123 *     The ID of the client whose process should be removed.
    124 *
    125 * @return
    126 *     The process associated with the client having the given ID which has now
    127 *     been removed from the given map, or NULL if no such process exists.
    128 */
    129guacd_proc* guacd_proc_map_remove(guacd_proc_map* map, const char* id);
    130
    131/**
    132 * A callback function that will be invoked with every guacd_proc stored
    133 * in the provided map, when provided to guacd_proc_map_foreach(), along with
    134 * any provided arbitrary data.
    135 *
    136 * @param proc
    137 *     The current guacd process.
    138 *
    139 * @param data
    140 *     The arbitrary data provided to guacd_proc_map_foreach().
    141 */
    142typedef void guacd_proc_map_foreach_callback(guacd_proc* proc, void* data);
    143
    144/**
    145 * Invoke the provided callback with any provided arbitrary data and each guacd
    146 * proc contained in the provided map, once each and in no particular order.
    147 *
    148 * @param map
    149 *     The map from which all guacd processes should be extracted and provided
    150 *     to the callback.
    151 *
    152 * @param callback
    153 *     The callback function to be invoked once with each guacd process
    154 *     contained in the provided map.
    155 *
    156 * @param data
    157 *     Arbitrary data to be provided to the callback function.
    158 */
    159void guacd_proc_map_foreach(guacd_proc_map* map,
    160        guacd_proc_map_foreach_callback* callback, void* data);
    161
    162#endif
    163