/*
 * au_svr.pgc - au (승인/한도) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of au's ~30 online services now lives in its own file
 * (app/src/au/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/au/svc/<SVCNAME>.h); those objects are archived into libausvc.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 au service's copybook header (declares its record struct + prototype) */
#include "AUTH.h"
#include "AUTH_CANCEL.h"
#include "AUTH_PARTCXL.h"
#include "LIMIT_CHK.h"
#include "LIMIT_DEC.h"
#include "LIMIT_RST.h"
#include "LIMIT_INQ.h"
#include "STANDIN.h"
#include "FRAUD_DETECT.h"
#include "AUTH_RETRY.h"
#include "INSTALL_AUTH.h"
#include "AUTH_STATUS.h"
#include "AUTH_REVERSE.h"
#include "AUTH_APPROVE.h"
#include "AUTH_DECLINE.h"
#include "CARD_VALIDATE.h"
#include "VELOCITY_CHK.h"
#include "BLACKLIST_CHK.h"
#include "AUTH_HOLD.h"
#include "AUTH_RELEASE.h"
#include "AUTH_HISTORY.h"
#include "LIMIT_SET.h"
#include "LIMIT_TEMP.h"
#include "AUTH_SUMMARY.h"
#include "AUTH_ROUTE.h"
#include "DCC_QUOTE.h"
#include "AUTH_CAPTURE.h"
#include "PREAUTH.h"
#include "PREAUTH_COMPLETE.h"
#include "AUTH_VOID.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"AUTH", AUTH},                 {"AUTH_CANCEL", AUTH_CANCEL},
    {"AUTH_PARTCXL", AUTH_PARTCXL}, {"LIMIT_CHK", LIMIT_CHK},
    {"LIMIT_DEC", LIMIT_DEC},       {"LIMIT_RST", LIMIT_RST},
    {"LIMIT_INQ", LIMIT_INQ},       {"STANDIN", STANDIN},
    {"FRAUD_DETECT", FRAUD_DETECT}, {"AUTH_RETRY", AUTH_RETRY},
    {"INSTALL_AUTH", INSTALL_AUTH}, {"AUTH_STATUS", AUTH_STATUS},
    {"AUTH_REVERSE", AUTH_REVERSE}, {"AUTH_APPROVE", AUTH_APPROVE},
    {"AUTH_DECLINE", AUTH_DECLINE}, {"CARD_VALIDATE", CARD_VALIDATE},
    {"VELOCITY_CHK", VELOCITY_CHK}, {"BLACKLIST_CHK", BLACKLIST_CHK},
    {"AUTH_HOLD", AUTH_HOLD},       {"AUTH_RELEASE", AUTH_RELEASE},
    {"AUTH_HISTORY", AUTH_HISTORY}, {"LIMIT_SET", LIMIT_SET},
    {"LIMIT_TEMP", LIMIT_TEMP},     {"AUTH_SUMMARY", AUTH_SUMMARY},
    {"AUTH_ROUTE", AUTH_ROUTE},     {"DCC_QUOTE", DCC_QUOTE},
    {"AUTH_CAPTURE", AUTH_CAPTURE}, {"PREAUTH", PREAUTH},
    {"PREAUTH_COMPLETE", PREAUTH_COMPLETE}, {"AUTH_VOID", AUTH_VOID},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) {
        userlog("au_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("au_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    }
    userlog("au_svr: %d au(승인/한도) 서비스 광고 완료, RM 오픈", i);
    return 0;
}

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

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