Changeset 3391:b2905b861e43 in roaraudio for libroarpulse/context.c


Ignore:
Timestamp:
02/11/10 14:39:58 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

we are now mostly done, just a commit inbetween

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/context.c

    r3390 r3391  
    3939#include <libroarpulse/libroarpulse.h> 
    4040 
     41struct _roar_pa_cb_st { 
     42 union { 
     43  pa_context_success_cb_t scb; 
     44  pa_context_notify_cb_t  ncb; 
     45 } cb; 
     46 void * userdata; 
     47}; 
     48 
     49#define _call_cbs(x,c,s) ((x).cb.scb == NULL ? (void)0 : (x).cb.scb((c), (s), (x).userdata)) 
     50#define _call_cbn(x,c)   ((x).cb.ncb == NULL ? (void)0 : (x).cb.ncb((c), (x).userdata)) 
     51 
    4152struct pa_context { 
    4253 size_t refc; 
    4354 struct roar_connection con; 
    4455 char * server; 
     56 char * name; 
    4557 int state; 
     58 struct { 
     59  struct _roar_pa_cb_st set_name; 
     60  struct _roar_pa_cb_st state_change; 
     61 } cb; 
    4662}; 
    4763 
     
    5066pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist); 
    5167 
     68void pa_context_set_state(pa_context *c, pa_context_state_t st); 
     69 
    5270pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) { 
    5371 return pa_context_new_with_proplist(mainloop, name, NULL); 
     
    7795 if ( c->server != NULL ) 
    7896  roar_mm_free(c->server); 
     97 
     98 if ( c->name != NULL ) 
     99  roar_mm_free(c->name); 
    79100 
    80101 roar_mm_free(c); 
     
    109130 server = roar_pa_find_server((char*)server); 
    110131 
    111  if ( roar_simple_connect(&(c->con), (char*)server, "libroarpulse [pa_context_connect()]") == -1 ) { 
    112   c->state = PA_CONTEXT_FAILED; 
     132 if ( roar_simple_connect(&(c->con), (char*)server, 
     133                          c->name != NULL ? c->name : "libroarpulse [pa_context_connect()]") == -1 ) { 
     134  pa_context_set_state(c, PA_CONTEXT_FAILED); 
    113135  return -1; 
    114136 } 
    115137 
    116138 c->server = roar_mm_strdup(server); 
    117  c->state  = PA_CONTEXT_READY; 
     139 pa_context_set_state(c, PA_CONTEXT_READY); 
     140 
     141 _call_cbs(c->cb.set_name, c, 1); 
    118142 
    119143 return 0; 
     
    129153 roar_disconnect(&(c->con)); 
    130154 
    131  c->state = PA_CONTEXT_TERMINATED; 
    132 } 
     155 pa_context_set_state(c, PA_CONTEXT_TERMINATED); 
     156} 
     157 
     158 
     159 
     160/** Set a callback function that is called whenever the context status changes */ 
     161void pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, void *userdata) { 
     162 if ( c == NULL ) 
     163  return; 
     164 
     165 c->cb.state_change.cb.ncb   = cb; 
     166 c->cb.state_change.userdata = userdata; 
     167} 
     168 
     169void pa_context_set_state(pa_context *c, pa_context_state_t st) { 
     170 if ( c == NULL ) 
     171  return; 
     172 
     173 c->state = st; 
     174 
     175 _call_cbn(c->cb.state_change, c); 
     176} 
     177 
     178/** Return the error number of the last failed operation */ 
     179int pa_context_errno(pa_context *c); 
     180 
     181/** Return non-zero if some data is pending to be written to the connection */ 
     182int pa_context_is_pending(pa_context *c) { 
     183 return 0; 
     184} 
     185 
     186/** Return the current context status */ 
     187pa_context_state_t pa_context_get_state(pa_context *c) { 
     188 if ( c == NULL ) 
     189  return PA_CONTEXT_FAILED; 
     190 
     191 return c->state; 
     192} 
     193 
     194/** Drain the context. If there is nothing to drain, the function returns NULL */ 
     195pa_operation* pa_context_drain(pa_context *c, pa_context_notify_cb_t cb, void *userdata) { 
     196 
     197 if ( cb != NULL ) 
     198  cb(c, userdata); 
     199 
     200 return NULL; 
     201} 
     202 
     203/** Tell the daemon to exit. The returned operation is unlikely to 
     204 * complete succesfully, since the daemon probably died before 
     205 * returning a success notification */ 
     206pa_operation* pa_context_exit_daemon(pa_context *c, pa_context_success_cb_t cb, void *userdata); 
     207 
     208/** Set the name of the default sink. \since 0.4 */ 
     209pa_operation* pa_context_set_default_sink(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { 
     210 if ( cb != NULL ) 
     211  cb(c, 0, userdata); 
     212 
     213 return NULL; 
     214} 
     215 
     216/** Set the name of the default source. \since 0.4 */ 
     217pa_operation* pa_context_set_default_source(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { 
     218 if ( cb != NULL ) 
     219  cb(c, 0, userdata); 
     220 
     221 return NULL; 
     222} 
     223 
     224/** Returns 1 when the connection is to a local daemon. Returns negative when no connection has been made yet. \since 0.5 */ 
     225int pa_context_is_local(pa_context *c) { 
     226 if ( c == NULL ) 
     227  return -1; 
     228 
     229 if ( c->state != PA_CONTEXT_READY ) 
     230  return -1; 
     231 
     232 // how is /local/ defined? 
     233 return 0; 
     234} 
     235 
     236/** Set a different application name for context on the server. \since 0.5 */ 
     237pa_operation* pa_context_set_name(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) { 
     238 if ( c == NULL ) 
     239  return NULL; 
     240 
     241 if ( c->state != PA_CONTEXT_UNCONNECTED ) 
     242  return NULL; 
     243 
     244 c->name = roar_mm_strdup(name); 
     245 c->cb.set_name.cb.scb   = cb; 
     246 c->cb.set_name.userdata = userdata; 
     247 
     248 return NULL; 
     249} 
     250 
     251/** Return the server name this context is connected to. \since 0.7 */ 
     252const char* pa_context_get_server(pa_context *c) { 
     253 if ( c == NULL ) 
     254  return NULL; 
     255 
     256 return c->server; 
     257} 
     258 
     259/** Return the protocol version of the library. \since 0.8 */ 
     260uint32_t pa_context_get_protocol_version(pa_context *c) { 
     261 return 0; 
     262} 
     263 
     264/** Return the protocol version of the connected server. \since 0.8 */ 
     265uint32_t pa_context_get_server_protocol_version(pa_context *c) { 
     266 return 0; 
     267} 
     268 
    133269 
    134270//ll 
Note: See TracChangeset for help on using the changeset viewer.