Commit 591fc11a authored by Arnaud Blanchard's avatar Arnaud Blanchard

Add const before dims as they are not changed

parent 86ab3d79
......@@ -53,21 +53,27 @@ Shared memory are opened with POSIX shm_open. The file /tmp/blc_channels.txt mai
typedef struct blc_channel
#ifdef __cplusplus
:blc_array {
///Constructor initiating an empty blc_channel
blc_channel();
///Constructor opening the blc_channel in reading mode by default (otherwise use BLC_CHANNEL_WRITE)
blc_channel(char const *new_name, int mode);
///Constructor creating or opening the channel if it exist. In this case it has to be compatible with its properties.
blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length, va_list vargs);
///Constructor creating or opening the channel if it exist. In this case it has to be compatible with its properties.
blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims);
blc_channel(char const *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
//Unmap the memory and close the file but the other informations are kept. The semaphores are not affected. @TODO See what to do with semaphores
~blc_channel();
///Before writting, check that name, type, format and parameter have been initialized.
void check_name_type_format_parameter();
/**Check if the current description of the blc_channel and the blc_channel **name** are compatible. Useful to know if you need to use another name for a new blc_channel or to remove the previous one.
The return value indicates the conflict:
- -1 if it does not exist
- 0 if there is no conflict
- 1 the number of dimensions differs
- 2 the type differs
......@@ -76,15 +82,17 @@ typedef struct blc_channel
int conflict(const char *name);
/**Set the blc_channel properties with the string (i.e "UIN8 RGB3 3x800x600 /channel_name")*/
int sscan_info(char const *string);
int sscan_info(char const *string, bool scan_id=false);
/**Set the blc_channel properties with the content of the file (i.e "UIN8 RGB3 3x800x600 /channel_name").
**scan_id** is a flag precising if the channel id preceeds the properties*/
int fscan_info(FILE *file, int scan_id);
int fscan_info(FILE *file, int scan_id=false);
/**Write the properties of the blc_channel on the buffer*/
int sprint_info(char *buffer, size_t buffer_size);
int sprint_info(char *buffer, size_t buffer_size, bool print_id=false);
/**Write the properties of the blc_channel in the file. **print_id** is a flag in order to require to print or not the blc_channel id*/
int fprint_info(FILE *file, int print_id);
int fprint_info(FILE *file, bool print_id=false);
/**Create a new blc_channel with the already defined arguments*/
void create(int mode);
/**Create a new blc_channel with the list of dims described as va_args*/
void vcreate(char const *name, int mode, uint32_t type, uint32_t format, int dims_nb, size_t length0, va_list arguments);
/**Create a new blc_channel with the list of dims described as va_args*/
......@@ -94,18 +102,19 @@ typedef struct blc_channel
/**Creates a new blc_channel and with the dims as a variable list of arguments */
void create(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, size_t length0, ...);
/**Creates a new blc_channel and with the dims as an array of dims*/
void create(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims);
void create(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims);
/**Creates a new blc_channel and with the dims as a string (i.e. "3x800x600") */
void create(char const *new_name, int mode, uint32_t type, uint32_t format, const char *size_string);
void create(char const *new_name, int mode, uint32_t type, uint32_t format, char const *size_string);
/**Open a blc_channel with mode. The name should already be defined (e.g. with get_info) */
void open( int mode);
/**Open a blc_channel with **name** */
void open(const char *name, int mode);
/**Create the blc_channel if it does not exist otherwise, open it. In this later case the properties have to be compatible.
You can use conflict function to check before if there is incompatibility*/
You can use conflict function to check before if there is incompatibility.
Return 1 if it has been created*/
int create_or_open(char const *new_name, int mode);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, size_t length0, ...);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, char const *size_string);
///Send the name of the channel on stdout. Useful to send this blc_channel on a pipe. It is a simple printf but with a unavoided fflush (with a pipe \n does not have effect)
......
......@@ -45,15 +45,16 @@ blc_channel::blc_channel(char const *new_name, int mode){
open(new_name, mode);
}
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length, va_list vargs):access_mode(0), fd(-1), sem_new_data(NULL), sem_ack_data(NULL)
{
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims){
create_or_open(new_name, access_mode, type, format, dims_nb, dims);
}
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length, va_list vargs):access_mode(0), fd(-1), sem_new_data(NULL), sem_ack_data(NULL){
vcreate_or_open(new_name, mode, type,format, dims_nb, length, vargs);
}
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length, ...):access_mode(0), fd(-1), sem_new_data(NULL), sem_ack_data(NULL)
{
blc_channel::blc_channel(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length, ...):access_mode(0), fd(-1), sem_new_data(NULL), sem_ack_data(NULL){
va_list arguments;
va_start(arguments, length);
vcreate_or_open(new_name, mode, type,format, dims_nb, length, arguments);
va_end(arguments);
......@@ -228,7 +229,7 @@ void blc_channel::create(int access_mode){
open_semaphores(1);
if (sync_new_data) {
if (access_mode==BLC_CHANNEL_READ){
if (access_mode==O_RDONLY){
while (sem_trywait(sem_new_data)==-1){ //If the semaphore is busy we post it until it is unlocked
if (errno==EAGAIN) SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
else EXIT_ON_SYSTEM_ERROR("blc_channel '%s'", this->name);
......@@ -241,7 +242,7 @@ void blc_channel::create(int access_mode){
}
if (sync_ack_data) {
if (access_mode==BLC_CHANNEL_READ){
if (access_mode==O_RDONLY){
while (sem_trywait(sem_new_data)==-1){ //If the semaphore is busy we post it until it is unlocked
if (errno==EAGAIN) SYSTEM_ERROR_CHECK(sem_post(sem_new_data), -1, "blc_channel '%s'", this->name);
else EXIT_ON_SYSTEM_ERROR("blc_channel '%s'", this->name);
......@@ -254,7 +255,7 @@ void blc_channel::create(int access_mode){
}
SYSTEM_ERROR_CHECK(ftruncate(fd, size), -1, "fd:%d, size '%ld' for channel '%s'.", fd, size, name);
if (access_mode==BLC_CHANNEL_READ){
if (access_mode==O_RDONLY){
close(fd);
fd = shm_open(name, O_RDONLY, S_IRWXU);
}
......@@ -269,7 +270,7 @@ void blc_channel::create(char const *new_name, int access_mode){
}
///Create a blc channel
void blc_channel::create(char const *new_name, int access_mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims){
void blc_channel::create(char const *new_name, int access_mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims){
def_array(type, format, dims_nb, dims);
create(new_name, access_mode);
}
......@@ -358,7 +359,7 @@ void blc_channel::open(int access_mode){
if (sync_ack_data){
sprintf(name_tmp, "blc_channel%d_sem_ack_data0", id);
SYSTEM_ERROR_CHECK(sem_ack_data = sem_open(name_tmp, NO_FLAG), SEM_FAILED, "Opening named semaphore '%s' for blc_channel '%s'", name_tmp, name);
if (access_mode==BLC_CHANNEL_READ){ //As we have just started. Any data is new
if (access_mode==O_RDONLY){ //As we have just started. Any data is new
while (sem_trywait(sem_ack_data)==-1){ //If the semaphore is busy we post it until it is unlocked
if (errno==EAGAIN) SYSTEM_ERROR_CHECK(sem_post(sem_ack_data), -1, "blc_channel '%s'", this->name);
else EXIT_ON_SYSTEM_ERROR("blc_channel '%s'", this->name);
......@@ -375,7 +376,7 @@ void blc_channel::open(const char *name, int mode){
}
int blc_channel::create_or_open(char const *new_name, int access_mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims){
int blc_channel::create_or_open(char const *new_name, int access_mode, uint32_t type, uint32_t format, int dims_nb, blc_dim const *dims){
int id, dim, created;
uint32_t new_type_str, new_format_str;
blc_channel info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment