/*
 * mm_svr.pgc - mm (마스터/master) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of mm's ~75 online services now lives in its own file
 * (app/src/mm/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/mm/svc/<SVCNAME>.h); those objects are archived into libmmsvc.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, tpclose().
 *
 * 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 mm service's copybook header (declares its prototype) */
#include "MM_MERCH_REG.h"
#include "MM_MERCH_UPD.h"
#include "MM_MERCH_INQ.h"
#include "MM_MERCH_DEL.h"
#include "MM_FEERATE_SET.h"
#include "MM_FEERATE_INQ.h"
#include "MM_FEERATE_HIST.h"
#include "MM_BIN_REG.h"
#include "MM_BIN_INQ.h"
#include "MM_LIMIT_SET.h"
#include "MM_LIMIT_INQ.h"
#include "MM_CODE_REG.h"
#include "MM_CODE_INQ.h"
#include "MM_ISSUER_REG.h"
#include "MM_ISSUER_INQ.h"
#include "MM_MERCH_STATUS.h"
#include "MM_MERCH_ACCT.h"
#include "MM_MERCH_GRADE.h"
#include "MM_TERMINAL_REG.h"
#include "MM_TERMINAL_INQ.h"
#include "MM_MCC_REG.h"
#include "MM_HOLIDAY_REG.h"
#include "MM_FX_REG.h"
#include "MM_FX_INQ.h"
#include "MM_MERCH_BULK.h"
#include "MM_VALIDATE.h"
#include "MM_MERCH_SUM.h"
#include "MM_CODE_CACHE.h"
#include "MM_STATUS.h"
#include "MM_CONFIRM.h"
#include "MM_TERM_MOVE.h"
#include "MM_TERM_SCRAP.h"
#include "MM_TERM_SUSPEND.h"
#include "MM_TERM_CNT.h"
#include "MM_APPLY_REG.h"
#include "MM_APPLY_REVIEW.h"
#include "MM_APPLY_APPROVE.h"
#include "MM_APPLY_REJECT.h"
#include "MM_APPLY_STATUS.h"
#include "MM_CONTRACT_NEW.h"
#include "MM_CONTRACT_RENEW.h"
#include "MM_CONTRACT_END.h"
#include "MM_CONTRACT_INQ.h"
#include "MM_PARTNER_REG.h"
#include "MM_PARTNER_INQ.h"
#include "MM_PARTNER_STATUS.h"
#include "MM_REL_LINK.h"
#include "MM_REL_UNLINK.h"
#include "MM_REL_LIST.h"
#include "MM_MCC_UPD.h"
#include "MM_MCC_INQ.h"
#include "MM_MCC_RISKLIST.h"
#include "MM_RATE_REQ.h"
#include "MM_RATE_APPROVE.h"
#include "MM_RATE_REJECT.h"
#include "MM_MERCH_PAUSE.h"
#include "MM_MERCH_RESUME.h"
#include "MM_MERCH_CLOSE.h"
#include "MM_ACCT_VERIFY.h"
#include "MM_ACCT_VRF_HIST.h"
#include "MM_ACCT_VRF_STAT.h"
#include "MM_GRADE_PREVIEW.h"
#include "MM_GRADE_ADJUST.h"
#include "MM_GRADE_DIST.h"
#include "MM_AUDIT_TRAIL.h"
#include "MM_AUDIT_RECENT.h"
#include "MM_AUDIT_PURGE.h"
#include "MM_CHK_TERM.h"
#include "MM_CHK_FEERATE.h"
#include "MM_CHK_LIMIT.h"
#include "MM_CODEMAP_SET.h"
#include "MM_CODEMAP_GET.h"
#include "MM_CODEMAP_DEL.h"
#include "MM_BIZNO_CHECK.h"
#include "MM_BIZNO_UPD.h"

/* ----- 신규 마스터 서비스 58종 (단말 생애주기/심사/계약/제휴/관계/MCC/요율/휴폐업/계좌/리스크/감사/정합성) */
#include "MM_TERM_INSTALL.h"
#include "MM_TERM_SWAP.h"
#include "MM_TERM_ACTIVATE.h"
#include "MM_TERM_DEACT.h"
#include "MM_TERM_RETIRE.h"
#include "MM_TERM_REASSIGN.h"
#include "MM_TERM_MODEL_UPD.h"
#include "MM_TERM_LIST.h"
#include "MM_TERM_HIST.h"
#include "MM_APPLY_HOLD.h"
#include "MM_APPLY_RESUME.h"
#include "MM_APPLY_DOCCHK.h"
#include "MM_APPLY_SCORE.h"
#include "MM_APPLY_ASSIGN.h"
#include "MM_APPLY_WITHDRAW.h"
#include "MM_APPLY_CNT.h"
#include "MM_CONTRACT_AMEND.h"
#include "MM_CONTRACT_SUSPEND.h"
#include "MM_CONTRACT_REACT.h"
#include "MM_CONTRACT_HIST.h"
#include "MM_CONTRACT_EXPCHK.h"
#include "MM_PARTNER_UPD.h"
#include "MM_PARTNER_LIST.h"
#include "MM_AGENT_REG.h"
#include "MM_AGENT_INQ.h"
#include "MM_AGENT_STATUS.h"
#include "MM_BRANCH_REG.h"
#include "MM_BRANCH_INQ.h"
#include "MM_BRANCH_LIST.h"
#include "MM_REL_PARENT.h"
#include "MM_REL_CHILDREN.h"
#include "MM_REL_MOVE.h"
#include "MM_REL_VERIFY.h"
#include "MM_MCC_DEL.h"
#include "MM_MCC_ASSIGN.h"
#include "MM_MCC_RISKSET.h"
#include "MM_MCC_CNT.h"
#include "MM_RATE_STATUS.h"
#include "MM_RATE_HIST.h"
#include "MM_RATE_CANCEL.h"
#include "MM_RATE_PENDING.h"
#include "MM_MERCH_DORMANT.h"
#include "MM_BIZ_SUSPEND.h"
#include "MM_BIZ_REOPEN.h"
#include "MM_BIZ_CLOSE.h"
#include "MM_ACCT_REG.h"
#include "MM_ACCT_INQ.h"
#include "MM_ACCT_MASK.h"
#include "MM_RISK_SCORE.h"
#include "MM_RISK_SET.h"
#include "MM_RISK_INQ.h"
#include "MM_GRADE_HIST.h"
#include "MM_AUDIT_STAT.h"
#include "MM_AUDIT_DIFF.h"
#include "MM_CHK_ACCT.h"
#include "MM_CHK_MCC.h"
#include "MM_CHK_ORPHAN.h"
#include "MM_CHK_GRADE.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"MM_MERCH_REG", MM_MERCH_REG},
    {"MM_MERCH_UPD", MM_MERCH_UPD},
    {"MM_MERCH_INQ", MM_MERCH_INQ},
    {"MM_MERCH_DEL", MM_MERCH_DEL},
    {"MM_FEERATE_SET", MM_FEERATE_SET},
    {"MM_FEERATE_INQ", MM_FEERATE_INQ},
    {"MM_FEERATE_HIST", MM_FEERATE_HIST},
    {"MM_BIN_REG", MM_BIN_REG},
    {"MM_BIN_INQ", MM_BIN_INQ},
    {"MM_LIMIT_SET", MM_LIMIT_SET},
    {"MM_LIMIT_INQ", MM_LIMIT_INQ},
    {"MM_CODE_REG", MM_CODE_REG},
    {"MM_CODE_INQ", MM_CODE_INQ},
    {"MM_ISSUER_REG", MM_ISSUER_REG},
    {"MM_ISSUER_INQ", MM_ISSUER_INQ},
    {"MM_MERCH_STATUS", MM_MERCH_STATUS},
    {"MM_MERCH_ACCT", MM_MERCH_ACCT},
    {"MM_MERCH_GRADE", MM_MERCH_GRADE},
    {"MM_TERMINAL_REG", MM_TERMINAL_REG},
    {"MM_TERMINAL_INQ", MM_TERMINAL_INQ},
    {"MM_MCC_REG", MM_MCC_REG},
    {"MM_HOLIDAY_REG", MM_HOLIDAY_REG},
    {"MM_FX_REG", MM_FX_REG},
    {"MM_FX_INQ", MM_FX_INQ},
    {"MM_MERCH_BULK", MM_MERCH_BULK},
    {"MM_VALIDATE", MM_VALIDATE},
    {"MM_MERCH_SUM", MM_MERCH_SUM},
    {"MM_CODE_CACHE", MM_CODE_CACHE},
    {"MM_STATUS", MM_STATUS},
    {"MM_CONFIRM", MM_CONFIRM},
    {"MM_TERM_MOVE", MM_TERM_MOVE},
    {"MM_TERM_SCRAP", MM_TERM_SCRAP},
    {"MM_TERM_SUSPEND", MM_TERM_SUSPEND},
    {"MM_TERM_CNT", MM_TERM_CNT},
    {"MM_APPLY_REG", MM_APPLY_REG},
    {"MM_APPLY_REVIEW", MM_APPLY_REVIEW},
    {"MM_APPLY_APPROVE", MM_APPLY_APPROVE},
    {"MM_APPLY_REJECT", MM_APPLY_REJECT},
    {"MM_APPLY_STATUS", MM_APPLY_STATUS},
    {"MM_CONTRACT_NEW", MM_CONTRACT_NEW},
    {"MM_CONTRACT_RENEW", MM_CONTRACT_RENEW},
    {"MM_CONTRACT_END", MM_CONTRACT_END},
    {"MM_CONTRACT_INQ", MM_CONTRACT_INQ},
    {"MM_PARTNER_REG", MM_PARTNER_REG},
    {"MM_PARTNER_INQ", MM_PARTNER_INQ},
    {"MM_PARTNER_STATUS", MM_PARTNER_STATUS},
    {"MM_REL_LINK", MM_REL_LINK},
    {"MM_REL_UNLINK", MM_REL_UNLINK},
    {"MM_REL_LIST", MM_REL_LIST},
    {"MM_MCC_UPD", MM_MCC_UPD},
    {"MM_MCC_INQ", MM_MCC_INQ},
    {"MM_MCC_RISKLIST", MM_MCC_RISKLIST},
    {"MM_RATE_REQ", MM_RATE_REQ},
    {"MM_RATE_APPROVE", MM_RATE_APPROVE},
    {"MM_RATE_REJECT", MM_RATE_REJECT},
    {"MM_MERCH_PAUSE", MM_MERCH_PAUSE},
    {"MM_MERCH_RESUME", MM_MERCH_RESUME},
    {"MM_MERCH_CLOSE", MM_MERCH_CLOSE},
    {"MM_ACCT_VERIFY", MM_ACCT_VERIFY},
    {"MM_ACCT_VRF_HIST", MM_ACCT_VRF_HIST},
    {"MM_ACCT_VRF_STAT", MM_ACCT_VRF_STAT},
    {"MM_GRADE_PREVIEW", MM_GRADE_PREVIEW},
    {"MM_GRADE_ADJUST", MM_GRADE_ADJUST},
    {"MM_GRADE_DIST", MM_GRADE_DIST},
    {"MM_AUDIT_TRAIL", MM_AUDIT_TRAIL},
    {"MM_AUDIT_RECENT", MM_AUDIT_RECENT},
    {"MM_AUDIT_PURGE", MM_AUDIT_PURGE},
    {"MM_CHK_TERM", MM_CHK_TERM},
    {"MM_CHK_FEERATE", MM_CHK_FEERATE},
    {"MM_CHK_LIMIT", MM_CHK_LIMIT},
    {"MM_CODEMAP_SET", MM_CODEMAP_SET},
    {"MM_CODEMAP_GET", MM_CODEMAP_GET},
    {"MM_CODEMAP_DEL", MM_CODEMAP_DEL},
    {"MM_BIZNO_CHECK", MM_BIZNO_CHECK},
    {"MM_BIZNO_UPD", MM_BIZNO_UPD},
    {"MM_TERM_INSTALL", MM_TERM_INSTALL},
    {"MM_TERM_SWAP", MM_TERM_SWAP},
    {"MM_TERM_ACTIVATE", MM_TERM_ACTIVATE},
    {"MM_TERM_DEACT", MM_TERM_DEACT},
    {"MM_TERM_RETIRE", MM_TERM_RETIRE},
    {"MM_TERM_REASSIGN", MM_TERM_REASSIGN},
    {"MM_TERM_MODEL_UPD", MM_TERM_MODEL_UPD},
    {"MM_TERM_LIST", MM_TERM_LIST},
    {"MM_TERM_HIST", MM_TERM_HIST},
    {"MM_APPLY_HOLD", MM_APPLY_HOLD},
    {"MM_APPLY_RESUME", MM_APPLY_RESUME},
    {"MM_APPLY_DOCCHK", MM_APPLY_DOCCHK},
    {"MM_APPLY_SCORE", MM_APPLY_SCORE},
    {"MM_APPLY_ASSIGN", MM_APPLY_ASSIGN},
    {"MM_APPLY_WITHDRAW", MM_APPLY_WITHDRAW},
    {"MM_APPLY_CNT", MM_APPLY_CNT},
    {"MM_CONTRACT_AMEND", MM_CONTRACT_AMEND},
    {"MM_CONTRACT_SUSPEND", MM_CONTRACT_SUSPEND},
    {"MM_CONTRACT_REACT", MM_CONTRACT_REACT},
    {"MM_CONTRACT_HIST", MM_CONTRACT_HIST},
    {"MM_CONTRACT_EXPCHK", MM_CONTRACT_EXPCHK},
    {"MM_PARTNER_UPD", MM_PARTNER_UPD},
    {"MM_PARTNER_LIST", MM_PARTNER_LIST},
    {"MM_AGENT_REG", MM_AGENT_REG},
    {"MM_AGENT_INQ", MM_AGENT_INQ},
    {"MM_AGENT_STATUS", MM_AGENT_STATUS},
    {"MM_BRANCH_REG", MM_BRANCH_REG},
    {"MM_BRANCH_INQ", MM_BRANCH_INQ},
    {"MM_BRANCH_LIST", MM_BRANCH_LIST},
    {"MM_REL_PARENT", MM_REL_PARENT},
    {"MM_REL_CHILDREN", MM_REL_CHILDREN},
    {"MM_REL_MOVE", MM_REL_MOVE},
    {"MM_REL_VERIFY", MM_REL_VERIFY},
    {"MM_MCC_DEL", MM_MCC_DEL},
    {"MM_MCC_ASSIGN", MM_MCC_ASSIGN},
    {"MM_MCC_RISKSET", MM_MCC_RISKSET},
    {"MM_MCC_CNT", MM_MCC_CNT},
    {"MM_RATE_STATUS", MM_RATE_STATUS},
    {"MM_RATE_HIST", MM_RATE_HIST},
    {"MM_RATE_CANCEL", MM_RATE_CANCEL},
    {"MM_RATE_PENDING", MM_RATE_PENDING},
    {"MM_MERCH_DORMANT", MM_MERCH_DORMANT},
    {"MM_BIZ_SUSPEND", MM_BIZ_SUSPEND},
    {"MM_BIZ_REOPEN", MM_BIZ_REOPEN},
    {"MM_BIZ_CLOSE", MM_BIZ_CLOSE},
    {"MM_ACCT_REG", MM_ACCT_REG},
    {"MM_ACCT_INQ", MM_ACCT_INQ},
    {"MM_ACCT_MASK", MM_ACCT_MASK},
    {"MM_RISK_SCORE", MM_RISK_SCORE},
    {"MM_RISK_SET", MM_RISK_SET},
    {"MM_RISK_INQ", MM_RISK_INQ},
    {"MM_GRADE_HIST", MM_GRADE_HIST},
    {"MM_AUDIT_STAT", MM_AUDIT_STAT},
    {"MM_AUDIT_DIFF", MM_AUDIT_DIFF},
    {"MM_CHK_ACCT", MM_CHK_ACCT},
    {"MM_CHK_MCC", MM_CHK_MCC},
    {"MM_CHK_ORPHAN", MM_CHK_ORPHAN},
    {"MM_CHK_GRADE", MM_CHK_GRADE},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) {
        userlog("mm_svr: tpopen 실패: %s", tpstrerror(tperrno));
        return -1;
    }
    for (i = 0; SVCS[i].name != NULL; i++) {
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("mm_svr: tpadvertise(%s) 실패: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    }
    userlog("mm_svr: mm 마스터 서비스 %d개 광고 완료, RM open", i);
    return 0;
}

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

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