Changeset 5715:0ead15b11f72 in roaraudio for roarclients


Ignore:
Timestamp:
10/25/12 17:53:50 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added CPI support, manpage still needs to be updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roarclients/roarpluginrunner.c

    r5712 r5715  
    5555                 "    --args ARGS          - Set plugin arguments.\n" 
    5656        ); 
     57 
     58 fprintf(stderr, "\nCPI Options:\n\n"); 
     59 fprintf(stderr, " -t --tcp                - Use TCP listen socket\n" 
     60                 " -u --unix               - Use UNIX Domain listen socket (default)\n" 
     61                 " -n --decnet             - use DECnet listen socket\n" 
     62                 "    --port PORT          - TCP Port to bind to\n" 
     63                 "    --bind ADDR          - Node/Hostname/Path to bind to\n" 
     64                 "    --proto PROTO        - Use PROTO as protocol on Socket\n" 
     65                 "    --new-sock           - Parameters for new socket follow\n" 
     66                 "    --client-fh FH       - Comunicate with a client over this handle\n" 
     67                 "\n" 
     68        ); 
    5769} 
    5870 
     
    7284 if ( roar_plugincontainer_load(cont, name, NULL) == -1 ) { 
    7385  err = roar_error; 
     86  roar_scheduler_source_del(g_sched, &s_container); 
    7487  roar_plugincontainer_unref(cont); 
    7588  roar_error = err; 
     
    425438} 
    426439 
     440static struct roar_scheduler_source * add_cpi_common(int proto) { 
     441 struct roar_scheduler_source * source; 
     442 int err; 
     443 
     444 if ( proto == -1 ) { 
     445  roar_err_set(ROAR_ERROR_INVAL); 
     446  return NULL; 
     447 } 
     448 
     449 source = roar_mm_malloc(sizeof(struct roar_scheduler_source)); 
     450 if ( source == NULL ) 
     451  return NULL; 
     452 
     453 memset(source, 0, sizeof(struct roar_scheduler_source)); 
     454 
     455 source->vio   = roar_mm_malloc(sizeof(struct roar_vio_calls)); 
     456 if ( source->vio == NULL ) { 
     457  err = roar_error; 
     458  roar_mm_free(source); 
     459  roar_error = err; 
     460  return NULL; 
     461 } 
     462 
     463 source->flags = ROAR_SCHEDULER_FLAG_FREE; 
     464 source->handle.cpi.proto = proto; 
     465 
     466 return source; 
     467} 
     468 
     469static int add_cpi_listen(int proto, int type, const char * host, int port) { 
     470 struct roar_scheduler_source * source = add_cpi_common(proto); 
     471 int err; 
     472 
     473 if ( source == NULL ) 
     474  return -1; 
     475 
     476 if ( roar_vio_open_socket_listen(source->vio, type, host, port) == -1 ) { 
     477  err = roar_error; 
     478  roar_mm_free(source->vio); 
     479  roar_mm_free(source); 
     480  roar_error = err; 
     481  return -1; 
     482 } 
     483 
     484 source->type  = ROAR_SCHEDULER_CPI_LISTEN; 
     485 
     486 source->vio->flags |= ROAR_VIO_FLAGS_FREESELF; 
     487 
     488 if ( roar_scheduler_source_add(g_sched, source) == -1 ) { 
     489  err = roar_error; 
     490  roar_vio_close(source->vio); 
     491  roar_mm_free(source); 
     492  roar_error = err; 
     493  return -1; 
     494 } 
     495 
     496 return 0; 
     497} 
     498 
     499static int add_cpi_client(int proto, int fh) { 
     500 struct roar_scheduler_source * source = add_cpi_common(proto); 
     501 struct roar_dl_librarypara * para; 
     502 int err; 
     503 
     504 if ( source == NULL ) 
     505  return -1; 
     506 
     507 if ( roar_vio_open_fh(source->vio, fh) == -1 ) { 
     508  err = roar_error; 
     509  roar_mm_free(source->vio); 
     510  roar_mm_free(source); 
     511  roar_error = err; 
     512  return -1; 
     513 } 
     514 
     515 source->type  = ROAR_SCHEDULER_CPI_CLIENT; 
     516 
     517 source->vio->flags |= ROAR_VIO_FLAGS_FREESELF; 
     518 
     519 if ( roar_scheduler_source_add(g_sched, source) == -1 ) { 
     520  err = roar_error; 
     521  roar_vio_close(source->vio); 
     522  roar_mm_free(source); 
     523  roar_error = err; 
     524  return -1; 
     525 } 
     526 
     527 if ( source->flags & ROAR_SCHEDULER_FLAG_STUB ) { 
     528  ROAR_ERR("Can not handle proto STUB clients. Try to use --client-fh as last argument."); 
     529 
     530  roar_scheduler_source_del(g_sched, source); 
     531 
     532  return -1; 
     533 } 
     534 
     535 if ( source->handle.cpi.impl->set_proto != NULL ) { 
     536  para = roar_dl_getpara(source->lhandle); 
     537 
     538  if ( source->lhandle != NULL ) 
     539   roar_dl_context_restore(source->lhandle); 
     540  source->handle.cpi.impl->set_proto(source->handle.cpi.client, source->vio, &(source->handle.cpi.obuffer), &(source->handle.cpi.userdata), source->handle.cpi.protopara, source->handle.cpi.protoparalen, para); 
     541  if ( source->lhandle != NULL ) 
     542   roar_dl_context_store(source->lhandle); 
     543 
     544  if ( para != NULL ) 
     545   roar_dl_para_unref(para); 
     546 } 
     547 
     548 return 0; 
     549} 
     550 
    427551int main (int argc, char * argv[]) { 
    428552 const char * appname    = "roarpluginrunner " ROAR_VSTR_ROARAUDIO; 
     
    433557 int i; 
    434558 const char * k; 
     559 int cpi_type = ROAR_SOCKET_TYPE_UNKNOWN; 
     560 int cpi_proto = -1; 
     561 int cpi_port = 0; 
     562 int cpi_touched = 0; 
     563 const char * cpi_host = NULL; 
    435564 
    436565 g_sched = roar_scheduler_new(ROAR_SCHEDULER_FLAG_NONE, ROAR_SCHEDULER_STRATEGY_DEFAULT); 
     
    459588  } else if ( !strcmp(k, "--server") ) { 
    460589   roar_libroar_set_server(argv[++i]); 
     590 
     591  } else if ( !strcmp(k, "--tcp") || !strcmp(k, "-t") ) { 
     592   cpi_type = ROAR_SOCKET_TYPE_TCP; 
     593   cpi_touched++; 
     594  } else if ( !strcmp(k, "--unix") || !strcmp(k, "-u") ) { 
     595   cpi_type = ROAR_SOCKET_TYPE_UNIX; 
     596   cpi_touched++; 
     597  } else if ( !strcmp(k, "--decnet") || !strcmp(k, "-n") ) { 
     598   cpi_type = ROAR_SOCKET_TYPE_DECNET; 
     599   cpi_touched++; 
     600  } else if ( !strcmp(k, "--port") ) { 
     601   cpi_port = atoi(argv[++i]); 
     602   cpi_touched++; 
     603  } else if ( !strcmp(k, "--bind") ) { 
     604   cpi_host = argv[++i]; 
     605   cpi_touched++; 
     606  } else if ( !strcmp(k, "--proto") ) { 
     607   cpi_proto = roar_str2proto(argv[++i]); 
     608   if ( cpi_proto == -1 ) { 
     609    fprintf(stderr, "Unknown protocol: %s: %s\n", argv[i], roar_error2str(roar_error)); 
     610    return 1; 
     611   } 
     612  } else if ( !strcmp(k, "--new-sock") ) { 
     613   if ( cpi_touched && add_cpi_listen(cpi_proto, cpi_type, cpi_host, cpi_port) == -1 ) { 
     614    fprintf(stderr, "Can not open socket for CPI: %s\n", roar_error2str(roar_error)); 
     615    return 1; 
     616   } 
     617   cpi_touched = 0; 
     618  } else if ( !strcmp(k, "--client-fh") ) { 
     619   if ( add_cpi_client(cpi_proto, atoi(argv[++i])) == -1 ) { 
     620    fprintf(stderr, "Can not add CPI client: %s\n", roar_error2str(roar_error)); 
     621    return 1; 
     622   } 
     623 
    461624  } else if ( !strcmp(k, "--appname") ) { 
    462625   appname = argv[++i]; 
     
    469632   _clear_para(); 
    470633  } else { 
     634   if ( cpi_touched && add_cpi_listen(cpi_proto, cpi_type, cpi_host, cpi_port) == -1 ) { 
     635    fprintf(stderr, "Can not open socket for CPI: %s\n", roar_error2str(roar_error)); 
     636    return 1; 
     637   } 
     638   cpi_touched = 0; 
     639 
    471640   if ( g_para == NULL ) 
    472641    g_para = roar_dl_para_new(action == RUN_AS_APPLICATION ? NULL : pluginargs, NULL, appname, abiversion); 
Note: See TracChangeset for help on using the changeset viewer.