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

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