static pwr_tStatus Timer ( pwr_tInt32 TimerId ) { char string[200]; mh_eEventPrio Prio; pwr_tObjid Object; pwr_tStatus sts; pwr_tInt32 TenthsOfSeconds = 10; pwr_tInt32 TimerIdentity = 10; for (;;) { printf("Outunit> "); if (gets(string) == NULL) exit(1); printf("\n"); if (string[0] == 'r') break; switch (string[0]) { case 'b': printf("Block an object\n"); printf(" Object name: "); gets(string); printf("\n"); if (string == NULL) break; sts = gdh_NameToObjid(string, &Object); if (EVEN(sts)) { printf("Cannot find object, sts = %d\n", sts); break; } printf(" Priority: "); gets(string); printf("\n"); if (string == NULL) break; Prio = atoi(string); printf("mh_OutunitBlock(Object, Prio = %d)\n", Prio); sts = mh_OutunitBlock(Object, Prio); if (EVEN(sts)) { printf("Cannot block object, sts = %d\n", sts); break; } break; default: break; } } sts = mh_OutunitSetTimer(&TenthsOfSeconds, &TimerIdentity); return 1; }
int print_data( pwr_sAttrRef *arp, FILE *fp) { int sts; char *s; pwr_tClassId classid; char *object_p; pwr_tAName dataname; pwr_tAName objectname; pwr_tAName attributename; pwr_tObjid objid; int object_backup; int array_element = 0; int index; int nr; sts = gdh_AttrrefToName( arp, dataname, sizeof(dataname), cdh_mNName); if ( EVEN(sts)) return sts; strcpy( objectname, dataname); if ( (s = strchr( objectname, '.'))) { *s = 0; object_backup = 0; strcpy( attributename, dataname); if ( (s = strchr( dataname, '['))) { array_element = 1; nr = sscanf( s+1, "%d", &index); if ( nr != 1) return 0; } } else { object_backup = 1; } sts = gdh_NameToObjid( objectname, &objid); if ( EVEN(sts)) return sts; sts = gdh_ObjidToPointer( objid, (void **)&object_p); if ( EVEN(sts)) return sts; sts = gdh_GetObjectClass( objid, &classid); if ( EVEN(sts)) return sts; if ( object_backup) { print_object( objid, classid, object_p, 0, objectname, fp); } else { print_attribute( objid, classid, object_p, attributename, array_element, index, fp); } return 1; }
static void pwrsrv_ObjectName( rpvd_sMsgObjectName *msg) { rpvd_sMsgOid m; pwr_tStatus sts; char name[256]; /* Simulate an oid request */ m.Type = rpvd_eMsg_Oid; m.Id = msg->Id; if ( msg->POid.oix) { sts = gdh_ObjidToName( msg->POid, name, sizeof(name), cdh_mName_volumeStrict); if ( EVEN(sts)) { rpvd_sMsgObject rmsg; rmsg.Type = rpvd_eMsg_Object; rmsg.Id = msg->Id; rmsg.Status = sts; udp_Send( (char *)&rmsg, sizeof(rmsg)); return; } strcat( name, "-"); strcat( name, msg->Name); } else strncpy( name, msg->Name, sizeof(name)); sts = gdh_NameToObjid( name, &m.Oid); if ( EVEN(sts)) { rpvd_sMsgObject rmsg; rmsg.Type = rpvd_eMsg_Object; rmsg.Id = msg->Id; rmsg.Status = sts; udp_Send( (char *)&rmsg, sizeof(rmsg)); return; } pwrsrv_Oid( &m); }
static void load_backup () { pwr_tObjid oid; pwr_sClass_AvArea *avp; pwr_sClass_DvArea *dvp; pwr_sClass_IvArea *ivp; pwr_sClass_InitArea *iavp; pwr_sClass_InitArea *idvp; pwr_sClass_InitArea *iivp; pwr_tStatus sts; int i; pwr_sClass_IOHandler *iop; pwr_sAttrRef aref; sts = io_get_iohandler_object(&iop, NULL); if (EVEN(sts)) { errh_Error("io_get_iohandler_object, %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-av", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-av, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &avp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &avp), %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-av_init", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-av_init, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &iavp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &iavp), %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-dv", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-dv, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &dvp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &dvp), %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-dv_init", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-dv_init, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &idvp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &idvp), %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-iv", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-iv, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &ivp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &ivp), %m", sts); return; } sts = gdh_NameToObjid("pwrNode-active-io-iv_init", &oid); if (EVEN(sts)) { errh_Error("gdh_NameToObjid(pwrNode-active-io-iv_init, &oid), %m", sts); return; } sts = gdh_ObjidToPointer(oid, (void *) &iivp); if (EVEN(sts)) { errh_Error("gdh_ObjidToPointer(oid, (void *) &iivp), %m", sts); return; } for (i = 0; i < iop->AvCount; i++) { pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]); avp->Value[i]= *ifp; } for (i = 0; i < iop->DvCount; i++) { pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]); dvp->Value[i] = *ibp; } for (i = 0; i < iop->IvCount; i++) { pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]); ivp->Value[i] = *iip; } typedef struct { union { pwr_tFloat32 *f; pwr_tInt32 *i; pwr_tBoolean *b; } actval_p; pwr_tUInt32 validx; union { pwr_sClass_Av *av; pwr_sClass_Iv *iv; pwr_sClass_Dv *dv; pwr_sClass_Ai *ai; pwr_sClass_Ao *ao; pwr_sClass_Ii *ii; pwr_sClass_Io *io; pwr_sClass_Di *di; pwr_sClass_Do *dox; pwr_sClass_Co *co; } op; } ini_sRestoreSig; // Store ActualValue pointers ini_sRestoreSig *rsav = calloc( sizeof(ini_sRestoreSig), iop->AvCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Av, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Av, &aref, &aref)) { if ( i >= iop->AvCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsav[i].op.av); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsav[i].actval_p.f = rsav[i].op.av->ActualValue; rsav[i].validx = rsav[i].op.av->ValueIndex; i++; } ini_sRestoreSig *rsdv = calloc( sizeof(ini_sRestoreSig), iop->DvCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Dv, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Dv, &aref, &aref)) { if ( i >= iop->DvCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdv[i].op.dv); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsdv[i].actval_p.b = rsdv[i].op.dv->ActualValue; rsdv[i].validx = rsdv[i].op.dv->ValueIndex; i++; } ini_sRestoreSig *rsiv = calloc( sizeof(ini_sRestoreSig), iop->IvCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Iv, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Iv, &aref, &aref)) { if ( i >= iop->IvCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsiv[i].op.iv); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsiv[i].actval_p.i = rsiv[i].op.iv->ActualValue; rsiv[i].validx = rsiv[i].op.iv->ValueIndex; i++; } ini_sRestoreSig *rsai = calloc( sizeof(ini_sRestoreSig), iop->AiCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ai, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Ai, &aref, &aref)) { if ( i >= iop->AiCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsai[i].op.ai); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsai[i].actval_p.f = rsai[i].op.ai->ActualValue; rsai[i].validx = rsai[i].op.ai->ValueIndex; i++; } ini_sRestoreSig *rsao = calloc( sizeof(ini_sRestoreSig), iop->AoCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ao, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Ao, &aref, &aref)) { if ( i >= iop->AoCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsao[i].op.ao); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsao[i].actval_p.f = rsao[i].op.ao->ActualValue; rsao[i].validx = rsao[i].op.ao->ValueIndex; i++; } ini_sRestoreSig *rsii = calloc( sizeof(ini_sRestoreSig), iop->IiCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Ii, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Ii, &aref, &aref)) { if ( i >= iop->IiCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsii[i].op.ii); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsii[i].actval_p.i = rsii[i].op.ii->ActualValue; rsii[i].validx = rsii[i].op.ii->ValueIndex; i++; } ini_sRestoreSig *rsio = calloc( sizeof(ini_sRestoreSig), iop->IoCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Io, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Io, &aref, &aref)) { if ( i >= iop->IoCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsio[i].op.io); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsio[i].actval_p.i = rsio[i].op.io->ActualValue; rsio[i].validx = rsio[i].op.io->ValueIndex; i++; } ini_sRestoreSig *rsdi = calloc( sizeof(ini_sRestoreSig), iop->DiCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Di, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Di, &aref, &aref)) { if ( i >= iop->DiCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdi[i].op.di); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsdi[i].actval_p.b = rsdi[i].op.di->ActualValue; rsdi[i].validx = rsdi[i].op.di->ValueIndex; i++; } ini_sRestoreSig *rsdo = calloc( sizeof(ini_sRestoreSig), iop->DoCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Do, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Do, &aref, &aref)) { if ( i >= iop->DoCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsdo[i].op.dox); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsdo[i].actval_p.b = rsdo[i].op.dox->ActualValue; rsdo[i].validx = rsdo[i].op.dox->ValueIndex; i++; } ini_sRestoreSig *rsco = calloc( sizeof(ini_sRestoreSig), iop->CoCount); pwr_tInt32 **rscoa = calloc( sizeof(pwr_tInt32*), iop->CoCount); i = 0; for ( sts = gdh_GetClassListAttrRef(pwr_cClass_Co, &aref); ODD(sts); sts = gdh_GetNextAttrRef(pwr_cClass_Co, &aref, &aref)) { if ( i >= iop->CoCount) break; sts = gdh_AttrRefToPointer( &aref, (pwr_tAddress *)&rsco[i].op.co); if ( EVEN(sts)) { errh_Error("gdh_AttrRefToPointer Iv, %m", sts); return; } rsco[i].actval_p.i = rsco[i].op.co->RawValue; rsco[i].validx = rsco[i].op.co->ValueIndex; rscoa[i] = rsco[i].op.co->AbsValue; i++; } sts = bck_LoadBackup(); if (EVEN(sts)) { errh_Error("bck_LoadBackup, %m", sts); return; } // Set stored ActualValue pointers for ( i = 0; i < iop->AvCount; i++) { rsav[i].op.av->ActualValue = rsav[i].actval_p.f; rsav[i].op.av->ValueIndex = rsav[i].validx; } free( rsav); for ( i = 0; i < iop->DvCount; i++) { rsdv[i].op.dv->ActualValue = rsdv[i].actval_p.b; rsdv[i].op.dv->ValueIndex = rsdv[i].validx; } free( rsdv); for ( i = 0; i < iop->IvCount; i++) { rsiv[i].op.iv->ActualValue = rsiv[i].actval_p.i; rsiv[i].op.iv->ValueIndex = rsiv[i].validx; } free( rsiv); for ( i = 0; i < iop->AiCount; i++) { rsai[i].op.ai->ActualValue = rsai[i].actval_p.f; rsai[i].op.ai->ValueIndex = rsai[i].validx; } free( rsai); for ( i = 0; i < iop->AoCount; i++) { rsao[i].op.ao->ActualValue = rsao[i].actval_p.f; rsao[i].op.ao->ValueIndex = rsao[i].validx; } free( rsao); for ( i = 0; i < iop->IiCount; i++) { rsii[i].op.ii->ActualValue = rsii[i].actval_p.i; rsii[i].op.ii->ValueIndex = rsii[i].validx; } free( rsii); for ( i = 0; i < iop->IoCount; i++) { rsio[i].op.io->ActualValue = rsio[i].actval_p.i; rsio[i].op.io->ValueIndex = rsio[i].validx; } free( rsio); for ( i = 0; i < iop->DiCount; i++) { rsdi[i].op.di->ActualValue = rsdi[i].actval_p.b; rsdi[i].op.di->ValueIndex = rsdi[i].validx; } free( rsdi); for ( i = 0; i < iop->DoCount; i++) { rsdo[i].op.dox->ActualValue = rsdo[i].actval_p.b; rsdo[i].op.dox->ValueIndex = rsdo[i].validx; } free( rsdo); for ( i = 0; i < iop->CoCount; i++) { rsco[i].op.co->RawValue = rsco[i].actval_p.i; rsco[i].op.co->AbsValue = rscoa[i]; rsco[i].op.co->ValueIndex = rsco[i].validx; } free( rsco); free( rscoa); for (i = 0; i < iop->AvCount; i++) { pwr_tFloat32 *ifp = gdh_TranslateRtdbPointer(iavp->Value[i]); *ifp = avp->Value[i]; } for (i = 0; i < iop->DvCount; i++) { pwr_tBoolean *ibp = gdh_TranslateRtdbPointer(idvp->Value[i]); *ibp = dvp->Value[i]; } for (i = 0; i < iop->IvCount; i++) { pwr_tInt32 *iip = gdh_TranslateRtdbPointer(iivp->Value[i]); *iip = ivp->Value[i]; } }
pwr_tStatus sev_db::tree_update() { int new_item = 0; int num; pwr_tAName hname; pwr_tStatus sts; pwr_tOid oid; pwr_tCid cid = 0; char* s; pwr_sClass_SevItem ritem; char oname_array[20][pwr_cSizObjName + 1]; pwr_tObjName itemname; char root[] = "pwrNode-sev"; // Check root object sts = gdh_NameToObjid(root, &oid); if (EVEN(sts)) { sts = gdh_CreateObject( root, pwr_eClass_NodeHier, 0, &oid, pwr_cNObjid, 0, pwr_cNObjid); if (EVEN(sts)) return sts; } for (unsigned int i = 0; i < m_items.size(); i++) { if (m_items[i].deleted) continue; printf("Tree update item %s\n", m_items[i].oname); switch (m_items[i].attr[0].type) { case pwr_eType_Float32: case pwr_eType_Float64: case pwr_eType_Int8: case pwr_eType_Int16: case pwr_eType_Int32: case pwr_eType_Int64: case pwr_eType_UInt8: case pwr_eType_UInt16: case pwr_eType_UInt32: case pwr_eType_UInt64: case pwr_eType_Boolean: break; default: continue; } new_item = 0; if ((s = strchr(m_items[i].oname, ':'))) s++; else s = m_items[i].oname; num = dcli_parse(s, "-", "", (char*)oname_array, sizeof(oname_array) / sizeof(oname_array[0]), sizeof(oname_array[0]), 0); strcpy(hname, root); for (int j = 0; j < num; j++) { strcat(hname, "-"); strcat(hname, oname_array[j]); if (!new_item) sts = gdh_NameToObjid(hname, &oid); if (new_item || EVEN(sts)) { // Create object sts = gdh_CreateObject( hname, pwr_eClass_NodeHier, 0, &oid, pwr_cNObjid, 0, pwr_cNObjid); if (EVEN(sts)) return sts; new_item = 1; } } sprintf(itemname, "%sItem", m_items[i].attrnum > 1 ? "O" : ""); strcat(hname, "-"); strcat(hname, itemname); if (!new_item) sts = gdh_NameToObjid(hname, &oid); if (new_item || EVEN(sts)) { switch (m_items[i].attr[0].type) { case pwr_eType_Float32: case pwr_eType_Float64: cid = pwr_cClass_SevItemFloat; break; case pwr_eType_Int8: case pwr_eType_Int16: case pwr_eType_Int32: case pwr_eType_Int64: case pwr_eType_UInt8: case pwr_eType_UInt16: case pwr_eType_UInt32: case pwr_eType_UInt64: cid = pwr_cClass_SevItemInt; break; case pwr_eType_Boolean: cid = pwr_cClass_SevItemBoolean; break; default:; } sts = gdh_CreateObject(hname, cid, 0, &oid, pwr_cNObjid, 0, pwr_cNObjid); if (EVEN(sts)) return sts; memset(&ritem, 0, sizeof(ritem)); strncpy(ritem.TableName, m_items[i].tablename, sizeof(ritem.TableName)); strncpy(ritem.ObjectName, m_items[i].oname, sizeof(ritem.ObjectName)); strncpy(ritem.Attr, m_items[i].attr[0].aname, sizeof(ritem.Attr)); ritem.AttrType = m_items[i].attr[0].type; ritem.NoOfAttr = m_items[i].attrnum; ritem.Oid = m_items[i].oid; ritem.Id = m_items[i].id; ritem.Options = m_items[i].options; ritem.Deadband = m_items[i].deadband; ritem.ScanTime = m_items[i].scantime; ritem.StorageTime = m_items[i].storagetime; strncpy( ritem.Description, m_items[i].description, sizeof(ritem.Description)); sts = gdh_SetObjectInfo(hname, &ritem, sizeof(ritem)); if (EVEN(sts)) return sts; } if (!m_items[i].ip) { // Get pointer to object pwr_tAttrRef aref = cdh_ObjidToAref(oid); sts = gdh_DLRefObjectInfoAttrref( &aref, (void**)&m_items[i].ip, &m_items[i].refid); if (EVEN(sts)) return sts; } } return SEV__SUCCESS; }
int main(int argc, char *argv[]) { pwr_tStatus sts; pwr_tObjid Object; pwr_tClassId Class; mh_eOutunitType Type; mh_mOutunitFlags Flags; pwr_tInt32 TenthsOfSeconds = 10; pwr_tInt32 TimerId = 10; sts = gdh_Init("pwr_epri"); if (EVEN(sts)) { exit (sts); } if (argc > 1) { if (strcmp(argv[1], "-t") == 0) { /* test mode */ Object = pwr_cNObjid; Type = mh_eOutunitType_Logger; Flags = mh_mOutunitFlags_ReadWait; } else { Type = mh_eOutunitType_Printer; Flags = mh_mOutunitFlags_ReadWait; strcpy(EventPrinter ,argv[1]); sts = gdh_NameToObjid(argv[1], &Object); if (EVEN(sts)) { printf("%%PRI-E-NOVALID_EVENTPRINT. No valid EventPrinter object\n"); exit(sts); } sts = gdh_GetObjectClass(Object , &Class); if (Class != pwr_cClass_EventPrinter) { printf("%%PRI-E-NOVALID_EVENTPRINT. EventPrinter object, wrong class\n"); exit(sts); } } } else { printf("%%PRI-E-NO_EVENT_PRINTER. No EventPrinter object\n"); exit(2); } sts = mh_OutunitConnect( Object, Type, Flags, (mh_cbOutunitAck)PrintEvent, (mh_cbOutunitAlarm)PrintEvent, (mh_cbOutunitBlock)PrintEvent, (mh_cbOutunitCancel)PrintEvent, NULL, NULL, (mh_cbOutunitInfo)PrintEvent, (mh_cbOutunitReturn)PrintEvent, NULL ); if (EVEN(sts)) { printf("%%PRI-E-CONNECT. Could not connect Outunit to message handler.\n"); exit(sts); } if (Type == mh_eOutunitType_Printer) { sts = gdh_GetObjectInfo(EventPrinter, &EventPrinterObj, sizeof(EventPrinterObj) ); if (EVEN(sts)) { printf("%%PRI-E-EVENTPRINT Cannot get EventPrinter object\n"); exit(sts); } if ((Printer = fopen(EventPrinterObj.DeviceName, "w")) == NULL) { printf("%%PRI-E-NOPRINT Cannot open printer: %s\n", Printer); exit(1); } if (EventPrinterObj.RowSize == 0) EventPrinterObj.RowSize = 80; } else { #if 0 sts = mh_OutunitSetTimer(&TenthsOfSeconds, &TimerId); #endif Printer = stdout; EventPrinterObj.RowSize = 80; } for(;;) { sts = mh_OutunitReceive(); } }
int rtt_show_signals( menu_ctx parent_ctx, char* filename, char* windowname, int debug) { pwr_tFileName default_filename; FILE* file; char line[500]; int window_spaces; pwr_tOName window; pwr_tOName object; pwr_tOName objname; int spaces = 30; int sts; char* s; int wildcard; char title[250]; char classname[32]; int j; int index = 0; pwr_tObjid objid; pwr_tObjid childobjid; rtt_t_menu* menulist = 0; char filestr[80]; int lines; int window_found; pwr_tVolumeId volid; window_found = 0; rtt_toupper(windowname, windowname); /* Check if wildcard */ s = strchr(windowname, '*'); if (s == 0) wildcard = 0; else wildcard = 1; /* Open file */ if (filename == NULL) { /* Open file, first get the volume id */ if (!wildcard) { sts = gdh_NameToObjid(windowname, &objid); if (EVEN(sts)) { rtt_message('E', "Window not found"); return RTT__NOPICTURE; } volid = objid.vid; } else { sts = gdh_GetNodeObject(0, &objid); if (EVEN(sts)) return sts; volid = objid.vid; } sprintf(default_filename, "%srtt_plc_%s.dat", rtt_pwr_dir("pwrp_load"), rtt_VolumeIdToStr(volid)); rtt_get_defaultfilename(default_filename, filestr, NULL); file = fopen(filestr, "r"); } else { rtt_get_defaultfilename(filename, filestr, ".lis"); file = fopen(filestr, "r"); } if (file == 0) { rtt_message('E', "Unable to open file"); return RTT__NOPICTURE; } /* First line is a header, skip it */ sts = rtt_get_signal_line( file, line, sizeof(line), &window_spaces, object, &lines); if (EVEN(sts)) return RTT__NOFILE; /* Get the hierarchy */ while (spaces >= 30) { /* This is still the header */ sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) return RTT__NOFILE; } window_spaces = spaces; while (1) { while (spaces != window_spaces) { sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } strcpy(window, object); rtt_toupper(window, window); sts = rtt_wildcard(windowname, window); if (!sts) { window_found = 1; /* Hit, print the window */ /* Get objid for the object */ sts = gdh_NameToObjid(window, &objid); if (EVEN(sts)) { sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; continue; } /* Get the object name */ sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName); if (EVEN(sts)) return sts; /* Get class name */ sts = rtt_objidtoclassname(objid, classname); if (EVEN(sts)) return sts; /* Add class name to objname in title */ strcpy(title, objname); for (j = strlen(title); j < 45; j++) strcat(title, " "); strcat(title, " "); strcat(title, classname); /* Mark if the object has children */ sts = gdh_GetChild(objid, &childobjid); if (ODD(sts)) strcat(title, " *"); if (!debug) { sts = rtt_menu_list_add(&menulist, index, 0, title, &rtt_hierarchy_child, &rtt_object_parameters, &rtt_crossref_signal, objid, 0, 0, 0, 0); if (EVEN(sts)) return sts; index++; } /* Find the signal list */ sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; while (spaces > window_spaces) { if (streq(object, "Signals")) { /* This is the signals */ sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; lines = 1; while ((spaces > window_spaces) && (lines == 1)) { /* Insert the object in menulist */ /* Get objid for the object */ sts = gdh_NameToObjid(object, &objid); if (EVEN(sts)) { /* End of this list, read next line and continue */ sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; continue; } /* Get the object name */ sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName); if (EVEN(sts)) return sts; /* Get class name */ sts = rtt_objidtoclassname(objid, classname); if (EVEN(sts)) return sts; /* Add class name to objname in title */ strcpy(title, " "); strcat(title, objname); for (j = strlen(title); j < 45; j++) strcat(title, " "); strcat(title, " "); strcat(title, classname); if (!debug) { sts = rtt_menu_list_add(&menulist, index, 0, title, &rtt_hierarchy_child, &rtt_object_parameters, &rtt_crossref_signal, objid, 0, 0, 0, 0); if (EVEN(sts)) return sts; index++; } else { sts = rtt_debug_object_add( objid, (rtt_t_menu_upd**)&menulist, &index, &one, 0, 0); if (EVEN(sts)) return sts; } sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; /* Check if end of signals !! */ } } else { sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } } if (!wildcard) goto finish; } else { if (window_found) goto finish; sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } } finish: fclose(file); if (menulist != 0) { strcpy(title, "LIST OF SIGNALS"); /* sts = rtt_menu_bubblesort( menulist);*/ if (!debug) sts = rtt_menu_new( parent_ctx, pwr_cNObjid, &menulist, title, 0, RTT_MENUTYPE_DYN); else sts = rtt_menu_upd_new(parent_ctx, pwr_cNObjid, (rtt_t_menu_upd**)&menulist, title, 0, RTT_MENUTYPE_DYN); if (sts == RTT__FASTBACK) return sts; else if (sts == RTT__BACKTOCOLLECT) return sts; else if (EVEN(sts)) return sts; } else { rtt_message('E', "No windows found"); return RTT__NOPICTURE; } return RTT__SUCCESS; }
int rtt_crr_object(char* filename, char* objectname) { pwr_tFileName default_filename; FILE* file; char line[200]; int object_spaces; char object[80]; pwr_tOName objname; char show_objname[80]; int spaces; int first; int sts; char* s; int wildcard; int signalcount = 0; pwr_tFileName filestr; int lines; char* buff; pwr_tVolumeId volid; pwr_tObjid objid; int buffcnt = 0; rtt_toupper(objectname, objectname); /* Check if wildcard */ s = strchr(objectname, '*'); if (s == 0) wildcard = 0; else wildcard = 1; /* Open file */ if (filename == NULL) { /* Open file, first get the volume id */ if (!wildcard) { sts = gdh_NameToObjid(objectname, &objid); if (EVEN(sts)) { rtt_message('E', "Object not found"); return RTT__NOPICTURE; } volid = objid.vid; } else { sts = gdh_GetNodeObject(0, &objid); if (EVEN(sts)) return sts; volid = objid.vid; } sprintf(default_filename, "%srtt_crro_%s.dat", rtt_pwr_dir("pwrp_load"), rtt_VolumeIdToStr(volid)); rtt_get_defaultfilename(default_filename, filestr, NULL); file = fopen(filestr, "r"); } else { rtt_get_defaultfilename(filename, filestr, ".lis"); file = fopen(filestr, "r"); } if (file == 0) { rtt_message('E', "Unable to open file"); return RTT__NOPICTURE; } buff = calloc(1, CRR_BUFF_SIZE); if (!buff) { rtt_message('E', "Unable to allocate memory"); fclose(file); return RTT__NOPICTURE; } /* Get the object */ sts = rtt_get_signal_line(file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; object_spaces = spaces; first = 1; while (1) { if ((s = strchr(object, ':'))) strcpy(objname, s + 1); else strcpy(objname, object); strcpy(show_objname, objname); rtt_toupper(objname, objname); sts = rtt_wildcard(objectname, objname); if (sts) { pwr_tAName subname; strcpy(subname, objectname); strcat(subname, ".*"); sts = rtt_wildcard(subname, objname); } if (!sts) { /* Hit, print this object */ if (signalcount == 0) { rtt_clear_screen(); buffcnt = sprintf(buff, "Crossreferens list %s\n\n", show_objname); } signalcount++; sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; while (spaces > object_spaces) { str_trim(line, line); if (buffcnt > CRR_BUFF_SIZE - 100) { buffcnt += sprintf( buff + buffcnt, "RTT-E-QUOTAEXC, Crossref quota exceeded"); goto finish; } buffcnt += sprintf(buff + buffcnt, " %s\n", line); sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } } else { if (!wildcard && signalcount) goto finish; sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } while (spaces != object_spaces) { sts = rtt_get_signal_line( file, line, sizeof(line), &spaces, object, &lines); if (EVEN(sts)) goto finish; } } finish: fclose(file); if (signalcount > 0) { sts = rtt_view(0, 0, buff, "Crossreference list", RTT_VIEWTYPE_BUF); return sts; } else { rtt_message('E', "Object not found"); return RTT__NOPICTURE; } }
int XNav::GetObjectMenu( xmenu_sMenuCall *ip, pwr_tCid classid, xmenu_sMenuItem **Item, pwr_tUInt32 Level, int *nItems, int AddSeparator, pwr_sAttrRef *CurrentObject) { int sts; pwr_tObjid child; pwr_tObjid menu_objid; char menu[80]; pwr_tOName classname; pwr_sAttrRef currentar = pwr_cNAttrRef; pwr_tCid supercid; if ( cdh_ObjidIsNotNull( CurrentObject->Objid)) currentar = *CurrentObject; if ( ip->ItemType == xmenu_eItemType_Object) { // Popup-menu for an object if ( !cdh_tidIsCid( classid)) return XNAV__SUCCESS; // Get the RtXtt common menu-objects strcpy( menu, "pwrs:Class-$Object-RtXtt"); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, Level, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } // Get the RtXtt menu-objects for superclasses // TODO shadow overlayed methods... sts = gdh_GetSuperClass( classid, &supercid, CurrentObject->Objid); while ( ODD(sts)) { sts = gdh_ObjidToName( cdh_ClassIdToObjid( supercid), classname, sizeof(classname), cdh_mName_volumeStrict); if ( EVEN(sts)) return sts; sprintf( menu, "%s-RtXtt", classname); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } sts = gdh_GetSuperClass( supercid, &supercid, CurrentObject->Objid); } // Get the RtXtt menu-objects for this class, or for superclasses sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, sizeof(classname), cdh_mName_volumeStrict); if ( EVEN(sts)) return sts; sprintf( menu, "%s-RtXtt", classname); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } } else if ( ip->ItemType == xmenu_eItemType_AttrObject) { // Find attribute object methods... if ( !cdh_tidIsCid( classid)) return XNAV__SUCCESS; // Get the RtXtt common menu-objects strcpy( menu, "pwrs:Class-$Object-RtXttAttrObject"); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } // Get the RtXtt menu-objects for this class sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, sizeof(classname), cdh_mName_volumeStrict); if ( EVEN(sts)) return sts; sprintf( menu, "%s-RtXtt", classname); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } } else if ( ip->ItemType == xmenu_eItemType_Attribute) { // Find attribute methods... // Get the RtXttAttribute common menu-objects strcpy( menu, "pwrs:Class-$Object-RtXttAttribute"); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } } else if ( ip->ItemType == xmenu_eItemType_Crossref) { // Find attribute methods... // Get the RtXttCrossref common menu-objects strcpy( menu, "pwrs:Class-$Object-RtXttCrossref"); sts = gdh_NameToObjid( menu, &menu_objid); if ( ODD(sts)) { sts = gdh_GetChild( menu_objid, &child); while( ODD(sts)) { sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, ¤tar); if ( EVEN(sts)) return sts; sts = gdh_GetNextSibling( child, &child); } } } return XNAV__SUCCESS; }