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

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