Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Re-advertise related command back-end
0003  *
0004  * @file cmd_readv.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 
0039 #include <ndrstandard.h>
0040 
0041 #include "ndebug.h"
0042 #include "userlog.h"
0043 #include <ndrxd.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi.h>
0046 #include <cmd_processor.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /**
0056  * Request re-advertise from server for specific service!
0057  * @param srvid
0058  * @param svc
0059  * @return 
0060  */
0061 expublic int readv_request(int srvid, char *svc)
0062 {
0063     pm_node_t * p_pm;
0064     command_dynadvertise_t call_srv;
0065     int ret=EXSUCCEED;
0066     
0067     memset(&call_srv, 0, sizeof(call_srv));
0068     
0069     p_pm = G_process_model_hash[srvid];
0070     
0071     /*Fill some details for readvertise*/
0072     NDRX_STRCPY_SAFE(call_srv.svc_nm, svc);
0073     
0074     /* Call the server */
0075     ret = cmd_generic_call(NDRXD_COM_NXDREADV_RQ, NDRXD_SRC_ADMIN,
0076         NDRXD_CALL_TYPE_GENERIC,
0077         (command_call_t *)&call_srv, sizeof(call_srv),
0078         G_command_state.listenq_str,
0079         G_command_state.listenq,
0080         (mqd_t)EXFAIL,
0081         get_srv_admin_q(p_pm),
0082         0, NULL,
0083         NULL,
0084         NULL,
0085         NULL,
0086         EXFALSE);
0087     
0088     return ret;
0089 }
0090 
0091 /**
0092  * Commad for loading initial configuration.
0093  * If initial config is set, then just respond with OK.
0094  * @param args
0095  * @return 
0096  */
0097 expublic int cmd_xadreadv (command_call_t * call, char *data, size_t len, int context)
0098 {
0099     int ret=EXSUCCEED;
0100     command_dynadvertise_t *readv_xa = (command_dynadvertise_t *)call;
0101     command_dynadvertise_t call_srv;
0102     pm_node_t * p_pm;
0103     
0104     memset(&call_srv, 0, sizeof(call_srv));
0105     
0106     if (readv_xa->srvid<0 || readv_xa->srvid>=ndrx_get_G_atmi_env()->max_servers)
0107     {
0108         NDRXD_set_error_fmt(NDRXD_EINVPARAM, "Invalid server id %d",
0109                                     readv_xa->srvid);
0110         ret=EXFAIL;
0111         goto out;
0112     }
0113     
0114     p_pm = G_process_model_hash[readv_xa->srvid];
0115     
0116     if (NULL==p_pm)
0117     {
0118         NDRXD_set_error_fmt(NDRXD_EINVPARAM, "Server with ID %d not found", 
0119                                     readv_xa->srvid);
0120         ret=EXFAIL;
0121         goto out;
0122     }
0123     /*Fill some details for readvertise*/
0124     strcpy(call_srv.svc_nm, readv_xa->svc_nm);
0125     
0126     /* Call the server */
0127     ret = cmd_generic_call(NDRXD_COM_NXDREADV_RQ, NDRXD_SRC_ADMIN,
0128             NDRXD_CALL_TYPE_GENERIC,
0129             (command_call_t *)&call_srv, sizeof(call_srv),
0130             G_command_state.listenq_str,
0131             G_command_state.listenq,
0132             (mqd_t)EXFAIL,
0133             get_srv_admin_q(p_pm),
0134             0, NULL,
0135             NULL,
0136             NULL,
0137             NULL,
0138             EXFALSE);
0139 out:
0140     if (EXSUCCEED!=simple_command_reply(call, ret, 0L, NULL, NULL, 0L, 0, NULL))
0141     {
0142         userlog("Failed to send reply back to [%s]", call->reply_queue);
0143     }
0144 
0145     NDRX_LOG(log_warn, "cmd_readv_xadmin returns with status %d", ret);
0146     
0147     return EXSUCCEED; /* Do not want to break the system! */
0148 }
0149 
0150 /* vim: set ts=4 sw=4 et smartindent: */