extern "C" int LIBTUX_EXPORT _tmstartserver(int argc, char **argv, TMSVRARGS_T* tmsvrargs) { int nRet = 0; // 初始化Tuxedo系统 TPINIT tpinfo; memset(&tpinfo, 0, sizeof(tpinfo)); // 试图创建AppContext对象 if(!g_pAppContext) { g_pAppContext = new AppContext(); } // 初始化Tuxedo系统 nRet = g_pAppContext->tpinit(&tpinfo); if(nRet != 0) { logger->error(LTRACE, "tpinit error"); return -1; } // 作为Server,注册服务 nRet = g_pAppContext->tpregister(tmsvrargs->tmdsptchtbl, tmsvrargs->tmdsptchtbllen, 0); if(nRet != 0) { logger->error(LTRACE, "Register service error"); return -1; } // 初始化用户应用 nRet = tpsvrinit(argc, argv); if(nRet != 0) { userlog("tpsvrinit failed"); return -1; } // 运行Server g_pAppContext->tprun(0); // 结束Tuxedo系统 g_pAppContext->tpterm(); // 结束用户应用 tpsvrdone(); // 销毁Tuxedo系统 delete g_pAppContext; return 0; }
/** * Real processing starts here. * @param argc * @param argv * @return */ int ndrx_main(int argc, char** argv) { int ret=SUCCEED; /* do internal initialization, get configuration, request for admin q */ ret=ndrx_init(argc, argv); /* * Initialize services */ if (SUCCEED==ret) { ret=tpsvrinit(argc, argv); } /* * Push the services out! */ if (SUCCEED==ret) { ret=build_advertise_list(); } if (SUCCEED==ret) { /* initialize the library */ ret=initialize_atmi_library(); } /* * Open the queues */ if (SUCCEED==ret) { ret=sv_open_queue(); } /* Do lib updates after Q open... */ if (SUCCEED==ret) { ret=tp_internal_init_upd_replyq(G_server_conf.service_array[1]->q_descr, G_server_conf.service_array[1]->listen_q); } if (SUCCEED==ret) { /* As we can run even witout ndrxd, then we ingore the result of send op */ report_to_ndrxd(); } /* run process here! */ if (SUCCEED==ret) { ret=sv_wait_for_request(); } /* finish up. */ tpsvrdone(); un_initialize(); /* * Print error message on exit. */ if (SUCCEED!=ret) { printf("Error: %s\n", tpstrerror(tperrno)); } fprintf(stderr, "Server exit: %d, id: %d\n", ret, G_srv_id); return ret; }