/*
 * cm_svr.pgc - cm (공통 / common) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of cm's 133 online services lives in its own file
 * (app/src/cm/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/cm/svc/<SVCNAME>.h); those objects are archived into libcmsvc.a
 * and linked into this server. Here we only:
 *   - include every service copybook (for the extern prototypes),
 *   - tpopen() the ECPG XA RM,
 *   - tpadvertise() all 133 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 cm service's copybook header (declares its prototype) */
#include "CM_CODE.h"
#include "CM_CODENAME.h"
#include "CM_BIZDAY.h"
#include "CM_NEXTBIZ.h"
#include "CM_ADDDAYS.h"
#include "CM_WEEKDAY.h"
#include "CM_MONTHEND.h"
#include "CM_AMT_ROUND.h"
#include "CM_AMT_SPLIT.h"
#include "CM_SEQ.h"
#include "CM_FX.h"
#include "CM_FX_CONV.h"
#include "CM_LUHN.h"
#include "CM_CRC.h"
#include "CM_MASK.h"
#include "CM_FMT_DATE.h"
#include "CM_FMT_AMT.h"
#include "CM_PARAM.h"
#include "CM_PARAM_SET.h"
#include "CM_CACHE_LOAD.h"
#include "CM_CACHE_INV.h"
#include "CM_ERRMSG.h"
#include "CM_LOG.h"
#include "CM_HOLIDAY_CHK.h"
#include "CM_CHECKDIGIT.h"
#include "CM_INTEREST.h"
#include "CM_PRORATE.h"
#include "CM_NETTING_CALC.h"
#include "CM_STATUS.h"
#include "CM_PING.h"
/* --- 확장 서비스 (코드그룹/파라미터 승인/다국어/환율/캘린더/채번/알림/
 *     배치관리/헬스/감사/마스킹·암호화/체크섬/기간/한글금액) --- */
#include "CM_CODEGRP_REG.h"
#include "CM_CODEGRP_UPD.h"
#include "CM_CODEGRP_CLOSE.h"
#include "CM_CODEGRP_HIST.h"
#include "CM_CODEGRP_CNT.h"
#include "CM_PARAM_REQ.h"
#include "CM_PARAM_APPROVE.h"
#include "CM_PARAM_REJECT.h"
#include "CM_PARAM_PENDING.h"
#include "CM_MSG_GET.h"
#include "CM_MSG_SET.h"
#include "CM_MSG_FALLBACK.h"
#include "CM_FX_PUBLISH.h"
#include "CM_FX_HIST.h"
#include "CM_FX_VALID.h"
#include "CM_FX_CROSS.h"
#include "CM_FX_AGE.h"
#include "CM_HOLIDAY_REG.h"
#include "CM_HOLIDAY_DEL.h"
#include "CM_HOLIDAY_CNT.h"
#include "CM_BIZDAY_CNT.h"
#include "CM_PREVBIZ.h"
#include "CM_SEQ_DAILY.h"
#include "CM_SEQ_TYPED.h"
#include "CM_SEQ_PEEK.h"
#include "CM_SEQ_RESET.h"
#include "CM_NOTI_SEND.h"
#include "CM_NOTI_HIST.h"
#include "CM_BATSCHD_REG.h"
#include "CM_BATSCHD_GET.h"
#include "CM_BATHIST_CNT.h"
#include "CM_BATRERUN_REQ.h"
#include "CM_HEALTH_DB.h"
#include "CM_HEALTH_SEQ.h"
#include "CM_HEALTH_LOG.h"
#include "CM_AUDIT_BYSVC.h"
#include "CM_AUDIT_BYLVL.h"
#include "CM_AUDIT_RANGE.h"
#include "CM_MASK_CARD.h"
#include "CM_MASK_NAME.h"
#include "CM_MASK_PHONE.h"
#include "CM_ENC_HEX.h"
#include "CM_FILE_CKSUM.h"
#include "CM_DATEDIFF.h"
#include "CM_AMT_HANGUL.h"
/* --- 2차 확장 서비스 (코드그룹 버전/이관/정렬, 파라미터 이력/검증, 다국어
 *     렌더/커버리지, 환율 역/스프레드/추세/교차, 영업일·분기·주차, 채번 발번,
 *     알림 통계/재발송/한도, 배치 의존성, 헬스 종합, 감사 상위, 마스킹/해시/문자) --- */
#include "CM_CODEGRP_VER.h"
#include "CM_CODEGRP_DIFF.h"
#include "CM_CODE_MOVE.h"
#include "CM_CODE_REORDER.h"
#include "CM_CODE_TOGGLE.h"
#include "CM_CODE_SEARCH.h"
#include "CM_CODEGRP_SPAN.h"
#include "CM_CODE_EXPORT.h"
#include "CM_PARAM_HIST.h"
#include "CM_PARAM_CANCEL.h"
#include "CM_PARAM_DIFF.h"
#include "CM_PARAM_NUM.h"
#include "CM_PARAM_LIST.h"
#include "CM_MSG_DEL.h"
#include "CM_MSG_FORMAT.h"
#include "CM_MSG_LANGS.h"
#include "CM_MSG_RENDER.h"
#include "CM_FX_INVERT.h"
#include "CM_FX_MARGIN.h"
#include "CM_FX_TREND.h"
#include "CM_FX_MEAN.h"
#include "CM_FX_TICKS.h"
#include "CM_FX_TRIANGLE.h"
#include "CM_HOLIDAY_NEXT.h"
#include "CM_HOLIDAY_YEAR.h"
#include "CM_BIZDAY_ADD.h"
#include "CM_MKT_STATUS.h"
#include "CM_QTR_END.h"
#include "CM_ISO_WEEK.h"
#include "CM_DAYOFYEAR.h"
#include "CM_SEQ_STAMP.h"
#include "CM_SEQ_MULTI.h"
#include "CM_SEQ_ALLOC.h"
#include "CM_SEQ_VERIFY.h"
#include "CM_NOTI_RETRY.h"
#include "CM_NOTI_STAT.h"
#include "CM_NOTI_TMPL.h"
#include "CM_NOTI_QUOTA.h"
#include "CM_BATSCHD_DEL.h"
#include "CM_BATSCHD_LIST.h"
#include "CM_BATDEP_SET.h"
#include "CM_BATDEP_CHK.h"
#include "CM_BATLAST.h"
#include "CM_HEALTH_FX.h"
#include "CM_HEALTH_ALL.h"
#include "CM_HEALTH_PARAM.h"
#include "CM_AUDIT_TOP.h"
#include "CM_AUDIT_ERRPCT.h"
#include "CM_AUDIT_TAIL.h"
#include "CM_MASK_EMAIL.h"
#include "CM_MASK_ACCT.h"
#include "CM_MASK_RRN.h"
#include "CM_HASH_DJB2.h"
#include "CM_HASH_FNV.h"
#include "CM_HASH_SUM.h"
#include "CM_ADLER32.h"
#include "CM_STR_TRIM.h"
#include "CM_STR_PAD.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"CM_CODE", CM_CODE},             {"CM_CODENAME", CM_CODENAME},
    {"CM_BIZDAY", CM_BIZDAY},         {"CM_NEXTBIZ", CM_NEXTBIZ},
    {"CM_ADDDAYS", CM_ADDDAYS},       {"CM_WEEKDAY", CM_WEEKDAY},
    {"CM_MONTHEND", CM_MONTHEND},     {"CM_AMT_ROUND", CM_AMT_ROUND},
    {"CM_AMT_SPLIT", CM_AMT_SPLIT},   {"CM_SEQ", CM_SEQ},
    {"CM_FX", CM_FX},                 {"CM_FX_CONV", CM_FX_CONV},
    {"CM_LUHN", CM_LUHN},             {"CM_CRC", CM_CRC},
    {"CM_MASK", CM_MASK},             {"CM_FMT_DATE", CM_FMT_DATE},
    {"CM_FMT_AMT", CM_FMT_AMT},       {"CM_PARAM", CM_PARAM},
    {"CM_PARAM_SET", CM_PARAM_SET},   {"CM_CACHE_LOAD", CM_CACHE_LOAD},
    {"CM_CACHE_INV", CM_CACHE_INV},   {"CM_ERRMSG", CM_ERRMSG},
    {"CM_LOG", CM_LOG},               {"CM_HOLIDAY_CHK", CM_HOLIDAY_CHK},
    {"CM_CHECKDIGIT", CM_CHECKDIGIT}, {"CM_INTEREST", CM_INTEREST},
    {"CM_PRORATE", CM_PRORATE},       {"CM_NETTING_CALC", CM_NETTING_CALC},
    {"CM_STATUS", CM_STATUS},         {"CM_PING", CM_PING},
    /* --- 확장 서비스 --- */
    {"CM_CODEGRP_REG", CM_CODEGRP_REG},     {"CM_CODEGRP_UPD", CM_CODEGRP_UPD},
    {"CM_CODEGRP_CLOSE", CM_CODEGRP_CLOSE}, {"CM_CODEGRP_HIST", CM_CODEGRP_HIST},
    {"CM_CODEGRP_CNT", CM_CODEGRP_CNT},     {"CM_PARAM_REQ", CM_PARAM_REQ},
    {"CM_PARAM_APPROVE", CM_PARAM_APPROVE}, {"CM_PARAM_REJECT", CM_PARAM_REJECT},
    {"CM_PARAM_PENDING", CM_PARAM_PENDING}, {"CM_MSG_GET", CM_MSG_GET},
    {"CM_MSG_SET", CM_MSG_SET},             {"CM_MSG_FALLBACK", CM_MSG_FALLBACK},
    {"CM_FX_PUBLISH", CM_FX_PUBLISH},       {"CM_FX_HIST", CM_FX_HIST},
    {"CM_FX_VALID", CM_FX_VALID},           {"CM_FX_CROSS", CM_FX_CROSS},
    {"CM_FX_AGE", CM_FX_AGE},               {"CM_HOLIDAY_REG", CM_HOLIDAY_REG},
    {"CM_HOLIDAY_DEL", CM_HOLIDAY_DEL},     {"CM_HOLIDAY_CNT", CM_HOLIDAY_CNT},
    {"CM_BIZDAY_CNT", CM_BIZDAY_CNT},       {"CM_PREVBIZ", CM_PREVBIZ},
    {"CM_SEQ_DAILY", CM_SEQ_DAILY},         {"CM_SEQ_TYPED", CM_SEQ_TYPED},
    {"CM_SEQ_PEEK", CM_SEQ_PEEK},           {"CM_SEQ_RESET", CM_SEQ_RESET},
    {"CM_NOTI_SEND", CM_NOTI_SEND},         {"CM_NOTI_HIST", CM_NOTI_HIST},
    {"CM_BATSCHD_REG", CM_BATSCHD_REG},     {"CM_BATSCHD_GET", CM_BATSCHD_GET},
    {"CM_BATHIST_CNT", CM_BATHIST_CNT},     {"CM_BATRERUN_REQ", CM_BATRERUN_REQ},
    {"CM_HEALTH_DB", CM_HEALTH_DB},         {"CM_HEALTH_SEQ", CM_HEALTH_SEQ},
    {"CM_HEALTH_LOG", CM_HEALTH_LOG},       {"CM_AUDIT_BYSVC", CM_AUDIT_BYSVC},
    {"CM_AUDIT_BYLVL", CM_AUDIT_BYLVL},     {"CM_AUDIT_RANGE", CM_AUDIT_RANGE},
    {"CM_MASK_CARD", CM_MASK_CARD},         {"CM_MASK_NAME", CM_MASK_NAME},
    {"CM_MASK_PHONE", CM_MASK_PHONE},       {"CM_ENC_HEX", CM_ENC_HEX},
    {"CM_FILE_CKSUM", CM_FILE_CKSUM},       {"CM_DATEDIFF", CM_DATEDIFF},
    {"CM_AMT_HANGUL", CM_AMT_HANGUL},
    /* --- 2차 확장 서비스 --- */
    {"CM_CODEGRP_VER", CM_CODEGRP_VER},     {"CM_CODEGRP_DIFF", CM_CODEGRP_DIFF},
    {"CM_CODE_MOVE", CM_CODE_MOVE},         {"CM_CODE_REORDER", CM_CODE_REORDER},
    {"CM_CODE_TOGGLE", CM_CODE_TOGGLE},     {"CM_CODE_SEARCH", CM_CODE_SEARCH},
    {"CM_CODEGRP_SPAN", CM_CODEGRP_SPAN},   {"CM_CODE_EXPORT", CM_CODE_EXPORT},
    {"CM_PARAM_HIST", CM_PARAM_HIST},       {"CM_PARAM_CANCEL", CM_PARAM_CANCEL},
    {"CM_PARAM_DIFF", CM_PARAM_DIFF},       {"CM_PARAM_NUM", CM_PARAM_NUM},
    {"CM_PARAM_LIST", CM_PARAM_LIST},       {"CM_MSG_DEL", CM_MSG_DEL},
    {"CM_MSG_FORMAT", CM_MSG_FORMAT},       {"CM_MSG_LANGS", CM_MSG_LANGS},
    {"CM_MSG_RENDER", CM_MSG_RENDER},       {"CM_FX_INVERT", CM_FX_INVERT},
    {"CM_FX_MARGIN", CM_FX_MARGIN},         {"CM_FX_TREND", CM_FX_TREND},
    {"CM_FX_MEAN", CM_FX_MEAN},             {"CM_FX_TICKS", CM_FX_TICKS},
    {"CM_FX_TRIANGLE", CM_FX_TRIANGLE},     {"CM_HOLIDAY_NEXT", CM_HOLIDAY_NEXT},
    {"CM_HOLIDAY_YEAR", CM_HOLIDAY_YEAR},   {"CM_BIZDAY_ADD", CM_BIZDAY_ADD},
    {"CM_MKT_STATUS", CM_MKT_STATUS},       {"CM_QTR_END", CM_QTR_END},
    {"CM_ISO_WEEK", CM_ISO_WEEK},           {"CM_DAYOFYEAR", CM_DAYOFYEAR},
    {"CM_SEQ_STAMP", CM_SEQ_STAMP},         {"CM_SEQ_MULTI", CM_SEQ_MULTI},
    {"CM_SEQ_ALLOC", CM_SEQ_ALLOC},         {"CM_SEQ_VERIFY", CM_SEQ_VERIFY},
    {"CM_NOTI_RETRY", CM_NOTI_RETRY},       {"CM_NOTI_STAT", CM_NOTI_STAT},
    {"CM_NOTI_TMPL", CM_NOTI_TMPL},         {"CM_NOTI_QUOTA", CM_NOTI_QUOTA},
    {"CM_BATSCHD_DEL", CM_BATSCHD_DEL},     {"CM_BATSCHD_LIST", CM_BATSCHD_LIST},
    {"CM_BATDEP_SET", CM_BATDEP_SET},       {"CM_BATDEP_CHK", CM_BATDEP_CHK},
    {"CM_BATLAST", CM_BATLAST},             {"CM_HEALTH_FX", CM_HEALTH_FX},
    {"CM_HEALTH_ALL", CM_HEALTH_ALL},       {"CM_HEALTH_PARAM", CM_HEALTH_PARAM},
    {"CM_AUDIT_TOP", CM_AUDIT_TOP},         {"CM_AUDIT_ERRPCT", CM_AUDIT_ERRPCT},
    {"CM_AUDIT_TAIL", CM_AUDIT_TAIL},       {"CM_MASK_EMAIL", CM_MASK_EMAIL},
    {"CM_MASK_ACCT", CM_MASK_ACCT},         {"CM_MASK_RRN", CM_MASK_RRN},
    {"CM_HASH_DJB2", CM_HASH_DJB2},         {"CM_HASH_FNV", CM_HASH_FNV},
    {"CM_HASH_SUM", CM_HASH_SUM},           {"CM_ADLER32", CM_ADLER32},
    {"CM_STR_TRIM", CM_STR_TRIM},           {"CM_STR_PAD", CM_STR_PAD},
    {NULL, NULL}
};

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

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

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