Diff for /libaitio/inc/aitsess.h between versions 1.1.2.2 and 1.6

version 1.1.2.2, 2013/03/13 14:48:08 version 1.6, 2014/02/08 22:06:16
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013Copyright 2004 - 2014
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 48  SUCH DAMAGE. Line 48  SUCH DAMAGE.
   
   
 #include <pthread.h>  #include <pthread.h>
 #include <assert.h>  
 #include <semaphore.h>  #include <semaphore.h>
 #include <elwix.h>  #include <elwix.h>
   #include <aitio.h>
   
 #define SHARED_UNKNOWN  -1  #define SHARED_UNKNOWN  -1
 #define SHARED_IPC      0  #define SHARED_IPC      0
 #define SHARED_MAP      1  #define SHARED_MAP      1
   
#define IS_VAL          0x0#define SESS_OPT_SEED   -1
#define IS_ADD          0x40000000 
#define IS_DEF          0x80000000 
   
#define ISNEW(x)        (((x) & IS_ADD) == IS_ADD)#define SESS_F_ADD    0x10000000
#define ISDEF(x)        (((x) & IS_DEF) == IS_DEF)#define SESS_F_DEF    0x20000000
   
#define MAX_ATTRIBUTE   64#define SESS_RET_NEW(x) (((x) & SESS_F_ADD) == SESS_F_ADD)
#define MAX_SEMNAME     14#define SESS_RET_DEF(x) (((x) & SESS_F_DEF) == SESS_F_DEF)
 #define SESS_RET_VAL(x) ((x) & 0x0fffffff)
   
   
 /* Shared memory session */  /* Shared memory session */
   
 typedef struct tagSess {  typedef struct tagSess {
        key_t   key;        key_t   sess_key;
        char    type;        char    sess_type;
        char    zcpy;        char    sess_zcpy;
   
        char    name[BUFSIZ];        char    sess_name[STRSIZ];
        off_t   eom;        off_t   sess_size;
        void    *addr;        void    *sess_addr;
        off_t   offset;        off_t   sess_offset;
 
         union {          union {
                 int     shmid;                  int     shmid;
                 int     fd;                  int     fd;
        } mem;        } sess_mem;
         union {          union {
                 int     semid;                  int     semid;
                 sem_t   *sid;                  sem_t   *sid;
        } id;        } sess_id;
   
           /* Session callbacks */
         struct {          struct {
                 int (*create)(int, long, void *, ...);                  int (*create)(int, long, void *, ...);
                 void (*destroy)(void *);                  void (*destroy)(void *);
Line 97  typedef struct tagSess { Line 97  typedef struct tagSess {
                 int (*incSem)(void *);                  int (*incSem)(void *);
                 int (*decSem)(void *);                  int (*decSem)(void *);
         } sess;          } sess;
} ait_sess_t;} sess_t;
   
   /* --------------------------------------------------------- */
   
   #define ALLOC_MEMORY(sd, siz, s, ...)   (assert((s) && (s)->sess.create), \
                                                   (s)->sess.create((sd), (siz), (s), ## __VA_ARGS__))
   #define ATTACH_MEMORY(s)                (assert((s) && (s)->sess.attach), (s)->sess.attach((s), NULL))
   #define DETACH_MEMORY(s)                (assert((s) && (s)->sess.detach), (s)->sess.detach((s)))
   #define FREE_MEMORY(s)                  (assert((s) && (s)->sess.destroy), (s)->sess.destroy((s)))
   
   #define IS_SEMOK(s)                     (assert((s) && (s)->sess.isSemOK), (s)->sess.isSemOK((s)))
   #define INC_SEM(s)                      (assert((s) && (s)->sess.incSem), (s)->sess.incSem((s)))
   #define DEC_SEM(s)                      (assert((s) && (s)->sess.decSem), (s)->sess.decSem((s)))
   #define NOT_SEM(s)                      (assert((s) && (s)->sess.notSem), (s)->sess.notSem((s)))
   
   /* --------------------------------------------------------- */
   
   
 /*  /*
  * sess_initSession() - Initializing session structure,    * sess_initSession() - Initializing session structure, 
  *                      if session file not exists creating with specified tech   *                      if session file not exists creating with specified tech
Line 109  typedef struct tagSess { Line 124  typedef struct tagSess {
  * @Sess = Session item, if =NULL allocate memory for session after use must be free!   * @Sess = Session item, if =NULL allocate memory for session after use must be free!
  * return: 0 OK new key created, -1 error: no memory or file not created, 1 OK key finded   * return: 0 OK new key created, -1 error: no memory or file not created, 1 OK key finded
  */   */
int sess_initSession(int id, const char *csFName, ait_sess_t ** __restrict Sess);int sess_initSession(int id, const char *csFName, sess_t ** __restrict Sess);
 /*  /*
  * sess_freeSession() - Free allocated memory for session item and delete session file if present name   * sess_freeSession() - Free allocated memory for session item and delete session file if present name
  *   *
  * @Sess = Session item   * @Sess = Session item
  * return: none   * return: none
  */   */
void sess_freeSession(ait_sess_t ** __restrict Sess);void sess_freeSession(sess_t ** __restrict Sess);
   
 /*  /*
  * map_createSession() - MMAP Created session and allocated resources   * map_createSession() - MMAP Created session and allocated resources
  *   *
 * @nSeed = Seed for securing key, if =-1 must add ready for use key * @nSeed = Seed for securing key, if =SESS_OPT_SEED must add ready for use key
  * @nSize = Allocated shared memory size in bytes   * @nSize = Allocated shared memory size in bytes
  * @Sess = Session item   * @Sess = Session item
  * @... = If nSeed == -1 add ready for use key value   * @... = If nSeed == -1 add ready for use key value
  * return: 0 Ok successful, -1 error: not allocated resources   * return: 0 Ok successful, -1 error: not allocated resources
  */   */
int map_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...);int map_createSession(int nSeed, long nSize, sess_t * __restrict Sess, ...);
 /*  /*
  * map_destroySession() - MMAP free shared resources   * map_destroySession() - MMAP free shared resources
  *   *
  * @Sess = Session item   * @Sess = Session item
  * return: none   * return: none
  */   */
void map_destroySession(ait_sess_t * __restrict Sess);void map_destroySession(sess_t * __restrict Sess);
   
 /*  /*
  * ipc_createSession() - IPC Created session and allocated resources   * ipc_createSession() - IPC Created session and allocated resources
  *   *
 * @nSeed = Seed for securing key, if =-1 must add ready for use key * @nSeed = Seed for securing key, if =SESS_OPT_SEED must add ready for use key
  * @nSize = Allocated shared memory size in bytes   * @nSize = Allocated shared memory size in bytes
  * @Sess = Session item   * @Sess = Session item
  * @... = If nSeed == -1 add ready for use key value   * @... = If nSeed == -1 add ready for use key value
  * return: 0 Ok successful, -1 error: not allocated resources   * return: 0 Ok successful, -1 error: not allocated resources
  */   */
int ipc_createSession(int nSeed, long nSize, ait_sess_t * __restrict Sess, ...);int ipc_createSession(int nSeed, long nSize, sess_t * __restrict Sess, ...);
 /*  /*
  * ipc_destroySession() - IPC free shared resources   * ipc_destroySession() - IPC free shared resources
  *   *
  * @Sess = Session item   * @Sess = Session item
  * return: none   * return: none
  */   */
void ipc_destroySession(ait_sess_t * __restrict Sess);void ipc_destroySession(sess_t * __restrict Sess);
   
 /*  /*
  * map_attachSession() - MMAP Attach to shared memory & return begin address   * map_attachSession() - MMAP Attach to shared memory & return begin address
Line 161  void ipc_destroySession(ait_sess_t * __restrict Sess); Line 176  void ipc_destroySession(ait_sess_t * __restrict Sess);
  * @procMem = Custom start address (optionl) *default must be 0*   * @procMem = Custom start address (optionl) *default must be 0*
  * return: NULL failed attach, !=NULL begin address of memory   * return: NULL failed attach, !=NULL begin address of memory
  */   */
void *map_attachSession(ait_sess_t * __restrict s, void *procMem);void *map_attachSession(sess_t * __restrict s, void *procMem);
 /*  /*
  * map_detachSession() - MMAP Detach from shared memory   * map_detachSession() - MMAP Detach from shared memory
  *   *
  * @s = Session item   * @s = Session item
  * return: none   * return: none
  */   */
void map_detachSession(ait_sess_t * __restrict s);void map_detachSession(sess_t * __restrict s);
   
 /*  /*
  * ipc_attachSession() - IPC Attach to shared memory & return begin address   * ipc_attachSession() - IPC Attach to shared memory & return begin address
Line 177  void map_detachSession(ait_sess_t * __restrict s); Line 192  void map_detachSession(ait_sess_t * __restrict s);
  * @procMem = Custom start address (optionl) *default must be 0*   * @procMem = Custom start address (optionl) *default must be 0*
  * return: NULL failed attach, !=NULL begin address of memory   * return: NULL failed attach, !=NULL begin address of memory
  */   */
void *ipc_attachSession(ait_sess_t * __restrict s, void *procMem);void *ipc_attachSession(sess_t * __restrict s, void *procMem);
 /*  /*
  * ipc_detachSession() - IPC Detach from shared memory   * ipc_detachSession() - IPC Detach from shared memory
  *   *
  * @s = Session item   * @s = Session item
  * return: none   * return: none
  */   */
void ipc_detachSession(ait_sess_t * __restrict s);void ipc_detachSession(sess_t * __restrict s);
   
 /*  /*
  * sess_isAttached() - Check for attached shared memory   * sess_isAttached() - Check for attached shared memory
Line 192  void ipc_detachSession(ait_sess_t * __restrict s); Line 207  void ipc_detachSession(ait_sess_t * __restrict s);
  * @s = Session item   * @s = Session item
  * return: -1 null session item, 0 not attached, 1 attached memory   * return: -1 null session item, 0 not attached, 1 attached memory
  */   */
inline int sess_isAttached(ait_sess_t * __restrict s);int sess_isAttached(sess_t * __restrict s);
   
   
 /*  /*
Line 201  inline int sess_isAttached(ait_sess_t * __restrict s); Line 216  inline int sess_isAttached(ait_sess_t * __restrict s);
  * @s = Session item   * @s = Session item
  * return: none   * return: none
  */   */
void map_notSemaphore(ait_sess_t * __restrict s);void map_notSemaphore(sess_t * __restrict s);
 /*  /*
  * map_isSemaphoreOK() - MMAP Check semaphore   * map_isSemaphoreOK() - MMAP Check semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: -1 error: can`t return semaphore, 0 = false, 1 = true   * return: -1 error: can`t return semaphore, 0 = false, 1 = true
  */   */
int map_isSemaphoreOK(ait_sess_t * __restrict s);int map_isSemaphoreOK(sess_t * __restrict s);
 /*  /*
  * map_incSemaphore() - MMAP unblock semaphore, increment semaphore   * map_incSemaphore() - MMAP unblock semaphore, increment semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: 0 Ok, -1 error: can`t increment    * return: 0 Ok, -1 error: can`t increment 
  */   */
int map_incSemaphore(ait_sess_t * __restrict s);int map_incSemaphore(sess_t * __restrict s);
 /*  /*
  * map_decSemaphore() - MMAP block semaphore, decrement semaphore   * map_decSemaphore() - MMAP block semaphore, decrement semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: 0 Ok, -1 error: can`t decrement    * return: 0 Ok, -1 error: can`t decrement 
  */   */
int map_decSemaphore(ait_sess_t * __restrict s);int map_decSemaphore(sess_t * __restrict s);
   
 /*  /*
  * ipc_notSemaphore() - IPC negative block if semaphore isn`t signaled   * ipc_notSemaphore() - IPC negative block if semaphore isn`t signaled
Line 230  int map_decSemaphore(ait_sess_t * __restrict s); Line 245  int map_decSemaphore(ait_sess_t * __restrict s);
  * @s = Session item   * @s = Session item
  * return: none   * return: none
  */   */
void ipc_notSemaphore(ait_sess_t * __restrict s);void ipc_notSemaphore(sess_t * __restrict s);
 /*  /*
  * ipc_isSemaphoreOK() - IPC Check semaphore   * ipc_isSemaphoreOK() - IPC Check semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: -1 error: can`t return semaphore, 0 = false, 1 = true   * return: -1 error: can`t return semaphore, 0 = false, 1 = true
  */   */
int ipc_isSemaphoreOK(ait_sess_t * __restrict s);int ipc_isSemaphoreOK(sess_t * __restrict s);
 /*  /*
  * ipc_incSemaphore() - IPC unblock semaphore, increment semaphore   * ipc_incSemaphore() - IPC unblock semaphore, increment semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: 0 Ok, -1 error: can`t increment    * return: 0 Ok, -1 error: can`t increment 
  */   */
int ipc_incSemaphore(ait_sess_t * __restrict s);int ipc_incSemaphore(sess_t * __restrict s);
 /*  /*
  * ipc_decSemaphore() - IPC block semaphore, decrement semaphore   * ipc_decSemaphore() - IPC block semaphore, decrement semaphore
  *   *
  * @s = Session item   * @s = Session item
  * return: 0 Ok, -1 error: can`t decrement    * return: 0 Ok, -1 error: can`t decrement 
  */   */
int ipc_decSemaphore(ait_sess_t * __restrict s);int ipc_decSemaphore(sess_t * __restrict s);
   
   
 /* --------------------------------------------------------- */  
   
 #define ALLOC_MEMORY(sd, siz, s, ...)   (assert((s)), (s)->sess.create((sd), \  
                                                         (siz), (s), ## __VA_ARGS__))  
 #define ATTACH_MEMORY(s)                (assert((s)), (s)->sess.attach((s), NULL))  
 #define DETACH_MEMORY(s)                do { assert((s)); (s)->sess.detach((s)); } while(0)  
 #define FREE_MEMORY(s)                  do { assert((s)); (s)->sess.destroy((s)); } while(0)  
   
 #define IS_SEMOK(s)                     (assert((s)), (s)->sess.isSemOK((s)))  
 #define INC_SEM(s)                      (assert((s)), (s)->sess.incSem((s)))  
 #define DEC_SEM(s)                      (assert((s)), (s)->sess.decSem((s)))  
 #define NOT_SEM(s)                      do { assert((s)); (s)->sess.notSem((s)); } while(0)  
   
 /* --------------------------------------------------------- */  
   
 /*  /*
  * sess_FreeValues() - Free all values from value array allocated from sess_GetValues()  
  *  
  * @ppsVals = Array strings  
  * return: none  
  */  
 inline void sess_FreeValues(char *** __restrict ppsVals);  
 /*  
  * sess_GetValues() - Get all values from session shared memory   * sess_GetValues() - Get all values from session shared memory
  *   *
  * @s = Session item   * @s = Session item
 * @ppsVals = Return array strings * @Vals = Return array strings
 * return: -1 error: in parameter, !=-1 count of returned strings in ppsVals  * return: -1 error: in parameter, !=-1 count of returned strings in Vals 
 *              (must be sess_FreeValues after use!) *              (must call ait_freeVars() after use!)
  */   */
int sess_GetValues(ait_sess_t * __restrict s, char ***ppsVals);int sess_GetValues(sess_t * __restrict s, array_t ** __restrict Vals);
 /*  /*
  * sess_GetValue() - Get value from session shared memory from attribute   * sess_GetValue() - Get value from session shared memory from attribute
  *   *
  * @s = Session item   * @s = Session item
  * @csAttr = Attribute for search   * @csAttr = Attribute for search
 * @psVal = Return string buffer * @v = Return string value and after use must call ait_freeVar(), also may be =NULL
 * @pnLen = Length of return string buffer,  
        // *{pnLen} input is max_size of buffer & output is really taken bytes 
  * return: 0 not found, -1 error: in parameter, >0 get position,    * return: 0 not found, -1 error: in parameter, >0 get position, 
  *      if define item merged with IS_DEF   *      if define item merged with IS_DEF
  */   */
int sess_GetValue(ait_sess_t * __restrict s, const char *csAttr, char *psVal, int *pnLen);int sess_GetValue(sess_t * __restrict s, const char *csAttr, ait_val_t ** __restrict v);
 /*  /*
  * sess_DelValue() - Delete item from session shared memory   * sess_DelValue() - Delete item from session shared memory
  *   *
  * @s = Session item   * @s = Session item
  * @csAttr = Attribute for erasing   * @csAttr = Attribute for erasing
 * return: 0 Ok, -1 error: in parameter * return: -1 error: in parameter or !=-1 deleted items
  */   */
int sess_DelValue(ait_sess_t * __restrict s, const char *csAttr);int sess_DelValue(sess_t * __restrict s, const char *csAttr);
 /*  /*
  * sess_SetValue() - Set item into session shared memory or update if exists   * sess_SetValue() - Set item into session shared memory or update if exists
  *   *
Line 312  int sess_DelValue(ait_sess_t * __restrict s, const cha Line 303  int sess_DelValue(ait_sess_t * __restrict s, const cha
  * @csAttr = Attribute   * @csAttr = Attribute
  * @psVal = Value   * @psVal = Value
  * return: 0 nothing, -1 error: in parameter,    * return: 0 nothing, -1 error: in parameter, 
        >0 set position, if add item merged with IS_ADD and if define item merged with IS_DEF        >0 set position, if added new item merged with SESS_F_ADD and 
         if just define item merged with SESS_F_DEF
  */   */
int sess_SetValue(ait_sess_t * __restrict s, const char *csAttr, const char *psVal);int sess_SetValue(sess_t * __restrict s, const char *csAttr, const char *psVal);
   
 /*  /*
  * sess_prepareSession() - Attach to shared memory and de-marshaling data   * sess_prepareSession() - Attach to shared memory and de-marshaling data
Line 324  int sess_SetValue(ait_sess_t * __restrict s, const cha Line 316  int sess_SetValue(ait_sess_t * __restrict s, const cha
  * return: NULL error or no data, !=NULL array with variables,    * return: NULL error or no data, !=NULL array with variables, 
  *              after use must free resources with sess_doneSession()   *              after use must free resources with sess_doneSession()
  */   */
array_t *sess_prepareSession(ait_sess_t * __restrict s, char useDirect);array_t *sess_prepareSession(sess_t * __restrict s, char useDirect);
 /*  /*
  * sess_doneSession() - Free resources allocated with sess_prepareSession()   * sess_doneSession() - Free resources allocated with sess_prepareSession()
  *   *
Line 332  array_t *sess_prepareSession(ait_sess_t * __restrict s Line 324  array_t *sess_prepareSession(ait_sess_t * __restrict s
  * @arr = Array with variables for free   * @arr = Array with variables for free
  * return: none   * return: none
  */   */
void sess_doneSession(ait_sess_t * __restrict s, array_t ** __restrict arr);void sess_doneSession(sess_t * __restrict s, array_t ** __restrict arr);
 /*  /*
  * sess_commitSession() - Commit data to shared memory   * sess_commitSession() - Commit data to shared memory
  *   *
Line 340  void sess_doneSession(ait_sess_t * __restrict s, array Line 332  void sess_doneSession(ait_sess_t * __restrict s, array
  * @arr = Array with variables for save   * @arr = Array with variables for save
  * return -1 error or !=-1 size of stored variables into shared memory   * return -1 error or !=-1 size of stored variables into shared memory
  */   */
int sess_commitSession(ait_sess_t * __restrict s, array_t * __restrict arr);int sess_commitSession(sess_t * __restrict s, array_t * __restrict arr);
   
   
 #endif  #endif

Removed from v.1.1.2.2  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>