// netservice callback void ofxBonjourIp::NetServicePublishedCallBack(CFNetServiceRef theService, CFStreamError* error, void* info) { if(error->error != 0) ofLog() << "Error: " << error->error; const char *type = CFStringGetCStringPtr(CFNetServiceGetType(theService), kCFStringEncodingMacRoman); //_ofxBonjourIp._tcp. ofLog() << "type: " << type; const char *domain = CFStringGetCStringPtr(CFNetServiceGetDomain(theService), kCFStringEncodingMacRoman); //local. ofLog() << "domain: " << domain; int port = CFNetServiceGetPortNumber(theService); //7777 ofLog() << "port: " << port; const char *name = CFStringGetCStringPtr(CFNetServiceGetName(theService), kCFStringEncodingMacRoman); ofLog() << "name: " << name; // name is "" if not defined. should become device name once resolved? // info has a reference to the class object if(info != NULL) { // set the device ip ofxBonjourIp* bonjour = (ofxBonjourIp*)info; bonjour->deviceIp = ofxBonjourIp::GetMyIPAddress(); ofLog() << "device ip: " << bonjour->getDeviceIp(); // set the device name char szHostName[255]; gethostname(szHostName, 255); bonjour->deviceHostName = szHostName; ofLog() << "device host name: " << bonjour->getDeviceHostName(); ofNotifyEvent(bonjour->publishedServiceEvent,bonjour->deviceIp,bonjour); } }
void CZeroconfBrowserOSX::BrowserCallback(CFNetServiceBrowserRef browser, CFOptionFlags flags, CFTypeRef domainOrService, CFStreamError *error, void *info) { assert(info); if (error->error == noErr) { //make sure we receive a service assert(!(flags&kCFNetServiceFlagIsDomain)); CFNetServiceRef service = (CFNetServiceRef)domainOrService; assert(service); //get our instance CZeroconfBrowserOSX* p_this = reinterpret_cast<CZeroconfBrowserOSX*>(info); //store the service std::string name, type, domain; if (!DarwinCFStringRefToUTF8String(CFNetServiceGetName(service), name) || !DarwinCFStringRefToUTF8String(CFNetServiceGetType(service), type) || !DarwinCFStringRefToUTF8String(CFNetServiceGetDomain(service), domain)) { CLog::Log(LOGWARNING, "CZeroconfBrowserOSX::BrowserCallback failed to convert service strings."); return; } ZeroconfService s(name, type, domain); if (flags & kCFNetServiceFlagRemove) { CLog::Log(LOGDEBUG, "CZeroconfBrowserOSX::BrowserCallback service named: %s, type: %s, domain: %s disappeared", s.GetName().c_str(), s.GetType().c_str(), s.GetDomain().c_str()); p_this->removeDiscoveredService(browser, flags, s); } else { CLog::Log(LOGDEBUG, "CZeroconfBrowserOSX::BrowserCallback found service named: %s, type: %s, domain: %s", s.GetName().c_str(), s.GetType().c_str(), s.GetDomain().c_str()); p_this->addDiscoveredService(browser, flags, s); } if (! (flags & kCFNetServiceFlagMoreComing) ) { CGUIMessage message(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_PATH); message.SetStringParam("zeroconf://"); g_windowManager.SendThreadMessage(message); CLog::Log(LOGDEBUG, "CZeroconfBrowserOSX::BrowserCallback sent gui update for path zeroconf://"); } } else { CLog::Log(LOGERROR, "CZeroconfBrowserOSX::BrowserCallback returned" "(domain = %d, error = %" PRId64")", (int)error->domain, (int64_t)error->error); } }