[refactor] fix build warnings in avahi binding

This commit is contained in:
Julian Sparber
2017-09-29 18:21:40 +02:00
parent 67fbdccf62
commit 3246eb9c2d
4 changed files with 148 additions and 171 deletions

View File

@@ -128,33 +128,33 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN
int error; int error;
int ret = 1; int ret = 1;
*/ */
/* Allocate main loop object */ /* Allocate main loop object */
/*if (!(simple_poll = avahi_simple_poll_new())) { /*if (!(simple_poll = avahi_simple_poll_new())) {
fprintf(stderr, "Failed to create simple poll object.\n"); fprintf(stderr, "Failed to create simple poll object.\n");
goto fail; goto fail;
} }
*/ */
/* Allocate a new client */ /* Allocate a new client */
//client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error); //client = avahi_client_new(avahi_simple_poll_get(simple_poll), 0, client_callback, NULL, &error);
/* Check wether creating the client object succeeded */ /* Check wether creating the client object succeeded */
/*if (!client) { /*if (!client) {
fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
goto fail; goto fail;
} }
*//* Create the service browser */ *//* Create the service browser */
/*if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, client))) { /*if (!(sb = avahi_service_browser_new(client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, browse_callback, client))) {
fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client))); fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
goto fail; goto fail;
} }
*/ */
/* Run the main loop */ /* Run the main loop */
/* /*
avahi_simple_poll_loop(simple_poll); avahi_simple_poll_loop(simple_poll);
ret = 0; ret = 0;
fail: fail:
*/ */
/* Cleanup things */ /* Cleanup things */
/* /*
if (sb) if (sb)
avahi_service_browser_free(sb); avahi_service_browser_free(sb);
@@ -163,14 +163,14 @@ fail:
if (simple_poll) if (simple_poll)
avahi_simple_poll_free(simple_poll); avahi_simple_poll_free(simple_poll);
return ret; return ret;
} }
*/ */
int run_avahi_service(TeleportPeer* peers) { int run_avahi_service(TeleportPeer *peers) {
int error;
peerList = peers; peerList = peers;
/* Call this when the application starts up. */ /* Call this when the application starts up. */
int error;
if (!(threaded_poll = avahi_threaded_poll_new())) { if (!(threaded_poll = avahi_threaded_poll_new())) {
/* do something bad */ /* do something bad */

View File

@@ -1,8 +1,7 @@
#ifndef __BROWSER_H #ifndef __BROWSER_H
#define __BROWSER_H #define __BROWSER_H
extern int run_avahi_service(TeleportPeer *);
extern int run_avahi_service(); void avahi_shutdown(void);
void avahi_shutdown();
#endif /* __BROWSER_H */ #endif /* __BROWSER_H */

View File

@@ -1,22 +1,3 @@
/***
This file is part of avahi.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
@@ -38,7 +19,7 @@
#include "teleportapp.h" #include "teleportapp.h"
#include "teleportpeer.h" #include "teleportpeer.h"
#include "browser.h" #include "publish.h"
static AvahiThreadedPoll *threaded_poll = NULL; static AvahiThreadedPoll *threaded_poll = NULL;
static AvahiEntryGroup *group = NULL; static AvahiEntryGroup *group = NULL;
@@ -83,7 +64,7 @@ static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
/* Some kind of failure happened while we were registering our services */ /* Some kind of failure happened while we were registering our services */
//avahi_simple_poll_quit(simple_poll); //avahi_simple_poll_quit(simple_poll);
avahi_shutdown(); shutdown_avahi_publish_service();
break; break;
case AVAHI_ENTRY_GROUP_UNCOMMITED: case AVAHI_ENTRY_GROUP_UNCOMMITED:
@@ -156,7 +137,7 @@ collision:
fail: fail:
//avahi_simple_poll_quit(simple_poll); //avahi_simple_poll_quit(simple_poll);
avahi_shutdown(); shutdown_avahi_publish_service();
} }
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) {
@@ -176,7 +157,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN
fprintf(stderr, "Client failure: %s\n", avahi_strerror(avahi_client_errno(c))); fprintf(stderr, "Client failure: %s\n", avahi_strerror(avahi_client_errno(c)));
//avahi_simple_poll_quit(simple_poll); //avahi_simple_poll_quit(simple_poll);
avahi_shutdown(); shutdown_avahi_publish_service();
break; break;
@@ -203,7 +184,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN
} }
} }
static void update_service(char * service_name) { extern void update_service(char * service_name) {
avahi_free(name); avahi_free(name);
name = avahi_strdup(service_name); name = avahi_strdup(service_name);
@@ -222,8 +203,6 @@ static void update_service(char * service_name) {
int run_avahi_publish_service(char * service_name) { int run_avahi_publish_service(char * service_name) {
int error; int error;
int ret = 1;
struct timeval tv;
if (!(threaded_poll = avahi_threaded_poll_new())) { if (!(threaded_poll = avahi_threaded_poll_new())) {
fprintf(stderr, "Failed to create threaded poll object.\n"); fprintf(stderr, "Failed to create threaded poll object.\n");
@@ -246,11 +225,9 @@ int run_avahi_publish_service(char * service_name) {
return 0; return 0;
} }
void shutdown_avahi_publish_service(void) { void shutdown_avahi_publish_service(void) {
/* Call this when the app shuts down */ /* Call this when the app shuts down */
//fprintf(stderr, "Some error\n");
avahi_threaded_poll_stop(threaded_poll); avahi_threaded_poll_stop(threaded_poll);
avahi_client_free(client); avahi_client_free(client);
avahi_threaded_poll_free(threaded_poll); avahi_threaded_poll_free(threaded_poll);

View File

@@ -3,6 +3,7 @@
extern int run_avahi_publish_service(char *); extern int run_avahi_publish_service(char *);
extern void shutdown_avahi_publish_service(); extern void shutdown_avahi_publish_service(void);
extern void update_service(char *);
#endif /* __PUBLISH_H */ #endif /* __PUBLISH_H */