/*
 * rc_svr.pgc - rc (대사) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of rc's 133 online services now lives in its own file
 * (app/src/rc/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/rc/svc/<SVCNAME>.h); those objects are archived into librcsvc.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.
 *
 * rc_svr: ONE binary that tpadvertise()s ALL 133 online rc(대사) services.
 * RECONCILE keeps the proven chain: distinct XA branch, own recon ledger row,
 * then tpcall()s SETTLE inside the SAME global tx.
 */
#include <atmi.h>
#include <ubf.h>
#include <userlog.h>

/* every rc service's copybook header (declares its record struct + prototype) */
#include "RECONCILE.h"
#include "RC_APPR_ACQ.h"
#include "RC_ACQ_DEP.h"
#include "RC_RETURN.h"
#include "RC_AMTDIFF.h"
#include "RC_CNTDIFF.h"
#include "RC_3WAY.h"
#include "RC_TOLERANCE.h"
#include "RC_REMATCH.h"
#include "RC_HOLD.h"
#include "RC_UNMATCH.h"
#include "RC_RELEASE.h"
#include "RC_EXCEPTION.h"
#include "RC_AUTOFIX.h"
#include "RC_BYISSUER.h"
#include "RC_BYDATE.h"
#include "RC_BYMERCH.h"
#include "RC_PARTIAL.h"
#include "RC_DIFFRPT.h"
#include "RC_STATS.h"
#include "RC_PROGRESS.h"
#include "RC_SUMMARY.h"
#include "RC_REPROC.h"
#include "RC_DELAY.h"
#include "RC_LEDGERLINK.h"
#include "RC_ALERT.h"
#include "RC_MANUAL.h"
#include "RC_ROLLBACK.h"
#include "RC_CONFIRM.h"
#include "RC_STATUS.h"
#include "RC_4WAY.h"
#include "RC_DEPMATCH.h"
#include "RC_PAYMATCH.h"
#include "RC_BYCHANNEL.h"
#include "RC_BYCATEGORY.h"
#include "RC_BYMGROUP.h"
#include "RC_MANREG.h"
#include "RC_MANAPPRV.h"
#include "RC_MANREJECT.h"
#include "RC_HOLDRSN.h"
#include "RC_HOLDAGE.h"
#include "RC_DIFFCAUSE.h"
#include "RC_DIFFTREND.h"
#include "RC_CARRYOVER.h"
#include "RC_RETRO.h"
#include "RC_NOTIFY.h"
#include "RC_RATESTAT.h"
#include "RC_RATEBYISS.h"
#include "RC_THRESHOLD.h"
#include "RC_RERUN.h"
#include "RC_CANCELREC.h"
#include "RC_VOIDREC.h"
#include "RC_PARTACQ.h"
#include "RC_INSTRECON.h"
#include "RC_FEERECON.h"
#include "RC_FEEDIFF.h"
#include "RC_FXRECON.h"
#include "RC_FXRATECHK.h"
#include "RC_WHTRECON.h"
#include "RC_TAXRECON.h"
#include "RC_EDIRECON.h"
#include "RC_AUDITTRAIL.h"
#include "RC_AUDITLOG.h"
#include "RC_AGEING.h"
#include "RC_TOPDIFF.h"
#include "RC_ZEROAMT.h"
#include "RC_DUPCHK.h"
#include "RC_ORPHAN.h"
#include "RC_GAPSCAN.h"
#include "RC_SUMCHK.h"
#include "RC_LIMITCHK.h"
#include "RC_ESCALATE.h"
#include "RC_CLOSEDAY.h"
#include "RC_REOPEN.h"
#include "RC_SNAPSHOT.h"
#include "RC_APPRMATCH.h"
#include "RC_ACQMATCH.h"
#include "RC_DEPPAY.h"
#include "RC_PAYLEDGER.h"
#include "RC_LEDGERBAL.h"
#include "RC_APPRGAP.h"
#include "RC_DEPGAP.h"
#include "RC_PAYGAP.h"
#include "RC_CHANRECON.h"
#include "RC_ISSRECON.h"
#include "RC_BRANDRECON.h"
#include "RC_MGRPRECON.h"
#include "RC_POSRECON.h"
#include "RC_EDCRECON.h"
#include "RC_CHANDIFF.h"
#include "RC_ISSDIFF.h"
#include "RC_BRANDDIFF.h"
#include "RC_MGRPDIFF.h"
#include "RC_OVERAMT.h"
#include "RC_UNDERAMT.h"
#include "RC_ROUNDDIFF.h"
#include "RC_TIMEDIFF.h"
#include "RC_SIGNDIFF.h"
#include "RC_KINDSPLIT.h"
#include "RC_DIFFRANK.h"
#include "RC_MANREQ.h"
#include "RC_MANOK.h"
#include "RC_MANNG.h"
#include "RC_MANCANCEL.h"
#include "RC_MANLIST.h"
#include "RC_HOLDSET.h"
#include "RC_HOLDCLR.h"
#include "RC_CARRYIN.h"
#include "RC_CARRYFWD.h"
#include "RC_BACKDATE.h"
#include "RC_HOLDLIST.h"
#include "RC_FIXROUND.h"
#include "RC_FIXFEE.h"
#include "RC_FIXFX.h"
#include "RC_FIXDUP.h"
#include "RC_FIXSIGN.h"
#include "RC_REDIFF.h"
#include "RC_RELATE.h"
#include "RC_RECORR.h"
#include "RC_REFULL.h"
#include "RC_PARTDEP.h"
#include "RC_CANCMATCH.h"
#include "RC_REFUNDREC.h"
#include "RC_FEEBRK.h"
#include "RC_FXDIFF.h"
#include "RC_RATEDAY.h"
#include "RC_RATEWEEK.h"
#include "RC_RATEMON.h"
#include "RC_RATECHAN.h"
#include "RC_RATEMERCH.h"
#include "RC_EXCNOTIFY.h"
#include "RC_AUDITADD.h"
#include "RC_TRAILQRY.h"

/* ----- advertise table: {service name, function} ---------------------- */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"RECONCILE", RECONCILE},  {"RC_APPR_ACQ", RC_APPR_ACQ},
    {"RC_ACQ_DEP", RC_ACQ_DEP},  {"RC_RETURN", RC_RETURN},
    {"RC_AMTDIFF", RC_AMTDIFF},  {"RC_CNTDIFF", RC_CNTDIFF},
    {"RC_3WAY", RC_3WAY},  {"RC_TOLERANCE", RC_TOLERANCE},
    {"RC_REMATCH", RC_REMATCH},  {"RC_HOLD", RC_HOLD},
    {"RC_UNMATCH", RC_UNMATCH},  {"RC_RELEASE", RC_RELEASE},
    {"RC_EXCEPTION", RC_EXCEPTION},  {"RC_AUTOFIX", RC_AUTOFIX},
    {"RC_BYISSUER", RC_BYISSUER},  {"RC_BYDATE", RC_BYDATE},
    {"RC_BYMERCH", RC_BYMERCH},  {"RC_PARTIAL", RC_PARTIAL},
    {"RC_DIFFRPT", RC_DIFFRPT},  {"RC_STATS", RC_STATS},
    {"RC_PROGRESS", RC_PROGRESS},  {"RC_SUMMARY", RC_SUMMARY},
    {"RC_REPROC", RC_REPROC},  {"RC_DELAY", RC_DELAY},
    {"RC_LEDGERLINK", RC_LEDGERLINK},  {"RC_ALERT", RC_ALERT},
    {"RC_MANUAL", RC_MANUAL},  {"RC_ROLLBACK", RC_ROLLBACK},
    {"RC_CONFIRM", RC_CONFIRM},  {"RC_STATUS", RC_STATUS},
    {"RC_4WAY", RC_4WAY},  {"RC_DEPMATCH", RC_DEPMATCH},
    {"RC_PAYMATCH", RC_PAYMATCH},  {"RC_BYCHANNEL", RC_BYCHANNEL},
    {"RC_BYCATEGORY", RC_BYCATEGORY},  {"RC_BYMGROUP", RC_BYMGROUP},
    {"RC_MANREG", RC_MANREG},  {"RC_MANAPPRV", RC_MANAPPRV},
    {"RC_MANREJECT", RC_MANREJECT},  {"RC_HOLDRSN", RC_HOLDRSN},
    {"RC_HOLDAGE", RC_HOLDAGE},  {"RC_DIFFCAUSE", RC_DIFFCAUSE},
    {"RC_DIFFTREND", RC_DIFFTREND},  {"RC_CARRYOVER", RC_CARRYOVER},
    {"RC_RETRO", RC_RETRO},  {"RC_NOTIFY", RC_NOTIFY},
    {"RC_RATESTAT", RC_RATESTAT},  {"RC_RATEBYISS", RC_RATEBYISS},
    {"RC_THRESHOLD", RC_THRESHOLD},  {"RC_RERUN", RC_RERUN},
    {"RC_CANCELREC", RC_CANCELREC},  {"RC_VOIDREC", RC_VOIDREC},
    {"RC_PARTACQ", RC_PARTACQ},  {"RC_INSTRECON", RC_INSTRECON},
    {"RC_FEERECON", RC_FEERECON},  {"RC_FEEDIFF", RC_FEEDIFF},
    {"RC_FXRECON", RC_FXRECON},  {"RC_FXRATECHK", RC_FXRATECHK},
    {"RC_WHTRECON", RC_WHTRECON},  {"RC_TAXRECON", RC_TAXRECON},
    {"RC_EDIRECON", RC_EDIRECON},  {"RC_AUDITTRAIL", RC_AUDITTRAIL},
    {"RC_AUDITLOG", RC_AUDITLOG},  {"RC_AGEING", RC_AGEING},
    {"RC_TOPDIFF", RC_TOPDIFF},  {"RC_ZEROAMT", RC_ZEROAMT},
    {"RC_DUPCHK", RC_DUPCHK},  {"RC_ORPHAN", RC_ORPHAN},
    {"RC_GAPSCAN", RC_GAPSCAN},  {"RC_SUMCHK", RC_SUMCHK},
    {"RC_LIMITCHK", RC_LIMITCHK},  {"RC_ESCALATE", RC_ESCALATE},
    {"RC_CLOSEDAY", RC_CLOSEDAY},  {"RC_REOPEN", RC_REOPEN},
    {"RC_SNAPSHOT", RC_SNAPSHOT},
    {"RC_APPRMATCH", RC_APPRMATCH},  {"RC_ACQMATCH", RC_ACQMATCH},
    {"RC_DEPPAY", RC_DEPPAY},  {"RC_PAYLEDGER", RC_PAYLEDGER},
    {"RC_LEDGERBAL", RC_LEDGERBAL},  {"RC_APPRGAP", RC_APPRGAP},
    {"RC_DEPGAP", RC_DEPGAP},  {"RC_PAYGAP", RC_PAYGAP},
    {"RC_CHANRECON", RC_CHANRECON},  {"RC_ISSRECON", RC_ISSRECON},
    {"RC_BRANDRECON", RC_BRANDRECON},  {"RC_MGRPRECON", RC_MGRPRECON},
    {"RC_POSRECON", RC_POSRECON},  {"RC_EDCRECON", RC_EDCRECON},
    {"RC_CHANDIFF", RC_CHANDIFF},  {"RC_ISSDIFF", RC_ISSDIFF},
    {"RC_BRANDDIFF", RC_BRANDDIFF},  {"RC_MGRPDIFF", RC_MGRPDIFF},
    {"RC_OVERAMT", RC_OVERAMT},  {"RC_UNDERAMT", RC_UNDERAMT},
    {"RC_ROUNDDIFF", RC_ROUNDDIFF},  {"RC_TIMEDIFF", RC_TIMEDIFF},
    {"RC_SIGNDIFF", RC_SIGNDIFF},  {"RC_KINDSPLIT", RC_KINDSPLIT},
    {"RC_DIFFRANK", RC_DIFFRANK},  {"RC_MANREQ", RC_MANREQ},
    {"RC_MANOK", RC_MANOK},  {"RC_MANNG", RC_MANNG},
    {"RC_MANCANCEL", RC_MANCANCEL},  {"RC_MANLIST", RC_MANLIST},
    {"RC_HOLDSET", RC_HOLDSET},  {"RC_HOLDCLR", RC_HOLDCLR},
    {"RC_CARRYIN", RC_CARRYIN},  {"RC_CARRYFWD", RC_CARRYFWD},
    {"RC_BACKDATE", RC_BACKDATE},  {"RC_HOLDLIST", RC_HOLDLIST},
    {"RC_FIXROUND", RC_FIXROUND},  {"RC_FIXFEE", RC_FIXFEE},
    {"RC_FIXFX", RC_FIXFX},  {"RC_FIXDUP", RC_FIXDUP},
    {"RC_FIXSIGN", RC_FIXSIGN},  {"RC_REDIFF", RC_REDIFF},
    {"RC_RELATE", RC_RELATE},  {"RC_RECORR", RC_RECORR},
    {"RC_REFULL", RC_REFULL},  {"RC_PARTDEP", RC_PARTDEP},
    {"RC_CANCMATCH", RC_CANCMATCH},  {"RC_REFUNDREC", RC_REFUNDREC},
    {"RC_FEEBRK", RC_FEEBRK},  {"RC_FXDIFF", RC_FXDIFF},
    {"RC_RATEDAY", RC_RATEDAY},  {"RC_RATEWEEK", RC_RATEWEEK},
    {"RC_RATEMON", RC_RATEMON},  {"RC_RATECHAN", RC_RATECHAN},
    {"RC_RATEMERCH", RC_RATEMERCH},  {"RC_EXCNOTIFY", RC_EXCNOTIFY},
    {"RC_AUDITADD", RC_AUDITADD},  {"RC_TRAILQRY", RC_TRAILQRY},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) { userlog("rc_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("rc_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    userlog("rc_svr: %d rc services advertised, RM opened", i);
    return 0;
}

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

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