示例#1
0
文件: check_hrc.c 项目: foliern/lpel
static void *Outputter(void *arg)
{
  lpel_stream_desc_t *in = LpelStreamOpen((lpel_stream_t*)arg, 'r'); 
  char *item;
  int term = 0;

  printf("Outputter START\n");

  while (!term) {
    item = LpelStreamRead(in);
    assert( item != NULL );
    printf("\n\n*************************************\nOut: %s\n*************************************\n", item );

    if ( 0 == strcmp( item, "T\n")) {
      term = 1;
    }
    //free( item);
	SCCFreePtr(item);
  } // end while

  LpelStreamClose( in, 1);
  printf("Outputter TERM\n");

  LpelStop();
  return NULL;
}
示例#2
0
文件: check_hrc.c 项目: foliern/lpel
void *Relay(void *inarg)
{
  channels_t *ch = (channels_t *)inarg;
  int term = 0;
  int id = ch->id;
  char *item;
  lpel_stream_desc_t *in, *out;

  in = LpelStreamOpen(ch->in, 'r');
  out = LpelStreamOpen(ch->out, 'w');

  printf("Relay %d START\n", id);

  while (!term) {
    item = LpelStreamRead( in);
    assert( item != NULL );
    //printf("Relay %d: %s", id, item );
    if ( 0 == strcmp( item, "T\n")) {
      term = 1;
    }
    LpelStreamWrite( out, item);
  } // end while
  LpelStreamClose( in, 1);
  LpelStreamClose( out, 0);
  //free(ch);
  SCCFreePtr(ch);
  printf("Relay %d TERM\n", id);
  return NULL;
}
示例#3
0
void *Consumer(void *inarg)
{
  char *msg;
  int i, term;
  lpel_streamset_t lst = NULL;
  lpel_stream_iter_t *iter;

  printf("start Consumer\n" );
  /* open streams */
  for (i=0; i<NUM_COLL; i++) {
    LpelStreamsetPut( &lst, LpelStreamOpen(scoll[i], 'r'));
  }

  iter = LpelStreamIterCreate(&lst);

  term = 0;
  do {
    /* here we do wait */
    printf("Consumer poll\n");
    LpelStreamPoll( &lst);
    printf("Consumer resumes\n");

    printf("Consumer iterates:\n");
    LpelStreamIterReset(iter, &lst);
    while( LpelStreamIterHasNext(iter)) {
      lpel_stream_desc_t *snext = LpelStreamIterNext(iter);
      if ( NULL != LpelStreamPeek( snext )) {
        msg = (char *) LpelStreamRead( snext);
        if (0 == strcmp( msg, "T\n" )) {
          term=1;
        } else {
          printf("%s", msg );
          free(msg);
        }
      }
    }
    //sleep(5);
  } while (0 == term) ;

  /* print & free termination message */
  printf("%s", msg );
  free(msg);

  /* close streams */
  LpelStreamIterReset(iter, &lst);
  while( LpelStreamIterHasNext(iter)) {
    lpel_stream_desc_t *snext = LpelStreamIterNext(iter);
    LpelStreamClose( snext, 1);
  }
  LpelStreamIterDestroy( iter);
  printf("exit Consumer\n" );

  LpelStop();
  return NULL;
}
示例#4
0
void *SNetStreamRead(snet_stream_desc_t * sd)
{
  void *item = LpelStreamRead((lpel_stream_desc_t *) sd);
  usrdata_t *dat;

  /* call the read callback function */
  dat = LpelStreamGetUsrData(LpelStreamGet((lpel_stream_desc_t *) sd));
  if (dat != NULL) {
    if (dat->callback_read.func) {
      dat->callback_read.func(dat->callback_read.arg);
    }
  }

  return item;
}
示例#5
0
void *Relay(void *inarg)
{
  void *item;
  char *msg;
  int i, dest;
  lpel_stream_desc_t *out[NUM_COLL];
  lpel_stream_desc_t *in;
  int term = 0;

  printf("start Relay\n" );

  /* open streams */
  for (i=0; i<NUM_COLL; i++) {
    out[i] = LpelStreamOpen(scoll[i], 'w');
  }
  in = LpelStreamOpen(sinp, 'r');

  /* main task: relay to consumer via defined stream */
  while( !term) {
    item = LpelStreamRead(in);
    assert( item != NULL );
    msg = (char *)item;
    if  ( 0 == strcmp( msg, "T\n" ) ) {
      term = 1;
      dest = 0;
    } else {
      dest = atoi(msg);
    }
    if ( 0<dest && dest<NUM_COLL) {
      LpelStreamWrite( out[dest], item);
      printf("Relay dest: %d\n", dest);
    }
  }
  /* terminate msg goes to 0 */
  assert( dest==0 );
  printf("Relay dest: %d\n", dest);

  /* relay to all, close streams */
  for (i=0; i<NUM_COLL; i++) {
    LpelStreamWrite( out[i], item);
    LpelStreamClose( out[i], 0);
  }
  LpelStreamClose(in, 1);
  printf("exit Relay\n" );
  return NULL;
}