static void * receive ( qcom_sQid *qid, qcom_sGet *get ) { pwr_tStatus sts; void *mp; for (;;) { get->data = NULL; /* Loop until receiving a valid message. */ mp = qcom_Get(&sts, &qcom_cQnacp, get, qcom_cTmoEternal); if (mp == NULL) { errh_Error("qcom_Get, %m", sts); continue; } if (get->type.b == qcom_eBtype_event) { event(get); qcom_Free(&sts, mp); continue; } else if (get->type.b != net_cMsgClass) { errh_Error("Received bad message, type: <%d>, subtype: <%d>", get->type.b, get->type.s); qcom_Free(&sts, mp); continue; } return mp; } }
pwr_tStatus hd_NetSendMessage( qcom_sQid *qid, co_sPlatform *recPlatform, int subtype, hd_sHead *hp, unsigned int size ) { pwr_tStatus sts = HD__SUCCESS; pwr_tStatus sts2; qcom_sPut msg; XDR xdrs; if ((msg.data = (char*)qcom_Alloc(&sts, size)) == NULL) { return HD__INSVIRMEM; } msg.type.b = hd_cMsgClass; msg.type.s = hp->type = subtype; msg.reply = hp->qid; msg.size = size; if (recPlatform == NULL || co_IsXdrNeeded(&hp->platform, recPlatform)) { hp->xdr = TRUE; xdrmem_create(&xdrs, msg.data, size, XDR_ENCODE); sts = hd_NetXdrMessage(&xdrs, subtype, hp); if (EVEN(sts)) { qcom_Free(&sts2, msg.data); return sts; } } else { hp->xdr = FALSE; memcpy(msg.data, hp, size); } qcom_Put(&sts, qid, &msg); if (EVEN(sts)) { qcom_Free(&sts2, msg.data); } return sts; }
static pwr_tStatus logg_free_message( void) { pwr_tStatus sts; if (remlogg_get.data != 0) qcom_Free(&sts, remlogg_get.data); if (EVEN(sts)) return sts; return REM__SUCCESS; }
JNIEXPORT jobject JNICALL Java_jpwr_rt_Qcom_getString (JNIEnv *env, jobject object, jint qix, jint nid) { int sts; jclass cdhrString_id; jmethodID cdhrString_cid; jobject return_obj; jint jsts; qcom_sQid qid; qcom_sGet get; jstring jdata = NULL; int sts2; // static qcom_sAid op_aid = {0,0}; // qcom_sAid aid; cdhrString_id = (*env)->FindClass( env, "jpwr/rt/CdhrString"); cdhrString_cid = (*env)->GetMethodID( env, cdhrString_id, "<init>", "(Ljava/lang/String;I)V"); qid.qix = qix; qid.nid = nid; memset( &get, 0, sizeof(get)); qcom_Get( &sts, &qid, &get, 0); if ( ODD(sts)) { //printf("Qcom_get: Received data: %s\n", (char *)get.data); jdata = (*env)->NewStringUTF( env, (char *)get.data); // Get disconnect broadcast... // if ( get.type.b == qcom_eBtype_qcom && // get.type.s == qcom_eStype_applDisconnect) // { // aid = ((qcom_sAppl*) get.data)->aid; // printf("applDisconnect received %d\n", aid.aix); // if ( qcom_AidIsEqual( &aid, &op_aid)) // { // jdata = (*env)->NewStringUTF( env, "qcom_exit"); // } // } // else // { // op_aid = get.sender; // printf( "Aid received: %d\n", op_aid.aix); // jdata = (*env)->NewStringUTF( env, (char *)get.data); // } qcom_Free( &sts2, get.data); } jsts = (jint) sts; return_obj = (*env)->NewObject( env, cdhrString_id, cdhrString_cid, jdata, jsts); return return_obj; }
void ini_ProcWait ( pwr_tStatus *status, ini_sContext *cp ) { lst_sEntry *pl; ini_sProc *pp; pid_t pid; pid_t last_pid = 1; qcom_sGet get; int tmo = 1000; pwr_dStatus(sts, status, INI__SUCCESS); #if defined OS_LYNX || defined OS_LINUX for (;;) { int status; get.data = NULL; qcom_Get(sts, &cp->eventQ, &get, tmo); if (*sts == QCOM__TMO || *sts == QCOM__QEMPTY) { errh_Info("Timeout"); } else if (get.data == NULL) { errh_Info("Nulldata"); } else { errh_Info("%d %s", get.size, get.data); qcom_Free(NULL, get.data); } if (lst_Succ(NULL, &cp->proc_lh, &pl) == NULL) break; pid = waitpid(-1, &status, WNOHANG|WUNTRACED); if (pid == 0) continue; if (pid == last_pid) break; for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) { if (pp->proc.pid == pid) { errh_Info("Process %s exited with status %d", pp->proc.name, status); break; } } } #else sleep(100000); #endif errh_Info("Ich sterbe!!"); }
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 Jop::que_free( char *data) { int sts; qcom_Free( &sts, data); }
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 events ( ini_sContext *cp ) { lst_sEntry *pl; ini_sProc *pp; pid_t pid; pid_t last_pid = 1; pwr_tStatus sts = INI__SUCCESS; qcom_sGet get; #if defined OS_POSIX int tmo_ms = 1000; #else int tmo_ms = qcom_cTmoEternal; #endif cp->myQ.qix = 550715; cp->myQ.nid = 0; qcom_CreateQ(&sts, &cp->myQ, NULL, "events"); if (EVEN(sts)) { errh_LogFatal(&cp->log, "qcom_CreateQ, %m", sts); exit(sts); } for (;;) { int status; get.data = NULL; qcom_Get(&sts, &cp->myQ, &get, tmo_ms); /* Request for termination ?? */ if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.type.b == 11) { sts = terminate(cp); return sts; } /* Request for restart */ if (sts != QCOM__TMO && sts != QCOM__QEMPTY && get.data != NULL) { int len, i, argc, totlen; char **argv, *s; ini_sContext *ncp; for (argc = 0, s = get.data, totlen = 0; totlen < get.size; argc++) { len = strlen(s); s += len + 1; totlen += len + 1; } argv = (char **) calloc(sizeof(void*), argc); for (i = 0, s = get.data; i < argc; i++) { len = strlen(s); argv[i] = s; s += len + 1; } ncp = createContext(argc, argv); if (ncp != NULL) { ncp->log.put.type.b = 10; ncp->log.put.type.s = 1; ncp->log.send = 1; ncp->log.put.reply = cp->myQ; ncp->log.logQ = get.reply; ncp->eventQ = cp->eventQ; ncp->yourQ = get.reply; restart(ncp); free(ncp); } free(argv); qcom_Free(NULL, get.data); } #if defined OS_POSIX if (lst_Succ(NULL, &cp->proc_lh, &pl) == NULL) break; pid = waitpid(-1, &status, WNOHANG|WUNTRACED); if (pid == 0) continue; if (pid == last_pid) break; for (pp = lst_Succ(NULL, &cp->proc_lh, &pl); pp != NULL; pp = lst_Succ(NULL, pl, &pl)) { if (pp->proc.pid == pid) { errh_LogInfo(&cp->log, "Process %s exited with status %d", pp->proc.name, status); break; } } #endif } return INI__SUCCESS; }
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; 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); } }
int main ( int argc, char **argv ) { pwr_tStatus sts; qcom_sGet get; net_sNotify *notify; net_sMessage *mp; gdb_sNode *np; qcom_sQid qid = qcom_cNQid; errh_Init("pwr_nacp", errh_eAnix_neth_acp); errh_SetStatus( PWR__SRVSTARTUP); init(&qid); errh_SetStatus( PWR__SRUN); for (;;) { mp = receive(&qid, &get); np = node(mp); if (np == NULL) { errh_Error("sender %u.%u, type %u.%u, size %u, reply %u.%u", get.sender.nid, get.sender.aix, get.type.b, get.type.s, get.size, get.reply.nid, get.reply.qix); continue; } switch (get.type.s) { case net_eMsg_nodeUp: nodeUp((net_sNodeUp *) mp); break; case net_eMsg_createObject: gdb_ScopeLock { subc_ActivateList(&gdbroot->no_node->subc_lh, pwr_cNObjid); } gdb_ScopeUnlock; break; case net_eMsg_deleteObject: notify = (net_sNotify *) mp; gdb_ScopeLock { subc_ActivateList(&np->subc_lh, notify->oid); } gdb_ScopeUnlock; break; case net_eMsg_moveObject: case net_eMsg_renameObject: gdb_ScopeLock { subc_ActivateList(&np->subc_lh, pwr_cNObjid); subc_ActivateList(&gdbroot->no_node->subc_lh, pwr_cNObjid); } gdb_ScopeUnlock; break; default: errh_Error("Unexpected subtype %d received from %d.%d %X", get.type.s, get.reply.qix, get.reply.nid, get.pid); } qcom_Free(&sts, mp); } }
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; time_tClock wait_clock; qcom_sQid my_q = qcom_cNQid; qcom_sGet get; int tmo_ms = 0; // mcheck(memCheck); init(); if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) { exit(sts); } if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) { exit(-1); } gdbroot->db->log.b.tmon = 0; for (wait_clock = 0;;) { if (wait_clock != 0) { waitClock(wait_clock, &tmo_ms); } else { tmo_ms = 0; } #if defined OS_POSIX aproc_TimeStamp( ((float)tmo_ms)/1000, 5); get.data = NULL; qcom_Get(&sts, &my_q, &get, tmo_ms); if (sts != QCOM__TMO && sts != QCOM__QEMPTY) { if (get.type.b == qcom_eBtype_event) { event(&get); } qcom_Free(&sts, get.data); } #endif now_clock = time_Clock(NULL, NULL); if (now_clock < last_clock) { errh_Info("The uptime clock has wrapped"); toggleWrapped(); executeExpired(&wrap_lh, 1); } getNewTimers(); executeExpired(&timer_lh, 0); last_clock = now_clock; now_clock = time_Clock(NULL, NULL); getWaitClock(&wait_clock, last_clock); } }
int main () { pwr_tStatus sts; pwr_tObjid oid; qcom_sQid my_q = qcom_cNQid; qcom_sGet get; pwr_tBoolean firstTime = TRUE; pwr_tUInt32 nrOfEvents = 0; pwr_tUInt32 nrOfKeys = 0; errh_Init("pwr_elog", errh_eAnix_elog); errh_SetStatus( PWR__SRVSTARTUP); memset(&lHelCB, 0, sizeof(lHelCB)); /* Declare process */ sts = gdh_Init("pwr_elog"); If_Error_Log_Exit(sts, "gdh_Init"); Init(); /* Create queue for receival of events */ if (!qcom_CreateQ(&sts, &my_q, NULL, "events")) { errh_Fatal("qcom_CreateQ, %m", sts); errh_SetStatus( PWR__APPLTERM); exit(sts); } if (!qcom_Bind(&sts, &my_q, &qcom_cQini)) { errh_Fatal("qcom_Bind(Qini), %m", sts); errh_SetStatus( PWR__APPLTERM); exit(-1); } oid.vid = lHelCB.Nid; oid.oix = pwr_cNVolumeId; sts = mh_OutunitConnect( oid, mh_eOutunitType_Logger, mh_mOutunitFlags_ReadWait, (mh_cbOutunitAck)Insert, (mh_cbOutunitAlarm)Insert, (mh_cbOutunitBlock)Insert, (mh_cbOutunitCancel)Insert, NULL, NULL, (mh_cbOutunitInfo)Insert, (mh_cbOutunitReturn)Insert, NULL ); If_Error_Log_Exit(sts, "mh_OutunitConnect"); sts = mh_OutunitSetTimeout(lHelCB.ScanTime); errh_SetStatus( PWR__SRUN); for (;;) { sts = mh_OutunitReceive(); if (EVEN(sts) && sts != MH__TMO) Log_Error(sts, "mh_OutunitReceive"); Store(&firstTime, &nrOfEvents, &nrOfKeys); get.data = NULL; qcom_Get(&sts, &my_q, &get, 0); if (sts != QCOM__TMO && sts != QCOM__QEMPTY) { if (get.type.b == qcom_eBtype_event) { qcom_sEvent *ep = (qcom_sEvent*) get.data; ini_mEvent new_event; if (get.type.s == qcom_cIini) { new_event.m = ep->mask; if (new_event.b.terminate) { errh_SetStatus( PWR__APPLTERM); exit(0); } } } qcom_Free(&sts, get.data); } aproc_TimeStamp( lHelCB.ScanTime/1000, 5.0); } }