/*
 * st_svr.pgc - st (정산/수수료) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of st's 30 online services now lives in its own file
 * (app/src/st/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/st/svc/<SVCNAME>.h); those objects are archived into libstsvc.a and
 * linked into this server. Here we only include every service copybook, tpopen()
 * the ECPG XA RM, tpadvertise() all services from a {name, fn} table, and
 * tpclose() at shutdown.
 *
 * st_svr: ONE binary that tpadvertise()s ALL 30 online st(정산/수수료) services.
 * SETTLE keeps the proven behavior: its own XA branch writes the settlement +
 * settle ledger rows. Terminal service of the 매입 chain.
 */
#include <atmi.h>
#include <ubf.h>
#include <userlog.h>

/* every st service's copybook header (declares its record struct + prototype) */
#include "SETTLE.h"
#include "ST_MDR.h"
#include "ST_NETTING.h"
#include "ST_VAT.h"
#include "ST_VANFEE.h"
#include "ST_RELAYFEE.h"
#include "ST_WHT.h"
#include "ST_ADJUST.h"
#include "ST_ADVANCE.h"
#include "ST_DELAYINT.h"
#include "ST_HOLD.h"
#include "ST_RELEASE.h"
#include "ST_SPLIT.h"
#include "ST_PAYDATE.h"
#include "ST_BYMERCH.h"
#include "ST_MONTHLY.h"
#include "ST_OFFSET.h"
#include "ST_DIFFCHK.h"
#include "ST_RECALC.h"
#include "ST_RATEAPPLY.h"
#include "ST_REPORT.h"
#include "ST_XFERLINK.h"
#include "ST_STATS.h"
#include "ST_CANCEL.h"
#include "ST_LEDGERLINK.h"
#include "ST_BANDRATE.h"
#include "ST_CAP.h"
#include "ST_FXCONV.h"
#include "ST_CONFIRM.h"
#include "ST_STATUS.h"

/* ----- advertise table: {service name, function} ---------------------- */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"SETTLE", SETTLE},  {"ST_MDR", ST_MDR},
    {"ST_NETTING", ST_NETTING},  {"ST_VAT", ST_VAT},
    {"ST_VANFEE", ST_VANFEE},  {"ST_RELAYFEE", ST_RELAYFEE},
    {"ST_WHT", ST_WHT},  {"ST_ADJUST", ST_ADJUST},
    {"ST_ADVANCE", ST_ADVANCE},  {"ST_DELAYINT", ST_DELAYINT},
    {"ST_HOLD", ST_HOLD},  {"ST_RELEASE", ST_RELEASE},
    {"ST_SPLIT", ST_SPLIT},  {"ST_PAYDATE", ST_PAYDATE},
    {"ST_BYMERCH", ST_BYMERCH},  {"ST_MONTHLY", ST_MONTHLY},
    {"ST_OFFSET", ST_OFFSET},  {"ST_DIFFCHK", ST_DIFFCHK},
    {"ST_RECALC", ST_RECALC},  {"ST_RATEAPPLY", ST_RATEAPPLY},
    {"ST_REPORT", ST_REPORT},  {"ST_XFERLINK", ST_XFERLINK},
    {"ST_STATS", ST_STATS},  {"ST_CANCEL", ST_CANCEL},
    {"ST_LEDGERLINK", ST_LEDGERLINK},  {"ST_BANDRATE", ST_BANDRATE},
    {"ST_CAP", ST_CAP},  {"ST_FXCONV", ST_FXCONV},
    {"ST_CONFIRM", ST_CONFIRM},  {"ST_STATUS", ST_STATUS},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) { userlog("st_svr: tpopen FAIL: %s", tpstrerror(tperrno)); return -1; }
    for (i = 0; SVCS[i].name; i++)
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("st_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    userlog("st_svr: %d st services advertised, RM opened", i);
    return 0;
}

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

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