Program Listing for File cmb_event.h

Return to documentation for file (include/cmb_event.h)

/*
 * Copyright (c) Asbjørn M. Bonvik 1993-1995, 2025-26.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CIMBA_CMB_EVENT_H
#define CIMBA_CMB_EVENT_H

#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>

extern double cmb_time(void);

typedef void (cmb_event_func)(void *subject, void *object);

extern void cmb_event_queue_initialize(double start_time);

extern void cmb_event_queue_terminate(void);

extern void cmb_event_queue_clear(void);

extern bool cmb_event_queue_is_empty(void);

extern uint64_t cmb_event_queue_count(void);

extern uint64_t cmb_event_schedule(cmb_event_func *action,
                                   void *subject,
                                   void *object,
                                   double time,
                                   int64_t priority);

extern bool cmb_event_execute_next(void);

extern void cmb_event_queue_execute(void);

extern uint64_t cmb_event_current(void);

extern bool cmb_event_is_scheduled(uint64_t handle);

extern double cmb_event_time(uint64_t handle);

extern int64_t cmb_event_priority(uint64_t handle);

extern bool cmb_event_cancel(uint64_t handle);

extern bool cmb_event_reschedule(uint64_t handle, double time);

extern bool cmb_event_reprioritize(uint64_t handle, int64_t priority);

#define CMB_ANY_ACTION ((cmb_event_func *)UINT64_C(0xFFFFFFFFFFFFFFFF))

#define CMB_ANY_SUBJECT ((void *)UINT64_C(0xFFFFFFFFFFFFFFFF))

#define CMB_ANY_OBJECT ((void *)UINT64_C(0xFFFFFFFFFFFFFFFF))

extern uint64_t cmb_event_pattern_find(cmb_event_func *action,
                               const void *subject,
                               const void *object);

extern uint64_t cmb_event_pattern_count(cmb_event_func *action,
                                        const void *subject,
                                        const void *object);

extern uint64_t cmb_event_pattern_cancel(cmb_event_func *action,
                                         const void *subject,
                                         const void *object);

typedef const char *(cmb_event_print_formatter)(cmb_event_func *a, const void *s, const void *o);

extern void cmb_event_queue_print(FILE *fp, cmb_event_print_formatter *epf);

#endif /* CIMBA_CMB_EVENT_H */