![]() |
cacao
Release 0.1.03-dev
Compute And Control For Adaptive Optics
|
Read and Create image. More...
#include <math.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <semaphore.h>
#include "ImageStreamIO.h"
Macros | |
#define | _GNU_SOURCE |
#define | DEBUG_TRACEPOINTLOG(...) |
#define | ULONGLONG_IMG (80) |
#define | ImageStreamIO_printERROR(code, msg) if(internal_printError) internal_printError(__FILE__, __func__, __LINE__, code, msg); |
Functions | |
void | __attribute__ ((constructor)) |
Initialize module. More... | |
errno_t | init_ImageStreamIO () |
errno_t | ImageStreamIO_printERROR_ (const char *file, const char *func, int line, errno_t code, char *errmessage) |
errno_t | ImageStreamIO_printWARNING (char *warnmessage) |
errno_t | ImageStreamIO_set_default_printError () |
Set the error reporting function to the default provided by the library. More... | |
errno_t | ImageStreamIO_set_printError (errno_t(*new_printError)(const char *, const char *, int, errno_t, char *)) |
Set the error reporting function. The new function supplied by the pointer will be called whenever a library function reports an error. Pass NULL to turn off error reporting from within the library. More... | |
errno_t | ImageStreamIO_write_process_log (char *msg) |
Write entry into debug log. More... | |
errno_t | ImageStreamIO_printERROR_ (const char *file, const char *func, int line, __attribute__((unused)) errno_t code, char *errmessage) |
errno_t | ImageStreamIO_readBufferAt (const IMAGE *image, const unsigned int slice_index, void **buffer) |
Get the raw pointer to the beginning of the slice slice_index. More... | |
errno_t | ImageStreamIO_shmdirname (char *shmdname) |
errno_t | ImageStreamIO_filename (char *file_name, size_t ssz, const char *im_name) |
Get the standard stream filename. More... | |
int | ImageStreamIO_typesize (uint8_t datatype) |
Get the size in bytes from the data type code. More... | |
int | ImageStreamIO_bitpix (uint8_t datatype) |
Get the FITSIO BITPIX from the data type code. More... | |
uint64_t | ImageStreamIO_offset_data (IMAGE *image, void *map) |
uint64_t | ImageStreamIO_initialize_buffer (IMAGE *image) |
errno_t | ImageStreamIO_createIm (IMAGE *image, const char *name, long naxis, uint32_t *size, uint8_t datatype, int shared, int NBkw) |
Create shared memory image stream (legacy API) More... | |
errno_t | ImageStreamIO_createIm_gpu (IMAGE *image, const char *name, long naxis, uint32_t *size, uint8_t datatype, int8_t location, int shared, int NBsem, int NBkw, uint64_t imagetype) |
Create shared memory image stream. More... | |
errno_t | ImageStreamIO_destroyIm (IMAGE *image) |
Deallocate and remove an IMAGE structure. More... | |
errno_t | ImageStreamIO_openIm (IMAGE *image, const char *name) |
Connect to an existing shared memory image stream. More... | |
void * | ImageStreamIO_get_image_d_ptr (IMAGE *image) |
errno_t | ImageStreamIO_read_sharedmem_image_toIMAGE (const char *name, IMAGE *image) |
Read / connect to existing shared memory image stream. More... | |
errno_t | ImageStreamIO_closeIm (IMAGE *image) |
Close a shared memmory image stream. More... | |
errno_t | ImageStreamIO_destroysem (IMAGE *image) |
Destroy shmim semaphores. More... | |
int | ImageStreamIO_createsem (IMAGE *image, long NBsem) |
Create shmim semaphores. More... | |
long | ImageStreamIO_sempost (IMAGE *image, long index) |
Post all shmim semaphores. More... | |
long | ImageStreamIO_sempost_excl (IMAGE *image, long index) |
Post all shmim semaphores except one. More... | |
long | ImageStreamIO_sempost_loop (IMAGE *image, long index, long dtus) |
Post shmim semaphores at regular time interval. More... | |
int | ImageStreamIO_getsemwaitindex (IMAGE *image, int semindexdefault) |
Get available semaphore index. More... | |
int | ImageStreamIO_semwait (IMAGE *image, int index) |
Wait for semaphore. More... | |
int | ImageStreamIO_semtrywait (IMAGE *image, int index) |
int | ImageStreamIO_semtimedwait (IMAGE *image, int index, const struct timespec *semwts) |
long | ImageStreamIO_semflush (IMAGE *image, long index) |
Flush all semaphores of a shmim. More... | |
Variables | |
static int | INITSTATUS_ImageStreamIO = 0 |
errno_t(* | internal_printError )(const char *, const char *, int, errno_t, char *) = &ImageStreamIO_printERROR_ |
Read and Create image.
Read and create images and streams (shared memory)
#define _GNU_SOURCE |
#define DEBUG_TRACEPOINTLOG | ( | ... | ) |
#define ImageStreamIO_printERROR | ( | code, | |
msg | |||
) | if(internal_printError) internal_printError(__FILE__, __func__, __LINE__, code, msg); |
#define ULONGLONG_IMG (80) |
void __attribute__ | ( | (constructor) | ) |
Initialize module.
int ImageStreamIO_bitpix | ( | uint8_t | atype | ) |
Get the FITSIO BITPIX from the data type code.
[in] | datatype | the type code (see ImageStruct.h |
Close a shared memmory image stream.
For use in clients, detaches and cleans up memory used by non-owner process.
[in] | image | A real-time image structure which contains the image data and meta-data. |
errno_t ImageStreamIO_createIm | ( | IMAGE * | image, |
const char * | name, | ||
long | naxis, | ||
uint32_t * | size, | ||
uint8_t | datatype, | ||
int | shared, | ||
int | NBkw | ||
) |
Create shared memory image stream (legacy API)
[out] | image | IMAGE structure which will have its members allocated and initialized. |
[in] | name | the name of the shared memory file will be data.tmpfsdir/<name>_im.shm |
[in] | naxis | number of axes in the image. |
[in] | size | the size of the image along each axis. Must have naxis elements. |
[in] | datatype | data type code |
[in] | shared | if true then a shared memory buffer is allocated. If false, only local storage is used. |
[in] | NBkw | the number of keywords to allocate. |
errno_t ImageStreamIO_createIm_gpu | ( | IMAGE * | image, |
const char * | name, | ||
long | naxis, | ||
uint32_t * | size, | ||
uint8_t | datatype, | ||
int8_t | location, | ||
int | shared, | ||
int | NBsem, | ||
int | NBkw, | ||
uint64_t | imagetype | ||
) |
Create shared memory image stream.
[out] | image | IMAGE structure which will have its members allocated and initialized. |
[in] | name | the name of the shared memory file will be data.tmpfsdir/<name>_im.shm |
[in] | naxis | number of axes in the image. |
[in] | size | the size of the image along each axis. Must have naxis elements. |
[in] | datatype | data type code |
[in] | location | if -1 then a CPU memory buffer is allocated. If >=0, GPU memory buffer is allocated on devive location . |
[in] | shared | if true then a shared memory buffer is allocated. If false, only local storage is used. |
[in] | NBsem | the number of semaphores to allocate. |
[in] | NBkw | the number of keywords to allocate. |
[in] | imagetype | type of the stream |
int ImageStreamIO_createsem | ( | IMAGE * | image, |
long | NBsem | ||
) |
Create shmim semaphores.
Create semaphore of a shmim
[in] | image | IMAGE* pointer to shmim |
[in] | NBsem | number of semaphores to be created |
[in] | image | the name of the shared memory file |
[in] | NBsem | number of semaphores to be created |
Deallocate and remove an IMAGE structure.
For a shared image: Closes all semaphores, deallcoates sem pointers, and removes associated files. Unmaps the shared memory segment, and finally removes the file. Sets the metadata and keyword pointers to NULL.
For a non-shred image: Deallocates all arrays and sets pointers to NULL.
[in] | image | The IMAGE structure to deallocate and remove from the system. |
Destroy shmim semaphores.
Destroy semaphore of a shmim
[in] | image | IMAGE* pointer to shmim |
[in] | image | the name of the shared memory file |
errno_t ImageStreamIO_filename | ( | char * | file_name, |
size_t | ssz, | ||
const char * | im_name | ||
) |
Get the standard stream filename.
Fills in the file_name
string with the standard shared memory image path, e.g.
produces the output:
* /milk/shm/image00.im.shm 8
[out] | file_name | the file name string to fill in |
[in] | ssz | the allocated size of file_name |
[in] | im_name | the image name |
void* ImageStreamIO_get_image_d_ptr | ( | IMAGE * | image | ) |
int ImageStreamIO_getsemwaitindex | ( | IMAGE * | image, |
int | semindexdefault | ||
) |
Get available semaphore index.
Get available shmim semaphore index
[in] | image | IMAGE* pointer to shmim |
[in] | index | preferred semaphore index, if available |
[in] | image | the name of the shared memory file |
uint64_t ImageStreamIO_initialize_buffer | ( | IMAGE * | image | ) |
uint64_t ImageStreamIO_offset_data | ( | IMAGE * | image, |
void * | map | ||
) |
Connect to an existing shared memory image stream.
Wrapper for ImageStreamIO_read_sharedmem_image_toIMAGE
errno_t ImageStreamIO_printERROR_ | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
errno_t | code, | ||
char * | errmessage | ||
) |
errno_t ImageStreamIO_printERROR_ | ( | const char * | file, |
const char * | func, | ||
int | line, | ||
__attribute__((unused)) errno_t | code, | ||
char * | errmessage | ||
) |
Print error to stderr
errno_t ImageStreamIO_printWARNING | ( | char * | warnmessage | ) |
Print warning to stderr
errno_t ImageStreamIO_readBufferAt | ( | const IMAGE * | image, |
const unsigned int | slice_index, | ||
void ** | buffer | ||
) |
Get the raw pointer to the beginning of the slice slice_index.
Return the raw pointer to the beginning of the slice slice_index
[in] | image | IMAGE* pointer to shmim |
[in] | indec | const int slice_index of the slice to read |
[out] | buffer | void** pointer to the beginning of the slice |
long ImageStreamIO_semflush | ( | IMAGE * | image, |
long | index | ||
) |
Flush all semaphores of a shmim.
Flush shmim semaphore
[in] | image | IMAGE* pointer to shmim |
[in] | index | semaphore index flush all semaphores if index<0 |
[in] | image | the name of the shared memory file |
long ImageStreamIO_sempost | ( | IMAGE * | image, |
long | index | ||
) |
Post all shmim semaphores.
Posts semaphore of a shmim if index < 0, post all semaphores
[in] | image | IMAGE* pointer to shmim |
[in] | index | semaphore index index of semaphore to be posted if index=-1, post all semaphores |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
long ImageStreamIO_sempost_excl | ( | IMAGE * | image, |
long | index | ||
) |
Post all shmim semaphores except one.
Posts all semaphores of a shmim except one
[in] | image | IMAGE* pointer to shmim |
[in] | index | semaphore index index of semaphore to be excluded |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
long ImageStreamIO_sempost_loop | ( | IMAGE * | image, |
long | index, | ||
long | dtus | ||
) |
Post shmim semaphores at regular time interval.
Posts all semaphores of a shmim at regular time intervals
[in] | image | IMAGE* pointer to shmim |
[in] | index | semaphore index is =-1, post all semaphores |
[in] | dtus | time interval [us] |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
int ImageStreamIO_semtimedwait | ( | IMAGE * | image, |
int | index, | ||
const struct timespec * | semwts | ||
) |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
int ImageStreamIO_semtrywait | ( | IMAGE * | image, |
int | index | ||
) |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
int ImageStreamIO_semwait | ( | IMAGE * | image, |
int | index | ||
) |
Wait for semaphore.
Wait on a shmim semaphore
[in] | image | IMAGE* pointer to shmim |
[in] | index | semaphore index |
[in] | image | the name of the shared memory file |
[in] | index | semaphore index |
errno_t ImageStreamIO_set_default_printError | ( | ) |
Set the error reporting function to the default provided by the library.
errno_t ImageStreamIO_set_printError | ( | errno_t(*)(const char *, const char *, int, errno_t, char *) | new_printError | ) |
Set the error reporting function. The new function supplied by the pointer will be called whenever a library function reports an error. Pass NULL
to turn off error reporting from within the library.
new_printError | is a pointer to the function to use for reporting errors. Can be NULL. |
errno_t ImageStreamIO_shmdirname | ( | char * | shmdname | ) |
int ImageStreamIO_typesize | ( | uint8_t | atype | ) |
Get the size in bytes from the data type code.
[in] | datatype | the type code (see ImageStruct.h |
errno_t ImageStreamIO_write_process_log | ( | char * | msg | ) |
Write entry into debug log.
errno_t init_ImageStreamIO | ( | ) |
|
static |
errno_t(* internal_printError) (const char *, const char *, int, errno_t, char *) = &ImageStreamIO_printERROR_ |