Esempio n. 1
0
bool ContentDirectory::CreateObject(const std::string& containerID, const DigitalItemPtr& element)
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("ContainerID", containerID)));
  args.push_back(ElementPtr(new Element("Elements", element->DIDL())));
  vars = Request("CreateObject", args);
  if (!vars.empty() && vars[0]->compare("CreateObjectResponse") == 0)
    return true;
  return false;
}
Esempio n. 2
0
bool RenderingControl::GetMute(uint8_t* value, const char* channel)
{
  ElementList args;
  args.push_back(ElementPtr(new Element("InstanceID", "0")));
  args.push_back(ElementPtr(new Element("Channel", channel)));
  ElementList vars = Request("GetMute", args);
  if (!vars.empty() && vars[0]->compare("GetMuteResponse") == 0)
  {
    ElementList::const_iterator it = vars.FindKey("CurrentMute");
    if (it != vars.end())
      return (string_to_uint8((*it)->c_str(), value) == 0);
  }
  return false;
}
Esempio n. 3
0
bool RenderingControl::SetVolume(uint8_t value, const char* channel)
{
  char buf[4];
  memset(buf, 0, sizeof (buf));
  uint8_to_string(value, buf);
  ElementList args;
  args.push_back(ElementPtr(new Element("InstanceID", "0")));
  args.push_back(ElementPtr(new Element("Channel", channel)));
  args.push_back(ElementPtr(new Element("DesiredVolume", buf)));
  ElementList vars = Request("SetVolume", args);
  if (!vars.empty() && vars[0]->compare("SetVolumeResponse") == 0)
    return true;
  return false;
}
Esempio n. 4
0
bool ContentDirectory::RefreshShareIndex()
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("AlbumArtistDisplayOption", "")));
  vars = Request("RefreshShareIndex", args);
  if (!vars.empty() && vars[0]->compare("RefreshShareIndexResponse") == 0)
    return true;
  return false;
}
Esempio n. 5
0
bool ContentDirectory::DestroyObject(const std::string& objectID)
{
  ElementList vars;
  ElementList args;
  args.push_back(ElementPtr(new Element("ObjectID", objectID)));
  vars = Request("DestroyObject", args);
  if (!vars.empty() && vars[0]->compare("DestroyObjectResponse") == 0)
    return true;
  return false;
}
Esempio n. 6
0
ElementList Element::getElementsByName(string name)
{
	ElementList list;
	for(int i=0;i<(int)this->elements.size();i++)
	{
		if(this->elements.at(i).getTagName()==name)
			list.push_back(this->elements.at(i));
	}
	return list;
}
Esempio n. 7
0
void ElementUtilities::GetElementsByClassName(ElementList& elements, Element* root_element, const String& class_name)
{
	// Breadth first search on elements for the corresponding id
	typedef std::queue< Element* > SearchQueue;
	SearchQueue search_queue;
	for (int i = 0; i < root_element->GetNumChildren(); ++i)
		search_queue.push(root_element->GetChild(i));

	while (!search_queue.empty())
	{
		Element* element = search_queue.front();
		search_queue.pop();

		if (element->IsClassSet(class_name))
			elements.push_back(element);

		// Add all children to search.
		for (int i = 0; i < element->GetNumChildren(); i++)
			search_queue.push(element->GetChild(i));
	}
}
Esempio n. 8
0
void ElementUtilities::GetElementsByTagName(ElementList& elements, Element* root_element, const String& tag)
{
	// Breadth first search on elements for the corresponding id
	typedef Container::queue< Element* >::Type SearchQueue;
	SearchQueue search_queue;
	for (int i = 0; i < root_element->GetNumChildren(); ++i)
		search_queue.push(root_element->GetChild(i));

	while (!search_queue.empty())
	{
		Element* element = search_queue.front();
		search_queue.pop();

		if (element->GetTagName() == tag)
			elements.push_back(element);

		// Add all children to search.
		for (int i = 0; i < element->GetNumChildren(); i++)
			search_queue.push(element->GetChild(i));
	}
}
Esempio n. 9
0
bool ContentDirectory::Browse(const std::string& objectId, unsigned index, unsigned count, ElementList &vars)
{
  char buf[11];
  ElementList args;
  args.push_back(ElementPtr(new Element("ObjectID", objectId)));
  args.push_back(ElementPtr(new Element("BrowseFlag", "BrowseDirectChildren")));
  args.push_back(ElementPtr(new Element("Filter", "*")));
  uint32_to_string((uint32_t)index, buf);
  args.push_back(ElementPtr(new Element("StartingIndex", buf)));
  uint32_to_string((uint32_t)count, buf);
  args.push_back(ElementPtr(new Element("RequestedCount", buf)));
  args.push_back(ElementPtr(new Element("SortCriteria", "")));
  vars = Request("Browse", args);
  if (!vars.empty() && vars[0]->compare("BrowseResponse") == 0)
    return true;
  return false;
}
Esempio n. 10
0
// This is a rather ugly and slow way to delete a section.  It can leave stray
// comments in the middle of sections, but will remove the section entirely,
// even if it is multiply declared.  This whole function was a bit of an
// afterthought, since it isn't very likely to be used in the application this
// class was written for.  Sorry to all the purists out there.  :-(
void SimpleConfig::delSection(std::string const &section_name) {
	ConfigDictionary::iterator i = m_last.find(section_name);
	if (i != m_last.end()) {
		ElementList rebuild;
		ElementList::iterator at;
		bool blank = false;
		for (at = m_elements.begin(); at != m_elements.end(); at++) {
			ConfigSection *section = dynamic_cast<ConfigSection *>(*at);
			if (section && section->getName() == section_name) {
				delete *at;
				continue;
			}
			ConfigValue *value = dynamic_cast<ConfigValue *>(*at);
			if (value && value->getSection() == section_name) {
				std::string index = _hash_index(section_name, value->getKey());
				ConfigDictionary::iterator i = m_dict.find(index);
				if (i != m_dict.end()) m_dict.erase(i);
				delete *at;
				continue;
			}
			ConfigComment *comment = dynamic_cast<ConfigComment *>(*at);
			if (comment && comment->getComment() == "") {
				if (blank) {
					delete *at;
					continue;
				}
				blank = true;
			} else blank = false;
			rebuild.push_back(*at);
		}
		m_elements = rebuild;
		m_modified = true;
		if (m_autosave) save();
		m_last.erase(i);
	}
}
Esempio n. 11
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // temp vars
    QStringList pieces;
    QString line;
    QString delimiterPattern(","), tempData;

    int dimension = 2;
    int nInc = 100;

    // ========================= NODES FILE (open and read nodes file) =========================
    QString nodesFile = QFileDialog::getOpenFileName(this, QObject::tr("Open Nodes File"),"",QObject::tr("Data (*.dat*);; Text (*.txt*)"));

    QFile fileNodes(nodesFile);
    fileNodes.open(QIODevice::ReadOnly | QIODevice::Text);

    // get number of lines
    QTextStream inNodes(&fileNodes);

    NodeList nodes;
    DoubleList coords(2);
    DoubleList coordsPrescribed(2);
    double x1,x2,x1t,x2t;
    bool bflag;

    int idxNode = 0;
    while (!inNodes.atEnd())
    {
        // read node
        line = inNodes.readLine();
        pieces = line.split(delimiterPattern);

        tempData = pieces.value(0);
        x1 = tempData.toDouble();
        tempData = pieces.value(1);
        x2 = tempData.toDouble();
        tempData = pieces.value(2);
        bflag = tempData.toDouble();
        bflag = (bool) bflag;
        tempData = pieces.value(3);
        x1t = tempData.toDouble();
        tempData = pieces.value(4);
        x2t = tempData.toDouble();

        coords[0] = x1;
        coords[1] = x2;

        coordsPrescribed[0] = x1t;
        coordsPrescribed[1] = x2t;

        // write nodes array
        if (bflag)
        {
            nodes.push_back(Node());
            nodes[idxNode].initializeNode(coords,idxNode,dimension,bflag);
            nodes[idxNode].setPrescribedDisplacement(coordsPrescribed);
        }
        else
        {
            nodes.push_back(Node());
            nodes[idxNode].initializeNode(coords,idxNode,dimension,bflag);
        }

        // update counter
        idxNode++;

    }

    // total number of nodes
    int nNodes = idxNode;

    fileNodes.close();


    // ========================= ELEMENTS FILE (open and read nodes file) =========================

    QString elementsFile = QFileDialog::getOpenFileName(this, QObject::tr("Open Elements File"),"",QObject::tr("Data (*.dat*);; Text (*.txt*)"));

    QFile fileElements(elementsFile);
    fileElements.open(QIODevice::ReadOnly | QIODevice::Text);

    // get number of lines
    QTextStream inElements(&fileElements);

    ElementList elements;
    int idxN1,idxN2;
    double cl,ch,cutoff;

    int idxElement = 0;
    while (!inElements.atEnd())
    {
        // read node
        line = inElements.readLine();
        pieces = line.split(delimiterPattern);

        tempData = pieces.value(0);
        idxN1 = tempData.toDouble();
        idxN1 = (int) idxN1;
        tempData = pieces.value(1);
        idxN2 = tempData.toDouble();
        idxN2 = (int) idxN2;
        tempData = pieces.value(2);
        cl = tempData.toDouble();
        tempData = pieces.value(3);
        ch = tempData.toDouble();
        tempData = pieces.value(4);
        cutoff = tempData.toDouble();

        // write elements array
        elements.push_back(Element(nodes[idxN1],nodes[idxN2],cl,ch,cutoff));

        // update counter
        idxElement++;

    }

    // total number of nodes
    int nElements = idxElement;

    fileElements.close();


    // ========================= INITIALIZE NETWORK AND SOLVE =========================

    Network network(nodes,elements,nNodes,nElements,nInc);

}