int discovery_search_result(struct Upnp_Discovery *event) { if (event->ErrCode != UPNP_E_SUCCESS) { fprintf(stderr, "Error in discovering device\n"); exit(-1); } IXML_Document *desc = NULL; int ret = UpnpDownloadXmlDoc(event->Location, &desc); if (ret != UPNP_E_SUCCESS) { fprintf(stderr, "Error in obtaining device description\n"); exit(-1); } const char *UUID = get_device_property(desc, "UDN"); if (!list_contains(&devices, UUID, chromecast_matches_UUID)) { struct chromecast_device *device = malloc(sizeof(struct chromecast_device)); device->addr = ((struct sockaddr_in *)&event->DestAddr)->sin_addr; device->device_name = create_string_copy(get_device_property(desc, "friendlyName")); device->device_type = create_string_copy(get_device_property(desc, "deviceType")); device->device_UUID = create_string_copy(UUID); device->device_OS = create_string_copy(event->Os); device->device_manufacturer = create_string_copy(get_device_property(desc, "manufacturer")); device->device_model_name = create_string_copy(get_device_property(desc, "modelName")); device->service_type = create_string_copy(get_device_property(desc, "serviceType")); device->service_version = create_string_copy(event->ServiceVer); device->service_id = create_string_copy(get_device_property(desc, "serviceId")); list_add_sync(&devices, device); print_device(device); } ixmlDocument_free(desc); return 0; }
void RoiCounters::init_device() { INFO_STREAM << "RoiCounters::init_device() create device " << device_name << endl; yat::AutoMutex<> _lock(ControlFactory::instance().get_global_mutex()); // Initialise variables to default values //-------------------------------------------- get_device_property(); CREATE_DEVSTRING_ATTRIBUTE(attr_version_read, 256); //By default INIT, need to ensure that all objets are OK before set the device to STANDBY set_state(Tango::INIT); m_is_device_initialized = false; m_status_message.str(""); try { yat::AutoMutex<> _lock(ControlFactory::instance().get_global_mutex()); //- get the main object used to pilot the lima framework //in fact LimaDetector is create the singleton control objet m_ct = ControlFactory::instance().get_control("RoiCounters"); } catch(Exception& e) { INFO_STREAM << "Initialization Failed : " << e.getErrMsg() << endl; m_status_message << "Initialization Failed : " << e.getErrMsg() << endl; m_is_device_initialized = false; set_state(Tango::FAULT); return; } catch(...) { INFO_STREAM << "Initialization Failed : UNKNOWN" << endl; m_status_message << "Initialization Failed : UNKNOWN" << endl; set_state(Tango::FAULT); m_is_device_initialized = false; return; } //--------------------------------------------------------- //Configure/create all dynamic attributes //--------------------------------------------------------- if(!create_all_dynamic_attributes()) { m_is_device_initialized = false; return; } try { //create new operation std::stringstream opId("MyRoiCounters"); INFO_STREAM << "addOp(" << opId.str() << ")" << endl; m_ct->externalOperation()->addOp(ROICOUNTERS, opId.str(), 0/*level*/, m_soft_operation); //Write tango hardware at Init std::stringstream ssName; std::string strName; for(size_t i = 0; i < nbRoiCounters; i++) { //get memorized from properties attr_x_array[i] = (Tango::DevULong)(__x.at(i)); attr_y_array[i] = (Tango::DevULong)(__y.at(i)); attr_width_array[i] = (Tango::DevULong)(__width.at(i)); attr_height_array[i] = (Tango::DevULong)(__height.at(i)); ssName.str(""); ssName << "x" << i; strName = ssName.str(); INFO_STREAM << "Write tango hardware at Init - " << strName << endl; Tango::WAttribute &x = dev_attr->get_w_attr_by_name(strName.c_str()); x.set_write_value(attr_x_array[i]); yat4tango::DynamicAttributeWriteCallbackData cbd_x; cbd_x.tga = &x; write_rois_callback(cbd_x); ssName.str(""); ssName << "y" << i; strName = ssName.str(); INFO_STREAM << "Write tango hardware at Init - " << strName << endl; Tango::WAttribute &y = dev_attr->get_w_attr_by_name(strName.c_str()); y.set_write_value(attr_y_array[i]); yat4tango::DynamicAttributeWriteCallbackData cbd_y; cbd_y.tga = &y; write_rois_callback(cbd_y); ssName.str(""); ssName << "width" << i; strName = ssName.str(); INFO_STREAM << "Write tango hardware at Init - " << strName << endl; Tango::WAttribute &width = dev_attr->get_w_attr_by_name(strName.c_str()); width.set_write_value(attr_width_array[i]); yat4tango::DynamicAttributeWriteCallbackData cbd_width; cbd_width.tga = &width; write_rois_callback(cbd_width); ssName.str(""); ssName << "height" << i; strName = ssName.str(); INFO_STREAM << "Write tango hardware at Init - " << strName << endl; Tango::WAttribute &height = dev_attr->get_w_attr_by_name(strName.c_str()); height.set_write_value(attr_height_array[i]); yat4tango::DynamicAttributeWriteCallbackData cbd_height; cbd_height.tga = &height; write_rois_callback(cbd_height); } } catch(Exception& e) { ERROR_STREAM << "Initialization Failed : " << e.getErrMsg() << endl; m_status_message << "Initialization Failed : " << e.getErrMsg() << endl; m_is_device_initialized = false; set_state(Tango::FAULT); return; } catch(Tango::DevFailed& df) { ERROR_STREAM << df << endl; m_status_message << "Initialization Failed : "; for(unsigned i = 0; i < df.errors.length(); i++) { m_status_message << df.errors[i].desc << endl; } m_is_device_initialized = false; set_state(Tango::FAULT); return; } catch(...) { ERROR_STREAM << "Initialization Failed : UNKNOWN" << endl; m_status_message << "Initialization Failed : UNKNOWN" << endl; set_state(Tango::FAULT); m_is_device_initialized = false; return; } //everything is Ok m_is_device_initialized = true; set_state(Tango::STANDBY); dev_state(); }