예제 #1
0
void Publisher::entryGroupCallback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *context) {
	Publisher *publisher = (Publisher*) context;
	const char* name = publisher->info.getServiceName().c_str();
	const int port = publisher->info.getPort();

	// callback called whenever our entry group state changes
	switch (state) {
	case AVAHI_ENTRY_GROUP_ESTABLISHED:
		std::cout << "Registration ok:" << name <<":" << port << " (" << publisher->serviceType << ")" << std::endl;
		break;
	case AVAHI_ENTRY_GROUP_COLLISION:
		// build new name
		publisher->nextName();
		// retry
		publisher->createServices(avahi_entry_group_get_client(g));
		break;
	case AVAHI_ENTRY_GROUP_FAILURE:
		std::cerr << "Registration failure ("
				<< avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g)))
				<< ")" << std::endl;
		publisher->quit();
		break;
	case AVAHI_ENTRY_GROUP_UNCOMMITED:
	case AVAHI_ENTRY_GROUP_REGISTERING:
		;
	}
}
예제 #2
0
void Publisher::clientCallback(AvahiClient *client, AvahiClientState state, void *context) {
	Publisher *publisher = (Publisher*) context;

	// called on every server state change
	switch (state) {
	case AVAHI_CLIENT_S_RUNNING:
		// server is fine, we can register
		publisher->createServices(client);
		break;
	case AVAHI_CLIENT_S_COLLISION:
	case AVAHI_CLIENT_S_REGISTERING:
		// server not ready (collision, registering)
		// make sure we restart registration
		avahi_entry_group_reset(publisher->group);
		break;
	case AVAHI_CLIENT_CONNECTING:
		// wait
		break;
	case AVAHI_CLIENT_FAILURE:
		std::cerr << "Server connection failure: "
					<<  avahi_strerror(avahi_client_errno(client)) << std::endl;
		publisher->quit();
	}
}