Skip to content

Commit

Permalink
rpi: Upgrade stos to run avahi daemon and announce our hostname.
Browse files Browse the repository at this point in the history
Also change Showtime so it will configure the hostname announced in
avahi based on the name set in network configuartion
  • Loading branch information
andoma committed Jan 22, 2015
1 parent 415ecad commit 15746f9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Autobuild/rpi.sh
Expand Up @@ -6,8 +6,8 @@ build()
TOOLCHAIN_URL=http://www.lonelycoder.com/download/arm-unknown-linux-gnueabi.tar.gz
TOOLCHAIN="${WORKINGDIR}/arm-unknown-linux-gnueabi"

SYSROOT_URL=http://www.lonelycoder.com/download/rpi_alpha_sysroot.tar.gz
SYSROOT="${WORKINGDIR}/rpi_alpha_sysroot"
SYSROOT_URL=http://www.lonelycoder.com/download/rpi_sysroot-1.0-13-ga8630c9.tar.gz
SYSROOT="${WORKINGDIR}/rpi_sysroot-1.0-13-ga8630c9"


cleanup() {
Expand Down
2 changes: 1 addition & 1 deletion Manifests/rpi.json
@@ -1,3 +1,3 @@
{
"stosVersion": "1.0.9"
"stosVersion": "1.0.17"
}
5 changes: 5 additions & 0 deletions configure.rpi
Expand Up @@ -74,6 +74,11 @@ if [ -n "$SYSROOT" ]; then
echo >>${CONFIG_MAK} "CFLAGS_cfg += " `pkg-config --cflags gio-2.0`
echo "Using gio: `pkg-config --modversion gio-2.0`"

echo >>${CONFIG_MAK} "LDFLAGS_cfg += " `pkg-config --libs avahi-client`
echo >>${CONFIG_MAK} "CFLAGS_AVAHI += "`pkg-config --cflags avahi-client`
echo "Using AVAHI client: `pkg-config --modversion avahi-client`"
enable avahi

echo >>${CONFIG_MAK} "LDFLAGS_cfg += -lbz2"

enable connman
Expand Down
40 changes: 37 additions & 3 deletions src/sd/avahi.c
Expand Up @@ -39,6 +39,7 @@
#include "avahi.h"
#include "sd.h"

static AvahiSimplePoll *asp;

static struct service_instance_list services;

Expand All @@ -56,6 +57,7 @@ typedef struct service_aux {
static void
client_state_change(AvahiClient *c, AvahiClientState state, void *aux)
{
TRACE(TRACE_DEBUG, "AVAHI", "Client state change %d", state);
}


Expand Down Expand Up @@ -346,7 +348,7 @@ client_callback(AvahiClient *c, AvahiClientState state, void *userdata)
assert(c);

/* Called whenever the client or server state changes */

TRACE(TRACE_DEBUG, "AVAHI", "State %d", state);
switch (state) {
case AVAHI_CLIENT_S_RUNNING:

Expand Down Expand Up @@ -384,13 +386,16 @@ client_callback(AvahiClient *c, AvahiClientState state, void *userdata)
}
#endif

#if STOS
static int hostname_changed;
#endif

/**
*
*/
static void *
avahi_thread(void *aux)
{
AvahiSimplePoll *asp = avahi_simple_poll_new();
const AvahiPoll *ap = avahi_simple_poll_get(asp);

AvahiClient *c;
Expand All @@ -406,7 +411,20 @@ avahi_thread(void *aux)
avahi_client_new(ap, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, NULL);
#endif

while((avahi_simple_poll_iterate(asp, -1)) != -1) {}
#if STOS
avahi_client_set_host_name(c, gconf.system_name);
#endif

while((avahi_simple_poll_iterate(asp, -1)) != -1) {
#if STOS
if(avahi_client_get_state(c) != AVAHI_CLIENT_S_REGISTERING) {
if(hostname_changed) {
hostname_changed = 0;
avahi_client_set_host_name(c, gconf.system_name);
}
}
#endif
}

return NULL;
}
Expand All @@ -418,6 +436,22 @@ avahi_thread(void *aux)
void
avahi_init(void)
{
asp = avahi_simple_poll_new();

hts_thread_create_detached("AVAHI", avahi_thread, NULL,
THREAD_PRIO_BGTASK);
}

#if STOS

/**
*
*/
void
avahi_update_hostname(void)
{
hostname_changed = 1;
if(asp != NULL)
avahi_simple_poll_wakeup(asp);
}
#endif
25 changes: 7 additions & 18 deletions src/settings.c
Expand Up @@ -1186,6 +1186,11 @@ static void
set_system_name(void *opaque, const char *str)
{
snprintf(gconf.system_name, sizeof(gconf.system_name), "%s", str);
#if STOS && ENABLE_AVAHI
extern void avahi_update_hostname(void);
avahi_update_hostname();
#endif

}


Expand Down Expand Up @@ -1253,29 +1258,13 @@ settings_init(void)
// Add configurable system name

htsmsg_t *s = htsmsg_store_load("netinfo") ?: htsmsg_create_map();

const char *sysname = NULL;
#if !defined(STOS) && (defined(linux) || defined(__APPLE__))
char hname[64];
if(!gethostname(hname, sizeof(hname)))
sysname = hname;
#endif

if(sysname == NULL)
sysname = showtime_get_system_type();



char default_name[64];
snprintf(default_name, sizeof(default_name), "Showtime on %s", sysname);


setting_create(SETTING_STRING, gconf.settings_network,
SETTINGS_INITIAL_UPDATE | SETTINGS_EMPTY_IS_DEFAULT,
SETTING_TITLE(_p("System name")),
SETTING_VALUE(default_name),
SETTING_VALUE("Showtime"),
SETTING_CALLBACK(set_system_name, NULL),
SETTING_HTSMSG("systemname", s, "netinfo"),
SETTING_HTSMSG("sysname", s, "netinfo"),
NULL);


Expand Down

0 comments on commit 15746f9

Please sign in to comment.