/*
 * py_svr.pgc - py (지급) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of py's 133 online services now lives in its own file
 * (app/src/py/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/py/svc/<SVCNAME>.h); those objects are archived into libpysvc.a and
 * linked into this server. Here we only:
 *   - include every service copybook (for the extern prototypes),
 *   - tpopen() the ECPG XA RM,
 *   - tpadvertise() all services from a {name, fn} table,
 *   - tpclose() at shutdown.
 *
 * XA: the connection is opened once by tpopen() (ECPG XA switch libndrxxaecpg.so);
 * 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 py service's copybook header (declares its record struct + prototype) */
#include "PAY_FILEGEN.h"
#include "PAY_RESULT.h"
#include "PAY_REPROC.h"
#include "PAY_HOLD.h"
#include "PAY_RELEASE.h"
#include "PAY_CANCEL.h"
#include "PAY_ACCTCHK.h"
#include "PAY_SPLIT.h"
#include "PAY_INT.h"
#include "PAY_XFERLINK.h"
#include "PAY_STATUS.h"
#include "PAY_SCHEDULE.h"
#include "PAY_MERCHSUM.h"
#include "PAY_NETOFF.h"
#include "PAY_ADVANCE.h"
#include "PAY_RETRY.h"
#include "PAY_APPROVE.h"
#include "PAY_REJECT.h"
#include "PAY_RECON.h"
#include "PAY_STATEMENT.h"
#include "PAY_FEEDED.h"
#include "PAY_ADJUST.h"
#include "PAY_BULK.h"
#include "PAY_INQUIRY.h"
#include "PAY_HISTORY.h"
#include "PAY_REVERSE.h"
#include "PAY_CONFIRM.h"
#include "PAY_REMIT.h"
#include "PAY_CLOSE.h"
#include "PAY_SUMMARY.h"
#include "PAY_BANKFILE.h"
#include "PAY_FILEVERIFY.h"
#include "PAY_FILEREBUILD.h"
#include "PAY_FILESTAT.h"
#include "PAY_NOTIFYSMS.h"
#include "PAY_NOTIFYEMAIL.h"
#include "PAY_NOTIFYPLAN.h"
#include "PAY_ACCTCHANGE.h"
#include "PAY_REPAYNEW.h"
#include "PAY_HOLDREASON.h"
#include "PAY_HOLDLIST.h"
#include "PAY_HOLDAGING.h"
#include "PAY_SEIZE.h"
#include "PAY_SEIZEREL.h"
#include "PAY_SEIZECHK.h"
#include "PAY_URGENT.h"
#include "PAY_ADVCALC.h"
#include "PAY_ADVREPAY.h"
#include "PAY_MERGE.h"
#include "PAY_SPLITRATIO.h"
#include "PAY_FEERATE.h"
#include "PAY_FEEWAIVE.h"
#include "PAY_FEEMIN.h"
#include "PAY_FAILSTAT.h"
#include "PAY_FAILTOP.h"
#include "PAY_FAILRATE.h"
#include "PAY_XFERMATCH.h"
#include "PAY_XFERMISS.h"
#include "PAY_REFUND.h"
#include "PAY_CANCELHIST.h"
#include "PAY_LIMITCHK.h"
#include "PAY_LIMITHOLD.h"
#include "PAY_DORMANT.h"
#include "PAY_DORMSTOP.h"
#include "PAY_APPRREQ.h"
#include "PAY_APPRBULK.h"
#include "PAY_APPRLIMIT.h"
#include "PAY_STATCHAN.h"
#include "PAY_STATBANK.h"
#include "PAY_STATDAILY.h"
#include "PAY_STATRANGE.h"
#include "PAY_SCHEDCANCEL.h"
#include "PAY_LEDGERSUM.h"
#include "PAY_ACCTLIST.h"
#include "PAY_NETRECALC.h"
#include "PAY_XFERFILE.h"
#include "PAY_FILECONF.h"
#include "PAY_FILECANCEL.h"
#include "PAY_BANKVERIFY.h"
#include "PAY_XFERTYPE.h"
#include "PAY_NOTIFYPUSH.h"
#include "PAY_NOTIFYKAKAO.h"
#include "PAY_NOTIFYALL.h"
#include "PAY_NOTIFYFAIL.h"
#include "PAY_NOTIFYRESEND.h"
#include "PAY_ACCTVERIFY.h"
#include "PAY_ACCTFREEZE.h"
#include "PAY_ACCTREOPEN.h"
#include "PAY_REPAYACCT.h"
#include "PAY_HOLDBYRSN.h"
#include "PAY_HOLDCLEAR.h"
#include "PAY_HOLDEXT.h"
#include "PAY_HOLDNOTE.h"
#include "PAY_SEIZELIST.h"
#include "PAY_SEIZEAMT.h"
#include "PAY_OFFSETAPPLY.h"
#include "PAY_GARNISH.h"
#include "PAY_ADVGRANT.h"
#include "PAY_URGENTQ.h"
#include "PAY_RESVLIST.h"
#include "PAY_RESVMODIFY.h"
#include "PAY_SPLITEVEN.h"
#include "PAY_CARRYOVER.h"
#include "PAY_COMBINE.h"
#include "PAY_ROLLFWD.h"
#include "PAY_FEEFIXED.h"
#include "PAY_FEECAP.h"
#include "PAY_FEEREFUND.h"
#include "PAY_FEESUM.h"
#include "PAY_FAILRSN.h"
#include "PAY_REQUEUE.h"
#include "PAY_FAILCLEAR.h"
#include "PAY_RETRYONE.h"
#include "PAY_XFERDIFF.h"
#include "PAY_XFERUNMATCH.h"
#include "PAY_VOIDONE.h"
#include "PAY_RECLAIM.h"
#include "PAY_CHARGEBACK.h"
#include "PAY_LIMITSET.h"
#include "PAY_LIMITLIST.h"
#include "PAY_LIMITWARN.h"
#include "PAY_APPRHIST.h"
#include "PAY_APPRCANCEL.h"
#include "PAY_CLOSEDSTOP.h"
#include "PAY_DORMLIST.h"
#include "PAY_REACTIVATE.h"
#include "PAY_STATSTATUS.h"
#include "PAY_STATAMT.h"
#include "PAY_STATFEE.h"
#include "PAY_STATMONTH.h"
#include "PAY_PENDLIST.h"
#include "PAY_APPRPEND.h"
#include "PAY_XFERCONF.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"PAY_FILEGEN", PAY_FILEGEN},   {"PAY_RESULT", PAY_RESULT},
    {"PAY_REPROC", PAY_REPROC},     {"PAY_HOLD", PAY_HOLD},
    {"PAY_RELEASE", PAY_RELEASE},   {"PAY_CANCEL", PAY_CANCEL},
    {"PAY_ACCTCHK", PAY_ACCTCHK},   {"PAY_SPLIT", PAY_SPLIT},
    {"PAY_INT", PAY_INT},           {"PAY_XFERLINK", PAY_XFERLINK},
    {"PAY_STATUS", PAY_STATUS},     {"PAY_SCHEDULE", PAY_SCHEDULE},
    {"PAY_MERCHSUM", PAY_MERCHSUM}, {"PAY_NETOFF", PAY_NETOFF},
    {"PAY_ADVANCE", PAY_ADVANCE},   {"PAY_RETRY", PAY_RETRY},
    {"PAY_APPROVE", PAY_APPROVE},   {"PAY_REJECT", PAY_REJECT},
    {"PAY_RECON", PAY_RECON},       {"PAY_STATEMENT", PAY_STATEMENT},
    {"PAY_FEEDED", PAY_FEEDED},     {"PAY_ADJUST", PAY_ADJUST},
    {"PAY_BULK", PAY_BULK},         {"PAY_INQUIRY", PAY_INQUIRY},
    {"PAY_HISTORY", PAY_HISTORY},   {"PAY_REVERSE", PAY_REVERSE},
    {"PAY_CONFIRM", PAY_CONFIRM},   {"PAY_REMIT", PAY_REMIT},
    {"PAY_CLOSE", PAY_CLOSE},       {"PAY_SUMMARY", PAY_SUMMARY},
    {"PAY_BANKFILE", PAY_BANKFILE},     {"PAY_FILEVERIFY", PAY_FILEVERIFY},
    {"PAY_FILEREBUILD", PAY_FILEREBUILD}, {"PAY_FILESTAT", PAY_FILESTAT},
    {"PAY_NOTIFYSMS", PAY_NOTIFYSMS},   {"PAY_NOTIFYEMAIL", PAY_NOTIFYEMAIL},
    {"PAY_NOTIFYPLAN", PAY_NOTIFYPLAN}, {"PAY_ACCTCHANGE", PAY_ACCTCHANGE},
    {"PAY_REPAYNEW", PAY_REPAYNEW},     {"PAY_HOLDREASON", PAY_HOLDREASON},
    {"PAY_HOLDLIST", PAY_HOLDLIST},     {"PAY_HOLDAGING", PAY_HOLDAGING},
    {"PAY_SEIZE", PAY_SEIZE},           {"PAY_SEIZEREL", PAY_SEIZEREL},
    {"PAY_SEIZECHK", PAY_SEIZECHK},     {"PAY_URGENT", PAY_URGENT},
    {"PAY_ADVCALC", PAY_ADVCALC},       {"PAY_ADVREPAY", PAY_ADVREPAY},
    {"PAY_MERGE", PAY_MERGE},           {"PAY_SPLITRATIO", PAY_SPLITRATIO},
    {"PAY_FEERATE", PAY_FEERATE},       {"PAY_FEEWAIVE", PAY_FEEWAIVE},
    {"PAY_FEEMIN", PAY_FEEMIN},         {"PAY_FAILSTAT", PAY_FAILSTAT},
    {"PAY_FAILTOP", PAY_FAILTOP},       {"PAY_FAILRATE", PAY_FAILRATE},
    {"PAY_XFERMATCH", PAY_XFERMATCH},   {"PAY_XFERMISS", PAY_XFERMISS},
    {"PAY_REFUND", PAY_REFUND},         {"PAY_CANCELHIST", PAY_CANCELHIST},
    {"PAY_LIMITCHK", PAY_LIMITCHK},     {"PAY_LIMITHOLD", PAY_LIMITHOLD},
    {"PAY_DORMANT", PAY_DORMANT},       {"PAY_DORMSTOP", PAY_DORMSTOP},
    {"PAY_APPRREQ", PAY_APPRREQ},       {"PAY_APPRBULK", PAY_APPRBULK},
    {"PAY_APPRLIMIT", PAY_APPRLIMIT},   {"PAY_STATCHAN", PAY_STATCHAN},
    {"PAY_STATBANK", PAY_STATBANK},     {"PAY_STATDAILY", PAY_STATDAILY},
    {"PAY_STATRANGE", PAY_STATRANGE},   {"PAY_SCHEDCANCEL", PAY_SCHEDCANCEL},
    {"PAY_LEDGERSUM", PAY_LEDGERSUM},   {"PAY_ACCTLIST", PAY_ACCTLIST},
    {"PAY_NETRECALC", PAY_NETRECALC},
    {"PAY_XFERFILE", PAY_XFERFILE},
    {"PAY_FILECONF", PAY_FILECONF},
    {"PAY_FILECANCEL", PAY_FILECANCEL},
    {"PAY_BANKVERIFY", PAY_BANKVERIFY},
    {"PAY_XFERTYPE", PAY_XFERTYPE},
    {"PAY_NOTIFYPUSH", PAY_NOTIFYPUSH},
    {"PAY_NOTIFYKAKAO", PAY_NOTIFYKAKAO},
    {"PAY_NOTIFYALL", PAY_NOTIFYALL},
    {"PAY_NOTIFYFAIL", PAY_NOTIFYFAIL},
    {"PAY_NOTIFYRESEND", PAY_NOTIFYRESEND},
    {"PAY_ACCTVERIFY", PAY_ACCTVERIFY},
    {"PAY_ACCTFREEZE", PAY_ACCTFREEZE},
    {"PAY_ACCTREOPEN", PAY_ACCTREOPEN},
    {"PAY_REPAYACCT", PAY_REPAYACCT},
    {"PAY_HOLDBYRSN", PAY_HOLDBYRSN},
    {"PAY_HOLDCLEAR", PAY_HOLDCLEAR},
    {"PAY_HOLDEXT", PAY_HOLDEXT},
    {"PAY_HOLDNOTE", PAY_HOLDNOTE},
    {"PAY_SEIZELIST", PAY_SEIZELIST},
    {"PAY_SEIZEAMT", PAY_SEIZEAMT},
    {"PAY_OFFSETAPPLY", PAY_OFFSETAPPLY},
    {"PAY_GARNISH", PAY_GARNISH},
    {"PAY_ADVGRANT", PAY_ADVGRANT},
    {"PAY_URGENTQ", PAY_URGENTQ},
    {"PAY_RESVLIST", PAY_RESVLIST},
    {"PAY_RESVMODIFY", PAY_RESVMODIFY},
    {"PAY_SPLITEVEN", PAY_SPLITEVEN},
    {"PAY_CARRYOVER", PAY_CARRYOVER},
    {"PAY_COMBINE", PAY_COMBINE},
    {"PAY_ROLLFWD", PAY_ROLLFWD},
    {"PAY_FEEFIXED", PAY_FEEFIXED},
    {"PAY_FEECAP", PAY_FEECAP},
    {"PAY_FEEREFUND", PAY_FEEREFUND},
    {"PAY_FEESUM", PAY_FEESUM},
    {"PAY_FAILRSN", PAY_FAILRSN},
    {"PAY_REQUEUE", PAY_REQUEUE},
    {"PAY_FAILCLEAR", PAY_FAILCLEAR},
    {"PAY_RETRYONE", PAY_RETRYONE},
    {"PAY_XFERDIFF", PAY_XFERDIFF},
    {"PAY_XFERUNMATCH", PAY_XFERUNMATCH},
    {"PAY_VOIDONE", PAY_VOIDONE},
    {"PAY_RECLAIM", PAY_RECLAIM},
    {"PAY_CHARGEBACK", PAY_CHARGEBACK},
    {"PAY_LIMITSET", PAY_LIMITSET},
    {"PAY_LIMITLIST", PAY_LIMITLIST},
    {"PAY_LIMITWARN", PAY_LIMITWARN},
    {"PAY_APPRHIST", PAY_APPRHIST},
    {"PAY_APPRCANCEL", PAY_APPRCANCEL},
    {"PAY_CLOSEDSTOP", PAY_CLOSEDSTOP},
    {"PAY_DORMLIST", PAY_DORMLIST},
    {"PAY_REACTIVATE", PAY_REACTIVATE},
    {"PAY_STATSTATUS", PAY_STATSTATUS},
    {"PAY_STATAMT", PAY_STATAMT},
    {"PAY_STATFEE", PAY_STATFEE},
    {"PAY_STATMONTH", PAY_STATMONTH},
    {"PAY_PENDLIST", PAY_PENDLIST},
    {"PAY_APPRPEND", PAY_APPRPEND},
    {"PAY_XFERCONF", PAY_XFERCONF},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) {
        userlog("py_svr: tpopen FAIL: %s", tpstrerror(tperrno));
        return -1;
    }
    for (i = 0; SVCS[i].name != NULL; i++) {
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("py_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    }
    userlog("py_svr: %d py(지급) 서비스 광고 완료, RM 오픈", i);
    return 0;
}

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

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