Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Internal servers header.
0003  *
0004  * @file srv_int.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 
0035 #ifndef SRV_INT_H
0036 #define SRV_INT_H
0037 
0038 #ifdef  __cplusplus
0039 extern NDRX_API "C" {
0040 #endif
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <ndrx_config.h>
0043 #include <sys_mqueue.h>
0044 #include <atmi.h>
0045 #include <setjmp.h>
0046 #include <ndrxdcmn.h>
0047 #include <exhash.h>
0048 #include <sys_unix.h>
0049 #include <atmi.h>
0050 #include <atmi_int.h>
0051 #include <exthpool.h>
0052 #include <thlock.h>
0053 /*---------------------------Externs------------------------------------*/
0054 extern NDRX_API long G_libatmisrv_flags; /**< present in integra.c or standard.c */
0055 extern NDRX_API int G_atmisrv_reply_type; /**< ATMI server return value (no long jump) */
0056 extern NDRX_API int G_shutdown_req; /**< is shutdown requested? */
0057 /* system call for server init */
0058 extern int (*ndrx_G_tpsvrinit_sys)(int, char **);
0059 
0060 /*---------------------------Macros-------------------------------------*/
0061 #define MIN_SVC_LIST_LEN        30
0062 #define SVN_LIST_REALLOC        15
0063 
0064 #define RETURN_FAILED             0x00000001
0065 #define RETURN_TYPE_TPRETURN      0x00000002
0066 #define RETURN_TYPE_TPFORWARD     0x00000004
0067 #define RETURN_SVC_FAIL           0x00000008
0068 #define RETURN_TYPE_THREAD        0x00000010  /**< processing sent to thread   */
0069 
0070 /* with linux 4.5 this is supported */ 
0071 #ifndef EPOLLEXCLUSIVE
0072 
0073 #define EPOLLEXCLUSIVE (1 << 28)
0074 
0075 #endif
0076 
0077 /*---------------------------Enums--------------------------------------*/
0078 /*---------------------------Typedefs-----------------------------------*/
0079 
0080    
0081 /**
0082  * Service name/alias entry.
0083  */
0084 typedef struct svc_entry svc_entry_t;
0085 struct svc_entry
0086 {
0087     char svc_nm[XATMI_SERVICE_NAME_LENGTH+1];
0088     char svc_aliasof[XATMI_SERVICE_NAME_LENGTH+1];
0089     svc_entry_t *next, *prev;
0090 };
0091 
0092 /**
0093  * Hash of buffer conversion functions.
0094  */
0095 typedef struct xbufcvt_entry xbufcvt_entry_t;
0096 struct xbufcvt_entry
0097 {
0098     char fn_nm[XATMI_SERVICE_NAME_LENGTH+1]; /* function name */
0099     long xcvtflags; /* Conversion function */
0100     EX_hash_handle hh;         /* makes this structure hashable */
0101 };
0102 
0103 /**
0104  * Skip service from advertse Feature #275
0105  */
0106 typedef struct ndrx_svchash ndrx_svchash_t;
0107 struct ndrx_svchash
0108 {
0109     char svc_nm[XATMI_SERVICE_NAME_LENGTH+1]; /* function name */
0110     EX_hash_handle hh;         /* makes this structure hashable */
0111 };
0112 
0113 /**
0114  * Service entry descriptor.
0115  */
0116 typedef struct svc_entry_fn svc_entry_fn_t;
0117 struct svc_entry_fn
0118 {
0119     char svc_nm[XATMI_SERVICE_NAME_LENGTH+1]; /* service name */
0120     char fn_nm[XATMI_SERVICE_NAME_LENGTH+1]; /* function name */
0121     void (*p_func)(TPSVCINFO *);
0122     /* listing support */
0123     svc_entry_fn_t *next, *prev;
0124     char listen_q[FILENAME_MAX+1]; /* queue on which to listen */
0125     int is_admin;
0126     mqd_t q_descr; /* queue descriptor */
0127     ndrx_stopwatch_t qopen_time;
0128     long xcvtflags; /* Conversion function */
0129     
0130     /* have flags for transaction -> authtran & timeout */
0131     int autotran;       /**< shall we start transaction upport receving msg?  */
0132     unsigned long trantime; /**< transaction timeout if doing autotran        */
0133 };
0134 
0135 /*
0136  * Basic call info
0137  */
0138 struct basic_call_info
0139 {
0140     char *buf_ptr;
0141     long len;
0142     int no;
0143 };
0144 typedef struct basic_call_info call_basic_info_t;
0145 
0146 /**
0147  * Basic server configuration.
0148  */
0149 struct srv_conf
0150 {
0151     char binary_name[MAXTIDENT+1];
0152     int srv_id;
0153     char err_output[FILENAME_MAX+1];
0154     char std_output[FILENAME_MAX+1];
0155     int log_work;
0156     int advertise_all;
0157     int no_built_advertise; /**< Do not advertise services provided by buildserver */
0158     svc_entry_t *svc_list;
0159     svc_entry_t *funcsvc_list;  /**< Function mappings to services -S */
0160     char q_prefix[FILENAME_MAX+1];
0161     
0162     int app_argc;/**< Arguments passed after -- */
0163     char **app_argv;
0164     
0165     /*<THESE LISTS ARE USED ONLY TILL SERVER GOES ONLINE, STATIC INIT>      */
0166     svc_entry_fn_t *service_raw_list; /**< As from initialization           */
0167     int service_raw_list_count; /**< Number of services in raw list         */
0168     svc_entry_fn_t **service_array; /**< Direct array of items              */
0169     /*</THESE LISTS ARE USED ONLY TILL SERVER GOES ONLINE, STATIC INIT>     */
0170     
0171     svc_entry_fn_t *service_list; /**< Final list used for processing */
0172     
0173     int adv_service_count; /**< advertised service count. */
0174     int flags; /**< Special flags of the server (see: ndrxdcmn.h:SRV_KEY_FLAGS_BRIDGE) */
0175     int nodeid; /**< Other node id of the bridge */
0176     int (*p_qmsg)(char **buf, int len, char msg_type); /**< Q message processor for bridge */
0177     /**************** POLLING *****************/
0178     struct ndrx_epoll_event *events;
0179     int epollfd;
0180     int time_out;
0181     int max_events; /**< Max epoll events. */
0182     
0183     int (*p_periodcb)(void);/**< Periodic callback */
0184     int periodcb_sec; /**< Number of seconds for each cb call */
0185     
0186     int (*p_shutdowncb)(int *shutdown_req);/**< Redirect shutdown request to callback
0187                                * for advanced shutdown sequences such as tmq */
0188     
0189     /** Callback used before server goes in poll state */
0190     int (*p_b4pollcb)(void);
0191     xbufcvt_entry_t *xbufcvt_tab; /**< string hashlist for buffer convert funcs */
0192     
0193     char rqaddress[NDRX_MAX_Q_SIZE+1]; /**< request address if used... (sysv) */
0194     
0195     int is_threaded;            /**< is multi-threaded server       */
0196     int mindispatchthreads;     /**< minimum dispatch threads       */
0197     int maxdispatchthreads;     /**< maximum dispatch trheads       */
0198   
0199     threadpool dispthreads;     /**< thread pool for dispatch threads*/
0200     NDRX_SPIN_LOCKDECL (mt_lock);   /**< mt lock for data sync        */
0201     
0202     int ddr_keep_grp;           /**< shall we keep DDR group name in svcnm? */
0203     int procgrp_lp_no;          /**< Singleton group lock provider group id, 0 - not used */
0204 };
0205 
0206 typedef struct srv_conf srv_conf_t;
0207 
0208 
0209 /**
0210  * Server multi threading, context switching
0211  */
0212 struct server_ctx_info
0213 {
0214     tp_conversation_control_t G_accepted_connection;
0215     tp_command_call_t         G_last_call;
0216     int                       is_in_global_tx;  /* Running in global tx      */
0217     TPTRANID                  tranid;           /* Transaction ID  (if used) */
0218 };
0219 typedef struct server_ctx_info server_ctx_info_t;
0220 
0221 /**
0222  * Defer server tpacall
0223  */
0224 typedef struct ndrx_tpacall_defer ndrx_tpacall_defer_t;
0225 struct ndrx_tpacall_defer
0226 {   
0227     /** service to call */
0228     char svcnm[MAXTIDENT+1];
0229     
0230     /** data may be null if sending NULL buffer */
0231     char *data;
0232     
0233     /** data len */
0234     long len;
0235     
0236     /** call flags */
0237     long flags;
0238     
0239     ndrx_tpacall_defer_t *next;
0240     ndrx_tpacall_defer_t *prev;
0241 };
0242 
0243 /*---------------------------Globals------------------------------------*/
0244 extern NDRX_API srv_conf_t G_server_conf;
0245 extern NDRX_API shm_srvinfo_t *G_shm_srv;
0246 extern NDRX_API pollextension_rec_t *ndrx_G_pollext;
0247 extern NDRX_API ndrx_svchash_t *ndrx_G_svchash_skip;
0248 extern NDRX_API ndrx_svchash_t *ndrx_G_svchash_funcs;
0249 extern NDRX_API int G_shutdown_req;
0250 extern NDRX_API int G_shutdown_nr_wait;   /* Number of self shutdown messages to wait */
0251 extern NDRX_API int G_shutdown_nr_got;    /* Number of self shutdown messages got  */
0252 extern NDRX_API void (*___G_test_delayed_startup)(void);
0253 
0254 extern NDRX_API int (*G_tpsvrinit__)(int, char **);
0255 extern NDRX_API int (*ndrx_G_tpsvrinit_sys)(int, char **);
0256 extern NDRX_API void (*G_tpsvrdone__)(void);
0257 extern NDRX_API int (*ndrx_G_tpsvrthrinit)(int, char **);
0258 extern NDRX_API void (*ndrx_G_tpsvrthrdone)(void);
0259 
0260 /*---------------------------Statics------------------------------------*/
0261 /*---------------------------Prototypes---------------------------------*/
0262 extern NDRX_API int sv_open_queue(void);
0263 extern NDRX_API int sv_wait_for_request(void);
0264 extern NDRX_API int unadvertse_to_ndrxd(char *srvcnm);
0265 
0266 /* Server specific functions: */
0267 extern NDRX_API void _tpreturn (int rval, long rcode, char *data, long len, long flags);
0268 extern NDRX_API void _tpforward (char *svc, char *data,
0269                 long len, long flags);
0270 extern NDRX_API void _tpcontinue (void);
0271 
0272 extern NDRX_API int ndrx_sv_set_autojoin(int new_flag);
0273 extern NDRX_API int ndrx_sv_latejoin(void);
0274 
0275 /* ndrd api */
0276 extern NDRX_API int advertse_to_ndrxd(svc_entry_fn_t *entry);
0277 extern NDRX_API int advertse_to_ndrxd(svc_entry_fn_t *entry);
0278 extern NDRX_API int report_to_ndrxd(void);
0279 extern NDRX_API void ndrx_set_report_to_ndrxd_cb(int (*report_to_ndrxd_callback) (void));
0280 /* Return list of connected bridge nodes. */
0281 extern NDRX_API int ndrxd_get_bridges(char *nodes_out);
0282 extern NDRX_API int pingrsp_to_ndrxd(command_srvping_t *ping);
0283     
0284 /* Advertise & unadvertise */
0285 extern NDRX_API int dynamic_unadvertise(char *svcname, int *found, svc_entry_fn_t *copy);
0286 extern NDRX_API int dynamic_advertise(svc_entry_fn_t *entry_new, 
0287                     char *svc_nm, void (*p_func)(TPSVCINFO *), char *fn_nm);
0288 /* We want to re-advertise the stuff, this could be used for race conditions! */
0289 extern NDRX_API int dynamic_readvertise(char *svcname);
0290 
0291 /* Polling extension */
0292 extern NDRX_API void ndrx_ext_pollsync(int flag);
0293 extern NDRX_API pollextension_rec_t * ext_find_poller(int fd);
0294 extern NDRX_API int _tpext_addpollerfd(int fd, uint32_t events, 
0295         void *ptr1, int (*p_pollevent)(int fd, uint32_t events, void *ptr1));
0296 extern NDRX_API int _tpext_delpollerfd(int fd);
0297 extern NDRX_API int _tpext_addperiodcb(int secs, int (*p_periodcb)(void));
0298 extern NDRX_API int _tpext_delperiodcb(void);
0299 extern NDRX_API int _tpext_addb4pollcb(int (*p_b4pollcb)(void));
0300 extern NDRX_API int _tpext_delb4pollcb(void);
0301 extern NDRX_API int process_admin_req(char **buf, long len, 
0302         int *shutdown_req);
0303 
0304 /* auto buffer convert: */
0305 extern NDRX_API long ndrx_xcvt_lookup(char *fn_nm);
0306 
0307 extern NDRX_API int atmisrv_build_advertise_list(void);
0308 extern NDRX_API int atmisrv_initialise_atmi_library(void);
0309 extern NDRX_API void atmisrv_un_initialize(int fork_uninit);
0310 
0311 extern NDRX_API int atmisrv_array_remove_element(void *arr, int elem, int len, int sz);
0312 
0313 extern NDRX_API int ndrx_svchash_add(ndrx_svchash_t **hash, char *svc_nm);
0314 extern NDRX_API int ndrx_svchash_chk(ndrx_svchash_t **hash, char *svc_nm);
0315 extern NDRX_API void ndrx_svchash_cleanup(ndrx_svchash_t **hash);
0316 
0317 extern NDRX_API int ndrx_svc_entry_fn_cmp(svc_entry_fn_t *a, svc_entry_fn_t *b);
0318 extern NDRX_API void ndrx_sv_advertise_lock();
0319 extern NDRX_API void ndrx_sv_advertise_unlock();
0320 extern NDRX_API void ndrx_sv_do_shutdown(char *requester, int *shutdown_req);
0321 extern NDRX_API int ndrx_tpext_addbshutdowncb(int (*p_shutdowncb)(int *shutdown_req));
0322 #ifdef  __cplusplus
0323 }
0324 #endif
0325 
0326 #endif  /* SRV_INT_H */
0327 
0328 /* vim: set ts=4 sw=4 et smartindent: */