static pwr_tStatus configure_object_reset( ldh_sMenuCall *ip, pwr_sAttrRef *aref, pwr_sMenuButton *mb) { pwr_tStatus sts; pwr_tCid cid; ldh_sParDef *bodydef; int rows; int i, j; pwr_sAttrRef aaref, daref; pwr_tDisableAttr disable = 0; char vect[10][80]; int vect_cnt; int skip; char *s; // Attribute objects in argument 2 are not controlled by the configure method if ( mb) { vect_cnt = dcli_parse( mb->MethodArguments[2], ",", "", (char *)vect, sizeof( vect) / sizeof( vect[0]), sizeof( vect[0]), 0); for ( j = 0; j < vect_cnt; j++) dcli_trim( vect[j], vect[j]); } else vect_cnt = 0; sts = ldh_GetAttrRefTid( ip->PointedSession, aref, &cid); if ( EVEN(sts)) return sts; sts = ldh_GetObjectBodyDef( ip->PointedSession, cid, "RtBody", 1, &bodydef, &rows); if (EVEN(sts)) return sts; for ( i = 0; i < rows; i++) { // Check if attribute is controlled by this method skip = 0; if ( mb) { // Remove leading Super. s = bodydef[i].ParName; while ( strncmp( s, "Super.", 6) == 0) s += 6; for ( j = 0; j < vect_cnt; j++) { if ( cdh_NoCaseStrcmp( vect[j], s) == 0) { // This object should not be reset skip = 1; break; } } if ( skip) continue; } if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_DISABLEATTR) { // Enable all attributes sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref); if ( EVEN(sts)) return sts; daref = cdh_ArefToDisableAref( &aaref); sts = ldh_WriteAttribute( ip->PointedSession, &daref, (void *)&disable, sizeof(disable)); if ( EVEN(sts)) return sts; } if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_CLASS) { // Reset object attribute sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref); if ( EVEN(sts)) return sts; sts = configure_object_reset( ip, &aaref, 0); if ( EVEN(sts)) return sts; } } free( (char *)bodydef); return LDH__SUCCESS; }
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) { pwr_tStatus sts; unsigned int disable_mask; pwr_sMenuButton mb; pwr_tEnum graph_configuration; pwr_sAttrRef aaref; char vect[10][80]; char item[3][80]; int i; int nr; int vect_cnt; sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject, "SysBody", &mb, sizeof(pwr_sMenuButton)); // Reset previoius disable configuration configure_object_reset( ip, &ip->Pointed, &mb); // Set disable attributes from argument 0 if ( mb.MethodArguments[0][0] != '(') { // Old syntax, eg '7, CircuitBreaker 4, Contactor 5' vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, sizeof( vect) / sizeof( vect[0]), sizeof( vect[0]), 0); for ( i = 0; i < vect_cnt; i++) { nr = dcli_parse( vect[i], " ", "", (char *)item, sizeof( item) / sizeof( item[0]), sizeof( item[0]), 0); if ( nr == 1) { if ( sscanf( item[0], "%d", &disable_mask) != 1) graph_configuration = 0; sts = configure_object( ip, &ip->Pointed, disable_mask); if ( EVEN(sts)) return sts; } else if ( nr == 2) { pwr_tAName aname; if ( sscanf( item[1], "%d", &disable_mask) != 1) disable_mask = 0; strncpy( aname, item[0], sizeof(aname)); sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, &aaref); if ( ODD(sts)) { sts = configure_object( ip, &aaref, disable_mask); if ( EVEN(sts)) return sts; } } } } else { // New syntax, eg '(7 (CircuitBreaker 4, Contactor 5))' char str1[256]; char *s; strncpy( str1, &mb.MethodArguments[0][1], sizeof(str1)); s = strrchr( str1, ')'); if ( !s) return LDH__COMPSYNTAX; *s = 0; dcli_trim( str1, str1); nr = sscanf( str1, "%d", &disable_mask); if ( nr != 1) return LDH__COMPSYNTAX; sts = configure_object( ip, &ip->Pointed, disable_mask); if ( EVEN(sts)) return sts; sts = configure_attrmask( ip, &ip->Pointed, str1); if ( EVEN(sts)) return sts; } // Set GraphConfiguration from argument 1 vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, sizeof( vect) / sizeof( vect[0]), sizeof( vect[0]), 0); for ( i = 0; i < vect_cnt; i++) { nr = dcli_parse( vect[i], " ", "", (char *)item, sizeof( item) / sizeof( item[0]), sizeof( item[0]), 0); if ( nr == 1) { if ( sscanf( item[0], "%d", &graph_configuration) != 1) graph_configuration = 0; sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", &aaref); if ( ODD(sts)) { sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, sizeof(graph_configuration)); if ( EVEN(sts)) return sts; } } else if ( nr == 2) { pwr_tAName aname; if ( sscanf( item[1], "%d", &graph_configuration) != 1) graph_configuration = 0; strncpy( aname, item[0], sizeof(aname)); strncat( aname, ".GraphConfiguration", sizeof(aname)); sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, &aaref); if ( ODD(sts)) { sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, sizeof(graph_configuration)); if ( EVEN(sts)) return sts; } } } return 1; }
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) { pwr_tStatus sts; unsigned int disable_mask; pwr_sMenuButton mb; pwr_tEnum graph_configuration; pwr_sAttrRef aaref; char vect[10][80]; char item[3][80]; int i; int nr; int vect_cnt; sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject, "SysBody", &mb, sizeof(pwr_sMenuButton)); // Reset previoius disable configuration configure_object_reset( ip, &ip->Pointed, &mb); // Set disable attributes from argument 0 vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, sizeof( vect) / sizeof( vect[0]), sizeof( vect[0]), 0); for ( i = 0; i < vect_cnt; i++) { nr = dcli_parse( vect[i], " ", "", (char *)item, sizeof( item) / sizeof( item[0]), sizeof( item[0]), 0); if ( nr == 1) { if ( sscanf( item[0], "%d", &disable_mask) != 1) graph_configuration = 0; sts = configure_object( ip, &ip->Pointed, disable_mask); if ( EVEN(sts)) return sts; } else if ( nr == 2) { pwr_tAName aname; if ( sscanf( item[1], "%d", &disable_mask) != 1) disable_mask = 0; strcpy( aname, item[0]); sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, &aaref); if ( ODD(sts)) { sts = configure_object( ip, &aaref, disable_mask); if ( EVEN(sts)) return sts; } } } // Set GraphConfiguration from argument 1 vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, sizeof( vect) / sizeof( vect[0]), sizeof( vect[0]), 0); for ( i = 0; i < vect_cnt; i++) { nr = dcli_parse( vect[i], " ", "", (char *)item, sizeof( item) / sizeof( item[0]), sizeof( item[0]), 0); if ( nr == 1) { if ( sscanf( item[0], "%d", &graph_configuration) != 1) graph_configuration = 0; sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", &aaref); if ( ODD(sts)) { sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, sizeof(graph_configuration)); if ( EVEN(sts)) return sts; } } else if ( nr == 2) { pwr_tAName aname; if ( sscanf( item[1], "%d", &graph_configuration) != 1) graph_configuration = 0; strcpy( aname, item[0]); strcat( aname, ".GraphConfiguration"); sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, &aaref); if ( ODD(sts)) { sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, sizeof(graph_configuration)); if ( EVEN(sts)) return sts; } } } return 1; }