Changeset 3392:842c8d8f99a9 in roaraudio


Ignore:
Timestamp:
02/11/10 14:57:22 (10 years ago)
Author:
phi
Branch:
default
Message:

wrote most of the context code, should work now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/context.c

    r3391 r3392  
    5656 char * name; 
    5757 int state; 
     58 int errnum; 
    5859 struct { 
    5960  struct _roar_pa_cb_st set_name; 
     
    8788 c->state = PA_CONTEXT_UNCONNECTED; 
    8889 
     90 c->errnum = PA_OK; 
     91 
    8992 return NULL; 
    9093} 
     
    123126  return -1; 
    124127 
    125  if ( c->state != PA_CONTEXT_UNCONNECTED ) 
    126   return -1; 
     128 if ( c->state != PA_CONTEXT_UNCONNECTED ) { 
     129  c->errnum = PA_ERR_BADSTATE; 
     130  pa_context_set_state(c, PA_CONTEXT_FAILED); 
     131  return -1; 
     132 } 
    127133 
    128134 // we do currently not support to spawn a daemon, so we ignore flags and api. 
     
    132138 if ( roar_simple_connect(&(c->con), (char*)server, 
    133139                          c->name != NULL ? c->name : "libroarpulse [pa_context_connect()]") == -1 ) { 
     140  c->errnum = PA_ERR_CONNECTIONREFUSED; 
    134141  pa_context_set_state(c, PA_CONTEXT_FAILED); 
    135142  return -1; 
     
    177184 
    178185/** Return the error number of the last failed operation */ 
    179 int pa_context_errno(pa_context *c); 
     186int pa_context_errno(pa_context *c) { 
     187 if ( c == NULL ) 
     188  return PA_ERR_INVALID; 
     189 
     190 return c->errnum; 
     191} 
    180192 
    181193/** Return non-zero if some data is pending to be written to the connection */ 
     
    204216 * complete succesfully, since the daemon probably died before 
    205217 * returning a success notification */ 
    206 pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata); 
     218pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata) { 
     219 int s = 1; 
     220 
     221 if ( c == NULL ) 
     222  return NULL; 
     223 
     224 if ( c->state == PA_CONTEXT_READY ) { 
     225  if ( roar_exit(&(c->con)) == -1 ) { 
     226   c->errnum = PA_ERR_INTERNAL; 
     227   s = 0; 
     228  } 
     229 } else { 
     230  c->errnum = PA_ERR_BADSTATE; 
     231  s = 0; 
     232 } 
     233 
     234 if ( cb != NULL ) 
     235  cb(c, s, userdata); 
     236 
     237 return NULL; 
     238} 
    207239 
    208240/** Set the name of the default sink. \since 0.4 */ 
    209241pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { 
     242 if ( c != NULL ) 
     243  c->errnum = PA_ERR_NOTSUPPORTED; 
     244 
    210245 if ( cb != NULL ) 
    211246  cb(c, 0, userdata); 
     
    216251/** Set the name of the default source. \since 0.4 */ 
    217252pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { 
     253 if ( c != NULL ) 
     254  c->errnum = PA_ERR_NOTSUPPORTED; 
     255 
    218256 if ( cb != NULL ) 
    219257  cb(c, 0, userdata); 
     
    239277  return NULL; 
    240278 
    241  if ( c->state != PA_CONTEXT_UNCONNECTED ) 
    242   return NULL; 
     279 if ( c->state != PA_CONTEXT_UNCONNECTED ) { 
     280  c->errnum = PA_ERR_BADSTATE; 
     281 
     282  if ( cb != NULL ) 
     283   cb(c, 0, userdata); 
     284 
     285  return NULL; 
     286 } 
    243287 
    244288 c->name = roar_mm_strdup(name); 
Note: See TracChangeset for help on using the changeset viewer.