Changeset 1657:915ca3b23d62 in roaraudio


Ignore:
Timestamp:
05/08/09 16:52:20 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

started VIO api for 2popen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_cmd.c

    r1652 r1657  
    217217} 
    218218 
     219 
     220 
     221int roar_vio_open_2popen(struct roar_vio_calls * calls, char * command, int options) { 
     222#ifndef ROAR_WITHOUT_VIO_CMD 
     223 struct roar_vio_2popen_state * state; 
     224 
     225 if ( calls == NULL || command == NULL || options < 0 ) 
     226  return -1; 
     227 
     228 if ( (state = malloc(sizeof(struct roar_vio_2popen_state))) == NULL ) 
     229  return -1; 
     230 
     231 ROAR_DBG("roar_vio_open_2popen(*): pre reqs are OK"); 
     232 
     233 // clear all 
     234 memset(calls, 0, sizeof(struct roar_vio_calls)); 
     235 memset(state, 0, sizeof(struct roar_vio_cmd_state)); 
     236 
     237 // init reader and writer: 
     238 state->child.pid = -1; 
     239 state->child.in  = -1; 
     240 state->child.out = -1; 
     241 
     242 state->child.cmd = strdup(command); 
     243 
     244 // init state 
     245 state->options = options; 
     246 state->state   = ROAR_VIO_CMD_STATE_OPEN; 
     247 
     248 // init calls 
     249 calls->close    = roar_vio_2popen_close; 
     250/* 
     251 calls->read     = roar_vio_2popen_read; 
     252 calls->write    = roar_vio_2popen_write; 
     253 calls->nonblock = roar_vio_2popen_nonblock; 
     254 calls->sync     = roar_vio_2popen_sync; 
     255 calls->ctl      = roar_vio_2popen_ctl; 
     256*/ 
     257 calls->inst     = (void*) state; 
     258 
     259 ROAR_DBG("roar_vio_open_2popen(*): var setup OK"); 
     260 
     261 if ( !(options & ROAR_VIO_CMD_OPTS_ON_DEMAND) ) { 
     262  if ( roar_vio_cmd_fork(&(state->child)) == -1 ) 
     263   return roar_vio_2popen_close(calls); 
     264 } 
     265 
     266 return 0; 
     267#else 
     268 return -1; 
     269#endif 
     270} 
     271 
     272#ifndef ROAR_WITHOUT_VIO_CMD 
     273int roar_vio_2popen_close(struct roar_vio_calls * vio) { 
     274 struct roar_vio_2popen_state * state = (struct roar_vio_2popen_state *)vio->inst; 
     275 
     276 state->state = ROAR_VIO_CMD_STATE_CLOSING; 
     277 
     278 if ( state->child.opened ) 
     279  roar_vio_cmd_wait(&(state->child)); 
     280 
     281 if ( state->child.cmd != NULL ) 
     282  free(state->child.cmd); 
     283 
     284 free(state); 
     285 
     286 return 0; 
     287} 
     288#endif 
     289 
     290 
    219291// VIOs: 
    220292 
     
    479551 struct roar_vio_cmd_state * state = (struct roar_vio_cmd_state *)vio->inst; 
    480552 char buf[1]; 
    481  int i; 
    482553 
    483554 ROAR_WARN("roar_vio_cmd_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data); 
Note: See TracChangeset for help on using the changeset viewer.