Home | History | Annotate | Download | only in avahi-compat-howl

Lines Matching defs:self

101 static sw_discovery discovery_ref(sw_discovery self);
102 static void discovery_unref(sw_discovery self);
156 sw_discovery self = userdata;
159 assert(self);
161 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
163 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
169 sw_discovery self = data;
175 self->thread = pthread_self();
176 self->thread_running = 1;
181 if ((command = read_command(self->thread_fd)) < 0)
191 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
196 if ((ret = avahi_simple_poll_run(self->simple_poll)) < 0) {
207 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
209 if (write_command(self->thread_fd, ret < 0 ? COMMAND_POLL_FAILED : COMMAND_POLL_DONE) < 0)
224 static int oid_alloc(sw_discovery self, oid_type type) {
226 assert(self);
230 while (self->oid_index >= OID_MAX)
231 self->oid_index -= OID_MAX;
233 if (self->oid_table[self->oid_index].type == OID_UNUSED) {
234 self->oid_table[self->oid_index].type = type;
235 self->oid_table[self->oid_index].discovery = self;
237 assert(OID_GET_INDEX(&self->oid_table[self->oid_index]) == self->oid_index);
239 return self->oid_index ++;
242 self->oid_index ++;
250 static void oid_release(sw_discovery self, sw_discovery_oid oid) {
251 assert(self);
254 assert(self->oid_table[oid].type != OID_UNUSED);
256 self->oid_table[oid].type = OID_UNUSED;
257 self->oid_table[oid].discovery = NULL;
258 self->oid_table[oid].reply = NULL;
259 self->oid_table[oid].object = NULL;
260 self->oid_table[oid].extra = NULL;
261 self->oid_table[oid].service_data = NULL;
264 static oid_data* oid_get(sw_discovery self, sw_discovery_oid oid) {
265 assert(self);
270 if (self->oid_table[oid].type == OID_UNUSED)
273 return &self->oid_table[oid];
276 static service_data* service_data_new(sw_discovery self) {
279 assert(self);
284 AVAHI_LLIST_PREPEND(service_data, services, self->services, sdata);
290 static void service_data_free(sw_discovery self, service_data* sdata) {
291 assert(self);
294 AVAHI_LLIST_REMOVE(service_data, services, self->services, sdata);
307 sw_discovery self = userdata;
311 assert(self);
313 discovery_ref(self);
317 switch (self->oid_table[oid].type) {
320 reg_client_callback(&self->oid_table[oid], state);
325 ((sw_discovery_browse_reply) self->oid_table[oid].reply)(self, oid, SW_DISCOVERY_BROWSE_INVALID, 0, NULL, NULL, NULL, self->oid_table[oid].extra);
334 discovery_unref(self);
337 sw_result sw_discovery_init(sw_discovery * self) {
343 assert(self);
347 *self = NULL;
352 if (!(*self = avahi_new(struct _sw_discovery, 1))) {
357 (*self)->n_ref = 1;
358 (*self)->thread_fd = fd[0];
359 (*self)->main_fd = fd[1];
361 (*self)->client = NULL;
362 (*self)->simple_poll = NULL;
364 memset((*self)->oid_table, 0, sizeof((*self)->oid_table));
365 (*self)->oid_index = 0;
367 (*self)->thread_running = 0;
369 AVAHI_LLIST_HEAD_INIT(service_info, (*self)->services);
373 ASSERT_SUCCESS(pthread_mutex_init(&(*self)->mutex, &mutex_attr));
374 ASSERT_SUCCESS(pthread_mutex_init(&(*self)->salt_mutex, &mutex_attr));
376 if (!((*self)->simple_poll = avahi_simple_poll_new()))
379 avahi_simple_poll_set_func((*self)->simple_poll, poll_func, *self);
381 if (!((*self)->client = avahi_client_new(avahi_simple_poll_get((*self)->simple_poll), 0, client_callback, *self, &error))) {
387 if (avahi_simple_poll_prepare((*self)->simple_poll, -1) < 0)
391 if (write_command((*self)->main_fd, COMMAND_POLL) < 0)
394 if (pthread_create(&(*self)->thread, NULL, thread_func, *self) != 0)
397 (*self)->thread_running = 1;
403 if (*self)
404 sw_discovery_fina(*self);
409 static int stop_thread(sw_discovery self) {
410 assert(self);
412 if (!self->thread_running)
415 if (write_command(self->main_fd, COMMAND_QUIT) < 0)
418 avahi_simple_poll_wakeup(self->simple_poll);
420 ASSERT_SUCCESS(pthread_join(self->thread, NULL));
421 self->thread_running = 0;
425 static sw_discovery discovery_ref(sw_discovery self) {
426 assert(self);
427 assert(self->n_ref >= 1);
429 self->n_ref++;
431 return self;
434 static void discovery_unref(sw_discovery self) {
435 assert(self);
436 assert(self->n_ref >= 1);
438 if (--self->n_ref > 0)
441 stop_thread(self);
443 if (self->client)
444 avahi_client_free(self->client);
446 if (self->simple_poll)
447 avahi_simple_poll_free(self->simple_poll);
449 if (self->thread_fd >= 0)
450 close(self->thread_fd);
452 if (self->main_fd >= 0)
453 close(self->main_fd);
455 ASSERT_SUCCESS(pthread_mutex_destroy(&self->mutex));
456 ASSERT_SUCCESS(pthread_mutex_destroy(&self->salt_mutex));
458 while (self->services)
459 service_data_free(self, self->services);
461 avahi_free(self);
464 sw_result sw_discovery_fina(sw_discovery self) {
465 assert(self);
469 stop_thread(self);
470 discovery_unref(self);
475 sw_result sw_discovery_run(sw_discovery self) {
476 assert(self);
480 return sw_salt_run((sw_salt) self);
483 sw_result sw_discovery_stop_run(sw_discovery self) {
484 assert(self);
488 return sw_salt_stop_run((sw_salt) self);
491 int sw_discovery_socket(sw_discovery self) {
492 assert(self);
496 return self->main_fd;
499 sw_result sw_discovery_read_socket(sw_discovery self) {
502 assert(self);
504 discovery_ref(self);
506 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
509 if (read_command(self->main_fd) != COMMAND_POLL_DONE)
512 if (avahi_simple_poll_dispatch(self->simple_poll) < 0)
515 if (self->n_ref > 1) /* Perhaps we should die */
518 if (avahi_simple_poll_prepare(self->simple_poll, -1) < 0)
521 if (self->n_ref > 1)
524 if (write_command(self->main_fd, COMMAND_POLL) < 0)
531 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
533 discovery_unref(self);
538 sw_result sw_discovery_salt(sw_discovery self, sw_salt *salt) {
539 assert(self);
544 *salt = (sw_salt) self;
549 sw_result sw_salt_step(sw_salt self, sw_uint32 * msec) {
556 if (!((sw_discovery) self)->thread_running)
560 p.fd = ((sw_discovery) self)->main_fd;
582 if ((result = sw_discovery_read_socket((sw_discovery) self)) != SW_OKAY)
589 sw_result sw_salt_run(sw_salt self) {
594 assert(self);
597 if ((ret = sw_salt_step(self, NULL)) != SW_OKAY)
601 sw_result sw_salt_stop_run(sw_salt self) {
604 assert(self);
606 if (stop_thread((sw_discovery) self) < 0)
612 sw_result sw_salt_lock(sw_salt self) {
615 assert(self);
616 ASSERT_SUCCESS(pthread_mutex_lock(&((sw_discovery) self)->salt_mutex));
621 sw_result sw_salt_unlock(sw_salt self) {
622 assert(self);
626 ASSERT_SUCCESS(pthread_mutex_unlock(&((sw_discovery) self)->salt_mutex));
755 sw_discovery self,
773 assert(self);
785 if ((*oid = oid_alloc(self, OID_ENTRY_GROUP)) == (sw_discovery_oid) -1) {
790 if (!(sdata = service_data_new(self))) {
792 oid_release(self, *oid);
796 data = oid_get(self, *oid);
812 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
814 if (!(data->object = avahi_entry_group_new(self->client, reg_entry_group_callback, data))) {
815 result = map_error(avahi_client_errno(self->client));
819 if (avahi_client_get_state(self->client) == AVAHI_CLIENT_S_RUNNING) {
832 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
836 sw_discovery_cancel(self, *oid);
881 sw_discovery self,
891 assert(self);
897 if ((*oid = oid_alloc(self, OID_DOMAIN_BROWSER)) == (sw_discovery_oid) -1)
900 data = oid_get(self, *oid);
907 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
909 if (!(data->object = avahi_domain_browser_new(self->client, ifindex, AVAHI_PROTO_INET, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, domain_browser_callback, data))) {
910 result = map_error(avahi_client_errno(self->client));
918 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
922 sw_discovery_cancel(self, *oid);
985 sw_discovery self,
998 assert(self);
1006 if ((*oid = oid_alloc(self, OID_SERVICE_RESOLVER)) == (sw_discovery_oid) -1)
1009 data = oid_get(self, *oid);
1016 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
1018 if (!(data->object = avahi_service_resolver_new(self->client, ifindex, AVAHI_PROTO_INET, name, type, domain, AVAHI_PROTO_INET, 0, service_resolver_callback, data))) {
1019 result = map_error(avahi_client_errno(self->client));
1027 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
1031 sw_discovery_cancel(self, *oid);
1079 sw_discovery self,
1091 assert(self);
1098 if ((*oid = oid_alloc(self, OID_SERVICE_BROWSER)) == (sw_discovery_oid) -1)
1101 data = oid_get(self, *oid);
1108 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
1110 if (!(data->object = avahi_service_browser_new(self->client, ifindex, AVAHI_PROTO_INET, type, domain, 0, service_browser_callback, data))) {
1111 result = map_error(avahi_client_errno(self->client));
1119 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
1123 sw_discovery_cancel(self, *oid);
1128 sw_result sw_discovery_cancel(sw_discovery self, sw_discovery_oid oid) {
1130 assert(self);
1134 if (!(data = oid_get(self, oid)))
1162 service_data_free(self, data->service_data);
1165 oid_release(self, oid);
1171 sw_discovery * self,
1174 assert(self);
1181 return sw_discovery_init(self);