From 783b3154cd7b4dbc3fea453dac5f7af09a011ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 10 Jun 2012 11:42:13 +0200 Subject: rename Eiotas->Edoors --- .gitignore | 2 +- CMakeLists.txt | 18 +- build.sh | 2 +- cmakeconfig.h.in | 8 +- src/include/Edoors.h | 42 +++++ src/include/Eiotas.h | 42 ----- src/include/edoors_board.h | 80 +++++++++ src/include/edoors_door.h | 79 +++++++++ src/include/edoors_iota.h | 96 +++++++++++ src/include/edoors_link.h | 54 ++++++ src/include/edoors_main.h | 86 ++++++++++ src/include/edoors_particle.h | 201 ++++++++++++++++++++++ src/include/edoors_room.h | 75 +++++++++ src/include/edoors_spin.h | 129 +++++++++++++++ src/include/edoors_userbits.h | 90 ++++++++++ src/include/eiotas_board.h | 80 --------- src/include/eiotas_door.h | 79 --------- src/include/eiotas_iota.h | 96 ----------- src/include/eiotas_link.h | 54 ------ src/include/eiotas_main.h | 86 ---------- src/include/eiotas_particle.h | 201 ---------------------- src/include/eiotas_room.h | 75 --------- src/include/eiotas_spin.h | 129 --------------- src/include/eiotas_userbits.h | 90 ---------- src/lib/CMakeLists.txt | 28 ++-- src/lib/edoors_board.c | 33 ++++ src/lib/edoors_door.c | 48 ++++++ src/lib/edoors_iota.c | 91 ++++++++++ src/lib/edoors_link.c | 27 +++ src/lib/edoors_main.c | 58 +++++++ src/lib/edoors_particle.c | 376 ++++++++++++++++++++++++++++++++++++++++++ src/lib/edoors_private.h | 126 ++++++++++++++ src/lib/edoors_room.c | 48 ++++++ src/lib/edoors_spin.c | 91 ++++++++++ src/lib/eiotas_board.c | 33 ---- src/lib/eiotas_door.c | 48 ------ src/lib/eiotas_iota.c | 91 ---------- src/lib/eiotas_link.c | 27 --- src/lib/eiotas_main.c | 58 ------- src/lib/eiotas_particle.c | 376 ------------------------------------------ src/lib/eiotas_private.h | 126 -------------- src/lib/eiotas_room.c | 48 ------ src/lib/eiotas_spin.c | 91 ---------- tests/CMakeLists.txt | 6 +- tests/helper.c | 4 +- tests/helper.h | 2 +- tests/main.c | 8 +- tests/particle.c | 152 ++++++++--------- tests/spin.c | 36 ++-- tests/user_door.c | 22 +-- 50 files changed, 1974 insertions(+), 1974 deletions(-) create mode 100644 src/include/Edoors.h delete mode 100644 src/include/Eiotas.h create mode 100644 src/include/edoors_board.h create mode 100644 src/include/edoors_door.h create mode 100644 src/include/edoors_iota.h create mode 100644 src/include/edoors_link.h create mode 100644 src/include/edoors_main.h create mode 100644 src/include/edoors_particle.h create mode 100644 src/include/edoors_room.h create mode 100644 src/include/edoors_spin.h create mode 100644 src/include/edoors_userbits.h delete mode 100644 src/include/eiotas_board.h delete mode 100644 src/include/eiotas_door.h delete mode 100644 src/include/eiotas_iota.h delete mode 100644 src/include/eiotas_link.h delete mode 100644 src/include/eiotas_main.h delete mode 100644 src/include/eiotas_particle.h delete mode 100644 src/include/eiotas_room.h delete mode 100644 src/include/eiotas_spin.h delete mode 100644 src/include/eiotas_userbits.h create mode 100644 src/lib/edoors_board.c create mode 100644 src/lib/edoors_door.c create mode 100644 src/lib/edoors_iota.c create mode 100644 src/lib/edoors_link.c create mode 100644 src/lib/edoors_main.c create mode 100644 src/lib/edoors_particle.c create mode 100644 src/lib/edoors_private.h create mode 100644 src/lib/edoors_room.c create mode 100644 src/lib/edoors_spin.c delete mode 100644 src/lib/eiotas_board.c delete mode 100644 src/lib/eiotas_door.c delete mode 100644 src/lib/eiotas_iota.c delete mode 100644 src/lib/eiotas_link.c delete mode 100644 src/lib/eiotas_main.c delete mode 100644 src/lib/eiotas_particle.c delete mode 100644 src/lib/eiotas_private.h delete mode 100644 src/lib/eiotas_room.c delete mode 100644 src/lib/eiotas_spin.c diff --git a/.gitignore b/.gitignore index 665282a..b2a6992 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *~ -eiotas-build/ +edoors-build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ca4910c..02a46e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,21 @@ cmake_minimum_required(VERSION 2.6) -project(eiotas) -set(EIOTAS_VERSION_MAJOR 0) -set(EIOTAS_VERSION_MINOR 0) -set(EIOTAS_VERSION_MICRO 1) -set(EIOTAS_VERSION ${EIOTAS_VERSION_MAJOR}.${EIOTAS_VERSION_MINOR}.${EIOTAS_VERSION_MICRO}) +project(edoors) +set(EDOORS_VERSION_MAJOR 0) +set(EDOORS_VERSION_MINOR 0) +set(EDOORS_VERSION_MICRO 1) +set(EDOORS_VERSION ${EDOORS_VERSION_MAJOR}.${EDOORS_VERSION_MINOR}.${EDOORS_VERSION_MICRO}) set(PACKAGE ${CMAKE_PROJECT_NAME}) -set(PACKAGE_VERSION ${EIOTAS_VERSION_MAJOR}.${EIOTAS_VERSION_MINOR}.${EIOTAS_VERSION_MICRO}) +set(PACKAGE_VERSION ${EDOORS_VERSION_MAJOR}.${EDOORS_VERSION_MINOR}.${EDOORS_VERSION_MICRO}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") # debug IF(WANT_DEBUG) SET(CMAKE_BUILD_TYPE Debug) - SET(EIOTAS_HAVE_DEBUG TRUE) + SET(EDOORS_HAVE_DEBUG TRUE) ELSE() SET(CMAKE_BUILD_TYPE Release) - SET(EIOTAS_HAVE_DEBUG FALSE) + SET(EDOORS_HAVE_DEBUG FALSE) ENDIF() # c flags @@ -37,7 +37,7 @@ ADD_DEFINITIONS(-DPACKAGE_BIN_DIR="${CMAKE_INSTALL_PREFIX}/bin" ADD_DEFINITIONS(-DHAVE_CONFIG_H) configure_file ( "${PROJECT_SOURCE_DIR}/cmakeconfig.h.in" - "${PROJECT_BINARY_DIR}/src/include/eiotas_config.h" + "${PROJECT_BINARY_DIR}/src/include/edoors_config.h" ) include_directories ("${PROJECT_BINARY_DIR}/src/include") diff --git a/build.sh b/build.sh index 8269b17..70726d2 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ CMAKE_OPTIONS=" -DWANT_DEBUG=1 \ " MAKE_OPTS="-j 3" -BUILD_DIR=./eiotas-build +BUILD_DIR=./edoors-build [ -f cmake_opts ] && source cmake_opts diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 301f61f..fab858f 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -1,9 +1,9 @@ #define PACKAGE "@CMAKE_PROJECT_NAME@" #define PACKAGE_NAME "@PACKAGE@" -#define VERSION "@EIOTAS_VERSION@" -#define VMAJ @EIOTAS_VERSION_MAJOR@ -#define VMIN @EIOTAS_VERSION_MINOR@ -#define VMIC @EIOTAS_VERSION_MICRO@ +#define VERSION "@EDOORS_VERSION@" +#define VMAJ @EDOORS_VERSION_MAJOR@ +#define VMIN @EDOORS_VERSION_MINOR@ +#define VMIC @EDOORS_VERSION_MICRO@ #cmakedefine HAVE___ATTRIBUTE__ #ifdef HAVE___ATTRIBUTE__ diff --git a/src/include/Edoors.h b/src/include/Edoors.h new file mode 100644 index 0000000..2c34aa3 --- /dev/null +++ b/src/include/Edoors.h @@ -0,0 +1,42 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_H__ +#define __EDOORS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "edoors_main.h" + +#include "edoors_particle.h" +#include "edoors_iota.h" +#include "edoors_link.h" +#include "edoors_room.h" +#include "edoors_door.h" +#include "edoors_board.h" +#include "edoors_spin.h" + +#include "edoors_userbits.h" + +#ifdef __cplusplus +} +#endif + +#endif // __EDOORS_H__ diff --git a/src/include/Eiotas.h b/src/include/Eiotas.h deleted file mode 100644 index 4ae6c2c..0000000 --- a/src/include/Eiotas.h +++ /dev/null @@ -1,42 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_H__ -#define __EIOTAS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "eiotas_main.h" - -#include "eiotas_particle.h" -#include "eiotas_iota.h" -#include "eiotas_link.h" -#include "eiotas_room.h" -#include "eiotas_door.h" -#include "eiotas_board.h" -#include "eiotas_spin.h" - -#include "eiotas_userbits.h" - -#ifdef __cplusplus -} -#endif - -#endif // __EIOTAS_H__ diff --git a/src/include/edoors_board.h b/src/include/edoors_board.h new file mode 100644 index 0000000..a04e325 --- /dev/null +++ b/src/include/edoors_board.h @@ -0,0 +1,80 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_BOARD_H__ +#define __EDOORS_BOARD_H__ + +#include "edoors_iota.h" +#include "edoors_room.h" +#include "edoors_userbits.h" + +#include + +/** + * @typedef Edoors_Board + * Type for a Particle Merging Door. + */ +typedef struct _Edoors_Board Edoors_Board; + +/** + * @struct _Edoors_Board + * Struct for a Particle Merging Door. + */ +struct _Edoors_Board { + Edoors_Iota iota; /**< structural info */ + Edoors_User_Bits user_bits; /**< user bits */ + Eina_Hash *postponed; /**< TODO Particles */ +}; + +/** + * @defgroup Edoors_Board Edoors_Board + * + * A Edoors_Board holds @ref Edoors_Particle received. + * When two @ref Edoors_Particle with the same link_value exists, they are merged together + * and delivered to user code through Edoors_Receive_Particle callback. + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param board The @ref Edoors_Board to free. + * + * This function will free all it's user data using user_bits ... FIXME + */ +void edoors_board_free(Edoors_Board *board); + +/** + * @brief Allocate the resources. + * + * @param name The name of this door. + * @param parent The direct hierarchical parent @ref Edoors_Room. + * @param user_bits A Edoors_User_Bits initilized with user side pointers. + * + * @return the new allocated @ref Edoors_Board @c NULL on failure + * + * @see Edoors_User_Bits + */ +EAPI Edoors_Board* edoors_board_add(const char* name, const Edoors_Room *parent, Edoors_User_Bits *user_bits); + +/** + * @} + */ + +#endif // __EDOORS_BOARD_H__ diff --git a/src/include/edoors_door.h b/src/include/edoors_door.h new file mode 100644 index 0000000..0017e73 --- /dev/null +++ b/src/include/edoors_door.h @@ -0,0 +1,79 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_DOOR_H__ +#define __EDOORS_DOOR_H__ + +#include "edoors_iota.h" +#include "edoors_room.h" +#include "edoors_userbits.h" + +#include + +/** + * @typedef Edoors_Door + * Type for a basic Door. + */ +typedef struct _Edoors_Door Edoors_Door; + +/** + * @struct _Edoors_Door + * Struct for a basic Door. + */ +struct _Edoors_Door { + Edoors_Iota iota; /**< structural info */ + Edoors_User_Bits user_bits; /**< user bits */ +}; + +/** + * @defgroup Edoors_Door Edoors_Door + * + * A Edoors_Door is the main structure used to interact with user code. + * @ref Edoors_Particle sent to user code are, follower and sent releaseed + * through edoors_spin_release_particle if not cprrectly managed by user code. + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param door The @ref Edoors_Door to free. + * + * This function will free all it's user data using user_bits ... FIXME + */ +void edoors_door_free(Edoors_Door *door); + +/** + * @brief Allocate the resources. + * + * @param name The name of this door. + * @param parent The direct hierarchical parent @ref Edoors_Room. + * @param user_bits A Edoors_User_Bits initilized with user side pointers. + * + * @return the new allocated @ref Edoors_Door @c NULL on failure + * + * @see Edoors_User_Bits + */ +EAPI Edoors_Door* edoors_door_add(const char* name, const Edoors_Room *parent, Edoors_User_Bits *user_bits); + +/** + * @} + */ + +#endif // __EDOORS_DOOR_H__ diff --git a/src/include/edoors_iota.h b/src/include/edoors_iota.h new file mode 100644 index 0000000..e6aaf64 --- /dev/null +++ b/src/include/edoors_iota.h @@ -0,0 +1,96 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_IOTA_H__ +#define __EDOORS_IOTA_H__ + +#include + +/** + * @enum _Edoors_Type + * List of available Edoors_Iota + */ +typedef enum _Edoors_Type +{ + EDOORS_TYPE_SPIN=0, + EDOORS_TYPE_ROOM, + EDOORS_TYPE_DOOR, + EDOORS_TYPE_BOARD, + EDOORS_TYPE_COUNT +} Edoors_Type; + +/** + * @typedef Edoors_Iota + * Type for structural and hierachical info + */ +typedef struct _Edoors_Iota Edoors_Iota; + +/** + * @struct _Edoors_Iota + * Struct for structural and hierachical info. + */ +struct _Edoors_Iota { + Edoors_Type type; /**< type of the iota */ + Edoors_Iota *spin; /**< top level iota which is a @ref Edoors_Spin */ + Edoors_Iota *parent; /**< direct parent in the hierarchy */ + Eina_Stringshare *name; /**< iota's name */ + Eina_Stringshare *path; /**< full path to this @ref Edoors_Iota */ +}; + +/** + * @defgroup Edoors_Iota Edoors_Iota + * + * This is the structural info stored in each @ref Edoors_Room, @ref Edoors_Door, @ref Edoors_Board + * + * @{ + */ + +/** + * @brief Print iota information using EINA_LOG_DBG. + * + * @param iota The @ref Edoors_Iota to show. + */ +EAPI void edoors_iota_show(Edoors_Iota *iota); + +/** + * @brief Free allocated resources. + * + * @param iota The @ref Edoors_Iota to free. + * + */ +void edoors_iota_free(Edoors_Iota *iota); + +/** + * @brief Require a @ref Edoors_Particle from the free list. + * + * @see edoors_spin_require_particle + */ +#define edoors_iota_require_particle(_iota) edoors_spin_require_particle((Edoors_Spin*)(_iota)->spin) + +/** + * @brief Release a particle. + * + * @see edoors_spin_release_particle + */ +#define edoors_iota_release_particle(_iota,_particle) edoors_spin_release_particle((Edoors_Spin*)(_iota)->spin,_particle) + +/** + * @} + */ + +#endif // __EDOORS_IOTA_H__ diff --git a/src/include/edoors_link.h b/src/include/edoors_link.h new file mode 100644 index 0000000..e0dc5fd --- /dev/null +++ b/src/include/edoors_link.h @@ -0,0 +1,54 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_LINK_H__ +#define __EDOORS_LINK_H__ + +/** + * @typedef Edoors_Link + * Type for a Link between @ref Edoors_Iota. + */ +typedef struct _Edoors_Link Edoors_Link; + +/** + * @struct _Edoors_Link + * Struct for a Link between @ref Edoors_Iota. + */ +struct _Edoors_Link { +}; + +/** + * @defgroup Edoors_Link Edoors_Link + * + * A Edoors_Link allows to apply a destination list to a @ref Edoors_Particle with no defined destination. + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param link The @ref Edoors_Link to free. + */ +void edoors_link_free(Edoors_Link *link); + +/** + * @} + */ + +#endif // __EDOORS_LINK_H__ diff --git a/src/include/edoors_main.h b/src/include/edoors_main.h new file mode 100644 index 0000000..01fe818 --- /dev/null +++ b/src/include/edoors_main.h @@ -0,0 +1,86 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_MAIN_H__ +#define __EDOORS_MAIN_H__ + +#include + +/** + * @typedef Edoors_Version + * Type for the version of Edoors. + */ +typedef struct _Edoors_Version Edoors_Version; + +/** + * @struct _Edoors_Version + * Struct version of Edoors. + */ +struct _Edoors_Version +{ + int major; /**< Major component of the version */ + int minor; /**< Minor component of the version */ + int micro; /**< Micro component of the version */ +}; + +EAPI extern Edoors_Version *edoors_version; + +EAPI extern int _edoors_log_dom; + +/** + * @defgroup Edoors_Main Edoors + * + * @{ + */ + +/** + * @brief Initialize the Edoors library. + * + * @return 1 or greater on success, 0 on error. + * + * This function sets up all the edoors modules. It returns 0 on + * failure (that is, when one of the module fails to initialize), + * otherwise it returns the number of times it has already been + * called. + * + * When Edoors is not used anymore, call edoors_shutdown() to shut down + * the Edoorslibrary. + */ +EAPI int edoors_init(); + +/** + * @brief Shut down the Edoors library. + * + * @return 0 when all the modules are completely shut down, 1 or + * greater otherwise. + * + * This function shuts down the Edoors library. It returns 0 when it has + * been called the same number of times than edoors_init(). In that case + * it shut down all the Edoors modules. + * + * Once this function succeeds (that is, @c 0 is returned), you must + * not call any of the Edoors function anymore. You must call + * edoors_init() again to use the Edoors functions again. + */ +EAPI int edoors_shutdown(); + +/** + * @} + */ + +#endif // __EDOORS_MAIN_H__ diff --git a/src/include/edoors_particle.h b/src/include/edoors_particle.h new file mode 100644 index 0000000..0aebd14 --- /dev/null +++ b/src/include/edoors_particle.h @@ -0,0 +1,201 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_PARTICLE_H__ +#define __EDOORS_PARTICLE_H__ + +#include +#include +#include +#include +#include + +#include "edoors_iota.h" + +/** + * @typedef Edoors_Particle + * Type for a Particle, holding data and spinning from Iotas to Iotas. + */ +typedef struct _Edoors_Particle Edoors_Particle; + +/** + * @struct _Edoors_Particle + * Struct for a Particle, holding data and spinning from Iotas to Iotas. + */ +struct _Edoors_Particle { + EINA_INLIST; /**< the Eina_Inlist info */ + time_t ts; /**< creation time */ + Edoors_Iota *src; /**< where it's born */ + Edoors_Iota *dst; /**< current destination */ + Eina_Array *dsts; /**< array of destinatinon strings */ + unsigned int cur_dst; /**< current destination index */ + Eina_Stringshare *cur_action; /**< action part of the current destination */ + Eina_Stringshare *cur_door; /**< door part of the current destination */ + Eina_Stringshare *cur_room; /**< room part of the current destination */ + Eina_Hash *payload; /**< string data carried by this particle */ + Eina_Inlist *merged; /**< list of merged particles */ + Eina_Array *link_fields; /**< fields used to generate the link value */ + Eina_Stringshare *link_value; /**< computed from link_fields and paylod, used for pearing particles */ +}; + +/** + * @defgroup Edoors_Particle Edoors_Particle + * + * The central part of Edoors. The Particle holds, the data, the destination list. + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param particle The @ref Edoors_Particle to free. + * + * This function will free all the merged @ref Edoors_Particle + */ +void edoors_particle_free(Edoors_Particle *particle); + +/** + * @brief Allocate the resources. + * + * @return the new allocated @ref Edoors_Particle @c NULL on failure + */ +Edoors_Particle* edoors_particle_alloc(); + +/** + * @brief Reset the @ref Edoors_Particle so that it can be required later. + * + * @param particle The @ref Edoors_Particle to reset + */ +EAPI void edoors_particle_reset(Edoors_Particle *particle); + +/** + * @brief Set @c src and @c ts timestamp. + * + * @param particle The @ref Edoors_Particle to init + * @param iota The @ref Edoors_Iota wich will be set as @c src + */ +EAPI void edoors_particle_init(Edoors_Particle *particle, Edoors_Iota *iota); + +/** + * @brief Merge a @ref Edoors_Particle into the other. + * + * @param particle The @ref Edoors_Particle to hold @p p + * @param p The @ref Edoors_Particle to be merged into @p particle + */ +EAPI void edoors_particle_merge(Edoors_Particle *particle, const Edoors_Particle *p); + +/** + * @brief Check if a current destination is defined + * + * @param particle The @ref Edoors_Particle to check + * + * @return EINA_TRUE if a current destination is defined, EINA_FALSE otherwise. + */ +EAPI Eina_Bool edoors_particle_has_dst(Edoors_Particle *particle); + +/** + * @brief Point to the next destination + * + * @param particle The @ref Edoors_Particle to mofify + * + * @return EINA_TRUE if next destination is defined, EINA_FALSE otherwise. + */ +EAPI Eina_Bool edoors_particle_next_dst(Edoors_Particle *particle); + +/** + * @brief Split current destination in room ; door ; action Eina_Stringshare + * + * @param particle The @ref Edoors_Particle to split current destination + * + */ +EAPI void edoors_particle_split_dst(Edoors_Particle *particle); + +/** + * @brief Add a destination and set it as current + * + * @param particle The @ref Edoors_Particle to add destination to + * @param destination The destination to add and set as current + */ +EAPI void edoors_particle_destination_set(Edoors_Particle *particle, const char *destination); + +/** + * @brief Add destinations to the @ref Edoors_Particle + * + * @param particle The @ref Edoors_Particle to add destinations to + * @param destinations A comma separated list of destination "/room0/room1/.../doorx?action" + * + * This function will append each destination found to the destination list of the @ref Edoors_Particle. + */ +EAPI void edoors_particle_destinations_add(Edoors_Particle *particle, const char *destinations); + +/** + * @brief Set the link fields + * + * @param particle The @ref Edoors_Particle to set the link fields to + * @param link_fields A comma separated list of fields name + * + */ +EAPI void edoors_particle_link_fields_set(Edoors_Particle *particle, const char *link_fields); + +/** + * @brief Restore the data associated to a given key + * + * @param particle The @ref Edoors_Particle to restore data from + * @param key The Eina_Hash key + * + * @return The data stored on success, NULL otherwise. + */ +EAPI const char* edoors_particle_data_get(Edoors_Particle *particle, const char *key); + +/** + * @brief Store a key:value data couple into the Edoors_Particle + * + * @param particle The @ref Edoors_Particle to store data into + * @param key The Eina_Hash key + * @param value The value to store + * + * @return EINA_FALSE if an error occurred, EINA_TRUE otherwise. + */ +EAPI Eina_Bool edoors_particle_data_set(Edoors_Particle *particle, const char *key, const char *value); + +/** + * @brief Delete the data associated to a given key + * + * @param particle The @ref Edoors_Particle to delete data from + * @param key The Eina_Hash key + * + * @return EINA_FALSE if an error occurred, EINA_TRUE otherwise. + */ +EAPI Eina_Bool edoors_particle_data_del(Edoors_Particle *particle, const char *key); + +/** + * @brief Check if two @ref Edoors_Particle have the same link_value + * + * @param particle The @ref Edoors_Particle to compare with + * @param p The @ref Edoors_Particle to compare with + * + * @return EINA_TRUE if the link value is the same, EINA_FALSE otherwise. + */ +EAPI Eina_Bool edoors_particle_match(Edoors_Particle *particle, const Edoors_Particle *p); + +/** + * @} + */ + +#endif // __EDOORS_PARTICLE_H__ diff --git a/src/include/edoors_room.h b/src/include/edoors_room.h new file mode 100644 index 0000000..2ccb4d7 --- /dev/null +++ b/src/include/edoors_room.h @@ -0,0 +1,75 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_ROOM_H__ +#define __EDOORS_ROOM_H__ + +#include "edoors_iota.h" + +#include + +/** + * @typedef Edoors_Room + * Type for a Room, which holds other child @ref Edoors_Iota. + */ +typedef struct _Edoors_Room Edoors_Room; + +/** + * @struct _Edoors_Room + * Struct for a Room, which holds other child @ref Edoors_Iota. + */ +struct _Edoors_Room { + Edoors_Iota iota; /**< @ref Edoors_Iota structural info */ + Eina_Hash *links; /**< TODO */ + Eina_Hash *children; /**< stringshared values optimized hash table holding @ref Edoors_Iota */ +}; + +/** + * @defgroup Edoors_Room Edoors_Room + * + * A Edoors_Room may hold children @ref Edoors_Room or @ref Edoors_Door (@ref Edoors_Board). + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param room The @ref Edoors_Room to free. + * + * This function will free all it's child @ref Edoors_Iota. + */ +void edoors_room_free(Edoors_Room *room); + +/** + * @brief Print iota information using EINA_LOG_DBG. + * + * @param name The name of this @ref Edoors_Iota. + * @param parent The direct hierarchical parent @ref Edoors_Room. + * + * @return the new @ref Edoors_Room, @c NULL on failure + * + * This function will register the new room as a child of it's parent @ref Edoors_Room. + */ +EAPI Edoors_Room* edoors_room_add(const char* name, const Edoors_Room *parent); + +/** + * @} + */ + +#endif // __EDOORS_ROOM_H__ diff --git a/src/include/edoors_spin.h b/src/include/edoors_spin.h new file mode 100644 index 0000000..92c0744 --- /dev/null +++ b/src/include/edoors_spin.h @@ -0,0 +1,129 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_SPIN_H__ +#define __EDOORS_SPIN_H__ + +#include "edoors_room.h" +#include "edoors_iota.h" +#include "edoors_particle.h" + +#include +#include + +/** + * @typedef Edoors_Spin + * Type for a Spin, the top level Room which holds @ref Edoors_Particle fifos and free @ref Edoors_Particle. + */ +typedef struct _Edoors_Spin Edoors_Spin; + +/** + * @struct _Edoors_Spin + * Struct for a Spin, the top level Room which holds @ref Edoors_Particle fifos and free @ref Edoors_Particle. + */ +struct _Edoors_Spin { + Edoors_Room room; /**< higher level Room */ + Eina_Array *free_particles; /**< lifo of free to reuse @ref Edoors_Particle TODO support different particle types, use an Eina_Hash */ + Eina_Inlist *app_fifo; /**< fifo of application priority particles */ + Eina_Inlist *sys_fifo; /**< fifo of system priority particles */ +}; + +/** + * @defgroup Edoors_Spin Edoors_Spin + * + * A Edoors_Spin is the top level object. It holds @ref Edoors_Particle free list, + * @ref Edoors_Particle system and application fifos. + * + * @{ + */ + +/** + * @brief Free allocated resources. + * + * @param spin The @ref Edoors_Spin to free. + * + * This function will free all it's child Iotas, + * all the @ref Edoors_Particle holded in app_fifo, sys_fifo and free_particles. + */ +EAPI void edoors_spin_free(Edoors_Spin *spin); + +/** + * @brief Allocate the resources. + * + * @param name The name of this spin. + * @param step The count of pointers to add when increasing the fifo size. + * + * @return the new allocated @ref Edoors_Spin @c NULL on failure + * + * @see eina_array_new(). + */ +EAPI Edoors_Spin* edoors_spin_add(const char* name, unsigned int step); + +/** + * @brief Require a @ref Edoors_Particle from the free list. + * + * @param spin The @ref Edoors_Spin to require a @ref Edoors_Particle from. + * + * @return a ready to use @ref Edoors_Particle + * + * This function will allocate and initialize a new @ref Edoors_Particle if there is none in the free list. + */ +EAPI Edoors_Particle* edoors_spin_require_particle(Edoors_Spin *spin); + +/** + * @brief Release a particle. + * + * @param spin The @ref Edoors_Spin to restore the particle to. + * @param particle The @ref Edoors_Particle to be restored. + * + * This function calls edoors_particle_reset() before giving back the @ref Edoors_Particle. + * Each @ref Edoors_Particle merged in the first one are also released. + * + * @see edoors_particle_reset(). + */ +EAPI void edoors_spin_release_particle(Edoors_Spin *spin, Edoors_Particle *particle); + +/** + * @brief Append the @ref Edoors_Particle to the app or sys fifo. + * + * @param spin The @ref Edoors_Spin to post the particle to. + * @param particle The @ref Edoors_Particle to be sent. + * @param system Post to the system fifo us true, otherwise to the application fifo. + * + */ +EAPI void edoors_spin_send_particle(Edoors_Spin *spin, const Edoors_Particle *particle, Eina_Bool system); + +/** + * @brief Require a @ref Edoors_Particle from the free list. + * + * @see edoors_spin_require_particle + */ +#define edoors_require_particle(_iota) edoors_spin_require_particle((Edoors_Spin*)((Edoors_Iota*)(_iota))->spin) + +/** + * @brief Release a particle. + * + * @see edoors_spin_release_particle + */ +#define edoors_release_particle(_iota,_particle) edoors_spin_release_particle((Edoors_Spin*)((Edoors_Iota*)(_iota))->spin,_particle) + +/** + * @} + */ + +#endif // __EDOORS_SPIN_H__ diff --git a/src/include/edoors_userbits.h b/src/include/edoors_userbits.h new file mode 100644 index 0000000..55eb81b --- /dev/null +++ b/src/include/edoors_userbits.h @@ -0,0 +1,90 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_USERBITS_H__ +#define __EDOORS_USERBITS_H__ + +#include "edoors_iota.h" +#include "edoors_particle.h" + +/** + * @typedef Edoors_User_Bits + * Type for a @ref Edoors_User_Bits. + */ +typedef struct _Edoors_User_Bits Edoors_User_Bits; + +/** + * @typedef Edoors_User_Data + * Struct for user allocated data attached to a @ref Edoors_Door or a @ref Edoors_Board + */ +typedef void Edoors_User_Data; + +/** + * @typedef Edoors_User_Data + * Type for function called on resources free + * + * @see edoors_door_free() + * @see edoors_board_free() + */ +typedef void (*Edoors_User_Data_Free) (Edoors_User_Data*); + +/** + * @typedef Edoors_Receive_Particle + * Type for function called on @ref Edoors_Particle receive + */ +typedef void (*Edoors_Receive_Particle) (Edoors_Iota *iota, Edoors_Particle *particle, Edoors_User_Data *data); + +/** + * @typedef Edoors_Init + * Type for function called on systsem init + */ +typedef void (*Edoors_Init) (Edoors_Iota *iota, Edoors_User_Data *data); + +/** + * @typedef Edoors_Shutdown + * Type for function called on system shutdown + */ +typedef void (*Edoors_Shutdown) (Edoors_Iota *iota, Edoors_User_Data *data); + +/** + * @typedef Edoors_Suspend + * Type for function called on system suspend + */ +typedef void (*Edoors_Suspend) (Edoors_Iota *iota, Edoors_User_Data *data); + +/** + * @typedef Edoors_Resume + * Type for function called on system resume + */ +typedef void (*Edoors_Resume) (Edoors_Iota *iota, Edoors_User_Data *data); + +/** + * @struct _Edoors_User_Bits + * Struct for a Edoors_User_Bits. + */ +struct _Edoors_User_Bits { + Edoors_User_Data *data; /**< user data */ + Edoors_User_Data_Free free_fct; /**< to free user data */ + Edoors_Receive_Particle recv_fct; /**< to receive and process a @ref Edoors_Particle */ + Edoors_Init init_fct; /**< to initialize user data on system init */ + Edoors_Shutdown shutdown_fct; /**< to finalize user data on system shutdown */ + Edoors_Suspend suspend_fct; /**< to serialize user data on system shutdown */ + Edoors_Resume resume_fct; /**< to deserialize data on system resume */ +}; + +#endif // __EDOORS_USERBITS_H__ diff --git a/src/include/eiotas_board.h b/src/include/eiotas_board.h deleted file mode 100644 index f12f8fc..0000000 --- a/src/include/eiotas_board.h +++ /dev/null @@ -1,80 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_BOARD_H__ -#define __EIOTAS_BOARD_H__ - -#include "eiotas_iota.h" -#include "eiotas_room.h" -#include "eiotas_userbits.h" - -#include - -/** - * @typedef Eiotas_Board - * Type for a Particle Merging Door. - */ -typedef struct _Eiotas_Board Eiotas_Board; - -/** - * @struct _Eiotas_Board - * Struct for a Particle Merging Door. - */ -struct _Eiotas_Board { - Eiotas_Iota iota; /**< structural info */ - Eiotas_User_Bits user_bits; /**< user bits */ - Eina_Hash *postponed; /**< TODO Particles */ -}; - -/** - * @defgroup Eiotas_Board Eiotas_Board - * - * A Eiota_Board holds @ref Eiotas_Particle received. - * When two @ref Eiotas_Particle with the same link_value exists, they are merged together - * and delivered to user code through Eiotas_Receive_Particle callback. - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param board The @ref Eiotas_Board to free. - * - * This function will free all it's user data using user_bits ... FIXME - */ -void eiotas_board_free(Eiotas_Board *board); - -/** - * @brief Allocate the resources. - * - * @param name The name of this door. - * @param parent The direct hierarchical parent @ref Eiotas_Room. - * @param user_bits A Eiotas_User_Bits initilized with user side pointers. - * - * @return the new allocated @ref Eiotas_Board @c NULL on failure - * - * @see Eiotas_User_Bits - */ -EAPI Eiotas_Board* eiotas_board_add(const char* name, const Eiotas_Room *parent, Eiotas_User_Bits *user_bits); - -/** - * @} - */ - -#endif // __EIOTAS_BOARD_H__ diff --git a/src/include/eiotas_door.h b/src/include/eiotas_door.h deleted file mode 100644 index 6d7e481..0000000 --- a/src/include/eiotas_door.h +++ /dev/null @@ -1,79 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_DOOR_H__ -#define __EIOTAS_DOOR_H__ - -#include "eiotas_iota.h" -#include "eiotas_room.h" -#include "eiotas_userbits.h" - -#include - -/** - * @typedef Eiotas_Door - * Type for a basic Door. - */ -typedef struct _Eiotas_Door Eiotas_Door; - -/** - * @struct _Eiotas_Door - * Struct for a basic Door. - */ -struct _Eiotas_Door { - Eiotas_Iota iota; /**< structural info */ - Eiotas_User_Bits user_bits; /**< user bits */ -}; - -/** - * @defgroup Eiotas_Door Eiotas_Door - * - * A Eiota_Door is the main structure used to interact with user code. - * @ref Eiotas_Particle sent to user code are, follower and sent releaseed - * through eiotas_spin_release_particle if not cprrectly managed by user code. - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param door The @ref Eiotas_Door to free. - * - * This function will free all it's user data using user_bits ... FIXME - */ -void eiotas_door_free(Eiotas_Door *door); - -/** - * @brief Allocate the resources. - * - * @param name The name of this door. - * @param parent The direct hierarchical parent @ref Eiotas_Room. - * @param user_bits A Eiotas_User_Bits initilized with user side pointers. - * - * @return the new allocated @ref Eiotas_Door @c NULL on failure - * - * @see Eiotas_User_Bits - */ -EAPI Eiotas_Door* eiotas_door_add(const char* name, const Eiotas_Room *parent, Eiotas_User_Bits *user_bits); - -/** - * @} - */ - -#endif // __EIOTAS_DOOR_H__ diff --git a/src/include/eiotas_iota.h b/src/include/eiotas_iota.h deleted file mode 100644 index 36ce1cc..0000000 --- a/src/include/eiotas_iota.h +++ /dev/null @@ -1,96 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_IOTA_H__ -#define __EIOTAS_IOTA_H__ - -#include - -/** - * @enum _Eiotas_Type - * List of available Eiotas_Iota - */ -typedef enum _Eiotas_Type -{ - EIOTAS_TYPE_SPIN=0, - EIOTAS_TYPE_ROOM, - EIOTAS_TYPE_DOOR, - EIOTAS_TYPE_BOARD, - EIOTAS_TYPE_COUNT -} Eiotas_Type; - -/** - * @typedef Eiotas_Iota - * Type for structural and hierachical info - */ -typedef struct _Eiotas_Iota Eiotas_Iota; - -/** - * @struct _Eiotas_Iota - * Struct for structural and hierachical info. - */ -struct _Eiotas_Iota { - Eiotas_Type type; /**< type of the iota */ - Eiotas_Iota *spin; /**< top level iota which is a @ref Eiotas_Spin */ - Eiotas_Iota *parent; /**< direct parent in the hierarchy */ - Eina_Stringshare *name; /**< iota's name */ - Eina_Stringshare *path; /**< full path to this @ref Eiotas_Iota */ -}; - -/** - * @defgroup Eiotas_Iota Eiotas_Iota - * - * This is the structural info stored in each @ref Eiotas_Room, @ref Eiotas_Door, @ref Eiotas_Board - * - * @{ - */ - -/** - * @brief Print iota information using EINA_LOG_DBG. - * - * @param iota The @ref Eiotas_Iota to show. - */ -EAPI void eiotas_iota_show(Eiotas_Iota *iota); - -/** - * @brief Free allocated resources. - * - * @param iota The @ref Eiotas_Iota to free. - * - */ -void eiotas_iota_free(Eiotas_Iota *iota); - -/** - * @brief Require a @ref Eiotas_Particle from the free list. - * - * @see eiotas_spin_require_particle - */ -#define eiotas_iota_require_particle(_iota) eiotas_spin_require_particle((Eiotas_Spin*)(_iota)->spin) - -/** - * @brief Release a particle. - * - * @see eiotas_spin_release_particle - */ -#define eiotas_iota_release_particle(_iota,_particle) eiotas_spin_release_particle((Eiotas_Spin*)(_iota)->spin,_particle) - -/** - * @} - */ - -#endif // __EIOTAS_IOTA_H__ diff --git a/src/include/eiotas_link.h b/src/include/eiotas_link.h deleted file mode 100644 index 2d10300..0000000 --- a/src/include/eiotas_link.h +++ /dev/null @@ -1,54 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_LINK_H__ -#define __EIOTAS_LINK_H__ - -/** - * @typedef Eiotas_Link - * Type for a Link between @ref Eiotas_Iota. - */ -typedef struct _Eiotas_Link Eiotas_Link; - -/** - * @struct _Eiotas_Link - * Struct for a Link between @ref Eiotas_Iota. - */ -struct _Eiotas_Link { -}; - -/** - * @defgroup Eiotas_Link Eiotas_Link - * - * A Eiota_Link allows to apply a destination list to a @ref Eiotas_Particle with no defined destination. - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param link The @ref Eiotas_Link to free. - */ -void eiotas_link_free(Eiotas_Link *link); - -/** - * @} - */ - -#endif // __EIOTAS_LINK_H__ diff --git a/src/include/eiotas_main.h b/src/include/eiotas_main.h deleted file mode 100644 index 75ac6fe..0000000 --- a/src/include/eiotas_main.h +++ /dev/null @@ -1,86 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_MAIN_H__ -#define __EIOTAS_MAIN_H__ - -#include - -/** - * @typedef Eiotas_Version - * Type for the version of Eiotas. - */ -typedef struct _Eiotas_Version Eiotas_Version; - -/** - * @struct _Eiotas_Version - * Struct version of Eiotas. - */ -struct _Eiotas_Version -{ - int major; /**< Major component of the version */ - int minor; /**< Minor component of the version */ - int micro; /**< Micro component of the version */ -}; - -EAPI extern Eiotas_Version *eiotas_version; - -EAPI extern int _eiotas_log_dom; - -/** - * @defgroup Eiotas_Main Eiotas - * - * @{ - */ - -/** - * @brief Initialize the Eiotas library. - * - * @return 1 or greater on success, 0 on error. - * - * This function sets up all the eiotas modules. It returns 0 on - * failure (that is, when one of the module fails to initialize), - * otherwise it returns the number of times it has already been - * called. - * - * When Eiotas is not used anymore, call eiotas_shutdown() to shut down - * the Eiotaslibrary. - */ -EAPI int eiotas_init(); - -/** - * @brief Shut down the Eiotas library. - * - * @return 0 when all the modules are completely shut down, 1 or - * greater otherwise. - * - * This function shuts down the Eiotas library. It returns 0 when it has - * been called the same number of times than eiotas_init(). In that case - * it shut down all the Eiotas modules. - * - * Once this function succeeds (that is, @c 0 is returned), you must - * not call any of the Eiotas function anymore. You must call - * eiotas_init() again to use the Eiotas functions again. - */ -EAPI int eiotas_shutdown(); - -/** - * @} - */ - -#endif // __EIOTAS_MAIN_H__ diff --git a/src/include/eiotas_particle.h b/src/include/eiotas_particle.h deleted file mode 100644 index ca8cc8e..0000000 --- a/src/include/eiotas_particle.h +++ /dev/null @@ -1,201 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_PARTICLE_H__ -#define __EIOTAS_PARTICLE_H__ - -#include -#include -#include -#include -#include - -#include "eiotas_iota.h" - -/** - * @typedef Eiotas_Particle - * Type for a Particle, holding data and spinning from Iotas to Iotas. - */ -typedef struct _Eiotas_Particle Eiotas_Particle; - -/** - * @struct _Eiotas_Particle - * Struct for a Particle, holding data and spinning from Iotas to Iotas. - */ -struct _Eiotas_Particle { - EINA_INLIST; /**< the Eina_Inlist info */ - time_t ts; /**< creation time */ - Eiotas_Iota *src; /**< where it's born */ - Eiotas_Iota *dst; /**< current destination */ - Eina_Array *dsts; /**< array of destinatinon strings */ - unsigned int cur_dst; /**< current destination index */ - Eina_Stringshare *cur_action; /**< action part of the current destination */ - Eina_Stringshare *cur_door; /**< door part of the current destination */ - Eina_Stringshare *cur_room; /**< room part of the current destination */ - Eina_Hash *payload; /**< string data carried by this particle */ - Eina_Inlist *merged; /**< list of merged particles */ - Eina_Array *link_fields; /**< fields used to generate the link value */ - Eina_Stringshare *link_value; /**< computed from link_fields and paylod, used for pearing particles */ -}; - -/** - * @defgroup Eiotas_Particle Eiotas_Particle - * - * The central part of Eiotas. The Particle holds, the data, the destination list. - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param particle The @ref Eiotas_Particle to free. - * - * This function will free all the merged @ref Eiotas_Particle - */ -void eiotas_particle_free(Eiotas_Particle *particle); - -/** - * @brief Allocate the resources. - * - * @return the new allocated @ref Eiotas_Particle @c NULL on failure - */ -Eiotas_Particle* eiotas_particle_alloc(); - -/** - * @brief Reset the @ref Eiotas_Particle so that it can be required later. - * - * @param particle The @ref Eiotas_Particle to reset - */ -EAPI void eiotas_particle_reset(Eiotas_Particle *particle); - -/** - * @brief Set @c src and @c ts timestamp. - * - * @param particle The @ref Eiotas_Particle to init - * @param iota The @ref Eiotas_Iota wich will be set as @c src - */ -EAPI void eiotas_particle_init(Eiotas_Particle *particle, Eiotas_Iota *iota); - -/** - * @brief Merge a @ref Eiotas_Particle into the other. - * - * @param particle The @ref Eiotas_Particle to hold @p p - * @param p The @ref Eiotas_Particle to be merged into @p particle - */ -EAPI void eiotas_particle_merge(Eiotas_Particle *particle, const Eiotas_Particle *p); - -/** - * @brief Check if a current destination is defined - * - * @param particle The @ref Eiotas_Particle to check - * - * @return EINA_TRUE if a current destination is defined, EINA_FALSE otherwise. - */ -EAPI Eina_Bool eiotas_particle_has_dst(Eiotas_Particle *particle); - -/** - * @brief Point to the next destination - * - * @param particle The @ref Eiotas_Particle to mofify - * - * @return EINA_TRUE if next destination is defined, EINA_FALSE otherwise. - */ -EAPI Eina_Bool eiotas_particle_next_dst(Eiotas_Particle *particle); - -/** - * @brief Split current destination in room ; door ; action Eina_Stringshare - * - * @param particle The @ref Eiotas_Particle to split current destination - * - */ -EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle); - -/** - * @brief Add a destination and set it as current - * - * @param particle The @ref Eiotas_Particle to add destination to - * @param destination The destination to add and set as current - */ -EAPI void eiotas_particle_destination_set(Eiotas_Particle *particle, const char *destination); - -/** - * @brief Add destinations to the @ref Eiotas_Particle - * - * @param particle The @ref Eiotas_Particle to add destinations to - * @param destinations A comma separated list of destination "/room0/room1/.../doorx?action" - * - * This function will append each destination found to the destination list of the @ref Eiotas_Particle. - */ -EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char *destinations); - -/** - * @brief Set the link fields - * - * @param particle The @ref Eiotas_Particle to set the link fields to - * @param link_fields A comma separated list of fields name - * - */ -EAPI void eiotas_particle_link_fields_set(Eiotas_Particle *particle, const char *link_fields); - -/** - * @brief Restore the data associated to a given key - * - * @param particle The @ref Eiotas_Particle to restore data from - * @param key The Eina_Hash key - * - * @return The data stored on success, NULL otherwise. - */ -EAPI const char* eiotas_particle_data_get(Eiotas_Particle *particle, const char *key); - -/** - * @brief Store a key:value data couple into the Eiotas_Particle - * - * @param particle The @ref Eiotas_Particle to store data into - * @param key The Eina_Hash key - * @param value The value to store - * - * @return EINA_FALSE if an error occurred, EINA_TRUE otherwise. - */ -EAPI Eina_Bool eiotas_particle_data_set(Eiotas_Particle *particle, const char *key, const char *value); - -/** - * @brief Delete the data associated to a given key - * - * @param particle The @ref Eiotas_Particle to delete data from - * @param key The Eina_Hash key - * - * @return EINA_FALSE if an error occurred, EINA_TRUE otherwise. - */ -EAPI Eina_Bool eiotas_particle_data_del(Eiotas_Particle *particle, const char *key); - -/** - * @brief Check if two @ref Eiotas_Particle have the same link_value - * - * @param particle The @ref Eiotas_Particle to compare with - * @param p The @ref Eiotas_Particle to compare with - * - * @return EINA_TRUE if the link value is the same, EINA_FALSE otherwise. - */ -EAPI Eina_Bool eiotas_particle_match(Eiotas_Particle *particle, const Eiotas_Particle *p); - -/** - * @} - */ - -#endif // __EIOTAS_PARTICLE_H__ diff --git a/src/include/eiotas_room.h b/src/include/eiotas_room.h deleted file mode 100644 index 53b035a..0000000 --- a/src/include/eiotas_room.h +++ /dev/null @@ -1,75 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_ROOM_H__ -#define __EIOTAS_ROOM_H__ - -#include "eiotas_iota.h" - -#include - -/** - * @typedef Eiotas_Room - * Type for a Room, which holds other child @ref Eiotas_Iota. - */ -typedef struct _Eiotas_Room Eiotas_Room; - -/** - * @struct _Eiotas_Room - * Struct for a Room, which holds other child @ref Eiotas_Iota. - */ -struct _Eiotas_Room { - Eiotas_Iota iota; /**< @ref Eiotas_Iota structural info */ - Eina_Hash *links; /**< TODO */ - Eina_Hash *children; /**< stringshared values optimized hash table holding @ref Eiotas_Iota */ -}; - -/** - * @defgroup Eiotas_Room Eiotas_Room - * - * A Eiota_Room may hold children @ref Eiotas_Room or @ref Eiotas_Door (@ref Eiotas_Board). - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param room The @ref Eiotas_Room to free. - * - * This function will free all it's child @ref Eiotas_Iota. - */ -void eiotas_room_free(Eiotas_Room *room); - -/** - * @brief Print iota information using EINA_LOG_DBG. - * - * @param name The name of this @ref Eiotas_Iota. - * @param parent The direct hierarchical parent @ref Eiotas_Room. - * - * @return the new @ref Eiotas_Room, @c NULL on failure - * - * This function will register the new room as a child of it's parent @ref Eiotas_Room. - */ -EAPI Eiotas_Room* eiotas_room_add(const char* name, const Eiotas_Room *parent); - -/** - * @} - */ - -#endif // __EIOTAS_ROOM_H__ diff --git a/src/include/eiotas_spin.h b/src/include/eiotas_spin.h deleted file mode 100644 index fbe5440..0000000 --- a/src/include/eiotas_spin.h +++ /dev/null @@ -1,129 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_SPIN_H__ -#define __EIOTAS_SPIN_H__ - -#include "eiotas_room.h" -#include "eiotas_iota.h" -#include "eiotas_particle.h" - -#include -#include - -/** - * @typedef Eiotas_Spin - * Type for a Spin, the top level Room which holds @ref Eiotas_Particle fifos and free @ref Eiotas_Particle. - */ -typedef struct _Eiotas_Spin Eiotas_Spin; - -/** - * @struct _Eiotas_Spin - * Struct for a Spin, the top level Room which holds @ref Eiotas_Particle fifos and free @ref Eiotas_Particle. - */ -struct _Eiotas_Spin { - Eiotas_Room room; /**< higher level Room */ - Eina_Array *free_particles; /**< lifo of free to reuse @ref Eiotas_Particle TODO support different particle types, use an Eina_Hash */ - Eina_Inlist *app_fifo; /**< fifo of application priority particles */ - Eina_Inlist *sys_fifo; /**< fifo of system priority particles */ -}; - -/** - * @defgroup Eiotas_Spin Eiotas_Spin - * - * A Eiota_Spin is the top level object. It holds @ref Eiotas_Particle free list, - * @ref Eiotas_Particle system and application fifos. - * - * @{ - */ - -/** - * @brief Free allocated resources. - * - * @param spin The @ref Eiotas_Spin to free. - * - * This function will free all it's child Iotas, - * all the @ref Eiotas_Particle holded in app_fifo, sys_fifo and free_particles. - */ -EAPI void eiotas_spin_free(Eiotas_Spin *spin); - -/** - * @brief Allocate the resources. - * - * @param name The name of this spin. - * @param step The count of pointers to add when increasing the fifo size. - * - * @return the new allocated @ref Eiotas_Spin @c NULL on failure - * - * @see eina_array_new(). - */ -EAPI Eiotas_Spin* eiotas_spin_add(const char* name, unsigned int step); - -/** - * @brief Require a @ref Eiotas_Particle from the free list. - * - * @param spin The @ref Eiotas_Spin to require a @ref Eiotas_Particle from. - * - * @return a ready to use @ref Eiotas_Particle - * - * This function will allocate and initialize a new @ref Eiotas_Particle if there is none in the free list. - */ -EAPI Eiotas_Particle* eiotas_spin_require_particle(Eiotas_Spin *spin); - -/** - * @brief Release a particle. - * - * @param spin The @ref Eiotas_Spin to restore the particle to. - * @param particle The @ref Eiotas_Particle to be restored. - * - * This function calls eiotas_particle_reset() before giving back the @ref Eiotas_Particle. - * Each @ref Eiotas_Particle merged in the first one are also released. - * - * @see eiotas_particle_reset(). - */ -EAPI void eiotas_spin_release_particle(Eiotas_Spin *spin, Eiotas_Particle *particle); - -/** - * @brief Append the @ref Eiotas_Particle to the app or sys fifo. - * - * @param spin The @ref Eiotas_Spin to post the particle to. - * @param particle The @ref Eiotas_Particle to be sent. - * @param system Post to the system fifo us true, otherwise to the application fifo. - * - */ -EAPI void eiotas_spin_send_particle(Eiotas_Spin *spin, const Eiotas_Particle *particle, Eina_Bool system); - -/** - * @brief Require a @ref Eiotas_Particle from the free list. - * - * @see eiotas_spin_require_particle - */ -#define eiotas_require_particle(_iota) eiotas_spin_require_particle((Eiotas_Spin*)((Eiotas_Iota*)(_iota))->spin) - -/** - * @brief Release a particle. - * - * @see eiotas_spin_release_particle - */ -#define eiotas_release_particle(_iota,_particle) eiotas_spin_release_particle((Eiotas_Spin*)((Eiotas_Iota*)(_iota))->spin,_particle) - -/** - * @} - */ - -#endif // __EIOTAS_SPIN_H__ diff --git a/src/include/eiotas_userbits.h b/src/include/eiotas_userbits.h deleted file mode 100644 index b48c7c2..0000000 --- a/src/include/eiotas_userbits.h +++ /dev/null @@ -1,90 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_USERBITS_H__ -#define __EIOTAS_USERBITS_H__ - -#include "eiotas_iota.h" -#include "eiotas_particle.h" - -/** - * @typedef Eiotas_User_Bits - * Type for a @ref Eiotas_User_Bits. - */ -typedef struct _Eiotas_User_Bits Eiotas_User_Bits; - -/** - * @typedef Eiotas_User_Data - * Struct for user allocated data attached to a @ref Eiotas_Door or a @ref Eiotas_Board - */ -typedef void Eiotas_User_Data; - -/** - * @typedef Eiotas_User_Data - * Type for function called on resources free - * - * @see eiotas_door_free() - * @see eiotas_board_free() - */ -typedef void (*Eiotas_User_Data_Free) (Eiotas_User_Data*); - -/** - * @typedef Eiotas_Receive_Particle - * Type for function called on @ref Eiotas_Particle receive - */ -typedef void (*Eiotas_Receive_Particle) (Eiotas_Iota *iota, Eiotas_Particle *particle, Eiotas_User_Data *data); - -/** - * @typedef Eiotas_Init - * Type for function called on systsem init - */ -typedef void (*Eiotas_Init) (Eiotas_Iota *iota, Eiotas_User_Data *data); - -/** - * @typedef Eiotas_Shutdown - * Type for function called on system shutdown - */ -typedef void (*Eiotas_Shutdown) (Eiotas_Iota *iota, Eiotas_User_Data *data); - -/** - * @typedef Eiotas_Suspend - * Type for function called on system suspend - */ -typedef void (*Eiotas_Suspend) (Eiotas_Iota *iota, Eiotas_User_Data *data); - -/** - * @typedef Eiotas_Resume - * Type for function called on system resume - */ -typedef void (*Eiotas_Resume) (Eiotas_Iota *iota, Eiotas_User_Data *data); - -/** - * @struct _Eiotas_User_Bits - * Struct for a Eiotas_User_Bits. - */ -struct _Eiotas_User_Bits { - Eiotas_User_Data *data; /**< user data */ - Eiotas_User_Data_Free free_fct; /**< to free user data */ - Eiotas_Receive_Particle recv_fct; /**< to receive and process a @ref Eiotas_Particle */ - Eiotas_Init init_fct; /**< to initialize user data on system init */ - Eiotas_Shutdown shutdown_fct; /**< to finalize user data on system shutdown */ - Eiotas_Suspend suspend_fct; /**< to serialize user data on system shutdown */ - Eiotas_Resume resume_fct; /**< to deserialize data on system resume */ -}; - -#endif // __EIOTAS_USERBITS_H__ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e2871fc..cd1ae1e 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,12 +1,12 @@ -LIST(APPEND EIOTAS_CC_SOURCES - eiotas_main.c - eiotas_particle.c - eiotas_link.c - eiotas_iota.c - eiotas_spin.c - eiotas_room.c - eiotas_door.c - eiotas_board.c +LIST(APPEND EDOORS_CC_SOURCES + edoors_main.c + edoors_particle.c + edoors_link.c + edoors_iota.c + edoors_spin.c + edoors_room.c + edoors_door.c + edoors_board.c ) include_directories( @@ -14,11 +14,11 @@ include_directories( ${PROJECT_SOURCE_DIR}/src/include ) -add_library(eiotas SHARED ${EIOTAS_CC_SOURCES}) -target_link_libraries(eiotas +add_library(edoors SHARED ${EDOORS_CC_SOURCES}) +target_link_libraries(edoors ${EINA_LIBRARIES} ) -set_target_properties(eiotas PROPERTIES - VERSION ${EIOTAS_VERSION} SOVERSION ${EIOTAS_VERSION_MAJOR}) -set_target_properties(eiotas PROPERTIES OUTPUT_NAME "eiotas") +set_target_properties(edoors PROPERTIES + VERSION ${EDOORS_VERSION} SOVERSION ${EDOORS_VERSION_MAJOR}) +set_target_properties(edoors PROPERTIES OUTPUT_NAME "edoors") diff --git a/src/lib/edoors_board.c b/src/lib/edoors_board.c new file mode 100644 index 0000000..452207c --- /dev/null +++ b/src/lib/edoors_board.c @@ -0,0 +1,33 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_board.h" +#include "edoors_private.h" + +EAPI Edoors_Board* edoors_board_add(const char* name, const Edoors_Room *parent, Edoors_User_Bits *user_bits) +{ + // TODO + return NULL; +} + +void edoors_board_free(Edoors_Board *board) +{ + DBG("Door free 0x%X",PRINTPTR(board)); + // TODO +} + diff --git a/src/lib/edoors_door.c b/src/lib/edoors_door.c new file mode 100644 index 0000000..60ce591 --- /dev/null +++ b/src/lib/edoors_door.c @@ -0,0 +1,48 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_door.h" +#include "edoors_private.h" + +EAPI Edoors_Door* edoors_door_add(const char* name, const Edoors_Room *parent, Edoors_User_Bits *user_bits) +{ + CHECK_PARENT(); + + CHECK_USERBITS(user_bits); + + BUILD_INSTANCE(Edoors_Door,door); + + INIT_IOTA(&door->iota,name,parent,EDOORS_TYPE_DOOR); + + ADD_TO_PARENT(parent,(&door->iota),"Door") + + memcpy(&door->user_bits,user_bits,sizeof(Edoors_User_Bits)); + + return door; +} + +void edoors_door_free(Edoors_Door *door) +{ + DBG("Door free 0x%X",PRINTPTR(door)); + + edoors_iota_desinit(&door->iota); + door->user_bits.free_fct(door->user_bits.data); + + free(door); +} + diff --git a/src/lib/edoors_iota.c b/src/lib/edoors_iota.c new file mode 100644 index 0000000..4735ba3 --- /dev/null +++ b/src/lib/edoors_iota.c @@ -0,0 +1,91 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_iota.h" +#include "edoors_spin.h" +#include "edoors_room.h" +#include "edoors_door.h" +#include "edoors_board.h" +#include "edoors_private.h" + +int edoors_iota_init(Edoors_Iota *iota, const char *name, Edoors_Iota *parent, Edoors_Type type) +{ + int ln, lp; + char tmp[EDOORS_MAX_PATH_LENGTH]; + + ln = strlen(name); + if(name==NULL || ln==0) { + ERR("name can't be NULL or empty"); + return 1; + } + + iota->type = type; + iota->spin = ( parent ? parent->spin : iota ); + iota->parent = parent; + if(parent) { + lp = eina_stringshare_strlen(parent->path); + if((ln+lp+2)>EDOORS_MAX_PATH_LENGTH) { + ERR("buffer overflow (%d)",(ln+lp+2)); + return 1; + } + memcpy(tmp,parent->path,lp); + tmp[lp]='/'; + memcpy((tmp+lp+sizeof(char)),name,ln+sizeof(char)); + iota->name = eina_stringshare_add(name); + iota->path = eina_stringshare_add(tmp); + } else { + iota->name = eina_stringshare_add(name); + iota->path = eina_stringshare_add(name); + } + + return 0; +} + +void edoors_iota_desinit(Edoors_Iota *iota) +{ + STRINGSHARE_FREE(iota->name); + STRINGSHARE_FREE(iota->path); +} + +void edoors_iota_free(Edoors_Iota *iota) +{ + switch(iota->type) { + case EDOORS_TYPE_SPIN: + edoors_spin_free((Edoors_Spin*)iota); + break; + case EDOORS_TYPE_ROOM: + edoors_room_free((Edoors_Room*)iota); + break; + case EDOORS_TYPE_DOOR: + edoors_door_free((Edoors_Door*)iota); + break; + case EDOORS_TYPE_BOARD: + edoors_board_free((Edoors_Board*)iota); + break; + default: + CRITICAL("SPANK SPANK: 0x%X type %d is unknown, memory leak",PRINTPTR(iota),iota->type); + break; + } +} + +EAPI void edoors_iota_show(Edoors_Iota *iota) +{ + DBG("Iota(%d) 0x%X : %s (%s) [0x%X] {0x%X}",iota->type,PRINTPTR(iota),iota->name,iota->path, + PRINTPTR(iota->parent),PRINTPTR(iota->spin)); +} + diff --git a/src/lib/edoors_link.c b/src/lib/edoors_link.c new file mode 100644 index 0000000..82cb2f3 --- /dev/null +++ b/src/lib/edoors_link.c @@ -0,0 +1,27 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_link.h" +#include "edoors_private.h" + +void edoors_link_free(Edoors_Link *link) +{ + DBG("Link free 0x%X",PRINTPTR(link)); + // TODO +} + diff --git a/src/lib/edoors_main.c b/src/lib/edoors_main.c new file mode 100644 index 0000000..e2242a4 --- /dev/null +++ b/src/lib/edoors_main.c @@ -0,0 +1,58 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_main.h" +#include "edoors_private.h" + +#include "eina_main.h" +#include + +static int _edoors_main_count = 0; + +int _edoors_log_dom; + +static Edoors_Version _version = { VMAJ, VMIN, VMIC }; + +EAPI Edoors_Version *edoors_version = &_version; + +EAPI int edoors_init() +{ + if (EINA_LIKELY(_edoors_main_count > 0)) + return ++_edoors_main_count; + + if(!eina_init()) { + fprintf(stderr,"Error during the initialization of Eina_Log module\n"); + return EXIT_FAILURE; + } + + _edoors_log_dom = eina_log_domain_register("edoors", EINA_COLOR_CYAN); + _edoors_main_count = 1; + + return 1; +} + +EAPI int edoors_shutdown() +{ + _edoors_main_count--; + if (EINA_UNLIKELY(_edoors_main_count == 0)) { + eina_shutdown(); + } + + return _edoors_main_count; +} + diff --git a/src/lib/edoors_particle.c b/src/lib/edoors_particle.c new file mode 100644 index 0000000..468cd5b --- /dev/null +++ b/src/lib/edoors_particle.c @@ -0,0 +1,376 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_particle.h" +#include "edoors_private.h" + +static void update_link_value(Edoors_Particle *particle, const char *field); +static char* add_destination(Edoors_Particle *particle, const char *dst); + +Edoors_Particle* edoors_particle_alloc() +{ + BUILD_INSTANCE(Edoors_Particle,particle); + + particle->ts = 0; + particle->src = NULL; + particle->dst = NULL; + particle->dsts = eina_array_new(EDOORS_PARTICLE_ARRAY_STEP); + particle->cur_dst = 0; + particle->cur_action = NULL; + particle->cur_door = NULL; + particle->cur_room = NULL; + particle->payload = eina_hash_string_small_new((Eina_Free_Cb)&eina_stringshare_del); + particle->merged = NULL; + particle->link_fields = eina_array_new(EDOORS_PARTICLE_ARRAY_STEP); + particle->link_value = NULL; + + return particle; +} + +void edoors_particle_free(Edoors_Particle *particle) +{ + unsigned int i; + Eina_Stringshare *s; + Edoors_Particle *p; + Eina_Inlist *li; + Eina_Array_Iterator it; + + DBG("Particle free 0x%X",PRINTPTR(particle)); + + EINA_ARRAY_ITER_NEXT(particle->dsts, i, s, it) eina_stringshare_del(s); + eina_array_free(particle->dsts); + STRINGSHARE_FREE(particle->cur_action); + STRINGSHARE_FREE(particle->cur_door); + STRINGSHARE_FREE(particle->cur_room); + eina_hash_free(particle->payload); + EINA_INLIST_FOREACH_SAFE(particle->merged, li, p) edoors_particle_free(p); + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); + eina_array_free(particle->link_fields); + STRINGSHARE_FREE(particle->link_value); + + free(particle); +} + +EAPI void edoors_particle_reset(Edoors_Particle *particle) +{ + unsigned int i; + Eina_Stringshare *s; + Edoors_Particle *p; + Eina_Inlist *li; + Eina_Array_Iterator it; + + particle->ts = 0; + particle->src = NULL; + particle->dst = NULL; + EINA_ARRAY_ITER_NEXT(particle->dsts, i, s, it) eina_stringshare_del(s); + eina_array_clean(particle->dsts); + particle->cur_dst = 0; + STRINGSHARE_FREE(particle->cur_action); + STRINGSHARE_FREE(particle->cur_door); + STRINGSHARE_FREE(particle->cur_room); + eina_hash_free_buckets(particle->payload); + EINA_INLIST_FOREACH_SAFE(particle->merged, li, p) edoors_particle_free(p); + particle->merged = NULL; + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); + eina_array_clean(particle->link_fields); + STRINGSHARE_FREE(particle->link_value); +} + +EAPI void edoors_particle_init(Edoors_Particle *particle, Edoors_Iota *iota) +{ + particle->src = iota; + particle->ts = time(NULL); +} + +EAPI void edoors_particle_merge(Edoors_Particle *particle, const Edoors_Particle *p) +{ + particle->merged = eina_inlist_append(particle->merged, EINA_INLIST_GET((Edoors_Particle*)p)); +} + +EAPI Eina_Bool edoors_particle_has_dst(Edoors_Particle *particle) +{ + return ( (eina_array_count_get(particle->dsts)>particle->cur_dst) ? EINA_TRUE : EINA_FALSE ); +} + +EAPI Eina_Bool edoors_particle_next_dst(Edoors_Particle *particle) +{ + particle->cur_dst+=1; + return ( (eina_array_count_get(particle->dsts)>particle->cur_dst) ? EINA_TRUE : EINA_FALSE ); +} + +EAPI void edoors_particle_split_dst(Edoors_Particle *particle) +{ + unsigned int l, n; + char *sep, *tmp; + Eina_Stringshare *dst; + + if(!edoors_particle_has_dst(particle)) { + STRINGSHARE_FREE(particle->cur_action); + STRINGSHARE_FREE(particle->cur_door); + STRINGSHARE_FREE(particle->cur_room); + return; + } + + dst = eina_array_data_get(particle->dsts,particle->cur_dst); + l = eina_stringshare_strlen(dst); + + sep = (char*)dst+l-sizeof(char); + for(; (sep!=dst && *sep!=EDOORS_ACTION_SEP ); sep--) /* reverse search for action separator */; + + if(*sep==EDOORS_ACTION_SEP) { + tmp = sep+sizeof(char); + /* action defined */ + if(particle->cur_action) { + if(strcmp(particle->cur_action,tmp)!=0) { + eina_stringshare_del(particle->cur_action); + particle->cur_action = eina_stringshare_add(tmp); + } + /* else : keep the same stringshare */ + } else { + particle->cur_action = eina_stringshare_add(tmp); + } + tmp = sep; + sep = sep-sizeof(char); + } else { + STRINGSHARE_FREE(particle->cur_action); + tmp = (char*)dst+l; + sep = (char*)dst+l-sizeof(char); + } + + for(; (sep!=dst && *sep!=EDOORS_PATH_SEP ); sep--) /* reverse search path for separator */; + + if(sep==dst) { + /* no room */ + n=(tmp-sep); + STRINGSHARE_FREE(particle->cur_room); + } else { + n=(sep-dst); + /* door defined */ + if(particle->cur_room) { + if( eina_stringshare_strlen(particle->cur_room)!=n || strncmp(particle->cur_room,dst,n)!=0) { + eina_stringshare_del(particle->cur_room); + particle->cur_room = eina_stringshare_add_length(dst,n); + } + /* else : keep the same stringshare */ + } else { + particle->cur_room = eina_stringshare_add_length(dst,n); + } + n=(tmp-sep-sizeof(char)); + sep++; + } + /* door defined */ + if(particle->cur_door) { + if( eina_stringshare_strlen(particle->cur_door)!=n || strncmp(particle->cur_door,sep,n)!=0) { + eina_stringshare_del(particle->cur_door); + particle->cur_door = eina_stringshare_add_length(sep,n); + } + /* else : keep the same stringshare */ + } else { + particle->cur_door = eina_stringshare_add_length(sep,n); + } +} + +EAPI void edoors_particle_destination_set(Edoors_Particle *particle, const char *destination) +{ + char *tmp; + + tmp = add_destination(particle,destination); + if(*tmp=='\0' || *tmp==' ' || *tmp==EDOORS_FIELDS_SEP) + particle->cur_dst = eina_array_count_get(particle->dsts)-1; +} + +EAPI void edoors_particle_destinations_add(Edoors_Particle *particle, const char* destinations) +{ + char *dst; + + dst = (char*)destinations; + for(;;) { + dst = add_destination(particle,dst); + for(; (*dst && *dst!=EDOORS_FIELDS_SEP); dst++) /* eat whatever is following */; + if(!*dst) return; + dst++; + } +} + +static char* add_destination(Edoors_Particle *particle, const char *dst) +{ + char *start, *end, *last_path_sep, *action_sep; + Eina_Stringshare *s; + + for(start=(char*)dst; *start && *start==' '; start++) /* eat leading spaces */; + + if(*start=='\0' || *start==EDOORS_FIELDS_SEP) { + ERR("ignore empty destination"); + return start; + } + + if(*start==EDOORS_ACTION_SEP || *start==EDOORS_PATH_SEP ) { + ERR("ignore destination starting with '%c' ",*start); + return start; + } + + last_path_sep = action_sep = NULL; + for(end=start; (*end && *end!=EDOORS_FIELDS_SEP && *end!=' '); end++) { + if(*end==EDOORS_PATH_SEP) { + last_path_sep = end; + } else if(*end==EDOORS_ACTION_SEP) { + if(action_sep) { + ERR("ignore destination with more then 1 '%c' ",EDOORS_ACTION_SEP); + return end; + } + if(last_path_sep==(end-sizeof(char))) { + ERR("ignore destination with '%c%c' ",EDOORS_PATH_SEP,EDOORS_ACTION_SEP); + return end; + } + action_sep = end; + } + } + + if(last_path_sep==(end-sizeof(char)) || action_sep==(end-sizeof(char)) ) { + ERR("ignore destination ending with '%c' ",*(end-sizeof(char))); + return end; + } + + s = eina_stringshare_add_length(start,(end-start)); + eina_array_push(particle->dsts,s); + DBG("add dst >%s<",s); + + return end; +} + +EAPI void edoors_particle_link_fields_set(Edoors_Particle *particle, const char *link_fields) +{ + int n; + unsigned int i; + Eina_Stringshare *s; + Eina_Array_Iterator it; + char *field, *sep; + + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); + eina_array_clean(particle->link_fields); + + field = (char*)link_fields; + for(; *field;) { + for(; *field==' '; field++) /* eat leading spaces */; + sep = field; + for(; (*sep && *sep!=EDOORS_FIELDS_SEP && *sep!=' '); sep++) /* search field end */; + n = (sep-field); + if(n==0) { + ERR("ignore empty field"); + } else { + s = eina_stringshare_add_length(field,n); + eina_array_push(particle->link_fields,s); + DBG("add field >%s<",s); + } + for(; (*sep && *sep!=EDOORS_FIELDS_SEP); sep++) /* eat whatever following */; + if(!*sep) return; + field = sep+sizeof(char); + } + update_link_value(particle,NULL); +} + +EAPI const char* edoors_particle_data_get(Edoors_Particle *particle, const char* key) +{ + return eina_hash_find(particle->payload,key); +} + +EAPI Eina_Bool edoors_particle_data_set(Edoors_Particle *particle, const char* key, const char* value) +{ + unsigned int i; + Eina_Stringshare *s; + Eina_Array_Iterator it; + + s = eina_stringshare_add(value); + if(!eina_hash_add(particle->payload,key,s)) return EINA_FALSE; + update_link_value(particle,key); + + return EINA_TRUE; +} + +EAPI Eina_Bool edoors_particle_data_del(Edoors_Particle *particle, const char* key) +{ + unsigned int i; + Eina_Stringshare *s; + Eina_Array_Iterator it; + + if(!eina_hash_del(particle->payload,key,NULL)) return EINA_FALSE; + update_link_value(particle,key); + + return EINA_TRUE; +} + +EAPI Eina_Bool edoors_particle_match(Edoors_Particle *particle, const Edoors_Particle *p) +{ + return ( (particle->link_value==p->link_value) ? EINA_TRUE : EINA_FALSE ); +} + +static void update_link_value(Edoors_Particle *particle, const char *field) +{ + unsigned int i; + unsigned int l,t; + Eina_Stringshare *k; + Eina_Stringshare *v; + Eina_Array_Iterator it; + Eina_Bool update; + char tmp[EDOORS_MAX_VALUE_LENGTH]; + char *dst; + + if(field!=NULL) { + /* check if link_value has to be updated */ + update = EINA_FALSE; + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, k, it) { + if(strcmp(field,k)==0) { + update = EINA_TRUE; + break; + } + } + if(!update) return; + } + + t = 1; + dst = tmp; + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, k, it) { + v = eina_hash_find(particle->payload,k); + if(v!=NULL) { + l = strlen(v); + t += l; + if(t>EDOORS_MAX_VALUE_LENGTH) { + ERR("buffer overflow (%d>%d) link_value untouched",t,EDOORS_MAX_VALUE_LENGTH); + return; + } + memcpy(dst,v,l); + dst += l; + } + } + *dst='\0'; + + if(particle->link_value) { + if(t==1) { + eina_stringshare_del(particle->link_value); + particle->link_value = NULL; + } else if(strcmp(particle->link_value,tmp)!=0) { + eina_stringshare_del(particle->link_value); + particle->link_value = eina_stringshare_add(tmp); + } + /* else : keep the same stringshare */ + } else if(t!=1) { + particle->link_value = eina_stringshare_add(tmp); + } + /* else : keep particle->link_value=NULL*/ +} + diff --git a/src/lib/edoors_private.h b/src/lib/edoors_private.h new file mode 100644 index 0000000..c392443 --- /dev/null +++ b/src/lib/edoors_private.h @@ -0,0 +1,126 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#ifndef __EDOORS_PRIVATE_H__ +#define __EDOORS_PRIVATE_H__ + +#ifdef HAVE_CONFIG_H +# include "edoors_config.h" +#endif +#include "edoors_main.h" +#include "edoors_iota.h" + +#include +#undef EINA_LOG_DOMAIN_DEFAULT +#define EINA_LOG_DOMAIN_DEFAULT edoors_log_dom +#define EIOTA_LOG_DOMAIN "edoors" + +#define EDOORS_MAX_VALUE_LENGTH 1024 +#define EDOORS_MAX_PATH_LENGTH 256 +#define EDOORS_MAX_ACTION_LENGTH 16 + +#define EDOORS_PATH_SEP '/' +#define EDOORS_FIELDS_SEP ',' +#define EDOORS_ACTION_SEP '?' +#define EDOORS_PARTICLE_ARRAY_STEP 3 + +void edoors_iota_desinit(Edoors_Iota *iota); + +int edoors_iota_init(Edoors_Iota *iota, const char *name, Edoors_Iota *parent, Edoors_Type type); + +#undef PRINTPTR +#ifdef __clang__ +# define PRINTPTR(_p) (unsigned int)_p +#else +# define PRINTPTR(_p) (_p) +#endif + +#define CHECK_PARENT() \ + if(parent==NULL) { \ + ERR("NULL parent not allowed"); \ + return NULL; \ + } + +#define STRINGSHARE_FREE(_st) \ + if(_st) { \ + eina_stringshare_del(_st); \ + _st = NULL; \ + } + +#define BUILD_INSTANCE(_type,_x) \ + _type *_x = (_type*)malloc(sizeof(_type)); \ + if(_x==NULL) { \ + ERR("malloc error"); \ + return NULL; \ + } + +#define INIT_IOTA(_iota,_name,_parent,_type) \ + if(edoors_iota_init(_iota,_name,(Edoors_Iota*)_parent,_type)) { \ + return NULL; \ + } + +#define ADD_TO_PARENT(_parent,_iota,_st_name) \ + if(eina_hash_find(_parent->children,_iota->name)) { \ + ERR("%s %s already exists in %s",_st_name,_iota->name,parent->iota.path); \ + edoors_iota_desinit(_iota); \ + return NULL; \ + } \ + eina_hash_direct_add(_parent->children,_iota->name,_iota); + +#define CHECK_USERBITS(_user_bits) \ + if(_user_bits->data==NULL) { \ + ERR("user_bits->data NULL is not allowed"); \ + return NULL; \ + } \ + if(_user_bits->free_fct==NULL) { \ + ERR("user_bits->free_fct NULL is not allowed"); \ + return NULL; \ + } \ + if(_user_bits->recv_fct==NULL) { \ + ERR("user_bits->recv_fct NULL is not allowed"); \ + return NULL; \ + } \ + +/* TODO user_bits->start_fct; user_bits->stop_fct; user_bits->suspend_fct; user_bits->resume_fct; */ + +#ifdef CRITICAL +#undef CRITICAL +#endif +#define CRITICAL(...) EINA_LOG_DOM_CRIT(_edoors_log_dom, __VA_ARGS__) + +#ifdef ERR +#undef ERR +#endif +#define ERR(...) EINA_LOG_DOM_ERR(_edoors_log_dom, __VA_ARGS__) + +#ifdef WRN +#undef WRN +#endif +#define WRN(...) EINA_LOG_DOM_WARN(_edoors_log_dom, __VA_ARGS__) + +#ifdef INF +#undef INF +#endif +#define INF(...) EINA_LOG_DOM_INFO(_edoors_log_dom, __VA_ARGS__) + +#ifdef DBG +#undef DBG +#endif +#define DBG(...) EINA_LOG_DOM_DBG(_edoors_log_dom, __VA_ARGS__) + +#endif // __EDOORS_PRIVATE_H__ diff --git a/src/lib/edoors_room.c b/src/lib/edoors_room.c new file mode 100644 index 0000000..3d5d251 --- /dev/null +++ b/src/lib/edoors_room.c @@ -0,0 +1,48 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_room.h" +#include "edoors_private.h" + +EAPI Edoors_Room* edoors_room_add(const char* name, const Edoors_Room *parent) +{ + CHECK_PARENT(); + + BUILD_INSTANCE(Edoors_Room,room); + + INIT_IOTA(&room->iota,name,parent,EDOORS_TYPE_ROOM); + + ADD_TO_PARENT(parent,(&room->iota),"Room") + + room->links = NULL; // TODO + room->children = eina_hash_stringshared_new((Eina_Free_Cb)&edoors_iota_free); + + return room; +} + +void edoors_room_free(Edoors_Room *room) +{ + DBG("Room free 0x%X",PRINTPTR(room)); + + edoors_iota_desinit(&room->iota); + // TODO room->links + eina_hash_free(room->children); + + free(room); +} + diff --git a/src/lib/edoors_spin.c b/src/lib/edoors_spin.c new file mode 100644 index 0000000..bb59fc4 --- /dev/null +++ b/src/lib/edoors_spin.c @@ -0,0 +1,91 @@ +/* EDOORS + * Copyright (C) 2012 Jérémy Zurcher + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +#include "edoors_spin.h" +#include "edoors_iota.h" +#include "edoors_particle.h" +#include "edoors_private.h" + +EAPI Edoors_Spin* edoors_spin_add(const char* name, unsigned int step) +{ + BUILD_INSTANCE(Edoors_Spin,spin); + + INIT_IOTA(&spin->room.iota,name,NULL,EDOORS_TYPE_SPIN); + + spin->room.links = NULL; /* not used */ + spin->room.children = eina_hash_stringshared_new((Eina_Free_Cb)&edoors_iota_free); + spin->free_particles = eina_array_new(step); + spin->sys_fifo = NULL; + spin->app_fifo = NULL; + + return spin; +} + +EAPI void edoors_spin_free(Edoors_Spin *spin) +{ + unsigned int i; + Edoors_Particle *particle; + Eina_Array_Iterator iterator; + Eina_Inlist *list; + + DBG("Spin free 0x%X",PRINTPTR(spin)); + + edoors_iota_desinit(&spin->room.iota); + eina_hash_free(spin->room.children); + EINA_ARRAY_ITER_NEXT(spin->free_particles, i, particle, iterator) edoors_particle_free(particle); + eina_array_free(spin->free_particles); + EINA_INLIST_FOREACH_SAFE(spin->sys_fifo, list,particle) edoors_particle_free(particle); + EINA_INLIST_FOREACH_SAFE(spin->app_fifo, list,particle) edoors_particle_free(particle); + + free(spin); +} + +EAPI Edoors_Particle* edoors_spin_require_particle(Edoors_Spin *spin) +{ + Edoors_Particle *particle; + if(eina_array_count(spin->free_particles)>0) { + particle = eina_array_pop(spin->free_particles); + } else { + particle = (Edoors_Particle*)edoors_particle_alloc(); + } + return particle; +} + +EAPI void edoors_spin_release_particle(Edoors_Spin *spin, Edoors_Particle *particle) +{ + Edoors_Particle *p; + Eina_Inlist *list; + + while (particle->merged) { + p = EINA_INLIST_CONTAINER_GET(particle->merged,Edoors_Particle); + particle->merged = eina_inlist_remove(particle->merged,particle->merged); + edoors_spin_release_particle(spin,p); + } + edoors_particle_reset(particle); + eina_array_push(spin->free_particles,particle); +} + +EAPI void edoors_spin_send_particle(Edoors_Spin *spin, const Edoors_Particle *particle, Eina_Bool system) +{ + if(system) { + spin->sys_fifo = eina_inlist_append(spin->sys_fifo,EINA_INLIST_GET((Edoors_Particle*)particle)); + } else { + spin->app_fifo = eina_inlist_append(spin->app_fifo,EINA_INLIST_GET((Edoors_Particle*)particle)); + } +} + diff --git a/src/lib/eiotas_board.c b/src/lib/eiotas_board.c deleted file mode 100644 index 26a066b..0000000 --- a/src/lib/eiotas_board.c +++ /dev/null @@ -1,33 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_board.h" -#include "eiotas_private.h" - -EAPI Eiotas_Board* eiotas_board_add(const char* name, const Eiotas_Room *parent, Eiotas_User_Bits *user_bits) -{ - // TODO - return NULL; -} - -void eiotas_board_free(Eiotas_Board *board) -{ - DBG("Door free 0x%X",PRINTPTR(board)); - // TODO -} - diff --git a/src/lib/eiotas_door.c b/src/lib/eiotas_door.c deleted file mode 100644 index 37d5c3a..0000000 --- a/src/lib/eiotas_door.c +++ /dev/null @@ -1,48 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_door.h" -#include "eiotas_private.h" - -EAPI Eiotas_Door* eiotas_door_add(const char* name, const Eiotas_Room *parent, Eiotas_User_Bits *user_bits) -{ - CHECK_PARENT(); - - CHECK_USERBITS(user_bits); - - BUILD_INSTANCE(Eiotas_Door,door); - - INIT_IOTA(&door->iota,name,parent,EIOTAS_TYPE_DOOR); - - ADD_TO_PARENT(parent,(&door->iota),"Door") - - memcpy(&door->user_bits,user_bits,sizeof(Eiotas_User_Bits)); - - return door; -} - -void eiotas_door_free(Eiotas_Door *door) -{ - DBG("Door free 0x%X",PRINTPTR(door)); - - eiotas_iota_desinit(&door->iota); - door->user_bits.free_fct(door->user_bits.data); - - free(door); -} - diff --git a/src/lib/eiotas_iota.c b/src/lib/eiotas_iota.c deleted file mode 100644 index d41a69d..0000000 --- a/src/lib/eiotas_iota.c +++ /dev/null @@ -1,91 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_iota.h" -#include "eiotas_spin.h" -#include "eiotas_room.h" -#include "eiotas_door.h" -#include "eiotas_board.h" -#include "eiotas_private.h" - -int eiotas_iota_init(Eiotas_Iota *iota, const char *name, Eiotas_Iota *parent, Eiotas_Type type) -{ - int ln, lp; - char tmp[EIOTAS_MAX_PATH_LENGTH]; - - ln = strlen(name); - if(name==NULL || ln==0) { - ERR("name can't be NULL or empty"); - return 1; - } - - iota->type = type; - iota->spin = ( parent ? parent->spin : iota ); - iota->parent = parent; - if(parent) { - lp = eina_stringshare_strlen(parent->path); - if((ln+lp+2)>EIOTAS_MAX_PATH_LENGTH) { - ERR("buffer overflow (%d)",(ln+lp+2)); - return 1; - } - memcpy(tmp,parent->path,lp); - tmp[lp]='/'; - memcpy((tmp+lp+sizeof(char)),name,ln+sizeof(char)); - iota->name = eina_stringshare_add(name); - iota->path = eina_stringshare_add(tmp); - } else { - iota->name = eina_stringshare_add(name); - iota->path = eina_stringshare_add(name); - } - - return 0; -} - -void eiotas_iota_desinit(Eiotas_Iota *iota) -{ - STRINGSHARE_FREE(iota->name); - STRINGSHARE_FREE(iota->path); -} - -void eiotas_iota_free(Eiotas_Iota *iota) -{ - switch(iota->type) { - case EIOTAS_TYPE_SPIN: - eiotas_spin_free((Eiotas_Spin*)iota); - break; - case EIOTAS_TYPE_ROOM: - eiotas_room_free((Eiotas_Room*)iota); - break; - case EIOTAS_TYPE_DOOR: - eiotas_door_free((Eiotas_Door*)iota); - break; - case EIOTAS_TYPE_BOARD: - eiotas_board_free((Eiotas_Board*)iota); - break; - default: - CRITICAL("SPANK SPANK: 0x%X type %d is unknown, memory leak",PRINTPTR(iota),iota->type); - break; - } -} - -EAPI void eiotas_iota_show(Eiotas_Iota *iota) -{ - DBG("Iota(%d) 0x%X : %s (%s) [0x%X] {0x%X}",iota->type,PRINTPTR(iota),iota->name,iota->path, - PRINTPTR(iota->parent),PRINTPTR(iota->spin)); -} - diff --git a/src/lib/eiotas_link.c b/src/lib/eiotas_link.c deleted file mode 100644 index 96cdab6..0000000 --- a/src/lib/eiotas_link.c +++ /dev/null @@ -1,27 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_link.h" -#include "eiotas_private.h" - -void eiotas_link_free(Eiotas_Link *link) -{ - DBG("Link free 0x%X",PRINTPTR(link)); - // TODO -} - diff --git a/src/lib/eiotas_main.c b/src/lib/eiotas_main.c deleted file mode 100644 index e4799a1..0000000 --- a/src/lib/eiotas_main.c +++ /dev/null @@ -1,58 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_main.h" -#include "eiotas_private.h" - -#include "eina_main.h" -#include - -static int _eiotas_main_count = 0; - -int _eiotas_log_dom; - -static Eiotas_Version _version = { VMAJ, VMIN, VMIC }; - -EAPI Eiotas_Version *eiotas_version = &_version; - -EAPI int eiotas_init() -{ - if (EINA_LIKELY(_eiotas_main_count > 0)) - return ++_eiotas_main_count; - - if(!eina_init()) { - fprintf(stderr,"Error during the initialization of Eina_Log module\n"); - return EXIT_FAILURE; - } - - _eiotas_log_dom = eina_log_domain_register("eiotas", EINA_COLOR_CYAN); - _eiotas_main_count = 1; - - return 1; -} - -EAPI int eiotas_shutdown() -{ - _eiotas_main_count--; - if (EINA_UNLIKELY(_eiotas_main_count == 0)) { - eina_shutdown(); - } - - return _eiotas_main_count; -} - diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c deleted file mode 100644 index 5051750..0000000 --- a/src/lib/eiotas_particle.c +++ /dev/null @@ -1,376 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_particle.h" -#include "eiotas_private.h" - -static void update_link_value(Eiotas_Particle *particle, const char *field); -static char* add_destination(Eiotas_Particle *particle, const char *dst); - -Eiotas_Particle* eiotas_particle_alloc() -{ - BUILD_INSTANCE(Eiotas_Particle,particle); - - particle->ts = 0; - particle->src = NULL; - particle->dst = NULL; - particle->dsts = eina_array_new(EIOTAS_PARTICLE_ARRAY_STEP); - particle->cur_dst = 0; - particle->cur_action = NULL; - particle->cur_door = NULL; - particle->cur_room = NULL; - particle->payload = eina_hash_string_small_new((Eina_Free_Cb)&eina_stringshare_del); - particle->merged = NULL; - particle->link_fields = eina_array_new(EIOTAS_PARTICLE_ARRAY_STEP); - particle->link_value = NULL; - - return particle; -} - -void eiotas_particle_free(Eiotas_Particle *particle) -{ - unsigned int i; - Eina_Stringshare *s; - Eiotas_Particle *p; - Eina_Inlist *li; - Eina_Array_Iterator it; - - DBG("Particle free 0x%X",PRINTPTR(particle)); - - EINA_ARRAY_ITER_NEXT(particle->dsts, i, s, it) eina_stringshare_del(s); - eina_array_free(particle->dsts); - STRINGSHARE_FREE(particle->cur_action); - STRINGSHARE_FREE(particle->cur_door); - STRINGSHARE_FREE(particle->cur_room); - eina_hash_free(particle->payload); - EINA_INLIST_FOREACH_SAFE(particle->merged, li, p) eiotas_particle_free(p); - EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); - eina_array_free(particle->link_fields); - STRINGSHARE_FREE(particle->link_value); - - free(particle); -} - -EAPI void eiotas_particle_reset(Eiotas_Particle *particle) -{ - unsigned int i; - Eina_Stringshare *s; - Eiotas_Particle *p; - Eina_Inlist *li; - Eina_Array_Iterator it; - - particle->ts = 0; - particle->src = NULL; - particle->dst = NULL; - EINA_ARRAY_ITER_NEXT(particle->dsts, i, s, it) eina_stringshare_del(s); - eina_array_clean(particle->dsts); - particle->cur_dst = 0; - STRINGSHARE_FREE(particle->cur_action); - STRINGSHARE_FREE(particle->cur_door); - STRINGSHARE_FREE(particle->cur_room); - eina_hash_free_buckets(particle->payload); - EINA_INLIST_FOREACH_SAFE(particle->merged, li, p) eiotas_particle_free(p); - particle->merged = NULL; - EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); - eina_array_clean(particle->link_fields); - STRINGSHARE_FREE(particle->link_value); -} - -EAPI void eiotas_particle_init(Eiotas_Particle *particle, Eiotas_Iota *iota) -{ - particle->src = iota; - particle->ts = time(NULL); -} - -EAPI void eiotas_particle_merge(Eiotas_Particle *particle, const Eiotas_Particle *p) -{ - particle->merged = eina_inlist_append(particle->merged, EINA_INLIST_GET((Eiotas_Particle*)p)); -} - -EAPI Eina_Bool eiotas_particle_has_dst(Eiotas_Particle *particle) -{ - return ( (eina_array_count_get(particle->dsts)>particle->cur_dst) ? EINA_TRUE : EINA_FALSE ); -} - -EAPI Eina_Bool eiotas_particle_next_dst(Eiotas_Particle *particle) -{ - particle->cur_dst+=1; - return ( (eina_array_count_get(particle->dsts)>particle->cur_dst) ? EINA_TRUE : EINA_FALSE ); -} - -EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle) -{ - unsigned int l, n; - char *sep, *tmp; - Eina_Stringshare *dst; - - if(!eiotas_particle_has_dst(particle)) { - STRINGSHARE_FREE(particle->cur_action); - STRINGSHARE_FREE(particle->cur_door); - STRINGSHARE_FREE(particle->cur_room); - return; - } - - dst = eina_array_data_get(particle->dsts,particle->cur_dst); - l = eina_stringshare_strlen(dst); - - sep = (char*)dst+l-sizeof(char); - for(; (sep!=dst && *sep!=EIOTAS_ACTION_SEP ); sep--) /* reverse search for action separator */; - - if(*sep==EIOTAS_ACTION_SEP) { - tmp = sep+sizeof(char); - /* action defined */ - if(particle->cur_action) { - if(strcmp(particle->cur_action,tmp)!=0) { - eina_stringshare_del(particle->cur_action); - particle->cur_action = eina_stringshare_add(tmp); - } - /* else : keep the same stringshare */ - } else { - particle->cur_action = eina_stringshare_add(tmp); - } - tmp = sep; - sep = sep-sizeof(char); - } else { - STRINGSHARE_FREE(particle->cur_action); - tmp = (char*)dst+l; - sep = (char*)dst+l-sizeof(char); - } - - for(; (sep!=dst && *sep!=EIOTAS_PATH_SEP ); sep--) /* reverse search path for separator */; - - if(sep==dst) { - /* no room */ - n=(tmp-sep); - STRINGSHARE_FREE(particle->cur_room); - } else { - n=(sep-dst); - /* door defined */ - if(particle->cur_room) { - if( eina_stringshare_strlen(particle->cur_room)!=n || strncmp(particle->cur_room,dst,n)!=0) { - eina_stringshare_del(particle->cur_room); - particle->cur_room = eina_stringshare_add_length(dst,n); - } - /* else : keep the same stringshare */ - } else { - particle->cur_room = eina_stringshare_add_length(dst,n); - } - n=(tmp-sep-sizeof(char)); - sep++; - } - /* door defined */ - if(particle->cur_door) { - if( eina_stringshare_strlen(particle->cur_door)!=n || strncmp(particle->cur_door,sep,n)!=0) { - eina_stringshare_del(particle->cur_door); - particle->cur_door = eina_stringshare_add_length(sep,n); - } - /* else : keep the same stringshare */ - } else { - particle->cur_door = eina_stringshare_add_length(sep,n); - } -} - -EAPI void eiotas_particle_destination_set(Eiotas_Particle *particle, const char *destination) -{ - char *tmp; - - tmp = add_destination(particle,destination); - if(*tmp=='\0' || *tmp==' ' || *tmp==EIOTAS_FIELDS_SEP) - particle->cur_dst = eina_array_count_get(particle->dsts)-1; -} - -EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char* destinations) -{ - char *dst; - - dst = (char*)destinations; - for(;;) { - dst = add_destination(particle,dst); - for(; (*dst && *dst!=EIOTAS_FIELDS_SEP); dst++) /* eat whatever is following */; - if(!*dst) return; - dst++; - } -} - -static char* add_destination(Eiotas_Particle *particle, const char *dst) -{ - char *start, *end, *last_path_sep, *action_sep; - Eina_Stringshare *s; - - for(start=(char*)dst; *start && *start==' '; start++) /* eat leading spaces */; - - if(*start=='\0' || *start==EIOTAS_FIELDS_SEP) { - ERR("ignore empty destination"); - return start; - } - - if(*start==EIOTAS_ACTION_SEP || *start==EIOTAS_PATH_SEP ) { - ERR("ignore destination starting with '%c' ",*start); - return start; - } - - last_path_sep = action_sep = NULL; - for(end=start; (*end && *end!=EIOTAS_FIELDS_SEP && *end!=' '); end++) { - if(*end==EIOTAS_PATH_SEP) { - last_path_sep = end; - } else if(*end==EIOTAS_ACTION_SEP) { - if(action_sep) { - ERR("ignore destination with more then 1 '%c' ",EIOTAS_ACTION_SEP); - return end; - } - if(last_path_sep==(end-sizeof(char))) { - ERR("ignore destination with '%c%c' ",EIOTAS_PATH_SEP,EIOTAS_ACTION_SEP); - return end; - } - action_sep = end; - } - } - - if(last_path_sep==(end-sizeof(char)) || action_sep==(end-sizeof(char)) ) { - ERR("ignore destination ending with '%c' ",*(end-sizeof(char))); - return end; - } - - s = eina_stringshare_add_length(start,(end-start)); - eina_array_push(particle->dsts,s); - DBG("add dst >%s<",s); - - return end; -} - -EAPI void eiotas_particle_link_fields_set(Eiotas_Particle *particle, const char *link_fields) -{ - int n; - unsigned int i; - Eina_Stringshare *s; - Eina_Array_Iterator it; - char *field, *sep; - - EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); - eina_array_clean(particle->link_fields); - - field = (char*)link_fields; - for(; *field;) { - for(; *field==' '; field++) /* eat leading spaces */; - sep = field; - for(; (*sep && *sep!=EIOTAS_FIELDS_SEP && *sep!=' '); sep++) /* search field end */; - n = (sep-field); - if(n==0) { - ERR("ignore empty field"); - } else { - s = eina_stringshare_add_length(field,n); - eina_array_push(particle->link_fields,s); - DBG("add field >%s<",s); - } - for(; (*sep && *sep!=EIOTAS_FIELDS_SEP); sep++) /* eat whatever following */; - if(!*sep) return; - field = sep+sizeof(char); - } - update_link_value(particle,NULL); -} - -EAPI const char* eiotas_particle_data_get(Eiotas_Particle *particle, const char* key) -{ - return eina_hash_find(particle->payload,key); -} - -EAPI Eina_Bool eiotas_particle_data_set(Eiotas_Particle *particle, const char* key, const char* value) -{ - unsigned int i; - Eina_Stringshare *s; - Eina_Array_Iterator it; - - s = eina_stringshare_add(value); - if(!eina_hash_add(particle->payload,key,s)) return EINA_FALSE; - update_link_value(particle,key); - - return EINA_TRUE; -} - -EAPI Eina_Bool eiotas_particle_data_del(Eiotas_Particle *particle, const char* key) -{ - unsigned int i; - Eina_Stringshare *s; - Eina_Array_Iterator it; - - if(!eina_hash_del(particle->payload,key,NULL)) return EINA_FALSE; - update_link_value(particle,key); - - return EINA_TRUE; -} - -EAPI Eina_Bool eiotas_particle_match(Eiotas_Particle *particle, const Eiotas_Particle *p) -{ - return ( (particle->link_value==p->link_value) ? EINA_TRUE : EINA_FALSE ); -} - -static void update_link_value(Eiotas_Particle *particle, const char *field) -{ - unsigned int i; - unsigned int l,t; - Eina_Stringshare *k; - Eina_Stringshare *v; - Eina_Array_Iterator it; - Eina_Bool update; - char tmp[EIOTAS_MAX_VALUE_LENGTH]; - char *dst; - - if(field!=NULL) { - /* check if link_value has to be updated */ - update = EINA_FALSE; - EINA_ARRAY_ITER_NEXT(particle->link_fields, i, k, it) { - if(strcmp(field,k)==0) { - update = EINA_TRUE; - break; - } - } - if(!update) return; - } - - t = 1; - dst = tmp; - EINA_ARRAY_ITER_NEXT(particle->link_fields, i, k, it) { - v = eina_hash_find(particle->payload,k); - if(v!=NULL) { - l = strlen(v); - t += l; - if(t>EIOTAS_MAX_VALUE_LENGTH) { - ERR("buffer overflow (%d>%d) link_value untouched",t,EIOTAS_MAX_VALUE_LENGTH); - return; - } - memcpy(dst,v,l); - dst += l; - } - } - *dst='\0'; - - if(particle->link_value) { - if(t==1) { - eina_stringshare_del(particle->link_value); - particle->link_value = NULL; - } else if(strcmp(particle->link_value,tmp)!=0) { - eina_stringshare_del(particle->link_value); - particle->link_value = eina_stringshare_add(tmp); - } - /* else : keep the same stringshare */ - } else if(t!=1) { - particle->link_value = eina_stringshare_add(tmp); - } - /* else : keep particle->link_value=NULL*/ -} - diff --git a/src/lib/eiotas_private.h b/src/lib/eiotas_private.h deleted file mode 100644 index 27ee9e8..0000000 --- a/src/lib/eiotas_private.h +++ /dev/null @@ -1,126 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#ifndef __EIOTAS_PRIVATE_H__ -#define __EIOTAS_PRIVATE_H__ - -#ifdef HAVE_CONFIG_H -# include "eiotas_config.h" -#endif -#include "eiotas_main.h" -#include "eiotas_iota.h" - -#include -#undef EINA_LOG_DOMAIN_DEFAULT -#define EINA_LOG_DOMAIN_DEFAULT eiotas_log_dom -#define EIOTA_LOG_DOMAIN "eiotas" - -#define EIOTAS_MAX_VALUE_LENGTH 1024 -#define EIOTAS_MAX_PATH_LENGTH 256 -#define EIOTAS_MAX_ACTION_LENGTH 16 - -#define EIOTAS_PATH_SEP '/' -#define EIOTAS_FIELDS_SEP ',' -#define EIOTAS_ACTION_SEP '?' -#define EIOTAS_PARTICLE_ARRAY_STEP 3 - -void eiotas_iota_desinit(Eiotas_Iota *iota); - -int eiotas_iota_init(Eiotas_Iota *iota, const char *name, Eiotas_Iota *parent, Eiotas_Type type); - -#undef PRINTPTR -#ifdef __clang__ -# define PRINTPTR(_p) (unsigned int)_p -#else -# define PRINTPTR(_p) (_p) -#endif - -#define CHECK_PARENT() \ - if(parent==NULL) { \ - ERR("NULL parent not allowed"); \ - return NULL; \ - } - -#define STRINGSHARE_FREE(_st) \ - if(_st) { \ - eina_stringshare_del(_st); \ - _st = NULL; \ - } - -#define BUILD_INSTANCE(_type,_x) \ - _type *_x = (_type*)malloc(sizeof(_type)); \ - if(_x==NULL) { \ - ERR("malloc error"); \ - return NULL; \ - } - -#define INIT_IOTA(_iota,_name,_parent,_type) \ - if(eiotas_iota_init(_iota,_name,(Eiotas_Iota*)_parent,_type)) { \ - return NULL; \ - } - -#define ADD_TO_PARENT(_parent,_iota,_st_name) \ - if(eina_hash_find(_parent->children,_iota->name)) { \ - ERR("%s %s already exists in %s",_st_name,_iota->name,parent->iota.path); \ - eiotas_iota_desinit(_iota); \ - return NULL; \ - } \ - eina_hash_direct_add(_parent->children,_iota->name,_iota); - -#define CHECK_USERBITS(_user_bits) \ - if(_user_bits->data==NULL) { \ - ERR("user_bits->data NULL is not allowed"); \ - return NULL; \ - } \ - if(_user_bits->free_fct==NULL) { \ - ERR("user_bits->free_fct NULL is not allowed"); \ - return NULL; \ - } \ - if(_user_bits->recv_fct==NULL) { \ - ERR("user_bits->recv_fct NULL is not allowed"); \ - return NULL; \ - } \ - -/* TODO user_bits->start_fct; user_bits->stop_fct; user_bits->suspend_fct; user_bits->resume_fct; */ - -#ifdef CRITICAL -#undef CRITICAL -#endif -#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eiotas_log_dom, __VA_ARGS__) - -#ifdef ERR -#undef ERR -#endif -#define ERR(...) EINA_LOG_DOM_ERR(_eiotas_log_dom, __VA_ARGS__) - -#ifdef WRN -#undef WRN -#endif -#define WRN(...) EINA_LOG_DOM_WARN(_eiotas_log_dom, __VA_ARGS__) - -#ifdef INF -#undef INF -#endif -#define INF(...) EINA_LOG_DOM_INFO(_eiotas_log_dom, __VA_ARGS__) - -#ifdef DBG -#undef DBG -#endif -#define DBG(...) EINA_LOG_DOM_DBG(_eiotas_log_dom, __VA_ARGS__) - -#endif // __EIOTAS_PRIVATE_H__ diff --git a/src/lib/eiotas_room.c b/src/lib/eiotas_room.c deleted file mode 100644 index bc508ae..0000000 --- a/src/lib/eiotas_room.c +++ /dev/null @@ -1,48 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_room.h" -#include "eiotas_private.h" - -EAPI Eiotas_Room* eiotas_room_add(const char* name, const Eiotas_Room *parent) -{ - CHECK_PARENT(); - - BUILD_INSTANCE(Eiotas_Room,room); - - INIT_IOTA(&room->iota,name,parent,EIOTAS_TYPE_ROOM); - - ADD_TO_PARENT(parent,(&room->iota),"Room") - - room->links = NULL; // TODO - room->children = eina_hash_stringshared_new((Eina_Free_Cb)&eiotas_iota_free); - - return room; -} - -void eiotas_room_free(Eiotas_Room *room) -{ - DBG("Room free 0x%X",PRINTPTR(room)); - - eiotas_iota_desinit(&room->iota); - // TODO room->links - eina_hash_free(room->children); - - free(room); -} - diff --git a/src/lib/eiotas_spin.c b/src/lib/eiotas_spin.c deleted file mode 100644 index 873a4d1..0000000 --- a/src/lib/eiotas_spin.c +++ /dev/null @@ -1,91 +0,0 @@ -/* EIOTAS - * Copyright (C) 2012 Jérémy Zurcher - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; - * if not, see . - */ - -#include "eiotas_spin.h" -#include "eiotas_iota.h" -#include "eiotas_particle.h" -#include "eiotas_private.h" - -EAPI Eiotas_Spin* eiotas_spin_add(const char* name, unsigned int step) -{ - BUILD_INSTANCE(Eiotas_Spin,spin); - - INIT_IOTA(&spin->room.iota,name,NULL,EIOTAS_TYPE_SPIN); - - spin->room.links = NULL; /* not used */ - spin->room.children = eina_hash_stringshared_new((Eina_Free_Cb)&eiotas_iota_free); - spin->free_particles = eina_array_new(step); - spin->sys_fifo = NULL; - spin->app_fifo = NULL; - - return spin; -} - -EAPI void eiotas_spin_free(Eiotas_Spin *spin) -{ - unsigned int i; - Eiotas_Particle *particle; - Eina_Array_Iterator iterator; - Eina_Inlist *list; - - DBG("Spin free 0x%X",PRINTPTR(spin)); - - eiotas_iota_desinit(&spin->room.iota); - eina_hash_free(spin->room.children); - EINA_ARRAY_ITER_NEXT(spin->free_particles, i, particle, iterator) eiotas_particle_free(particle); - eina_array_free(spin->free_particles); - EINA_INLIST_FOREACH_SAFE(spin->sys_fifo, list,particle) eiotas_particle_free(particle); - EINA_INLIST_FOREACH_SAFE(spin->app_fifo, list,particle) eiotas_particle_free(particle); - - free(spin); -} - -EAPI Eiotas_Particle* eiotas_spin_require_particle(Eiotas_Spin *spin) -{ - Eiotas_Particle *particle; - if(eina_array_count(spin->free_particles)>0) { - particle = eina_array_pop(spin->free_particles); - } else { - particle = (Eiotas_Particle*)eiotas_particle_alloc(); - } - return particle; -} - -EAPI void eiotas_spin_release_particle(Eiotas_Spin *spin, Eiotas_Particle *particle) -{ - Eiotas_Particle *p; - Eina_Inlist *list; - - while (particle->merged) { - p = EINA_INLIST_CONTAINER_GET(particle->merged,Eiotas_Particle); - particle->merged = eina_inlist_remove(particle->merged,particle->merged); - eiotas_spin_release_particle(spin,p); - } - eiotas_particle_reset(particle); - eina_array_push(spin->free_particles,particle); -} - -EAPI void eiotas_spin_send_particle(Eiotas_Spin *spin, const Eiotas_Particle *particle, Eina_Bool system) -{ - if(system) { - spin->sys_fifo = eina_inlist_append(spin->sys_fifo,EINA_INLIST_GET((Eiotas_Particle*)particle)); - } else { - spin->app_fifo = eina_inlist_append(spin->app_fifo,EINA_INLIST_GET((Eiotas_Particle*)particle)); - } -} - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07f7dd8..136ce69 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,12 +13,12 @@ include_directories( add_executable(tests ${TESTS_CC_SOURCES}) -get_target_property(eiotas_LIB_FILE eiotas LOCATION) +get_target_property(edoors_LIB_FILE edoors LOCATION) target_link_libraries(tests ${EINA_LIBRARIES} - ${eiotas_LIB_FILE} + ${edoors_LIB_FILE} ) -add_dependencies(tests eiotas) +add_dependencies(tests edoors) add_test(Example_tests tests) diff --git a/tests/helper.c b/tests/helper.c index 929aef7..a594318 100644 --- a/tests/helper.c +++ b/tests/helper.c @@ -3,13 +3,13 @@ void check_cond(Eina_Bool cond, char *msg) { if(!cond) { - EINA_LOG_DOM_ERR(_eiotas_log_dom,"%s",msg); + EINA_LOG_DOM_ERR(_edoors_log_dom,"%s",msg); } } void check_str(char *s0, char *s1, char *msg) { if(strcmp(s0,s1)!=0) { - EINA_LOG_DOM_ERR(_eiotas_log_dom,"%s => %s != %s\n",msg,s0,s1); + EINA_LOG_DOM_ERR(_edoors_log_dom,"%s => %s != %s\n",msg,s0,s1); } } diff --git a/tests/helper.h b/tests/helper.h index b0f9449..f5825a8 100644 --- a/tests/helper.h +++ b/tests/helper.h @@ -1,7 +1,7 @@ #ifndef _HELPER_H_ #define _HELPER_H_ -#include "Eiotas.h" +#include "Edoors.h" #include diff --git a/tests/main.c b/tests/main.c index b19b5f4..256a761 100644 --- a/tests/main.c +++ b/tests/main.c @@ -3,15 +3,15 @@ int main(int argc, char **argv) { - if(eiotas_init()==0) { + if(edoors_init()==0) { return EXIT_FAILURE; } - eina_log_domain_level_set("eiotas",EINA_LOG_LEVEL_ERR); - EINA_LOG_DOM_INFO(_eiotas_log_dom,"Eiotas version %d.%d.%d",eiotas_version->major,eiotas_version->minor,eiotas_version->micro); + eina_log_domain_level_set("edoors",EINA_LOG_LEVEL_ERR); + EINA_LOG_DOM_INFO(_edoors_log_dom,"Edoors version %d.%d.%d",edoors_version->major,edoors_version->minor,edoors_version->micro); test_spin(); test_particle(); - return eiotas_shutdown(); + return edoors_shutdown(); } diff --git a/tests/particle.c b/tests/particle.c index 60837ac..ec530ef 100644 --- a/tests/particle.c +++ b/tests/particle.c @@ -5,154 +5,154 @@ void test_particle() { void *p; Eina_Accessor *acc; - Eiotas_Particle *p0, *p1, *p2, *p3, *p4; + Edoors_Particle *p0, *p1, *p2, *p3, *p4; - Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10); + Edoors_Spin *dom0 = edoors_spin_add("dom0",10); - p0 = eiotas_require_particle(dom0); + p0 = edoors_require_particle(dom0); - check_cond(!eiotas_particle_has_dst(p0),"should be no destination"); + check_cond(!edoors_particle_has_dst(p0),"should be no destination"); - eiotas_particle_destinations_add(p0,"dom0/room0/door0?get"); - check_cond(eiotas_particle_has_dst(p0),"should be a destination"); - eiotas_particle_destinations_add(p0," dom0/room0/door0?get "); - eiotas_particle_destinations_add(p0," dom0/room0/door0?get "); - eiotas_particle_destinations_add(p0,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get"); - eiotas_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get , dom0/room0/door0?get "); - eiotas_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get, dom0/room0/door0?get "); - eiotas_particle_destinations_add(p0," /suffix, ?suffix, prefix/ , prefix? , ,, very/?wrong , very?wrong?too"); + edoors_particle_destinations_add(p0,"dom0/room0/door0?get"); + check_cond(edoors_particle_has_dst(p0),"should be a destination"); + edoors_particle_destinations_add(p0," dom0/room0/door0?get "); + edoors_particle_destinations_add(p0," dom0/room0/door0?get "); + edoors_particle_destinations_add(p0,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get"); + edoors_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get , dom0/room0/door0?get "); + edoors_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get, dom0/room0/door0?get "); + edoors_particle_destinations_add(p0," /suffix, ?suffix, prefix/ , prefix? , ,, very/?wrong , very?wrong?too"); acc = eina_array_accessor_new(p0->dsts); eina_accessor_data_get(acc,0,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,1,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,2,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,3,&p); - check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/room1/doorx?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,4,&p); - check_str("door?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("door?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,5,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,6,&p); - check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/room1/doorx?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,7,&p); - check_str("door?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("door?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,8,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,9,&p); - check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/room1/doorx?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,10,&p); - check_str("door?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("door?get",(char*)p,"edoors_particle_destinations_add"); eina_accessor_data_get(acc,11,&p); - check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add"); + check_str("dom0/room0/door0?get",(char*)p,"edoors_particle_destinations_add"); check_cond((eina_accessor_data_get(acc,12,&p)==EINA_FALSE),"eina_accessor_data_get should fail");; - eiotas_particle_link_fields_set(p0," key2,key9 , key1,key10 "); + edoors_particle_link_fields_set(p0," key2,key9 , key1,key10 "); acc = eina_array_accessor_new(p0->link_fields); eina_accessor_data_get(acc,0,&p); - check_str("key2",(char*)p,"eiotas_particle_link_fields_set"); + check_str("key2",(char*)p,"edoors_particle_link_fields_set"); eina_accessor_data_get(acc,1,&p); - check_str("key9",(char*)p,"eiotas_particle_link_fields_set"); + check_str("key9",(char*)p,"edoors_particle_link_fields_set"); eina_accessor_data_get(acc,2,&p); - check_str("key1",(char*)p,"eiotas_particle_link_fields_set"); + check_str("key1",(char*)p,"edoors_particle_link_fields_set"); eina_accessor_data_get(acc,3,&p); - check_str("key10",(char*)p,"eiotas_particle_link_fields_set"); + check_str("key10",(char*)p,"edoors_particle_link_fields_set"); check_cond((eina_accessor_data_get(acc,4,&p)==EINA_FALSE),"eina_accessor_data_get should fail");; check_cond((p0->link_value==NULL),"link_value should be NULL"); - eiotas_particle_data_set(p0,"key0","val0"); + edoors_particle_data_set(p0,"key0","val0"); check_cond((p0->link_value==NULL),"link_value should be NULL"); - eiotas_particle_data_set(p0,"key1","val1"); + edoors_particle_data_set(p0,"key1","val1"); check_str((char*)p0->link_value,"val1","link_value is wrong"); - eiotas_particle_data_set(p0,"key2","val2"); + edoors_particle_data_set(p0,"key2","val2"); check_str((char*)p0->link_value,"val2val1","link_value is wrong"); - eiotas_particle_data_set(p0,"key3","val3"); + edoors_particle_data_set(p0,"key3","val3"); check_str((char*)p0->link_value,"val2val1","link_value is wrong"); - if(strcmp(eiotas_particle_data_get(p0,"key0"),"val0")!=0) fprintf(stderr,"ERROR\n"); - if(strcmp(eiotas_particle_data_get(p0,"key1"),"val1")!=0) fprintf(stderr,"ERROR\n"); - if(strcmp(eiotas_particle_data_get(p0,"key2"),"val2")!=0) fprintf(stderr,"ERROR\n"); - if(strcmp(eiotas_particle_data_get(p0,"key3"),"val3")!=0) fprintf(stderr,"ERROR\n"); + if(strcmp(edoors_particle_data_get(p0,"key0"),"val0")!=0) fprintf(stderr,"ERROR\n"); + if(strcmp(edoors_particle_data_get(p0,"key1"),"val1")!=0) fprintf(stderr,"ERROR\n"); + if(strcmp(edoors_particle_data_get(p0,"key2"),"val2")!=0) fprintf(stderr,"ERROR\n"); + if(strcmp(edoors_particle_data_get(p0,"key3"),"val3")!=0) fprintf(stderr,"ERROR\n"); - eiotas_particle_data_del(p0,"key0"); - if(eiotas_particle_data_get(p0,"key0")!=NULL) fprintf(stderr,"ERROR\n"); + edoors_particle_data_del(p0,"key0"); + if(edoors_particle_data_get(p0,"key0")!=NULL) fprintf(stderr,"ERROR\n"); check_str((char*)p0->link_value,"val2val1","link_value is wrong"); - p1 = eiotas_require_particle(dom0); - check_cond(!eiotas_particle_match(p0,p1),"link_value is not the same"); - eiotas_particle_link_fields_set(p1," k0,k1"); - eiotas_particle_data_set(p1,"k0","val2"); - eiotas_particle_data_set(p1,"k1","val1"); + p1 = edoors_require_particle(dom0); + check_cond(!edoors_particle_match(p0,p1),"link_value is not the same"); + edoors_particle_link_fields_set(p1," k0,k1"); + edoors_particle_data_set(p1,"k0","val2"); + edoors_particle_data_set(p1,"k1","val1"); check_str((char*)p1->link_value,"val2val1","link_value is wrong"); - check_cond(eiotas_particle_match(p0,p1),"link_value is the same"); + check_cond(edoors_particle_match(p0,p1),"link_value is the same"); - eiotas_particle_data_del(p0,"key2"); - if(eiotas_particle_data_get(p0,"key2")!=NULL) fprintf(stderr,"ERROR\n"); + edoors_particle_data_del(p0,"key2"); + if(edoors_particle_data_get(p0,"key2")!=NULL) fprintf(stderr,"ERROR\n"); check_str((char*)p0->link_value,"val1","link_value is wrong"); - eiotas_particle_data_del(p0,"key1"); - if(eiotas_particle_data_get(p0,"key1")!=NULL) fprintf(stderr,"ERROR\n"); + edoors_particle_data_del(p0,"key1"); + if(edoors_particle_data_get(p0,"key1")!=NULL) fprintf(stderr,"ERROR\n"); check_cond((p0->link_value==NULL),"link_value should be NULL"); - p2 = eiotas_require_particle(dom0); + p2 = edoors_require_particle(dom0); - eiotas_particle_destinations_add(p2,"door"); - eiotas_particle_split_dst(p2); + edoors_particle_destinations_add(p2,"door"); + edoors_particle_split_dst(p2); check_cond((p2->cur_room==NULL),"room must be NULL"); check_str((char*)p2->cur_door,"door","door is wrong"); check_cond((p2->cur_action==NULL),"action must be NULL"); - eiotas_particle_next_dst(p2); - eiotas_particle_destinations_add(p2,"doora?get"); - eiotas_particle_split_dst(p2); + edoors_particle_next_dst(p2); + edoors_particle_destinations_add(p2,"doora?get"); + edoors_particle_split_dst(p2); check_str((char*)p2->cur_action,"get","action is wrong"); check_str((char*)p2->cur_door,"doora","door is wrong"); check_cond((p2->cur_room==NULL),"room must be NULL"); - eiotas_particle_next_dst(p2); - eiotas_particle_destinations_add(p2,"room/room/door"); - eiotas_particle_split_dst(p2); + edoors_particle_next_dst(p2); + edoors_particle_destinations_add(p2,"room/room/door"); + edoors_particle_split_dst(p2); check_cond((p2->cur_action==NULL),"action must be NULL"); check_str((char*)p2->cur_door,"door","door is wrong"); check_str((char*)p2->cur_room,"room/room","room is wrong"); - eiotas_particle_next_dst(p2); - eiotas_particle_destinations_add(p2,"room/room/door?get"); - eiotas_particle_split_dst(p2); + edoors_particle_next_dst(p2); + edoors_particle_destinations_add(p2,"room/room/door?get"); + edoors_particle_split_dst(p2); check_str((char*)p2->cur_action,"get","action is wrong"); check_str((char*)p2->cur_door,"door","door is wrong"); check_str((char*)p2->cur_room,"room/room","room is wrong"); - eiotas_particle_next_dst(p2); - eiotas_particle_destinations_add(p2,"room/room/doorb?get"); - eiotas_particle_split_dst(p2); + edoors_particle_next_dst(p2); + edoors_particle_destinations_add(p2,"room/room/doorb?get"); + edoors_particle_split_dst(p2); check_str((char*)p2->cur_action,"get","action is wrong"); check_str((char*)p2->cur_door,"doorb","door is wrong"); check_str((char*)p2->cur_room,"room/room","room is wrong"); - p3 = eiotas_require_particle(dom0); - eiotas_particle_destinations_add(p3,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get"); - eiotas_particle_split_dst(p3); + p3 = edoors_require_particle(dom0); + edoors_particle_destinations_add(p3,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get"); + edoors_particle_split_dst(p3); check_str((char*)p3->cur_action,"get","action is wrong"); check_str((char*)p3->cur_door,"doorx","door is wrong"); check_str((char*)p3->cur_room,"dom0/room0/room1","room is wrong"); - eiotas_particle_destination_set(p3," room/door?got nothing else matters "); - eiotas_particle_split_dst(p3); + edoors_particle_destination_set(p3," room/door?got nothing else matters "); + edoors_particle_split_dst(p3); check_str((char*)p3->cur_action,"got","action is wrong"); check_str((char*)p3->cur_door,"door","door is wrong"); check_str((char*)p3->cur_room,"room","room is wrong"); - p4 = eiotas_require_particle(dom0); - eiotas_particle_merge(p0,p1); - eiotas_particle_merge(p0,p2); - eiotas_particle_merge(p2,p3); - eiotas_particle_merge(p2,p4); + p4 = edoors_require_particle(dom0); + edoors_particle_merge(p0,p1); + edoors_particle_merge(p0,p2); + edoors_particle_merge(p2,p3); + edoors_particle_merge(p2,p4); - eiotas_particle_free(p0); + edoors_particle_free(p0); - eiotas_spin_free(dom0); + edoors_spin_free(dom0); } diff --git a/tests/spin.c b/tests/spin.c index 5f80a21..c3f5ba9 100644 --- a/tests/spin.c +++ b/tests/spin.c @@ -4,43 +4,43 @@ void test_spin() { int i; - Eiotas_Particle *p0, *p1, *p2; + Edoors_Particle *p0, *p1, *p2; /* add spin */ - Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10); - eiotas_iota_show((Eiotas_Iota*)dom0); + Edoors_Spin *dom0 = edoors_spin_add("dom0",10); + edoors_iota_show((Edoors_Iota*)dom0); /* particle require/release */ - p0 = eiotas_spin_require_particle(dom0); - p1 = eiotas_spin_require_particle(dom0); + p0 = edoors_spin_require_particle(dom0); + p1 = edoors_spin_require_particle(dom0); - eiotas_spin_release_particle(dom0,p0); - eiotas_spin_release_particle(dom0,p1); - p2 = eiotas_spin_require_particle(dom0); + edoors_spin_release_particle(dom0,p0); + edoors_spin_release_particle(dom0,p1); + p2 = edoors_spin_require_particle(dom0); check_cond((p2==p1),"Particle require fail\n"); - eiotas_release_particle(dom0,p2); + edoors_release_particle(dom0,p2); /* particle send(sys) */ - p0 = eiotas_spin_require_particle(dom0); - p1 = eiotas_spin_require_particle(dom0); - eiotas_spin_send_particle(dom0,p0,EINA_FALSE); - eiotas_spin_send_particle(dom0,p1,EINA_TRUE); + p0 = edoors_spin_require_particle(dom0); + p1 = edoors_spin_require_particle(dom0); + edoors_spin_send_particle(dom0,p0,EINA_FALSE); + edoors_spin_send_particle(dom0,p1,EINA_TRUE); /* add rooms */ - Eiotas_Room *room = &dom0->room; + Edoors_Room *room = &dom0->room; char name[8]; for(i=0; i<5; i++) { sprintf(name,"room%d",i); - Eiotas_Room *tmp = eiotas_room_add(name,room); + Edoors_Room *tmp = edoors_room_add(name,room); if(tmp!=NULL) { room = tmp; - eiotas_iota_show((Eiotas_Iota*)room); // MACROS + edoors_iota_show((Edoors_Iota*)room); // MACROS } } - room = eiotas_room_add("room0",&dom0->room); + room = edoors_room_add("room0",&dom0->room); check_cond(room==NULL,"room0 should already exists"); - eiotas_spin_free(dom0); + edoors_spin_free(dom0); } diff --git a/tests/user_door.c b/tests/user_door.c index 7a7c705..7acbc58 100644 --- a/tests/user_door.c +++ b/tests/user_door.c @@ -19,37 +19,37 @@ static Input* input_create(char *txt) static void input_free(Input *input) { - EINA_LOG_DOM_DBG(_eiotas_log_dom,"free Input\n"); + EINA_LOG_DOM_DBG(_edoors_log_dom,"free Input\n"); free(input); free_called = 1; } static void input_show(Input *input) { - EINA_LOG_DOM_DBG(_eiotas_log_dom,"Input [%d] %s\n",input->idx,input->txt); + EINA_LOG_DOM_DBG(_edoors_log_dom,"Input [%d] %s\n",input->idx,input->txt); } -static void input_receive(const Eiotas_Door *door, Eiotas_Particle *particle, Eiotas_User_Data *data) +static void input_receive(const Edoors_Door *door, Edoors_Particle *particle, Edoors_User_Data *data) { - EINA_LOG_DOM_DBG(_eiotas_log_dom,"input_receive 0x%X\n",PRINTPTR(data)); + EINA_LOG_DOM_DBG(_edoors_log_dom,"input_receive 0x%X\n",PRINTPTR(data)); } void test_user_door() { - Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10); + Edoors_Spin *dom0 = edoors_spin_add("dom0",10); Input *input = input_create("hello world"); input_show(input); - Eiotas_User_Bits user_bits; + Edoors_User_Bits user_bits; user_bits.data = input; - user_bits.free_fct = (Eiotas_User_Data_Free)&input_free; - user_bits.recv_fct = (Eiotas_Receive_Particle)&input_receive; - Eiotas_Door *din0 = eiotas_door_add("input0",&dom0->room,&user_bits); - eiotas_iota_show(&din0->iota); // eiotas_iota_show((Eiotas_Iota*)din0); + user_bits.free_fct = (Edoors_User_Data_Free)&input_free; + user_bits.recv_fct = (Edoors_Receive_Particle)&input_receive; + Edoors_Door *din0 = edoors_door_add("input0",&dom0->room,&user_bits); + edoors_iota_show(&din0->iota); // edoors_iota_show((Edoors_Iota*)din0); - eiotas_spin_free(dom0); + edoors_spin_free(dom0); check_cond((free_called==1),"input_free not called"); } -- cgit v1.1-2-g2b99