Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Command's `shm_psrv' backend
0003  *
0004  * @file cmd_shm_psrv.c
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 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <utlist.h>
0039 
0040 #include <ndrstandard.h>
0041 
0042 #include <ndebug.h>
0043 #include <userlog.h>
0044 #include <ndrxd.h>
0045 #include <ndrxdcmn.h>
0046 
0047 #include "cmd_processor.h"
0048 #include <atmi_shm.h>
0049 /*---------------------------Externs------------------------------------*/
0050 extern ndrx_shm_t G_srvinfo;
0051 extern int G_max_servers;
0052 /*---------------------------Macros-------------------------------------*/
0053 /*---------------------------Enums--------------------------------------*/
0054 /*---------------------------Typedefs-----------------------------------*/
0055 /*---------------------------Globals------------------------------------*/
0056 /*---------------------------Statics------------------------------------*/
0057 /*---------------------------Prototypes---------------------------------*/
0058 
0059 /**
0060  * Modify reply according the data.
0061  * @param call
0062  * @param pm
0063  */
0064 expublic void shm_psrv_reply_mod(command_reply_t *reply, size_t *send_size, mod_param_t *params)
0065 {
0066     command_reply_shm_psrv_t * shm_psrv_info = (command_reply_shm_psrv_t *)reply;
0067     shm_srvinfo_t *p_shm = (shm_srvinfo_t *)params->mod_param1;
0068     
0069     reply->msg_type = NDRXD_CALL_TYPE_PM_SHM_PSRV;
0070     /* calculate new send size */
0071     *send_size += (sizeof(command_reply_shm_psrv_t) - sizeof(command_reply_t));
0072     
0073     /* Copy data to reply structure */
0074     shm_psrv_info->execerr = p_shm->execerr;
0075     shm_psrv_info->last_command_id = p_shm->last_command_id;
0076     NDRX_STRCPY_SAFE(shm_psrv_info->last_reply_q, p_shm->last_reply_q);
0077     shm_psrv_info->slot = params->param2;
0078     shm_psrv_info->srvid =p_shm->srvid; 
0079     shm_psrv_info->status = p_shm->status;
0080 
0081     NDRX_LOG(log_debug, "magic: %ld", shm_psrv_info->rply.magic);
0082 }
0083 
0084 /**
0085  * Callback to report startup progress
0086  * @param call
0087  * @param pm
0088  * @return
0089  */
0090 exprivate void shm_psrv_progress(command_call_t * call, shm_srvinfo_t *p_shm, int slot)
0091 {
0092     int ret=EXSUCCEED;
0093     mod_param_t params;
0094     
0095     NDRX_LOG(log_debug, "startup_progress enter");
0096     memset(&params, 0, sizeof(mod_param_t));
0097 
0098     /* pass to reply process model node */
0099     params.mod_param1 = (void *)p_shm;
0100     params.param2 = slot;
0101 
0102     if (EXSUCCEED!=simple_command_reply(call, ret, NDRXD_CALL_FLAGS_RSPHAVE_MORE,
0103                             /* hook up the reply */
0104                             &params, shm_psrv_reply_mod, 0L, 0, NULL))
0105     {
0106         userlog("Failed to send progress back to [%s]", call->reply_queue);
0107     }
0108 
0109     NDRX_LOG(log_debug, "startup_progress exit");
0110 }
0111 
0112 /**
0113  * Call to psc command
0114  * @param args
0115  * @return
0116  */
0117 expublic int cmd_shm_psrv (command_call_t * call, char *data, size_t len, int context)
0118 {
0119     int ret=EXSUCCEED;
0120     int i;
0121     shm_srvinfo_t *srvinfo = (shm_srvinfo_t *) G_srvinfo.mem;
0122     
0123     /* We assume shm is OK! */
0124     for (i=0; i<G_max_servers; i++)
0125     {
0126         if (srvinfo[i].srvid)
0127         {
0128             shm_psrv_progress(call, &srvinfo[i], i);
0129         }
0130     }
0131 
0132     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0133     {
0134         userlog("Failed to send reply back to [%s]", call->reply_queue);
0135     }
0136     NDRX_LOG(log_warn, "cmd_shm_psrv returns with status %d", ret);
0137     
0138 out:
0139     return ret;
0140 }
0141 
0142 /* vim: set ts=4 sw=4 et smartindent: */