/*
 * vl_svr.pgc - vl (정합성검증/validation) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of vl's 133 online 검증 services now lives in its own file
 * (app/src/vl/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/vl/svc/<SVCNAME>.h); each SELECTs the target rows, applies a 검증
 * branch, and returns an 에러코드 in T_RC. Objects are archived into libvlsvc.a
 * and linked into this server. Here we only include every service copybook,
 * tpopen() the ECPG XA RM, tpadvertise() all services, tpclose() at shutdown.
 *
 * XA: the connection is opened once by tpopen() (ECPG XA switch); there is NO
 * EXEC SQL CONNECT. Each tpcall runs on this process's XA branch.
 */
#include <atmi.h>
#include <ubf.h>
#include <userlog.h>

/* every vl service's copybook header (declares its prototype) */
#include "VL_SALES.h"
#include "VL_CARD.h"
#include "VL_LIMIT.h"
#include "VL_AMOUNT.h"
#include "VL_ANOMALY.h"
#include "VL_REQUIRED.h"
#include "VL_CODEVAL.h"
#include "VL_APPR_ACQ.h"
#include "VL_DUP.h"
#include "VL_DATE.h"
#include "VL_FEE.h"
#include "VL_SETTLE.h"
#include "VL_LEDGER.h"
#include "VL_FORMAT.h"
#include "VL_REFINTEG.h"
#include "VL_DUPAUTH.h"
#include "VL_BIN.h"
#include "VL_EXPIRY.h"
#include "VL_TOLERANCE.h"
#include "VL_MERCH.h"
#include "VL_STATUS_CHK.h"
#include "VL_BALANCE.h"
#include "VL_SUMMARY.h"
#include "VL_REPORT.h"
#include "VL_BATCH_CHK.h"
#include "VL_THRESHOLD.h"
#include "VL_RULE.h"
#include "VL_CROSSCHK.h"
#include "VL_STATUS.h"
#include "VL_CONFIRM.h"
#include "VL_APPRAMT.h"
#include "VL_APPRAGG.h"
#include "VL_TRISTAGE.h"
#include "VL_TRIAGG.h"
#include "VL_LEDGBAL.h"
#include "VL_LEDGENTRY.h"
#include "VL_FEERECALC.h"
#include "VL_FEEADJNET.h"
#include "VL_DUPPAY.h"
#include "VL_DUPSETTLE.h"
#include "VL_DUPPAYDAY.h"
#include "VL_UNACQ.h"
#include "VL_UNACQAGE.h"
#include "VL_AGEDOPEN.h"
#include "VL_AGEDCONF.h"
#include "VL_NEGBAL.h"
#include "VL_NEGNET.h"
#include "VL_MDRRATE.h"
#include "VL_RATEDEV.h"
#include "VL_DAYLIMIT.h"
#include "VL_LIMITNEAR.h"
#include "VL_DATEREV.h"
#include "VL_LEDGDATE.h"
#include "VL_RIMERCH.h"
#include "VL_RIPURCH.h"
#include "VL_RISETTLE.h"
#include "VL_RILEDGER.h"
#include "VL_SUMRECON.h"
#include "VL_SUMFEE.h"
#include "VL_RULEREG.h"
#include "VL_RULEMOD.h"
#include "VL_RULEHIST.h"
#include "VL_RULEOFF.h"
#include "VL_RULESTAT.h"
#include "VL_SUSPACK.h"
#include "VL_SUSPACT.h"
#include "VL_SUSPFINAL.h"
#include "VL_SUSPREOPEN.h"
#include "VL_SUSPSTAT.h"
#include "VL_THRSET.h"
#include "VL_THRBUMP.h"
#include "VL_THRAUDIT.h"
#include "VL_CANCELMIS.h"
#include "VL_INSTCHK.h"
#include "VL_FXCHK.h"

/* --- vl 정합성검증 확장 서비스 (+58) --- */
#include "VL_AXPURAPPR.h"
#include "VL_AXPURSETT.h"
#include "VL_AXSETTPAY.h"
#include "VL_AXLEDGDC.h"
#include "VL_DUPPURCH.h"
#include "VL_DUPAPPR.h"
#include "VL_DUPLEDGR.h"
#include "VL_DUPSETTMR.h"
#include "VL_APPRNOPUR.h"
#include "VL_PURNOAPPR.h"
#include "VL_LONGOPEN.h"
#include "VL_TXNREV.h"
#include "VL_SETTLREV.h"
#include "VL_APPRLATE.h"
#include "VL_NEGFEE.h"
#include "VL_FEEHIGH.h"
#include "VL_OVERLIMIT.h"
#include "VL_LIMITPCT.h"
#include "VL_DATEFUT.h"
#include "VL_DATEGAP.h"
#include "VL_ZERONET.h"
#include "VL_RIAPPR.h"
#include "VL_RIPAY.h"
#include "VL_RITAXINV.h"
#include "VL_RICANCEL.h"
#include "VL_RIINSTALL.h"
#include "VL_RIFX.h"
#include "VL_SUMTXNCNT.h"
#include "VL_SUMGROSS.h"
#include "VL_SUMNETCHK.h"
#include "VL_SUMFEECHK.h"
#include "VL_RULEVER.h"
#include "VL_RULERENAME.h"
#include "VL_RULESEV.h"
#include "VL_RULEON.h"
#include "VL_RULECOUNT.h"
#include "VL_RULEFIND.h"
#include "VL_SUSPTRIAGE.h"
#include "VL_SUSPESCAL.h"
#include "VL_SUSPRECHK.h"
#include "VL_SUSPASSIGN.h"
#include "VL_SUSPNOTE.h"
#include "VL_SUSPBULK.h"
#include "VL_SUSPAGEAVG.h"
#include "VL_THRGET.h"
#include "VL_THRSCALE.h"
#include "VL_THRRESET.h"
#include "VL_THRCOMPARE.h"
#include "VL_SPIKEAMT.h"
#include "VL_OUTLIER.h"
#include "VL_VELOCITY.h"
#include "VL_ROUNDAMT.h"
#include "VL_NIGHTTXN.h"
#include "VL_CATSKEW.h"
#include "VL_ISSUERMIX.h"
#include "VL_CHANSPLIT.h"
#include "VL_STATMIX.h"
#include "VL_CANCELRATE.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"VL_SALES", VL_SALES},
    {"VL_CARD", VL_CARD},
    {"VL_LIMIT", VL_LIMIT},
    {"VL_AMOUNT", VL_AMOUNT},
    {"VL_ANOMALY", VL_ANOMALY},
    {"VL_REQUIRED", VL_REQUIRED},
    {"VL_CODEVAL", VL_CODEVAL},
    {"VL_APPR_ACQ", VL_APPR_ACQ},
    {"VL_DUP", VL_DUP},
    {"VL_DATE", VL_DATE},
    {"VL_FEE", VL_FEE},
    {"VL_SETTLE", VL_SETTLE},
    {"VL_LEDGER", VL_LEDGER},
    {"VL_FORMAT", VL_FORMAT},
    {"VL_REFINTEG", VL_REFINTEG},
    {"VL_DUPAUTH", VL_DUPAUTH},
    {"VL_BIN", VL_BIN},
    {"VL_EXPIRY", VL_EXPIRY},
    {"VL_TOLERANCE", VL_TOLERANCE},
    {"VL_MERCH", VL_MERCH},
    {"VL_STATUS_CHK", VL_STATUS_CHK},
    {"VL_BALANCE", VL_BALANCE},
    {"VL_SUMMARY", VL_SUMMARY},
    {"VL_REPORT", VL_REPORT},
    {"VL_BATCH_CHK", VL_BATCH_CHK},
    {"VL_THRESHOLD", VL_THRESHOLD},
    {"VL_RULE", VL_RULE},
    {"VL_CROSSCHK", VL_CROSSCHK},
    {"VL_STATUS", VL_STATUS},
    {"VL_CONFIRM", VL_CONFIRM},
    {"VL_APPRAMT", VL_APPRAMT},
    {"VL_APPRAGG", VL_APPRAGG},
    {"VL_TRISTAGE", VL_TRISTAGE},
    {"VL_TRIAGG", VL_TRIAGG},
    {"VL_LEDGBAL", VL_LEDGBAL},
    {"VL_LEDGENTRY", VL_LEDGENTRY},
    {"VL_FEERECALC", VL_FEERECALC},
    {"VL_FEEADJNET", VL_FEEADJNET},
    {"VL_DUPPAY", VL_DUPPAY},
    {"VL_DUPSETTLE", VL_DUPSETTLE},
    {"VL_DUPPAYDAY", VL_DUPPAYDAY},
    {"VL_UNACQ", VL_UNACQ},
    {"VL_UNACQAGE", VL_UNACQAGE},
    {"VL_AGEDOPEN", VL_AGEDOPEN},
    {"VL_AGEDCONF", VL_AGEDCONF},
    {"VL_NEGBAL", VL_NEGBAL},
    {"VL_NEGNET", VL_NEGNET},
    {"VL_MDRRATE", VL_MDRRATE},
    {"VL_RATEDEV", VL_RATEDEV},
    {"VL_DAYLIMIT", VL_DAYLIMIT},
    {"VL_LIMITNEAR", VL_LIMITNEAR},
    {"VL_DATEREV", VL_DATEREV},
    {"VL_LEDGDATE", VL_LEDGDATE},
    {"VL_RIMERCH", VL_RIMERCH},
    {"VL_RIPURCH", VL_RIPURCH},
    {"VL_RISETTLE", VL_RISETTLE},
    {"VL_RILEDGER", VL_RILEDGER},
    {"VL_SUMRECON", VL_SUMRECON},
    {"VL_SUMFEE", VL_SUMFEE},
    {"VL_RULEREG", VL_RULEREG},
    {"VL_RULEMOD", VL_RULEMOD},
    {"VL_RULEHIST", VL_RULEHIST},
    {"VL_RULEOFF", VL_RULEOFF},
    {"VL_RULESTAT", VL_RULESTAT},
    {"VL_SUSPACK", VL_SUSPACK},
    {"VL_SUSPACT", VL_SUSPACT},
    {"VL_SUSPFINAL", VL_SUSPFINAL},
    {"VL_SUSPREOPEN", VL_SUSPREOPEN},
    {"VL_SUSPSTAT", VL_SUSPSTAT},
    {"VL_THRSET", VL_THRSET},
    {"VL_THRBUMP", VL_THRBUMP},
    {"VL_THRAUDIT", VL_THRAUDIT},
    {"VL_CANCELMIS", VL_CANCELMIS},
    {"VL_INSTCHK", VL_INSTCHK},
    {"VL_FXCHK", VL_FXCHK},
    {"VL_AXPURAPPR", VL_AXPURAPPR},
    {"VL_AXPURSETT", VL_AXPURSETT},
    {"VL_AXSETTPAY", VL_AXSETTPAY},
    {"VL_AXLEDGDC", VL_AXLEDGDC},
    {"VL_DUPPURCH", VL_DUPPURCH},
    {"VL_DUPAPPR", VL_DUPAPPR},
    {"VL_DUPLEDGR", VL_DUPLEDGR},
    {"VL_DUPSETTMR", VL_DUPSETTMR},
    {"VL_APPRNOPUR", VL_APPRNOPUR},
    {"VL_PURNOAPPR", VL_PURNOAPPR},
    {"VL_LONGOPEN", VL_LONGOPEN},
    {"VL_TXNREV", VL_TXNREV},
    {"VL_SETTLREV", VL_SETTLREV},
    {"VL_APPRLATE", VL_APPRLATE},
    {"VL_NEGFEE", VL_NEGFEE},
    {"VL_FEEHIGH", VL_FEEHIGH},
    {"VL_OVERLIMIT", VL_OVERLIMIT},
    {"VL_LIMITPCT", VL_LIMITPCT},
    {"VL_DATEFUT", VL_DATEFUT},
    {"VL_DATEGAP", VL_DATEGAP},
    {"VL_ZERONET", VL_ZERONET},
    {"VL_RIAPPR", VL_RIAPPR},
    {"VL_RIPAY", VL_RIPAY},
    {"VL_RITAXINV", VL_RITAXINV},
    {"VL_RICANCEL", VL_RICANCEL},
    {"VL_RIINSTALL", VL_RIINSTALL},
    {"VL_RIFX", VL_RIFX},
    {"VL_SUMTXNCNT", VL_SUMTXNCNT},
    {"VL_SUMGROSS", VL_SUMGROSS},
    {"VL_SUMNETCHK", VL_SUMNETCHK},
    {"VL_SUMFEECHK", VL_SUMFEECHK},
    {"VL_RULEVER", VL_RULEVER},
    {"VL_RULERENAME", VL_RULERENAME},
    {"VL_RULESEV", VL_RULESEV},
    {"VL_RULEON", VL_RULEON},
    {"VL_RULECOUNT", VL_RULECOUNT},
    {"VL_RULEFIND", VL_RULEFIND},
    {"VL_SUSPTRIAGE", VL_SUSPTRIAGE},
    {"VL_SUSPESCAL", VL_SUSPESCAL},
    {"VL_SUSPRECHK", VL_SUSPRECHK},
    {"VL_SUSPASSIGN", VL_SUSPASSIGN},
    {"VL_SUSPNOTE", VL_SUSPNOTE},
    {"VL_SUSPBULK", VL_SUSPBULK},
    {"VL_SUSPAGEAVG", VL_SUSPAGEAVG},
    {"VL_THRGET", VL_THRGET},
    {"VL_THRSCALE", VL_THRSCALE},
    {"VL_THRRESET", VL_THRRESET},
    {"VL_THRCOMPARE", VL_THRCOMPARE},
    {"VL_SPIKEAMT", VL_SPIKEAMT},
    {"VL_OUTLIER", VL_OUTLIER},
    {"VL_VELOCITY", VL_VELOCITY},
    {"VL_ROUNDAMT", VL_ROUNDAMT},
    {"VL_NIGHTTXN", VL_NIGHTTXN},
    {"VL_CATSKEW", VL_CATSKEW},
    {"VL_ISSUERMIX", VL_ISSUERMIX},
    {"VL_CHANSPLIT", VL_CHANSPLIT},
    {"VL_STATMIX", VL_STATMIX},
    {"VL_CANCELRATE", VL_CANCELRATE},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) {
        userlog("vl_svr: tpopen 실패: %s", tpstrerror(tperrno));
        return -1;
    }
    for (i = 0; SVCS[i].name != NULL; i++) {
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("vl_svr: tpadvertise(%s) 실패: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    }
    userlog("vl_svr: vl 검증 서비스 %d개 광고 완료, RM open", i);
    return 0;
}

void tpsvrdone(void)
{
    tpclose();
    userlog("vl_svr: tpsvrdone");
}

/* vim: set ts=4 sw=4 et smartindent: */
