Changeset 3391:b2905b861e43 in roaraudio for libroarpulse/context.c
- Timestamp:
- 02/11/10 14:39:58 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/context.c
r3390 r3391 39 39 #include <libroarpulse/libroarpulse.h> 40 40 41 struct _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 41 52 struct pa_context { 42 53 size_t refc; 43 54 struct roar_connection con; 44 55 char * server; 56 char * name; 45 57 int state; 58 struct { 59 struct _roar_pa_cb_st set_name; 60 struct _roar_pa_cb_st state_change; 61 } cb; 46 62 }; 47 63 … … 50 66 pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *proplist); 51 67 68 void pa_context_set_state(pa_context *c, pa_context_state_t st); 69 52 70 pa_context *pa_context_new(pa_mainloop_api *mainloop, const char *name) { 53 71 return pa_context_new_with_proplist(mainloop, name, NULL); … … 77 95 if ( c->server != NULL ) 78 96 roar_mm_free(c->server); 97 98 if ( c->name != NULL ) 99 roar_mm_free(c->name); 79 100 80 101 roar_mm_free(c); … … 109 130 server = roar_pa_find_server((char*)server); 110 131 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); 113 135 return -1; 114 136 } 115 137 116 138 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); 118 142 119 143 return 0; … … 129 153 roar_disconnect(&(c->con)); 130 154 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 */ 161 void 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 169 void 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 */ 179 int pa_context_errno(pa_context *c); 180 181 /** Return non-zero if some data is pending to be written to the connection */ 182 int pa_context_is_pending(pa_context *c) { 183 return 0; 184 } 185 186 /** Return the current context status */ 187 pa_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 */ 195 pa_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 */ 206 pa_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 */ 209 pa_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 */ 217 pa_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 */ 225 int 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 */ 237 pa_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 */ 252 const 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 */ 260 uint32_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 */ 265 uint32_t pa_context_get_server_protocol_version(pa_context *c) { 266 return 0; 267 } 268 133 269 134 270 //ll
Note: See TracChangeset
for help on using the changeset viewer.