Commit ce696448 authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Re-organize headers and add more generic macros

- Split the gigantic <tao.h> header in smaller headers.
- Make most structures opaque. Structure definitions are in
  <tao-*-private.h> headers.
- Reduce the number of rebuilt files when a header is modified.
- In code, TAO headers should be included first, then "config.h" (if
  needed), finally standard C headers.
- Eliminate compatibility code for Booleans (trust <stdbool.h>).
- If one is lazy, <tao.h> can be included; but it is generally
  sufficient to include a subset of the TAO headers.
parent a9d0d5db
......@@ -2199,7 +2199,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED =
PREDEFINED = TAO__DOXYGEN
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
......
......@@ -9,13 +9,17 @@
//
// Copyright (C) 2019-2021, Éric Thiébaut.
#include <stdio.h>
#include "tao-alpao.h"
#include <asdkWrapper.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <tao-alpao.h>
#include <asdkWrapper.h>
// MANAGEMENT OF ERRORS -------------------------------------------------------
......
......@@ -9,11 +9,13 @@
//
// Copyright (C) 2019-2021, Éric Thiébaut.
#include <tao-mirrors.h>
#ifndef TAO_ALPAO_H_
#define TAO_ALPAO_H_ 1
#include <tao-mirrors.h>
#include <stdbool.h>
TAO_BEGIN_DECLS
// ---------------------------------------------------------------------------
......
......@@ -12,7 +12,7 @@
#ifndef _ANDOR_CONVERT_C
#define _ANDOR_CONVERT_C 1
#include <tao-andor.h>
#include "tao-andor.h"
// SRC_TYPE is uint8_t
#define SRC_TYPE uint8_t
......
......@@ -9,6 +9,8 @@
//
// Copyright (C) 2019-2021, Éric Thiébaut.
#include "tao-andor-private.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
......@@ -19,11 +21,6 @@
#include <errno.h>
#include <assert.h>
#include <tao.h>
#include <tao-private.h>
#include <tao-andor.h>
#include <tao-andor-private.h>
static struct {
const char* name;
const wchar_t* wname;
......
......@@ -12,8 +12,8 @@
#ifndef _ANDOR_ERRORS_C
#define _ANDOR_ERRORS_C 1
#include <tao-andor.h>
#include <tao-andor-private.h>
#include "tao-andor.h"
#include "tao-andor-private.h"
static void get_andor_error_details(
int code,
......
......@@ -9,7 +9,7 @@
//
// Copyright (C) 2019-2021, Éric Thiébaut.
#include <tao-andor-private.h>
#include "tao-andor-private.h"
#define STRINGIFY0(x) #x
#define JOIN0(a,b) a##b
......
......@@ -9,6 +9,11 @@
//
// Copyright (C) 2019-2021, Éric Thiébaut.
#include "tao-andor.h"
#include "tao-config.h"
#include "tao-servers-private.h"
#include "tao-cameras-private.h"
#include <limits.h>
#include <stdlib.h>
#include <string.h>
......@@ -20,11 +25,6 @@
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <tao-andor.h>
#include <tao.h>
#include <tao-config.h>
#include <tao-private.h>
#include <tao-servers.h>
#define JOINABLE_WORKER 1
......
......@@ -14,10 +14,11 @@
#ifndef TAO_ANDOR_PRIVATE_H_
#define TAO_ANDOR_PRIVATE_H_ 1
#include <wchar.h>
#include <atcore.h>
#include <tao-cameras-private.h>
#include <tao-andor.h>
#include <atcore.h>
TAO_BEGIN_DECLS
/**
......
......@@ -12,9 +12,10 @@
#ifndef TAO_ANDOR_H_
#define TAO_ANDOR_H_ 1
#include <tao-cameras.h>
#include <wchar.h>
#include <limits.h>
#include <tao-cameras.h>
TAO_BEGIN_DECLS
......
......@@ -52,16 +52,29 @@ if USE_CFITSIO
endif
include_HEADERS = \
tao-arrays.h \
tao-arrays-private.h \
tao-buffers.h \
tao-cameras.h \
tao-cameras-private.h \
tao-config.h \
tao-encodings.h \
tao-errors.h \
tao-errors-private.h \
tao-fits.h \
tao-generic.h \
tao-locks.h \
tao-macros.h \
tao-mirrors.h \
tao-mirrors-private.h \
tao-options.h \
tao-preprocessing.h \
tao-private.h \
tao-servers.h \
tao-servers-private.h \
tao-shared.h \
tao-shared-private.h \
tao-threadpools.h \
tao-utils.h \
tao.h
libtao_la_SOURCES = \
......
......@@ -10,10 +10,9 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "common.h"
#include "tao-private.h"
#include "tao-arrays-private.h"
#include "tao-utils.h"
#include <limits.h>
#include <string.h>
long tao_count_elements(
......
......@@ -9,16 +9,14 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "common.h"
#include "tao-buffers.h"
#include "tao-utils.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "tao-private.h"
#define if_likely(expr) if TAO_LIKELY(expr)
#define if_unlikely(expr) if TAO_UNLIKELY(expr)
......
......@@ -9,14 +9,14 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "common.h"
#include "tao-cameras-private.h"
#include "tao-generic.h"
#include <math.h>
#include <errno.h>
#include "config.h"
#include <tao-shared.h>
#include <tao-cameras.h>
#include <tao-private.h>
#include <errno.h>
#include <math.h>
#include <string.h>
#define INVALID_CAMERA_STATE -1
#define FRAMEGRABBER_TRY_LOCK 0
......
......@@ -9,14 +9,11 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "common.h"
#include "tao-utils.h"
#include "tao-buffers.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "tao-private.h"
#define IS_SPACE(c) ((c) == ' ' || (c) == '\t')
......
// common.h --
//
// Common definitions for compiling TAO library. This file should be included
// *before* other headers and should be the only one which includes "config.h".
// Since this file includes "config.h", it is not meant to be installed (unlike
// "tao.h" or "tao-*.h")
//
//-----------------------------------------------------------------------------
//
// This file if part of TAO real-time software licensed under the MIT license
// (https://git-cral.univ-lyon1.fr/tao/tao-rt).
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#ifndef TAO_COMMON_H_
#define TAO_COMMON_H_ 1
#include "config.h"
#if __STDC_VERSION__ < 199901L
# error C99 standard must be supported to compile TAO
# define inline static
#endif
#if SIZEOF_FLOAT == 4
# define float32_t float
#endif
#if SIZEOF_DOUBLE == 8
# define float64_t double
#endif
#ifndef __cplusplus
# ifdef HAVE_STDBOOL_H
# include <stdbool.h>
# else
// Provide definitions normally in <stdbool.h> (see
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdbool.h.html)
# if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
// _Bool is a keyword of the C language as of C99. The standard says
// that it is an unsigned integer type. */
# define true ((_Bool)1)
# define false ((_Bool)0)
# else
typedef enum {_False = 0, _True = 1} _Bool;
# define true _True
# define false _False
# endif
# define bool _Bool
# define __bool_true_false_are_defined 1
# endif
#endif
#endif // TAO_COMMON_H_
......@@ -9,16 +9,13 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "tao-config.h"
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "tao.h"
#include "tao-config.h"
FILE* tao_file_open(
const char* path,
......
......@@ -9,8 +9,13 @@
//
// Copyright (C) 2018-2021, Éric Thiébaut.
#include "common.h"
#include "tao-private.h"
#include "tao-encodings.h"
#include "tao-arrays-private.h"
#include "tao-shared-private.h"
#include "config.h"
#include <stdbool.h>
#define TYPE(id) TYPE1(id)
#define TYPE1(id) TYPE__##id
......@@ -39,12 +44,12 @@ typedef void fastcopy_proc(
long len);
typedef void copy_proc(
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy);
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy);
#define FASTCOPY1(PFX, DST, SRC) \
static void fastcopy_##PFX( \
......@@ -92,12 +97,12 @@ FASTCOPY_PROCS(dbl)
#if TAO_MAX_NDIMS >= 2
static void copy_2d(
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
{
long len1 = lens[0], dstdim1 = dstdims[0], srcdim1 = srcdims[0];
long len2 = lens[1];
......@@ -110,12 +115,12 @@ static void copy_2d(
#if TAO_MAX_NDIMS >= 3
static void copy_3d(
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
{
long len1 = lens[0], dstdim1 = dstdims[0], srcdim1 = srcdims[0];
long len2 = lens[1], dstdim2 = dstdims[1], srcdim2 = srcdims[1];
......@@ -131,12 +136,12 @@ static void copy_3d(
#if TAO_MAX_NDIMS >= 4
static void copy_4d(
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
{
long len1 = lens[0], dstdim1 = dstdims[0], srcdim1 = srcdims[0];
long len2 = lens[1], dstdim2 = dstdims[1], srcdim2 = srcdims[1];
......@@ -155,12 +160,12 @@ static void copy_4d(
#if TAO_MAX_NDIMS >= 5
static void copy_5d(
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
void* restrict dstdata,
const long* restrict dstdims,
const void* restrict srcdata,
const long* restrict srcdims,
const long* restrict lens,
fastcopy_proc* fastcopy)
{
long len1 = lens[0], dstdim1 = dstdims[0], srcdim1 = srcdims[0];
long len2 = lens[1], dstdim2 = dstdims[1], srcdim2 = srcdims[1];
......@@ -231,16 +236,16 @@ static copy_proc* copy_proc_table[] = {
#define NTYPES (TAO_DOUBLE - TAO_INT8 + 1)
tao_status tao_copy(
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dstdata == NULL || dstdims == NULL ||
srcdata == NULL || srcdims == NULL ||
......@@ -286,16 +291,16 @@ tao_status tao_copy(
}
void tao_copy_checked_args(
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
// Compute uni-dimensional offsets from the muti-dimensional offsets.
long dstoff = 0;
......@@ -370,13 +375,13 @@ static inline void* shared_array_data(const tao_shared_array* arr)
tao_status tao_copy_to_array(
tao_array* restrict dst,
const long* restrict dstoffs,
const void* restrict srcdata,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dst == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -393,13 +398,13 @@ tao_status tao_copy_to_array(
tao_status tao_copy_to_shared_array(
tao_shared_array* restrict dst,
const long* restrict dstoffs,
const void* restrict srcdata,
const long* restrict dstoffs,
const void* restrict srcdata,
tao_eltype srctype,
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
const long* restrict srcdims,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dst == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -416,14 +421,14 @@ tao_status tao_copy_to_shared_array(
}
tao_status tao_copy_from_array(
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
tao_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
tao_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (src == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -439,14 +444,14 @@ tao_status tao_copy_from_array(
}
tao_status tao_copy_from_shared_array(
void* restrict dstdata,
void* restrict dstdata,
tao_eltype dsttype,
const long* restrict dstdims,
const long* restrict dstoffs,
const long* restrict dstdims,
const long* restrict dstoffs,
tao_shared_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (src == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -463,12 +468,12 @@ tao_status tao_copy_from_shared_array(
}
tao_status tao_copy_array_to_array(
tao_array* restrict dst,
const long* restrict dstoffs,
tao_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
tao_array* restrict dst,
const long* restrict dstoffs,
tao_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dst == NULL || src == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -485,11 +490,11 @@ tao_status tao_copy_array_to_array(
tao_status tao_copy_array_to_shared_array(
tao_shared_array* restrict dst,
const long* restrict dstoffs,
const long* restrict dstoffs,
tao_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dst == NULL || src == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -506,11 +511,11 @@ tao_status tao_copy_array_to_shared_array(
tao_status tao_copy_shared_array_to_array(
tao_array* restrict dst,
const long* restrict dstoffs,
const long* restrict dstoffs,
tao_shared_array* restrict src,
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
const long* restrict srcoffs,
const long* restrict lens,
int ndims)
{
if (dst == NULL || src == NULL) {
tao_push_error(__func__, TAO_BAD_ADDRESS);
......@@ -527,11 +532,11 @@ tao_status tao_copy_shared_array_to_array(
tao_status tao_copy_shared_array_to_shared_array(
tao_shared_array* restrict dst,
const long* restrict dstoffs,
const long* restrict dstoffs,
tao_shared_array* restrict src,