void Publisher::createServices(AvahiClient *client) { int error; const char* name = info.getServiceName().c_str(); int port = info.getPort(); if (group == NULL) { group = avahi_entry_group_new(client, &Publisher::entryGroupCallback, this); if (group == NULL) { std::cerr << "Could not create avahi group (" << avahi_strerror(avahi_client_errno(client)) << ")." << std::endl; return; } } if (avahi_entry_group_is_empty(group)) { // new group or after reset error = avahi_entry_group_add_service(group, // group AVAHI_IF_UNSPEC, // interface AVAHI_PROTO_UNSPEC, // protocol to announce service with AVAHI_PUBLISH_USE_MULTICAST, // flags name, // service name serviceType, // service type NULL, // domain NULL, // host port, // port txtDataDeviceName.c_str(), txtDataProviderClassName.c_str(), txtDataSerialNumber.c_str(), NULL); // list of txt records if (error < 0) { // error if (error == AVAHI_ERR_COLLISION) { // collision with local service name nextName(); avahi_entry_group_reset(group); // retry createServices(client); } else { std::cerr << "Could not add service '" << name << "' (" << serviceType << ") to avahi group (" << avahi_strerror(error) << ")" << std::endl; return; } } // start registering the service error = avahi_entry_group_commit(group); if (error < 0) { std::cerr << "Could not commit avahi group " << "'" << name << "'" << " (" << avahi_strerror(error) << ")" << std::endl; } } }
void CommunicationManager::createServices(AvahiClient *c) { char *n, r[128]; int ret; /* If this is the first time we're called, let's create a new * entry group if necessary */ if (!this->group) { if (!(group = avahi_entry_group_new(c, CommunicationManager::entryGroupCallback, NULL))) { cout << "avahi_entry_group_new() failed: " << avahi_strerror(avahi_client_errno(c)) << endl; avahi_simple_poll_quit(simplePoll); return; } } /* If the group is empty (either because it was just created, or * because it was reset previously, add our entries. */ if (avahi_entry_group_is_empty(group)) { cout << "Adding service '" << name << "'" << endl;; /* Create some random TXT data */ snprintf(r, sizeof(r), "random=%i", rand()); /* We will now add two services and one subtype to the entry * group. The two services have the same name, but differ in * the service type (IPP vs. BSD LPR). Only services with the * same name should be put in the same entry group. */ /* Add the service for GingaMultimodalEvent*/ if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, (AvahiPublishFlags)0, name, "_GingaMultimodalEvent._tcp", NULL, NULL, 1234, "test=blah", r, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) { /* A service name collision with a local service happened. * Let's pick a new name */ n = avahi_alternative_service_name(name); avahi_free(name); name = n; cout << "Service name collision, renaming service to '" << name << "'" << endl; avahi_entry_group_reset(group); createServices(c); return; } cout << "Failed to add _GingaMultimodalEvent._tcp service: " << avahi_strerror(ret) << endl; avahi_simple_poll_quit(simplePoll); return; } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { cout << "Failed to commit entry group: " << avahi_strerror(ret) << endl; avahi_simple_poll_quit(simplePoll); } } }
void PyEntity::createPyServices( const PyEntityInput& input ) { createServices(*this,input.fServices); }