Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Latent command framework. Part of the Enduro/X standard library
0003  *  internal part.
0004  * 
0005  * @file lcfint.h
0006  */
0007 /* -----------------------------------------------------------------------------
0008  * Enduro/X Middleware Platform for Distributed Transaction Processing
0009  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011  * This software is released under one of the following licenses:
0012  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013  * See LICENSE file for full text.
0014  * -----------------------------------------------------------------------------
0015  * AGPL license:
0016  *
0017  * This program is free software; you can redistribute it and/or modify it under
0018  * the terms of the GNU Affero General Public License, version 3 as published
0019  * by the Free Software Foundation;
0020  *
0021  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024  * for more details.
0025  *
0026  * You should have received a copy of the GNU Affero General Public License along 
0027  * with this program; if not, write to the Free Software Foundation, Inc.,
0028  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029  *
0030  * -----------------------------------------------------------------------------
0031  * A commercial use license is available from Mavimax, Ltd
0032  * contact@mavimax.com
0033  * -----------------------------------------------------------------------------
0034  */
0035 #ifndef LCFINT_H__
0036 #define LCFINT_H__
0037 
0038 #if defined(__cplusplus)
0039 extern "C" {
0040 #endif
0041 
0042 /*---------------------------Includes-----------------------------------*/
0043 #include <ndrx_config.h>
0044 #include <sys/types.h>
0045 #include <nstopwatch.h>
0046 #include <lcf.h>
0047 
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 #define NDRX_LCF_DDR_PAGES             2 
0051 #define NDRX_LCF_RESVR                 4096 /**< Reserved space for future commands and seamless update        */
0052 #define NDRX_LCFCNT_DEFAULT            20   /**< Default count of LCF commands                                 */
0053 #define NDRX_LCF_STARTCMDEXP           60   /**< Number of secs for exiting command to be expired for new proc */
0054 
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 
0058 /* LCF will provide generic settings library settings for internal use */
0059 
0060 
0061 /**
0062  * Standard library configuration managed by lcf
0063  */
0064 typedef struct
0065 {
0066     char *qprefix;      /**< Queue prefix used by mappings  */
0067     long queuesmax;     /**< Max number of queues           */
0068 
0069     int  pgmax;         /**< Max number of singleton-groups */
0070     int  sgrefreshmax;  /**< Expected maximums singleton-group refresh time */
0071 
0072     int  svqreadersmax;    /**< Max number of concurrent lckrds*/
0073     int  lcfreadersmax; /**< Max number of concurrent lckrds*/
0074     
0075     int  lcfmax;        /**< Max number of LCF commands     */
0076     key_t ipckey;       /**< Semphoare key                  */
0077     int  startcmdexp;   /**< Startup command delay          */
0078     int lcf_norun;      /**< LCF is disabled                */
0079 } ndrx_nstd_libconfig_t;
0080 
0081 /**
0082  * This is local list of commands seen & processed
0083  * During the program startup we do no process any commands
0084  * Except logrotates 
0085  */
0086 typedef struct
0087 {
0088     int    cmdversion;         /**< command version, so that if we switch the logs check that
0089                                 * command is not changed (i.e. we want to update the stats) */
0090     ndrx_stopwatch_t publtim;/**< Time when command was published                    */
0091     int    command;         /**< Command code                                        */
0092 } ndrx_lcf_command_seen_t;
0093 
0094 /**
0095  * Shared memory settings
0096  */
0097 typedef struct
0098 {
0099     unsigned shmcfgver_lcf;     /**< Monitor the version, if changed run LCF with readlock */
0100     int use_ddr;            /**< Should DDR be used by callers                         */
0101     unsigned char ddr_page;          /**< DDR page number  0 or 1, version not changes, using long for align */
0102     unsigned char ddr_ver1;          /**< DDR Version when we prepare to install data        */
0103     char reserved[NDRX_LCF_RESVR];  /**< reserved space for future updates             */
0104     unsigned char is_mmon;   /**< Is maintenace mode ON? */
0105     
0106     /**< Array of LCF commands */
0107     ndrx_lcf_command_t commands[0];
0108 
0109     /** Opaque ndrx_sg_shm_t follows */
0110 } ndrx_lcf_shmcfg_t;
0111 
0112 /**
0113  * Needs hash for function registration data -> hash by name 
0114  */
0115 typedef struct 
0116 {
0117     int command;    /**< lcf comand code        */
0118     ndrx_lcf_reg_func_t cfunc;
0119     EX_hash_handle hh; /**< makes this structure hashable               */
0120 } ndrx_lcf_reg_funch_t;
0121 
0122 /**
0123  * Needs hash with callback data, hash by command code       
0124  * This is used by xadmin lookups
0125  */
0126 typedef struct 
0127 {
0128     char cmdstr[NDRX_LCF_ADMINCMD_MAX+1]; /**< Command code */
0129     ndrx_lcf_reg_xadmin_t xcmd;
0130     EX_hash_handle hh; /**< makes this structure hashable               */
0131 } ndrx_lcf_reg_xadminh_t;
0132 
0133 /*---------------------------Globals------------------------------------*/
0134 extern NDRX_API ndrx_lcf_shmcfg_t *ndrx_G_shmcfg;
0135 extern NDRX_API ndrx_nstd_libconfig_t ndrx_G_libnstd_cfg;
0136 /*---------------------------Statics------------------------------------*/
0137 /*---------------------------Prototypes---------------------------------*/
0138 
0139 extern NDRX_API int ndrx_lcf_init(void);
0140 extern NDRX_API void ndrx_lcf_detach(void);
0141 extern NDRX_API void ndrx_lcf_remove(key_t ipckeybase, char *q_prefix);
0142 extern NDRX_API void ndrx_lcf_reset(void);
0143 
0144 /** Register callback for command code */
0145 extern NDRX_API int ndrx_lcf_xadmin_add_int(ndrx_lcf_reg_xadmin_t *xcmd);
0146 extern NDRX_API int ndrx_lcf_func_add_int(ndrx_lcf_reg_func_t *cfunc);
0147 extern NDRX_API ndrx_lcf_reg_xadminh_t* ndrx_lcf_xadmin_find_int(char *cmdstr);
0148 extern NDRX_API int ndrx_lcf_publish_int(int slot, ndrx_lcf_command_t *cmd);
0149 extern NDRX_API void ndrx_lcf_xadmin_list(void (*pf_callback)(ndrx_lcf_reg_xadminh_t *xcmd));
0150 
0151 extern NDRX_API int ndrx_lcf_read_lock(void);
0152 extern NDRX_API int ndrx_lcf_read_unlock(void);
0153 extern NDRX_API int ndrx_lcf_supported_int(void);
0154 extern NDRX_API ndrx_lcf_reg_xadminh_t* ndrx_lcf_xadmin_find_int(char *cmdstr);
0155 
0156 #if defined(__cplusplus)
0157 }
0158 #endif
0159 
0160 #endif
0161 /* vim: set ts=4 sw=4 et smartindent: */