Commit 3f8cdcee authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Initial files for managing blc_channels

parents
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cmake_minimum_required(VERSION 2.6)
project(blc_channel)
add_definitions(-Wall -Wextra -Wno-multichar)
get_filename_component(BLAAR_DIR ${CMAKE_SOURCE_DIR} PATH)
if (NOT TARGET shared_blc_core)
add_subdirectory(${BLAAR_DIR}/blc/blc_core blc_core)
endif()
include_directories(include ${BLC_CORE_INCLUDE_DIR})
#source files
set(sources src/blc_channel.cpp)
add_library(shared_blc_channel SHARED ${sources})
add_library(static_blc_channel STATIC ${sources})
#Both librairies have the same name only the extension will change depending on the OS
set_target_properties(shared_blc_channel PROPERTIES OUTPUT_NAME blc_channel)
set_target_properties(static_blc_channel PROPERTIES OUTPUT_NAME blc_channel)
target_link_libraries(shared_blc_channel shared_blc_core)
#in case it is included for another project
set(BLC_CHANNEL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
#Describe what will be to install or in the package
install(DIRECTORY include/ DESTINATION include)
install(TARGETS shared_blc_channel shared_blc_channel DESTINATION lib)
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Arnaud Blanchard")
include(CPack)
#Building examples
#add_executable(blc_demo examples/blc_demo.c)
#target_link_libraries(blc_demo shared_blc)
#Add a target to generate documentation
#find_package(Doxygen)
#if(DOXYGEN_FOUND)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxyfile.in doxyfile.doxy) #Replace the CMAKE variables in the Doxyfile
#add_custom_target(doc_${PROJECT_NAME} ALL ${DOXYGEN_EXECUTABLE} doxyfile.doxy COMMENT "Generating API documentation with Doxygen" VERBATIM )
#else(DOXYGEN_FOUND)
#message("You need to install doxygen to generate the doc.")
#endif(DOXYGEN_FOUND)
blc_array
=========
Define a structure for n-dimentional array.
Depend on libblc_core
PROJECT_NAME = "BLC channelk"
OUTPUT_DIRECTORY = doc/blc_channel
OPTIMIZE_OUTPUT_FOR_C = YES
EXTRACT_LOCAL_CLASSES = NO
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES
HIDE_FRIEND_COMPOUNDS = YES
HIDE_IN_BODY_DOCS = YES
CASE_SENSE_NAMES = NO
SORT_MEMBER_DOCS = NO
QUIET = YES
INPUT = ${CMAKE_CURRENT_SOURCE_DIR}
RECURSIVE = YES
# USE_MDFILE_AS_MAINPAGE = ${CMAKE_CURRENT_SOURCE_DIR}/README.md
ALPHABETICAL_INDEX = NO
HTML_OUTPUT = html
LATEX_OUTPUT = latex
MACRO_EXPANSION = YES
PREDEFINED = __cplusplus = 1
REPEAT_BRIEF = YES
SKIP_FUNCTION_MACROS = NO
CLASS_DIAGRAMS = NO
/* Basic Library for C/C++ (blclib)
Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2015)
Author: Aranud Blanchard
This software is a computer program whose purpose is to simulate neural networks and control robots or simulations.
This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
 users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
 In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
 that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured
 and, more generally, to use and operate it in the same conditions as regards security.
 The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms. */
/**
*
* @date Oct 10, 2014
* @author Arnaud Blanchard
@defgroup blc_channel channels
@{
*/
#ifndef BLC_CHANNEL_H
#define BLC_CHANNEL_H
#include "blc_tools.h"
#include "blc_array.h"
#include <limits.h> //NAME_MAX, ...
#include <fcntl.h> //< O_... constants O_RDONLY, 0_RDWR, O_WRONLY
#define SEM_NAME_LEN 31 // At least on OSX
#define BLC_CHANNELS_MAX UINT16_MAX
#define BLC_CHANNEL_READ O_RDONLY
#define BLC_CHANNEL_WRITE O_RDWR
#define BLC_CHANNEL_READ_BLOCK (O_RDONLY | (O_ACCMODE + 1 )) // (O_ACCMODE + 1 First flag after access mode (O_RDONLY, O_RDWR))
#define BLC_CHANNEL_WRITE_BLOCK (O_RDWR | (O_ACCMODE + 1 )) // (O_ACCMODE + 1 First flag after access mode (O_RDONLY, O_RDWR)
#define BLC_PARAMETER_MAX 31
#define EXIT_ON_CHANNEL_ERROR(channel, ...) blc_channel_fatal_error(channel, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
typedef struct shared_control{
pthread_mutex_t mutex;
pthread_cond_t writer_cond, reader_cond;
int writing;
uint64_t new_value_flags, readers_flags, reading_flags; //bitfield max 64 blocking_readers;
}blc_share_control;
typedef struct blc_channel
#ifdef __cplusplus
:blc_array {
blc_channel();
blc_channel(char const *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
int fscan_info(FILE *file);
void fprint_info(FILE *file);
void map_memory(int mode);
void open_block_semaphore();
void open_ack_semaphore();
void create_semaphores();
void vcreate(char const *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, va_list arguments);
int vcreate_or_open(char const *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, va_list arguments);
void create(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
void create(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims);
void create();
void open(const char *name, int mode);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
int create_or_open(char const *new_name, int mode, uint32_t type, uint32_t format, int dims_nb, blc_dim *dims);
///Send the name of the channel on stdout
void publish();
void fprint_debug(FILE *file=stdout);
int create_or_open_control();
void close_control();
void begin_write();
void begin_read();
void end_write();
void end_read();
/* void protect(int value=1);*/
void set_namef(char const *name, ...);
void unlink(); //Remove the memory from the system unless another process retain it.
//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
void close();
#else
{
blc_array array;// Not beautiful but makes it easy to convert C++ heritage of "class" in C struct inclusion.
#endif
int id, mode;
char name[NAME_MAX+1];
char parameter[BLC_PARAMETER_MAX+1];
int fd, ctrl_fd ; ///< shared memory file descriptor
blc_share_control *control; //Part that we be share in purpose of control
uint64_t reader_flag;
}blc_channel;
extern int blc_channel_port;
void start_channel_server(int port);
START_EXTERN_C
void blc_channel_fatal_error(blc_channel *channel, const char *name_of_file, const char* name_of_function, int numero_of_line, const char *message, ...);
/*Create a channel with the name, the kind of semaphore "abp" a:ack, b:block, p:protect, the type of data UIN8, INT8, UI16, IN16, FL32, FL64. ( default 0:UIN8),
The format are four chars user defined but usually describe the image format 'RGB3', 'YUV2' ,..., parameter is an user defined text.
Dims_nb is the number of dimenssions of the data ( 1 for a vector).
The following value are the the length of each dims. You must have the same number of length than dim.
*/
void blc_channel_create(blc_channel* channel, const char *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/*Open an exisiting channel 'name' */
void blc_channel_open(blc_channel* channel, const char *name, int mode);
int blc_channel_create_or_open(blc_channel *channel, const char *name, int mode, uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/** Close the channel and unlink the shared memory. No new process can use it.*/
int blc_channel_unlink(blc_channel *channel);
/** Allocate (need to be free) and give the array of existing shared memory files on the system.*/
int blc_channel_get_all_infos(blc_channel **channels_infos);
/** Allocate (need to be free) and give the array of existing shared memory files on the system.*/
int blc_channel_get_all_infos_with_filter(blc_channel **channels_infos, char const *start_name_filter);
///Retrieve the informations about a channel if it is known and return the id. Otherwise, return -1
int blc_channel_get_info_with_name(blc_channel *info, char const *name);
/** Remove the channels
* \param channels Address of a pointer to an array containing a list of channel. This array may have been created by blc_channel_get_availables.
* \param channels_nb number of channels in the array.*/
void blc_channel_close_all(blc_channel *channels, int channels_nb);
void blc_channel_begin_write(blc_channel *channel);
void blc_channel_end_write(blc_channel *channel);
void blc_channel_begin_read(blc_channel *channel);
void blc_channel_end_read(blc_channel *channel);
void blc_channel_check_changes(void(*callback)(void* user_data), void *user_data);
END_EXTERN_C
///@}
#endif
This diff is collapsed.
This diff is collapsed.
Supports Markdown
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