/*
 * 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 ~30 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"

/* ----- 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},
    {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: */
