snet_record_t *SNetRecCopy( snet_record_t *rec) { snet_record_t *new_rec; switch (REC_DESCR( rec)) { case REC_data: new_rec = SNetMemAlloc( sizeof( snet_record_t)); REC_DESCR( new_rec) = REC_data; RECPTR( new_rec) = SNetMemAlloc( sizeof( snet_record_types_t)); RECORD( new_rec, data_rec) = SNetMemAlloc( sizeof( data_rec_t)); DATA_REC( new_rec, fields) = SNetRefMapCopy(DATA_REC(rec, fields)); DATA_REC( new_rec, tags) = SNetIntMapCopy( DATA_REC( rec, tags)); DATA_REC( new_rec, btags) = SNetIntMapCopy( DATA_REC( rec, btags)); SNetRecSetInterfaceId( new_rec, SNetRecGetInterfaceId( rec)); SNetRecSetDataMode( new_rec, SNetRecGetDataMode( rec)); DATA_REC( new_rec, parent_rids) = NULL; /* (DATA_REC( rec, parent_rids)==NULL) ? NULL : SNetRecIdListCopy(DATA_REC( rec, parent_rids)); */ break; case REC_sort_end: new_rec = SNetRecCreate( REC_DESCR( rec), SORT_E_REC( rec, level), SORT_E_REC( rec, num)); break; case REC_terminate: new_rec = SNetRecCreate( REC_terminate); TERM_REC(new_rec, local) = TERM_REC(rec, local); break; default: new_rec = NULL; SNetUtilDebugFatal("Can't copy record of type %d", REC_DESCR( rec)); break; } return new_rec; }
/* This function prints records to stdout */ static void printRec(snet_record_t *rec, handle_t *hnd) { snet_ref_t *field; int name, val; char *label = NULL; char *interface = NULL; snet_record_mode_t mode; /* Change this to redirect the output! */ if (rec != NULL) { fprintf(hnd->file, "<?xml version=\"1.0\" ?>\n"); switch( SNetRecGetDescriptor( rec)) { case REC_data: mode = SNetRecGetDataMode(rec); if (mode == MODE_textual) { fprintf(hnd->file, "<record xmlns=\"snet-home.org\" type=\"data\" mode=\"textual\" >\n"); } else { fprintf(hnd->file, "<record xmlns=\"snet-home.org\" type=\"data\" mode=\"binary\" >\n"); } /* Fields */ RECORD_FOR_EACH_FIELD(rec, name, field) { int id = SNetRecGetInterfaceId(rec); if((label = SNetInIdToLabel(hnd->labels, name)) != NULL){ if((interface = SNetInIdToInterface(hnd->interfaces, id)) != NULL) { fprintf(hnd->file, "<field label=\"%s\" interface=\"%s\">", label, interface); if(mode == MODE_textual) { SNetInterfaceGet(id)->serialisefun(hnd->file, SNetRefGetData(field)); } else { SNetInterfaceGet(id)->encodefun(hnd->file, SNetRefGetData(field)); } fprintf(hnd->file, "</field>\n"); SNetMemFree(interface); } SNetMemFree(label); } else{ SNetUtilDebugFatal("Unknown field %d at output!", name); } } /* Tags */ RECORD_FOR_EACH_TAG(rec, name, val) { if ((label = SNetInIdToLabel(hnd->labels, name)) != NULL) { fprintf(hnd->file, "<tag label=\"%s\">%d</tag>\n", label, val); } else{ SNetUtilDebugFatal("Unknown tag %d at output!", name); } SNetMemFree(label); } /* BTags */ RECORD_FOR_EACH_BTAG(rec, name, val) { if ((label = SNetInIdToLabel(hnd->labels, name)) != NULL){ fprintf(hnd->file, "<btag label=\"%s\">%d</btag>\n", label, val); } else{ SNetUtilDebugFatal("Unknown binding tag %d at output!", name); } SNetMemFree(label); } fprintf(hnd->file, "</record>\n"); break; case REC_sync: SNetUtilDebugFatal("REC_sync in output! This should not happen."); break; case REC_collect: SNetUtilDebugFatal("REC_collect in output! This should not happen."); break; case REC_sort_end: SNetUtilDebugFatal("REC_sort_end in output! This should not happen."); break; case REC_trigger_initialiser: SNetUtilDebugFatal("REC_trigger_initializer in output! This should not happen."); break; case REC_terminate: fprintf(hnd->file, "<record type=\"terminate\" />"); break; default: break; }