/** * This is the task doing the global input */ static void GlobInputTask(snet_entity_t *ent, void* data) { handle_t *hnd = (handle_t *)data; if(hnd->buffer != NULL) { int i; snet_stream_desc_t *outstream = SNetStreamOpen(hnd->buffer, 'w'); SNetInParserInit( hnd->file, hnd->labels, hnd->interfaces, outstream, ent); i = SNET_PARSE_CONTINUE; while(i != SNET_PARSE_TERMINATE){ i = SNetInParserParse(); } SNetInParserDestroy(); SNetStreamClose( outstream, false); } SNetMemFree(hnd); }
/* Create the node which reads records from an input file via the parser. * This is called from networkinterface.c to initialize the input module. */ void SNetInInputInit( FILE *file, snetin_label_t *labels, snetin_interface_t *interfaces, snet_stream_t *output) { input_arg_t *iarg; node_t *node; landing_input_t *linp; const int first_worker_id = 1; trace(__func__); /* Create input node in the fixed network. */ node = SNetNodeNew(NODE_input, (snet_stream_t **)NULL, 0, &output, 1, SNetNodeInput, SNetStopInput, SNetTermInput); iarg = NODE_SPEC(node, input); iarg->output = output; iarg->state = INPUT_reading; /* Create an empty input descriptor: needed for SNetStreamOpen. */ iarg->indesc = SNetNewAlign(snet_stream_desc_t); memset(iarg->indesc, 0, sizeof(snet_stream_desc_t)); /* Create landing: needed for locking the input node before use. */ iarg->indesc->landing = SNetNewLanding(node, NULL, LAND_input); linp = DESC_LAND_SPEC(iarg->indesc, input); linp->num_inputs = 0; /* Create output descriptor: needed by parser for writing. */ iarg->indesc->landing->id = first_worker_id; linp->outdesc = SNetStreamOpen(output, iarg->indesc); iarg->indesc->landing->id = 0; /* Initialize the parser */ SNetInParserInit(file, labels, interfaces, NULL, NULL); }