static Bool _ExecuteProcess(MessageHandler *handler, ProcessNode *node) { int (*apl)(char *, char *, char *, char *); char *module; long start, end; Bool rc; module = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.module")); if ((apl = cob_resolve(module)) != NULL) { PutApplication(node); start = GetNowTime(); (void)apl(McpData, SpaData, LinkData, ScrData); end = GetNowTime(); TimerPrintf(start, end, "OpenCOBOL %s:%s:%s\n", module, node->widget, node->event); GetApplication(node); if (ValueInteger(GetItemLongName(node->mcprec->value, "rc")) < 0) { rc = FALSE; } else { rc = TRUE; } } else { Warning("%s - %s is not found.", cob_resolve_error(), module); rc = FALSE; } return (rc); }
extern void *MCP_GetEventHandler(GHashTable *StatusTable, ProcessNode *node) { char *status, *event; GHashTable *EventTable; void (*handler)(ProcessNode *); status = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.status")); event = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.event")); dbgprintf("status = [%s]", status); dbgprintf("event = [%s]", status, event); if ((EventTable = g_hash_table_lookup(StatusTable, status)) == NULL) { EventTable = g_hash_table_lookup(StatusTable, ""); } if (EventTable != NULL) { if ((handler = g_hash_table_lookup(EventTable, event)) == NULL) { handler = g_hash_table_lookup(EventTable, ""); } } else { handler = NULL; } return (handler); }
static Bool _ExecuteProcess( MessageHandler *handler, ProcessNode *node) { VALUE app_class; VALUE app; ValueStruct *dc_module_value; char *dc_module; int state; ENTER_FUNC; if (handler->loadpath == NULL) { Warning("loadpath is required"); return FALSE; } dc_module_value = GetItemLongName(node->mcprec->value, "dc.module"); dc_module = ValueStringPointer(dc_module_value); app_class = load_application(handler->loadpath, dc_module); if (NIL_P(app_class)) { Warning("%s is not found", dc_module); return FALSE; } app = rb_protect_funcall(app_class, rb_intern("new"), &state, 0); if (state && error_handle(state)) { return FALSE; } PutApplication(node); rb_protect_funcall(app,rb_intern("exec_process"),&state,1,node_info); if (state && error_handle(state)) { Warning("eval exec_process failed"); return FALSE; } GetApplication(node); if (ValueInteger(GetItemLongName(node->mcprec->value, "rc")) < 0) { return FALSE; } else { return TRUE; } LEAVE_FUNC; }
static void ExecuteDB_Server(MessageHandler *handler) { RecordStruct *rec; ValueStruct *value, *ret; PathStruct *path; DB_Operation *op; size_t size; int rno, pno, ono; DBCOMM_CTRL ctrl; char *rname, *pname, *func; ConvFuncs *conv; InitializeCTRL(&ctrl); conv = handler->serialize; while (TRUE) { dbgmsg("read"); LBS_EmitStart(dbbuff); RecvLargeString(fpDBR, dbbuff); ON_IO_ERROR(fpDBR, badio); ConvSetRecName(handler->conv, recDBCTRL->name); InitializeValue(recDBCTRL->value); conv->UnPackValue(handler->conv, LBS_Body(dbbuff), recDBCTRL->value); rname = ValueStringPointer(GetItemLongName(recDBCTRL->value, "rname")); strncpy(ctrl.rname, rname, SIZE_NAME); value = NULL; ret = NULL; if ((rname != NULL) && ((rno = (int)(long)g_hash_table_lookup(DB_Table, rname)) != 0)) { ctrl.rno = rno - 1; rec = ThisDB[ctrl.rno]; value = rec->value; pname = ValueStringPointer(GetItemLongName(recDBCTRL->value, "pname")); strncpy(ctrl.pname, pname, SIZE_NAME); if ((pno = (int)(long)g_hash_table_lookup(rec->opt.db->paths, pname)) != 0) { ctrl.pno = pno - 1; path = rec->opt.db->path[pno - 1]; value = (path->args != NULL) ? path->args : value; } else { ctrl.pno = 0; path = NULL; } } else { rec = NULL; path = NULL; } func = ValueStringPointer(GetItemLongName(recDBCTRL->value, "func")); if (*func != 0) { if (path == NULL) { Error("path is NULL"); } else if ((ono = (int)(long)g_hash_table_lookup(path->opHash, func)) != 0) { op = path->ops[ono - 1]; value = (op->args != NULL) ? op->args : value; } if (rec != NULL) { ConvSetRecName(handler->conv, rec->name); } else { Error("rec is NULL"); } InitializeValue(value); conv->UnPackValue(handler->conv, LBS_Body(dbbuff), value); strncpy(ctrl.func, func, SIZE_FUNC); ret = ExecDB_Process(&ctrl, rec, value); } else { ctrl.rc = 0; } dbgmsg("write"); SetValueInteger(GetItemLongName(recDBCTRL->value, "rc"), ctrl.rc); ConvSetRecName(handler->conv, recDBCTRL->name); LBS_EmitStart(dbbuff); size = conv->SizeValue(handler->conv, recDBCTRL->value); LBS_ReserveSize(dbbuff, size, FALSE); conv->PackValue(handler->conv, LBS_Body(dbbuff), recDBCTRL->value); LBS_EmitEnd(dbbuff); SendLargeString(fpDBW, dbbuff); ON_IO_ERROR(fpDBW, badio); if (ret != NULL) { Send(fpDBW, conv->fsep, strlen(conv->fsep)); ON_IO_ERROR(fpDBW, badio); LBS_EmitStart(dbbuff); if (rec != NULL) { ConvSetRecName(handler->conv, rec->name); } size = conv->SizeValue(handler->conv, ret); LBS_ReserveSize(dbbuff, size, FALSE); conv->PackValue(handler->conv, LBS_Body(dbbuff), ret); LBS_EmitEnd(dbbuff); SendLargeString(fpDBW, dbbuff); ON_IO_ERROR(fpDBW, badio); FreeValueStruct(ret); } Send(fpDBW, conv->bsep, strlen(conv->bsep)); ON_IO_ERROR(fpDBW, badio); } badio: return; }
static Bool _ExecuteProcess(MessageHandler *handler, ProcessNode *node) { char *module; int pid; int pAPR[2], pAPW[2], pDBR[2], pDBW[2]; Bool rc; NETFILE *fpAPR, *fpAPW; char line[SIZE_BUFF], **cmd; if (handler->loadpath == NULL) { handler->loadpath = ExecPath; } signal(SIGPIPE, SignalHandler); module = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.module")); ExpandStart(line, handler->start, handler->loadpath, module, ""); cmd = ParCommandLine(line); if (pipe(pAPR) != 0) { perror("pipe"); exit(1); } if (pipe(pAPW) != 0) { perror("pipe"); exit(1); } if (pipe(pDBR) != 0) { perror("pipe"); exit(1); } if (pipe(pDBW) != 0) { perror("pipe"); exit(1); } if (setjmp(SubError) == 0) { if ((pid = fork()) == 0) { dup2(pAPW[0], STDIN_FILENO); dup2(pAPR[1], STDOUT_FILENO); close(pAPW[0]); close(pAPW[1]); close(pAPR[0]); close(pAPR[1]); dup2(pDBW[0], DBIN_FILENO); dup2(pDBR[1], DBOUT_FILENO); close(pDBW[0]); close(pDBW[1]); close(pDBR[0]); close(pDBR[1]); execv(cmd[0], cmd); } else { fpAPR = FileToNet(pAPR[0]); close(pAPR[1]); fpAPW = FileToNet(pAPW[1]); close(pAPW[0]); fpDBR = FileToNet(pDBR[0]); close(pDBR[1]); fpDBW = FileToNet(pDBW[1]); close(pDBW[0]); StartDB(handler); PutApplication(handler, fpAPW, node); GetApplication(handler, fpAPR, node); (void)wait(&pid); CancelDB(); signal(SIGPIPE, SIG_DFL); CloseNet(fpAPW); CloseNet(fpAPR); CloseNet(fpDBW); CloseNet(fpDBR); } rc = TRUE; } else { rc = FALSE; } return (rc); }