Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Common/shared data structures between server & client.
0003  *
0004  * @file ndrx_ddr.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #ifndef NDRX_DDR_H
0035 #define NDRX_DDR_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <ndrx_config.h>
0043 #include <ndrstandard.h>
0044 #include <atmi.h>
0045 #include <exhash.h>
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048     
0049 #define NDRX_DDR_FLAG_MIN            0x00000001  /**< This is min value      */
0050 #define NDRX_DDR_FLAG_MAX            0x00000002  /**< This is max value      */
0051 #define NDRX_DDR_FLAG_DEFAULT_VAL    0x00000004  /**< This is default value  */
0052 #define NDRX_DDR_FLAG_DEFAULT_GRP    0x00000008  /**< This is default group  */
0053 
0054 /* for sparc we set to 8 */
0055 #define DDR_DEFAULT_ALIGN       EX_ALIGNMENT_BYTES
0056 
0057 /**
0058  * Generic data alignment to default system ALGIN setting
0059  * @param DSIZE data on which to calc alignment
0060  */
0061 #define DDR_ALIGNED_GEN(DSIZE) \
0062     ((DSIZE + DDR_DEFAULT_ALIGN -1 ) / DDR_DEFAULT_ALIGN * DDR_DEFAULT_ALIGN)
0063 
0064 #define NDRX_DDRV_SVC_INDEX(MEM, IDX) ((ndrx_services_t*)(((char*)MEM)+(int)(sizeof(ndrx_services_t)*IDX)))
0065 /*---------------------------Enums--------------------------------------*/
0066 /*---------------------------Typedefs-----------------------------------*/
0067 
0068 /**
0069  * Routing criterion sequence contains the range
0070  * Positions to fields must have aligned access
0071  */
0072 typedef struct
0073 {
0074     char grp[NDRX_DDR_GRP_MAX+1];   /**< needs to assign a group code too    */
0075     double lowerd;                  /**< range is number lower part (double) */
0076     double upperd;                  /**< range is number upper part (double) */
0077     long lowerl;                    /**< range is number lower part (long)   */
0078     long upperl;                    /**< range is number upper part (long)   */
0079     int len;                        /**< total lenght of the field           */
0080     int flags;                      /**< routing flags MIN, MAX, DFLT        */
0081     int strrange_upper;             /**< Offset to upper block               */
0082     char strrange[1];               /**< string ranges (have space for eof debug)*/
0083 } ndrx_routcritseq_t;
0084 
0085 /**
0086  * Structure to keep the list of extended FDs.
0087  * NOTE ! size of the block is dynamic as ndrx_routcritseq_t
0088  * has unknown size at the start...
0089  */
0090 typedef struct ndrx_routcritseq_dl ndrx_routcritseq_dl_t;
0091 struct ndrx_routcritseq_dl
0092 {
0093     ndrx_routcritseq_dl_t *prev, *next;
0094     ndrx_routcritseq_t cseq;    /**< Criterion sequence         */
0095 };
0096 
0097 /**
0098  * Routing criterion
0099  * These might be several in the row if buffer types does not match.
0100  * 
0101  * So SHM would look like:
0102  * 
0103  * [ndrx_routcrit_t ndrx_routcritseq_t..N] .. [ndrx_routcrit_t ndrx_routcritseq_t..N]
0104  * 
0105  * Positions to fields must have aligned access
0106  * 
0107  */
0108 typedef struct
0109 {
0110     char criterion[NDRX_DDR_CRITMAX+1]; /**< criterion code, for debug      */
0111     int criterionid;            /**< criterion id                           */
0112     int len;                    /**< total len of the field including sequences */
0113     char field[MAXTIDENT+1];    /**< routing field id                       */
0114     short buffer_type_id;       /**< XATMI buffer type code                 */
0115     char buftype[256+1];        /**< Buffer type as defined                 */
0116     char fieldtype[16];         /**< Field type override, mandatory for json*/
0117     int  fieldtypeid;           /**< Type code of the field                 */
0118     BFLDID fldid;               /**< resolved field id for UBF              */
0119     long rangesnr;              /**< number of ranges follows               */
0120     char ranges[0];             /**< range offset of the ndrx_routcritseq_t */
0121 } ndrx_routcrit_t;
0122 
0123 /**
0124  * This is hash of the buffer types
0125  * Only one buffer type + subtype is allowed
0126  */
0127 typedef struct
0128 {
0129     char buftype[256+1];        /**< Buffer type, this is key for route crit has*/
0130     char *ranges;               /**< string dup of ranges                       */
0131     ndrx_routcrit_t routcrit;   /**< actula criterion data being hashed         */
0132     ndrx_routcritseq_dl_t *seq; /**< DL of criterion sequences                  */
0133     EX_hash_handle hh;          /**< Hash handle                                */
0134 } ndrx_routcrit_typehash_t;
0135 
0136 /**
0137  * Hash entry of criterions used
0138  * during config building
0139  */
0140 typedef struct
0141 {
0142     char criterion[NDRX_DDR_CRITMAX+1]; /**< criterion code                     */
0143     int criterionid;                    /**< store resolved id                  */
0144     long offset;                        /**< offset in shm where cirtion starts */    
0145     ndrx_routcrit_typehash_t *btypes;   /**< buffer types hash                  */
0146     EX_hash_handle hh;                  /**< Hash handle                        */
0147 } ndrx_routcrit_hash_t;
0148 
0149 
0150 /**
0151  * Routing information in shared memory
0152  */
0153 typedef struct
0154 {
0155     char svcnm[MAXTIDENT+1];    /**< service name in linear hash */
0156     int prio;                   /**< default call priority       */
0157     int cirterionid;            /**< criterion id                */
0158     char criterion[NDRX_DDR_CRITMAX+1]; /**< criterion code, is cirterion used ?*/
0159     long offset;                /**< memory offset where criterion id starts int cirt mem */
0160     int autotran;               /**< is autotran used?           */
0161     unsigned long trantime;     /**< transaction timeout time    */
0162     short flags;                /**< this is used by linear hash */
0163 } ndrx_services_t;
0164 
0165 /**
0166  * This is hash handler using during build of configuration
0167  */
0168 typedef struct
0169 {
0170     char svcnm[MAXTIDENT+1];    /**< service name in linear hash */
0171     ndrx_services_t routsvc;     /**< actula data                 */
0172     EX_hash_handle hh;          /**< Hash handle                 */
0173 } ndrx_services_hash_t;
0174 
0175 /*---------------------------Globals------------------------------------*/
0176 /*---------------------------Statics------------------------------------*/
0177 /*---------------------------Prototypes---------------------------------*/
0178 
0179 extern NDRX_API int ndrx_ddr_services_put(ndrx_services_t *svc, char *mem, long memmax);
0180 
0181 /** tpcalls shall route to this one... */
0182 extern NDRX_API int ndrx_ddr_grp_get(char *svcnm, size_t svcnmsz, char *data, long len,
0183         int *prio);
0184 extern NDRX_API int ndrx_ddr_service_get(char *svcnm, int *autotran, unsigned long *trantime);
0185 
0186 #ifdef  __cplusplus
0187 }
0188 #endif
0189 
0190 #endif  /* NDRX_DDR_H */
0191 
0192 /* vim: set ts=4 sw=4 et smartindent: */