int main (int argc, char *argv[]) { pwr_tStatus sts = 1; qdb_sPort port; qdb_sPort *pp; qcom_sQid qid = qdb_cQimport; qdb_sNode *np; errh_Init("pwr_qimp"); if (!qcom_Init(&sts, NULL)) exit(sts); if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts); port.sa.sin_family = AF_INET; port.sa.sin_addr.s_addr = htonl(INADDR_ANY); port.sa.sin_port = qdb->my_node->sa.sin_port; pp = qnet_Open(&sts, &port); while (qdb->g->up) { np = qnet_Get(&sts, pp); if (np->bp == NULL) pwr_Bugcheck(QCOM__WEIRD, "(np->bp == NULL)"); linkEvent(pp, np); } qnet_Close(&sts, pp); qcom_Exit(&sts); exit(QCOM__SUCCESS); }
static pwr_tStatus stop ( int argc, char **argv, ini_sContext *cp ) { pwr_tStatus sts; qcom_sQid qid; qcom_sPut put; char data[] = "Shutdown you fool!"; if (!qcom_Init(&sts, 0, "pwr_ini_stop")) { exit(sts); } qid.qix = 550715; qid.nid = 0; put.type.b = 11; put.type.s = 1; put.reply.qix = 0; put.reply.nid = 0; put.data = data; put.size = sizeof(data) + 1; qcom_Put(&sts, &qid, &put); return 0; }
static pwr_sClass_IOHandler * init (qcom_sQid *qid, lst_sEntry **csup_lh) { pwr_tStatus sts = 1; pwr_sClass_IOHandler *ihp; qcom_sQattr qAttr; qcom_sQid qini; pwr_tObjid oid; errh_Init("pwr_io", errh_eAnix_io); #if defined(OS_ELN) /* Event to kill dioc */ ker$create_event(&sts, &io_comm_terminate, EVENT$CLEARED); #endif if (!qcom_Init(&sts, 0, "pwr_io")) { errh_Fatal("qcom_Init, %m", sts); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); exit(sts); } qini = qcom_cQini; if (!qcom_Bind(&sts, qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); exit(-1); } sts = gdh_Init("pwr_io"); if (EVEN(sts)) { errh_Fatal("rt_io_comm aborted\n%m", sts); exit(sts); } sts = io_get_iohandler_object(&ihp, &oid); if (EVEN(sts)) { errh_Fatal("rt_io_comm aborted, no IoHandler object found\n%m", sts); exit(sts); } aproc_RegisterObject( oid); *csup_lh = csup_Init(&sts, oid, ihp->CycleTimeBus); return ihp; }
int main(int argc, char* argv[]) { pwr_tStatus sts; qcom_sAid aid; sevcli_tCtx sevcli; sevcli_sHistItem* items; unsigned int itemcnt; char servername[40] = ""; // Get options for (int i = 1; i < argc; i++) { if (streq(argv[i], "-s") && i + 1 < argc) { strncpy(servername, argv[i + 1], sizeof(servername)); i++; } } sts = qcom_Init(&sts, &aid, "sev_xtt"); if (EVEN(sts)) { co_error(sts); } sevcli_init(&sts, &sevcli); if (EVEN(sts)) { printf("Sev client init error %u\n", sts); debug_print("Shutting down...\n"); exit(0); } if (!streq(servername, "")) { sevcli_set_servernode(&sts, sevcli, servername); } sevcli_get_itemlist(&sts, sevcli, &items, &itemcnt); if (EVEN(sts)) { printf("Sev client get itemlist error %u\n", sts); debug_print("Shutting down...\n"); exit(0); } QApplication app(argc, argv); QApplication::setStyle(new PwrStyle()); setlocale(LC_NUMERIC, "POSIX"); setlocale(LC_TIME, "en_US"); XttTblQt* tbl = new XttTblQt(0, 0, sevcli, items, itemcnt); tbl->close_cb = tbl_close_cb; return app.exec(); }
main (int argc, char *argv[]) { pwr_tStatus sts; qcom_sQid qid; qcom_sQid fqid; qcom_sGet get; qcom_sPut put; qdb_sInit init; qdb_sNode *np; qcom_sQattr attr; void *p; if (!qcom_Init(&sts, NULL)) exit(sts); attr.type = qcom_eQtype_forward; attr.quota = 100; fqid.nid = pwr_cNNodeId; fqid.qix = 550715; if(!qcom_CreateQ(&sts, &fqid, &attr)) exit(sts); qid.nid = pwr_cNNodeId; qid.qix = qdb_cIloopBack; if(!qcom_CreateQ(&sts, &qid, NULL)) exit(sts); if(!qcom_Bind(&sts, &qid, &fqid)) exit(sts); while (1) { get.data = NULL; p = qcom_Get(&sts, &qid, &get, 60000); if (p == NULL) continue; // printf("\nsender..: %d,%d\n", get.sender.nid, get.pid); // printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix); // printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix); // printf("type....: %d,%d\n", get.type.b, get.type.s); // printf("size....: %d\n", get.size); put.reply = qid; put.type = get.type; put.size = get.size; put.data = p; qcom_Put(&sts, &get.reply, &put); if (EVEN(sts)) qcom_Free(&sts, p); } }
void init( qcom_sQid *qid) { qcom_sQid qini; qcom_sQattr qAttr; pwr_tStatus sts; sts = gdh_Init("rt_sysmon"); if ( EVEN(sts)) { errh_Fatal( "gdh_Init, %m", sts); exit(sts); } errh_Init("pwr_sysmon", errh_eAnix_sysmon); errh_SetStatus( PWR__SRVSTARTUP); if (!qcom_Init(&sts, 0, "pwr_sysmon")) { errh_Fatal("qcom_Init, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(sts); } qini = qcom_cQini; if (!qcom_Bind(&sts, qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); errh_SetStatus( PWR__SRVTERM); exit(-1); } }
main (int argc, char *argv[]) { pwr_tStatus sts; qcom_sQid qid; qcom_sGet get; qcom_sPut put; qcom_sQid loop; int data[DATA_SIZE]; int i; int j; int max = 1000; char *sp; qid = qcom_cNQid; if (argc < 2) exit(12); if (argc > 2) max = atoi(argv[2]); for (j = 0; j < DATA_SIZE; j++) data[j] = j; loop.nid = atoi(argv[1]); loop.qix = qcom_cIloopBack; if (!qcom_Init(&sts, NULL)) exit(sts); if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts); for (i = 1; i < max; i++) { for (j = 0; j < DATA_SIZE; j++) ++data[j]; sp = qcom_Alloc(&sts, sizeof(data)); if (sp == NULL) exit(sts); memcpy(sp, &data, sizeof(data)); put.type.b = 10; put.type.s = i; put.reply = qid; put.size = sizeof(data); put.data = sp; qcom_Put(&sts, &loop, &put); if (EVEN(sts)) exit(sts); get.data = NULL; sp = qcom_Get(&sts, &qid, &get, qcom_cTmoEternal); if (sp == NULL) continue; for (j = 0; j < DATA_SIZE; j++) { if (data[j] != *(int *)sp) { printf("index...: %d, (%d)\n", j, data[j]); break; } sp += sizeof(int); } // printf("\nsender..: %d,%X\n", get.sender.nid, get.pid); // printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix); // printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix); // printf("type....: %d,%d\n", get.type.b, get.type.s); // printf("size....: %d\n", get.size); // printf("memcmp..: %d\n", memcmp(get.data, &data, sizeof(data))); // printf("index...: %d, (%d)\n", j, data[j]); qcom_Free(&sts, get.data); } qcom_Exit(&sts); }
static pwr_tStatus stop ( int argc, char **argv, ini_sContext *cp ) { pwr_tStatus sts; qcom_sQid qid; qcom_sPut put; char data[] = "Shutdown you fool!"; /* qcom_sGet get; char *bp, *sp; int i; int len; int totlen; */ // errh_Interactive(); if (!qcom_Init(&sts, 0, "pwr_ini_stop")) { // errh_LogFatal(&cp->log, "qcom_Init, %m", sts); exit(sts); } // qcom_CreateQ(&sts, &cp->myQ, NULL, "pwr_ini_restart"); // if (EVEN(sts)) { // errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts); // exit(sts); // } // for (i = 0, totlen = 0; i < argc; i++) { // len = strlen(argv[i]); // totlen += 1 + len; // errh_LogInfo(&cp->log, "argv[%d]: %d \"%s\"", i, len, argv[i]); // } // bp = malloc(totlen); // for (i = 0, sp = bp; i < argc; i++) { // len = strlen(argv[i]); // memcpy(sp, argv[i], len + 1); // sp += len + 1; // } qid.qix = 550715; qid.nid = 0; put.type.b = 11; put.type.s = 1; put.reply.qix = 0; put.reply.nid = 0; put.data = data; put.size = sizeof(data) + 1; qcom_Put(&sts, &qid, &put); // while (1) { // char *s; // get.data = NULL; // s = qcom_Get(&sts, &cp->myQ, &get, 100000); // if (sts == QCOM__TMO && sts == QCOM__QEMPTY) { // break; // } else if (s != NULL) { // printf("%s\n", s); // qcom_Free(NULL, s); // } // if (get.type.s == 2) // break; // } return 0; }
static pwr_tStatus interactive ( int argc, char **argv, ini_sContext *cp ) { pwr_tStatus sts; qcom_sQid qid; qcom_sPut put; qcom_sGet get; char *bp, *sp; int i; int len; int totlen; errh_Interactive(); if (!qcom_Init(&sts, 0, "pwr_ini_restart")) { errh_LogFatal(&cp->log, "qcom_Init, %m", sts); exit(sts); } qcom_CreateQ(&sts, &cp->myQ, NULL, "pwr_ini_restart"); if (EVEN(sts)) { errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts); exit(sts); } for (i = 0, totlen = 0; i < argc; i++) { len = strlen(argv[i]); totlen += 1 + len; errh_LogInfo(&cp->log, "argv[%d]: %d \"%s\"", i, len, argv[i]); } bp = malloc(totlen); for (i = 0, sp = bp; i < argc; i++) { len = strlen(argv[i]); memcpy(sp, argv[i], len + 1); sp += len + 1; } qid.qix = 550715; qid.nid = 0; put.type.b = 10; put.type.s = 1; put.reply = cp->myQ; put.data = bp; put.size = totlen; qcom_Put(&sts, &qid, &put); while (1) { char *s; get.data = NULL; s = qcom_Get(&sts, &cp->myQ, &get, 100000); if (sts == QCOM__TMO && sts == QCOM__QEMPTY) { break; } else if (s != NULL) { printf("%s\n", s); qcom_Free(NULL, s); } if (get.type.s == 2) break; } return sts; }
int main (int argc, char **argv) { pwr_tStatus sts; unsigned int size; qcom_sQid myQId; alimsrv_sSupDataBuf *bp; qcom_sGet get; qcom_sPut put; alimsrv_sRequest request; XDR xdrs; qcom_sQattr qAttr; errh_Init("pwr_alim", errh_eAnix_alim); errh_SetStatus( PWR__SRVSTARTUP); if (!qcom_Init(&sts, 0, "pwr_alim")) { errh_Fatal("qcom_Init, %m", sts); exit(-1); } myQId.qix = alimsrv_cQix; myQId.nid = 0; qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, &myQId, &qAttr, "pwr_alim")) { errh_Fatal("qcom_CreateQ, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(-1); } if (!qcom_Bind(&sts, &myQId, &qcom_cQini)) { errh_Fatal("qcom_Bind, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(-1); } sts = gdh_Init("pwr_alim"); if (EVEN(sts)) { errh_Fatal("gdh_Init, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(-1); } init(); errh_SetStatus( PWR__SRUN); /* Loop forever and receive objid's */ for (;;) { do { get.maxSize = sizeof(request); get.data = (char *)&request; qcom_Get(&sts, &myQId, &get, qcom_cTmoEternal); if (sts != QCOM__TMO && sts != QCOM__QEMPTY) { if (get.type.b == qcom_eBtype_event) { event(&get); } } } while (ODD(sts) && get.type.s != alimsrv_eSubType_Request && get.type.b != alimsrv_cMsgType); if (EVEN(sts)) { errh_Error("qcom_Get, %m",sts); continue; } if (request.Xdr) { xdrmem_create(&xdrs, (char *)&request, sizeof(request), XDR_DECODE); if (!xdr_alimsrv_sRequest(&xdrs, &request)) { errh_Error("XDR Decode failed"); continue; } } bp = buildBuffer(&request, &size); if (ODD(sts)) { bp->Xdr = TRUE; xdrmem_create(&xdrs, (char *)bp, size, XDR_ENCODE); if (!xdr_alimsrv_sSupDataBuf(&xdrs, bp)) { errh_Error("XDR Encode failed"); } else { put.type.b = alimsrv_cMsgType; put.type.s = alimsrv_eSubType_Answer; put.reply = myQId; put.data = (char *) bp; put.size = size; if (!qcom_Reply(&sts, &get, &put)) errh_Error("qcom_Respond, %m", sts); } free(bp); } } }
int main (int argc, char **argv) { pwr_tStatus sts; pwr_tObjid ObjId; pwr_sClass_DsTrendConf *TConfP; pwr_tBoolean InitOK; pwr_tTime CurrentTime, LastScan, NextScan; pwr_tDeltaTime ScanDeltaTime, WaitTime; qcom_sQid qini; qcom_sQattr qAttr; int tmo; char mp[2000]; qcom_sQid qid = qcom_cNQid; qcom_sGet get; int swap = 0; trend_tCtx ctx; errh_Init("pwr_trend", errh_eAnix_trend); errh_SetStatus( PWR__SRVSTARTUP); sts = gdh_Init("ds_trend"); If_Error_Log_Exit(sts, "gdh_Init"); if (!qcom_Init(&sts, 0, "pwr_trend")) { errh_Fatal("qcom_Init, %m", sts); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); exit(sts); } qini = qcom_cQini; if (!qcom_Bind(&sts, &qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); exit(-1); } ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx)); /* Wait until local nethandler has started */ while(EVEN(gdh_NethandlerRunning())) sleep(1); /* Fetch ScanTime */ sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId); if (EVEN(sts)) { errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s"); ctx->scantime = 1; ctx->scantime_tc = 1.0; } else { gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP); ctx->scantime = TConfP->ScanTime; if ( ctx->scantime > 3600) ctx->scantime = 3600; else if ( ctx->scantime < 1) ctx->scantime = 1; ctx->scantime_tc = TConfP->ScanTime; if ( ctx->scantime_tc > 3600) ctx->scantime_tc = 3600; } ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5); aproc_RegisterObject( ObjId); InitOK = FALSE; sts = InitTrendList( ctx); if ( EVEN(sts)) { /* This should be removed when we can wait for init messages. */ errh_SetStatus(0); errh_Info("No DsTrend objects configured"); exit(0); } /* If even sts, just wait for init message */ time_GetTimeMonotonic(&LastScan); time_FloatToD( &ScanDeltaTime, ctx->scantime_tc); aproc_TimeStamp( ctx->scantime, 5.0); errh_SetStatus( PWR__SRUN); for (;;) { time_GetTimeMonotonic(&CurrentTime); time_Aadd(&NextScan, &LastScan, &ScanDeltaTime); if (time_Acomp(&CurrentTime, &NextScan) < 0) { time_Adiff(&WaitTime, &NextScan, &CurrentTime); tmo = 1000 * time_DToFloat( 0, &WaitTime); get.maxSize = sizeof(mp); get.data = mp; qcom_Get( &sts, &qid, &get, tmo); if (sts == QCOM__TMO || sts == QCOM__QEMPTY) { if ( !swap) StoreData( ctx); } else { ini_mEvent new_event; qcom_sEvent *ep = (qcom_sEvent*) get.data; new_event.m = ep->mask; if (new_event.b.oldPlcStop && !swap) { swap = 1; errh_SetStatus( PWR__SRVRESTART); CloseTrendList( ctx); } else if (new_event.b.swapDone && swap) { swap = 0; sts = InitTrendList( ctx); errh_SetStatus( PWR__SRUN); errh_Info("Warm restart completed"); } else if (new_event.b.terminate) { exit(0); } } } else if ( !swap) StoreData( ctx); LastScan = NextScan; aproc_TimeStamp( ctx->scantime, 5.0); } return 1; }
/* * Class: jpwr_rt_Qcom * Method: createIniEventQ * Signature: ()Ljpwr/rt/QcomrCreateQ; */ JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_createIniEventQ (JNIEnv *env, jobject object, jstring jname) { jclass qcomrCreateQ_id; jmethodID qcomrCreateQ_cid; jobject return_obj; jint jsts; qcom_sQid qid = qcom_cNQid; qcom_sQattr qAttr; qcom_sQid qini; int sts; char *cstr; const char *name; qcomrCreateQ_id = (*env)->FindClass( env, "jpwr/rt/QcomrCreateQ"); qcomrCreateQ_cid = (*env)->GetMethodID( env, qcomrCreateQ_id, "<init>", "(III)V"); name = (*env)->GetStringUTFChars( env, jname, 0); cstr = (char *)name; //printf("%s\n", cstr); // Create a queue to receive stop and restart events if (!qcom_Init(&sts, 0, cstr)) { errh_Fatal("qcom_Init, %m", sts); errh_SetStatus( PWR__APPLTERM); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, &qid, &qAttr, cstr)) { errh_Fatal("qcom_CreateQ, %m", sts); errh_SetStatus( PWR__APPLTERM); exit(sts); } (*env)->ReleaseStringUTFChars( env, jname, cstr); //printf( "Create que, qix %d, nid %d, sts %d\n", qid.qix, qid.nid, sts); jsts = (jint) sts; return_obj = (*env)->NewObject( env, qcomrCreateQ_id, qcomrCreateQ_cid, qid.qix, qid.nid, jsts); qini = qcom_cQini; if (!qcom_Bind(&sts, &qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); errh_SetStatus( PWR__APPLTERM); exit(-1); } return return_obj; }
int main (int argc, char ** argv) { pwr_tStatus sts; qcom_sQid my_q = qcom_cNQid; qcom_sGet get; errh_Init("pwr_linksup", errh_eAnix_linksup); errh_SetStatus( PWR__SRVSTARTUP); if (!qcom_Init(&sts, NULL, "pwr_linksup")) { errh_Error("qcom_Init, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(sts); } sts = gdh_Init("pwr_linksup"); if (EVEN(sts)) { errh_Fatal("gdh_Init, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(sts); } if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); errh_SetStatus( PWR__SRVTERM); exit(sts); } if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); errh_SetStatus( PWR__SRVTERM); exit(-1); } /* Wait for local nethandler to start */ while (EVEN(gdh_NethandlerRunning())) sleep(1); plc_UtlWaitForPlc(); LstIni(&node_l); LstIni(&timer_l); init_nodes(); if (!LstEmp(&node_l)) { list_state = eListState_Scan; } else { errh_Info("No nodes to supervise, exiting"); errh_SetStatus( pwr_cNStatus); exit(0); } errh_SetStatus( PWR__SRUN); for (;;) { scan_timers(); scan_nodes(); get.data = NULL; if (qcom_Get(&sts, &my_q, &get, cTimerTimeScan) != NULL) { if (get.type.b == qcom_eBtype_event) { event(&get); } else { errh_Info("unexpected message type, type: %d", get.type.b); } qcom_Free(&sts, get.data); } aproc_TimeStamp(((float)cTimerTimeScan)/1000, 5); } }
main (int argc, char *argv[]) { pwr_tStatus sts; qcom_sQid qid; qcom_sGet get; qcom_sPut put; qcom_sQid loop; int data[500]; int i; int j; int max = 1000; char *sp; int tmo; qid = qcom_cNQid; if (argc < 2) exit(12); if (argc > 2) max = atoi(argv[2]); for (j = 0; j < 500; j++) data[j] = j; loop.nid = atoi(argv[1]); loop.qix = qcom_cIloopBack; if (!qcom_Init(&sts, NULL)) exit(sts); if (!qcom_CreateQ(&sts, &qid, NULL)) exit(sts); for (i = 1; i < max; i++) { for (j = 0; j < 500; j++) ++data[j]; sp = qcom_Alloc(&sts, sizeof(data)); if (sp == NULL) exit(sts); memcpy(sp, &data, sizeof(data)); put.type.b = 10; put.type.s = i; put.reply = qid; put.size = sizeof(data); put.data = sp; get.data = NULL; tmo = 10 + (i%3)*3000; sp = qcom_Request(&sts, &loop, &put, &qid, &get, tmo); if (sp == NULL) { printf("\n%d tmo: %d empty buffer\n", i, tmo); continue; } for (j = 0; j < 500; j++) { if (data[j] != *(int *)sp) break; sp += sizeof(int); } printf("\nsender..: %d,%X\n", get.sender.nid, get.pid); printf("receiver: %d,%d\n", get.receiver.nid, get.receiver.qix); printf("reply...: %d,%d\n", get.reply.nid, get.reply.qix); printf("type....: %d,%d\n", get.type.b, get.type.s); printf("size....: %d\n", get.size); printf("memcmp..: %d\n", memcmp(get.data, &data, sizeof(data))); printf("index...: %d, (%d)\n", j, data[j]); qcom_Free(&sts, get.data); } qcom_Exit(&sts); }
int main(int argc, char** argv) { pwr_tStatus sts; io_tCtx io_ctx; float ctime = 1; pwr_sClass_EplHandler* plhp; pwr_tOid oid; int tmo; char mp[2000]; qcom_sGet get; qcom_sQattr qAttr; qcom_sQid qini; qcom_sQid qid = qcom_cNQid; if (argc > 1) { if (streq(argv[1], "-m")) { io_methods_print(); exit(0); } if (streq(argv[1], "-h")) { usage(); exit(0); } } // Make connection to error handler errh_Init("pwr_powerlink", errh_eAnix_powerlink); errh_SetStatus(PWR__SRVSTARTUP); if (!qcom_Init(&sts, 0, "pwr_powerlink")) { errh_Fatal("qcom_Init, %m", sts); exit(sts); } qAttr.type = qcom_eQtype_private; qAttr.quota = 100; if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); exit(sts); } qini = qcom_cQini; if (!qcom_Bind(&sts, &qid, &qini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); exit(-1); } // Make connection to realtime database sts = gdh_Init("rt_powerlink"); if (EVEN(sts)) { errh_Fatal("rt_powerlink aborted, gdh_Init failed\n%m", sts); errh_SetStatus(PWR__SRVTERM); exit(sts); } sts = gdh_GetClassList(pwr_cClass_Epl_CNServer, &oid); if (ODD(sts)) { system("rt_powerlink_cn &"); exit(0); } // Get Powerlink handler object sts = io_get_plhandler_object(&plhp, &oid); if (EVEN(sts)) { errh_SetStatus(0); errh_Info("rt_powerlink terminated, no EplHandler object found"); exit(sts); } // Create context and call init functions of all agent, // rack and cardobjects sts = io_init(io_mProcess_Powerlink, pwr_cNObjid, &io_ctx, 1, ctime); if (EVEN(sts)) { errh_SetStatus(PWR__SRVTERM); errh_Fatal("rt_powerlink aborted, io_init() failed\n%m", sts); exit(sts); } tmo = (plhp->CycleTime) * 1000; aproc_TimeStamp(plhp->CycleTime, 5.0); errh_SetStatus(PWR__SRUN); aproc_RegisterObject(oid); // Call IoAgentRead() IoAgentWrite() IoCardRead() IoCardWrite() // IoModuleRead() IoModuleWrite() forever for (;;) { get.maxSize = sizeof(mp); get.data = mp; qcom_Get(&sts, &qid, &get, tmo); if (sts == QCOM__TMO || sts == QCOM__QEMPTY) { sts = io_read(io_ctx); sts = io_write(io_ctx); aproc_TimeStamp(plhp->CycleTime, 5.0); } else { ini_mEvent new_event; qcom_sEvent* ep = (qcom_sEvent*)get.data; new_event.m = ep->mask; if (new_event.b.oldPlcStop) { // TODO } else if (new_event.b.swapDone) { // TODO } else if (new_event.b.terminate) { // io_close(io_ctx); exit(0); } } } }
static pwr_tStatus start( ini_sContext *cp) { pwr_tStatus sts; char console[80]; qini_sNode *nep; qcom_sAid aid; int fd; if ( strcmp( cp->console, "") == 0) strcpy( console, "/dev/console"); else strcpy( console, cp->console); if ((fd = open(console, O_APPEND | O_WRONLY)) == -1) errl_Init(NULL, ini_errl_cb, cp); else { close(fd); errl_Init(console, ini_errl_cb, cp); } errh_Init("pwr_ini", errh_eAnix_ini); if ( cp->flags.b.interactive) errh_Interactive(); ini_CheckContext(&sts, cp); ini_ReadBootFile(&sts, cp); ini_ReadNodeFile(&sts, cp); for (nep = tree_Minimum(&sts, cp->nid_t); nep != NULL; nep = tree_Successor(&sts, cp->nid_t, nep)) { if ( strcmp( cp->nodename, nep->name) == 0) { cp->me = nep; break; } } if (cp->me == NULL) { errh_LogFatal(&cp->log, "Cannot find my own node in %s\n", cp->nodefile.name); exit(QCOM__WEIRD); } if (!checkErrors(cp)) exit(0); /* Logfile is always $pwrp_log/pwr.log from V4.0.0 and handled by Linux log rotation */ char fname[256]; sprintf(fname, "$pwrp_log/pwr_%s.log", cp->nodename); dcli_translate_filename(fname, fname); errl_SetFile(fname); errh_LogInfo(&cp->log, "Setting log file to: %s", fname); // ini_SetSystemStatus( cp, PWR__STARTUP); errh_SetStatus( PWR__STARTUP); qini_BuildDb(&sts, cp->nid_t, cp->me, NULL, cp->busid); ini_ProcTable(&sts, cp); ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcStart); ini_ProcIter(&sts, cp, proc_mProcess_system, ini_ProcPrio); ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcStart); ini_ProcIter(&sts, cp, proc_mProcess_user, ini_ProcPrio); qcom_Init(&sts, &aid, "pwr_sev_init"); if (EVEN(sts)) { errh_LogFatal(&cp->log, "qcom_Init, %m", sts); exit(sts); } qcom_CreateQ(&sts, &cp->eventQ, NULL, "iniEvent"); if (EVEN(sts)) { errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts); exit(sts); } // ini_SetSystemStatus( cp, PWR__RUNNING); errh_SetStatus( PWR__SRUN); return sts; }