Example #1
0
bool CSettings::Load(const char* file)
{
  if (m_xmlDocument.LoadFile(file))
  {
    TiXmlElement* pRootElement = m_xmlDocument.RootElement();
    if (pRootElement)
    {
      TiXmlElement* pPdbFilesElement = pRootElement->FirstChildElement(ELEMENT_REGISTERED_PDB_FILES);
      if (pPdbFilesElement)
      {
        // get all the registered files
        TiXmlNode* pFileNode = NULL;
        pFileNode = pPdbFilesElement->IterateChildren("File", pFileNode);
        while (pFileNode)
        {
          TiXmlElement* pFileElement = pFileNode->ToElement();
          if (!pFileElement) return false;
          std::string pdbFile = pFileElement->GetText();
          m_pdbFiles.push_back(pdbFile);
          
          pFileNode = pPdbFilesElement->IterateChildren("File", pFileNode);
        }
      }
      return true;
    }
  }
  
  return false;
}
Example #2
0
void PlayerParameters::SaveParam(int index)
{
    TiXmlDocument fichier("data/player/param.xml");
    if(!fichier.LoadFile(TIXML_ENCODING_LEGACY))
        throw Exception("Impossible de charger le fichier: data/player/param.xml");

    TiXmlElement *rootNode = fichier.RootElement();
    TiXmlNode *player = 0;
    while((player=rootNode->IterateChildren("player",player)))
    {
        int current;
        player->ToElement()->Attribute("numero", &current);
        if(current==index)
        {
            player->FirstChild("rouge")->ToElement()->SetAttribute("value", m_param[index].couleur.r);
            player->FirstChild("vert")->ToElement()->SetAttribute("value", m_param[index].couleur.g);
            player->FirstChild("bleu")->ToElement()->SetAttribute("value", m_param[index].couleur.b);
            player->FirstChild("touches")->Clear();
            player->ToElement()->SetAttribute("name", Sanitanyse(m_param[index].nom));
            for(auto it: m_param[index].touches)
            {
                TiXmlNode *toucheNode = new TiXmlElement("touche");
                toucheNode->ToElement()->SetAttribute("name", it.first);
                toucheNode->ToElement()->SetAttribute("code", it.second);
                player->FirstChild("touches")->ToElement()->LinkEndChild(toucheNode);
            }

            fichier.SaveFile("data/player/param.xml");
            return;
        }
    }
}
Example #3
0
bool BXBoxeeWebFavorites::Parse()
{
  TiXmlHandle docHandle(&m_doc);

  TiXmlElement *pChild = docHandle.FirstChild("bookmarks").Element();
  if (!pChild)
  {
    LOG(LOG_LEVEL_ERROR,"BXBoxeeWebFavorites::Parse - FAILED to find <bookmark> node");
    return false;
  }

  m_webFavorites.clear();

  TiXmlNode *pMsgNode = 0;
  while ((pMsgNode = pChild->IterateChildren(pMsgNode)) != NULL)
  {
    if (pMsgNode->ValueStr().compare("bookmark") == 0)
    {
      BXObject obj;
      if (obj.FromXML(pMsgNode))
      {
        m_webFavorites.push_back(obj);
      }
    }
  }

  return true;
}
Example #4
0
bool CMetadataResolverMusic::LoadAlbumsInfo(BOXEE::BXXMLDocument& doc, vectorMetadata& list)
{
  TiXmlElement* pRootElement = doc.GetDocument().RootElement();
  bool bRetVal = true;
  if (pRootElement->ValueStr() == "results")
  {
    TiXmlNode* pTag = 0;
    BXMetadata album(MEDIA_ITEM_TYPE_AUDIO);

    while ((pTag = pRootElement->IterateChildren(pTag)))
    {
      if (pTag && pTag->ValueStr() == "album")
      {
        TiXmlElement* pValue = pTag->FirstChildElement();

        if (pValue && (LoadAlbumInfo(pValue,album)))
          list.push_back(album);
        else
           bRetVal = false;
      }
      else
        bRetVal = false;
    }
  }
  else
    bRetVal = false;

  return bRetVal;
}
Example #5
0
void COptions::SetXmlValue(unsigned int nID, wxString value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	char *utf8 = ConvUTF8(value);
	if (!utf8)
		return;

	TiXmlElement *settings = m_pXmlFile->GetElement()->FirstChildElement("Settings");
	if (!settings)
	{
		TiXmlNode *node = m_pXmlFile->GetElement()->LinkEndChild(new TiXmlElement("Settings"));
		if (!node)
		{
			delete [] utf8;
			return;
		}
		settings = node->ToElement();
		if (!settings)
		{
			delete [] utf8;
			return;
		}
	}
	else
	{
		TiXmlNode *node = 0;
		while ((node = settings->IterateChildren("Setting", node)))
		{
			TiXmlElement *setting = node->ToElement();
			if (!setting)
				continue;

			const char *attribute = setting->Attribute("name");
			if (!attribute)
				continue;
			if (strcmp(attribute, options[nID].name))
				continue;

			//setting->RemoveAttribute("type");
			setting->Clear();
			//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
			setting->LinkEndChild(new TiXmlText(utf8));

			delete [] utf8;
			return;
		}
	}
	wxASSERT(options[nID].name[0]);
	TiXmlElement *setting = new TiXmlElement("Setting");
	setting->SetAttribute("name", options[nID].name);
	//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
	setting->LinkEndChild(new TiXmlText(utf8));
	settings->LinkEndChild(setting);

	delete [] utf8;
}
Example #6
0
bool BXBoxeeServices::Parse()
{
    TiXmlHandle docHandle(&m_doc);
    TiXmlNode* pTSChild = docHandle.FirstChild("services").FirstChild("timestamp").FirstChild().Node();

    if (pTSChild)
    {
        m_timestamp = atoi(pTSChild->Value());
    }

    TiXmlElement *pChild = docHandle.FirstChild("services").Element();
    if (!pChild)
    {
        LOG(LOG_LEVEL_ERROR,"BXBoxeeServices::Parse - FAILED to find <applications> node");
        return false;
    }

    m_services.clear();

    TiXmlNode *pMsgNode = 0;
    while ((pMsgNode = pChild->IterateChildren(pMsgNode)) != NULL)
    {
        if (pMsgNode->ValueStr().compare("object") == 0)
        {
            BXObject obj;
            if (obj.FromXML(pMsgNode))
            {
                m_services.push_back(obj);
            }
        }
    }

    return true;
}
Example #7
0
void N7Xml::list_channels()
{
  CStdString strUrl;
  strUrl.Format("http://%s:%i/n7channel_nt.xml", g_strHostname.c_str(), g_iPort);
  CStdString strXML;

  CCurlFile http;
  if(!http.Get(strUrl, strXML))
  {
    XBMC->Log(LOG_DEBUG, "N7Xml - Could not open connection to N7 backend.");
  }
  else
  {
    TiXmlDocument xml;
    xml.Parse(strXML.c_str());
    TiXmlElement* rootXmlNode = xml.RootElement();
    if (rootXmlNode == NULL)
      return;
    TiXmlElement* channelsNode = rootXmlNode->FirstChildElement("channel");
    if (channelsNode)
    {
      XBMC->Log(LOG_DEBUG, "N7Xml - Connected to N7 backend.");
      m_connected = true;
      int iUniqueChannelId = 0;
      TiXmlNode *pChannelNode = NULL;
      while ((pChannelNode = channelsNode->IterateChildren(pChannelNode)) != NULL)
      {
        CStdString strTmp;
        PVRChannel channel;

        /* unique ID */
        channel.iUniqueId = ++iUniqueChannelId;

        /* channel number */
        if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
          channel.iChannelNumber = channel.iUniqueId;

        /* channel name */
        if (!XMLUtils::GetString(pChannelNode, "title", strTmp))
          continue;
        channel.strChannelName = strTmp;

        /* icon path */
        const TiXmlElement* pElement = pChannelNode->FirstChildElement("media:thumbnail");
        channel.strIconPath = pElement->Attribute("url");

        /* channel url */
        if (!XMLUtils::GetString(pChannelNode, "guid", strTmp))
          channel.strStreamURL = "";
        else
          channel.strStreamURL = strTmp;

        m_channels.push_back(channel);
      }
    }
  }
}
Example #8
0
void PlayerParameters::Load()
{
    TiXmlDocument fichier("data/player/param.xml");
    if(!fichier.LoadFile(TIXML_ENCODING_LEGACY))
        throw Exception("Impossible de charger le fichier: data/player/param.xml");

    TiXmlElement *rootNode = fichier.RootElement();
    TiXmlNode *player = 0;
    while((player=rootNode->IterateChildren("player",player)))
    {
        LoadPlayer(player);
    }
}
	void load( const TiXmlElement & elem, data::Crop & data ) const
	{
		data.id 		= xml::attribute( elem, "id" );
		data.seed 	= &db::getItem( xml::attribute( elem, "seedID" ) );
		data.crop 	= &db::getItem( xml::attribute( elem, "cropID" ) );
		data.image 	= xml::attribute( elem, "image" );
		data.seasons	= time::parseSeasons( xml::attribute( elem, "season" ) );
		data.regrowth	= std::stoi( xml::attribute( elem, "regrowth" ) );
		
		const TiXmlNode * it = nullptr;
		while ( ( it = elem.IterateChildren( "stage", it ) ) )
			data.growth.push_back( std::stoi( xml::attribute( static_cast< const TiXmlElement & >( *it ), "length" ) ) );
			
		if ( data.regrowth != 0 && data.regrowth > data.growth.size() )
			throw Exception( "regrowth index is invalid" );
	}
	void load( const TiXmlElement & elem, data::Item & data ) const 
	{ 
		data.id		= xml::attribute( elem, "id" );
		data.name		= xml::attribute( elem, "name" );
		data.desc		= xml::attribute( elem, "desc" );
		data.image	= xml::attribute( elem, "icon" );

		data.buy		= std::stoi( xml::attribute( elem, "buy" ) );
		data.sell		= std::stoi( xml::attribute( elem, "sell" ) );

		const TiXmlNode* it = nullptr;
		while ( ( it = elem.IterateChildren( "attribute", it ) ) )
		{
			const TiXmlElement& child = static_cast< const TiXmlElement& >( *it );
			data.attributes.insert( xml::attribute( child, "type" ) );
		}
	}
Example #11
0
bool OutputFile::getIt(ParamQt * p)
{
  int deb=0;
  currentIteration++;
  p->setRho(0);
  p->setTheta(0);
  p->setLL(0);
  TiXmlHandle root(&mDoc);
  TiXmlHandle h = root.FirstChild("outputFile");
  TiXmlHandle hIter = h.Child("Iteration", currentIteration);

  TiXmlElement* t;
  // <Tree>
  t = hIter.FirstChild("Tree").ToElement();
  if (t == NULL) // Can I use hIter to return false?
    return false;
  string s(t->GetText());
  while (s.at(0)==10 || s.at(0)==13) s=s.substr(1,s.length()-1);
  while (s.at(s.size()-1)==10 || s.at(s.size()-1)==13) s=s.substr(0,s.length()-1);
  p->setTreeData(new RecTree(getL(),s,false,false),blocks);

  // <number>, <theta>, <delta>, <rho>, <ll>.
  t = hIter.FirstChild("number").ToElement(); p->setNumber(atol(t->GetText()));
  t = hIter.FirstChild("theta").ToElement();  p->setTheta(p->getTheta() + atof(t->GetText()));
  t = hIter.FirstChild("delta").ToElement();  p->setDelta(atof(t->GetText()));
  t = hIter.FirstChild("rho").ToElement();    p->setRho(p->getRho() + atof(t->GetText()));
  t = hIter.FirstChild("ll").ToElement();     p->setLL(p->getLL() + atof(t->GetText()));

  // <recedge>
  TiXmlElement* parent = hIter.ToElement(); 
  TiXmlElement* child = 0;
  while (child = (TiXmlElement*) parent->IterateChildren("recedge", child))
    {
      int start=0,end=0,efrom=0,eto=0;
      double ato=0,afrom=0;
      t = child->FirstChildElement("start"); start = deb + atoi(t->GetText());
      t = child->FirstChildElement("end"); end = deb + atoi(t->GetText());
      t = child->FirstChildElement("efrom"); efrom = atoi(t->GetText());
      t = child->FirstChildElement("eto"); eto = atoi(t->GetText());
      t = child->FirstChildElement("afrom"); afrom = atof(t->GetText());
      t = child->FirstChildElement("ato"); ato = atof(t->GetText());
      p->getTree()->addRecEdge(afrom,ato,start,end,efrom,eto);
    }
  return true;
}
bool CGetResultListBG::ParseResultListXml(const CStdString& strHtml, CFileItemList& items)
{
  TiXmlDocument xmlDoc;
  xmlDoc.Parse(strHtml);

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (!pRootElement)
    return false;

  if (strcmpi(pRootElement->Value(), "search") != 0)
  {
    CLog::Log(LOGERROR, "CGetResultListBG::ParseResultListXml, could not parse manual resolution results (manual)");
    return false;
  }

  const TiXmlNode* pTag = 0;
  while ((pTag = pRootElement->IterateChildren(pTag)))
  {
    if (pTag->ValueStr() == "title")
    {
      const TiXmlNode *pValue = pTag->FirstChild();
      CStdString strValue = pValue->ValueStr();

      // Find the id attribute, we do not know its name but we know that there are two attributes and it's not the one called 'year'
      CStdString idAttributeName;
      CStdString idAttributeValue;

      TiXmlAttribute* attribute = ((TiXmlElement*)pTag)->FirstAttribute();
      while (attribute)
      {
        if ((strcmpi(attribute->Name(), "year") != 0) && (strcmpi(attribute->Name(), "type") != 0))
        {
          idAttributeName = attribute->Name();
          idAttributeValue = attribute->Value();
        }
        attribute = attribute->Next();
      }

      if (idAttributeName.IsEmpty() || idAttributeValue.IsEmpty())
      {
        // this should not happen, each search result should have an id
        CLog::Log(LOGERROR, "CGetResultListBG::ParseResultListXml, search result without id, value = %s (manual)", strValue.c_str());
        continue;
      }

      // Get the year
      CStdString strYear = ((TiXmlElement*)pTag)->Attribute("year");

      CStdString strType = ((TiXmlElement*)pTag)->Attribute("type");

      bool bIsMovie = false;
      if (strType == "movie")
      {
        bIsMovie = true;
      }
      else if (strType == "tv")
      {
        bIsMovie = false;
      }
      else
      {
        CLog::Log(LOGERROR, "CGetResultListBG::ParseResultListXml, invalid type = %s (manual)", strType.c_str());
        continue;
      }

      CStdString strMovieTypeLabel = "Movie";
      CStdString strTvTypeLabel = "TV";

      // Format label and create file item
      CStdString strLabel;
      if (strYear.IsEmpty())
        strLabel.Format("%s (%s)", strValue.c_str(), bIsMovie ? strMovieTypeLabel.c_str() : strTvTypeLabel.c_str());
      else
        strLabel.Format("%s (%s) (%s)", strValue.c_str(), strYear.c_str(), bIsMovie ? strMovieTypeLabel.c_str() : strTvTypeLabel.c_str());

      CFileItemPtr resultItem (new CFileItem(strLabel));
      resultItem->SetProperty("type", "msearch");
      resultItem->SetProperty("manualresolve::Title", strValue);
      resultItem->SetProperty("manualresolve::Year", strYear);
      resultItem->SetProperty("manualresolve::idName", idAttributeName);
      resultItem->SetProperty("manualresolve::idValue", idAttributeValue);
      resultItem->SetProperty("manualresolve::isMovie", bIsMovie);
      items.Add(resultItem);

      CLog::Log(LOGDEBUG, "CGetResultListBG::ParseResultListXml, added item, title = %s, type = %s, year = %s, idName = %s, idValue = %s (manual)",
          strValue.c_str(), bIsMovie ? "movie" : "tv", strYear.c_str(), idAttributeName.c_str(), idAttributeValue.c_str());
    }
  }

  return items.Size() > 0;
}
Example #13
0
bool XMLScene::parseNode(TiXmlElement *curr_node, bool is_inside_dl) {

	char node_id[MAX_STRING_LEN];

	if (strdup(node_id, curr_node->Attribute("id")) == NULL) {
		printf("Error reading \"id\" attribute!\n");
		throw InvalidXMLException();
	}

	printf("id: %s\n", node_id);

	bool is_dl = false;
	string dl_node_id;
	if (curr_node->QueryBoolAttribute("displaylist", &is_dl) != TIXML_SUCCESS) {
		printf("No \"displaylist\" attribute\n");
	}

	if (is_dl) {
		printf("Node \"%s\" defined as a display list.\n", node_id);
		dl_node_id = Scene::getInstance()->findNextNameAvail(node_id);
		printf("dl_node_id: %s\n", dl_node_id.c_str());
	}

	Node *n;

	if (is_dl) {
		n = new DisplayList(dl_node_id);
	} else {
		n = new Node(node_id);
	}

	nodes_being_processed.push_back(node_id);

	printf("Processing transformations...\n");

	TiXmlElement *transf_block = NULL;
	if ((transf_block = curr_node->FirstChildElement("transforms")) == NULL) {
		printf("Could not find \"transforms\" block on %s node!\n", node_id);
		throw InvalidXMLException();
	}

	TiXmlElement *transf = NULL;
	while ((transf = (TiXmlElement*) transf_block->IterateChildren(transf))) {
		char t_type[MAX_STRING_LEN];
		if (strdup(t_type, transf->Value()) == NULL) {
			printf("Invalid transformation on node %s\n", node_id);
			throw InvalidXMLException();
		}
		if (strcmp(t_type, "translate") == 0) {
			char tmp_str[MAX_STRING_LEN];
			double t_x = 0, t_y = 0, t_z = 0;

			if (strdup(tmp_str, transf->Attribute("to")) == NULL) {
				printf("Error on translate transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}

			if (sscanf(tmp_str, "%lf %lf %lf", &t_x, &t_y, &t_z) != 3) {
				printf("Error parsing translate transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}

			n->addTranslate(t_x, t_y, t_z);

			printf("Translate\nto: (%f %f %f)\n", t_x, t_y, t_z);

		} else if (strcmp(t_type, "rotate") == 0) {
			char tmp_str[2];
			char r_axis = '\0';
			double r_angle;
			if (strdup(tmp_str, transf->Attribute("axis")) == NULL) {
				printf("Error on rotate transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}
			r_axis = tmp_str[0];

			if (transf->QueryDoubleAttribute("angle", &r_angle)) {
				printf("Error parsing rotate transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}

			n->addRotation(r_angle, r_axis);

			printf("Rotate\naxis: %c\nangle: %f\n", r_axis, r_angle);

		} else if (strcmp(t_type, "scale") == 0) {
			char tmp_str[MAX_STRING_LEN];
			double f_x = 0, f_y = 0, f_z = 0;

			if (strdup(tmp_str, transf->Attribute("factor")) == NULL) {
				printf("Error on scale transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}

			if (sscanf(tmp_str, "%lf %lf %lf", &f_x, &f_y, &f_z) != 3) {
				printf("Error parsing scale transformation on node %s!\n", node_id);
				throw InvalidXMLException();
			}

			n->addScale(f_x, f_y, f_z);

			printf("Scale\nfactor: (%f %f %f)\n", f_x, f_y, f_z);

		} else {
			printf("Invalid transformation on node %s\n", node_id);
			throw InvalidXMLException();
		}
	}

	TiXmlElement *appearance = NULL;
	if ((appearance = curr_node->FirstChildElement("appearanceref"))) {
		char app_id[MAX_STRING_LEN];
		if (strdup(app_id, appearance->Attribute("id")) == NULL) {
			printf("Error on \"appearanceref\" block on node %s!\n", node_id);
			throw InvalidXMLException();
		}

		n->setAppearance(app_id);
		app_stck.push(app_id);

		printf("Appearance\nid: %s\n", app_id);
	} else {
		app_stck.push(app_stck.top());
	}

	TiXmlElement *animation = NULL;
	if ((animation = curr_node->FirstChildElement("animationref"))) {
		if (is_inside_dl || is_dl) {
			printf("Animation defined in \"%s\" is inside a display list!\n", node_id);
			throw InvalidXMLException();
		}

		char ani_id[MAX_STRING_LEN];
		if (strdup(ani_id, animation->Attribute("id")) == NULL) {
			printf("Error on \"animationref\" block on node %s!\n", node_id);
			throw InvalidXMLException();
		}

		n->setAnimation(ani_id);

		printf("Animation\nid: %s\n", ani_id);
	} else {
		printf("No animation defined on node \"%s\".\n", node_id);
	}

	printf("Processing children...\n");

	TiXmlElement *children = NULL;

	if ((children = curr_node->FirstChildElement("children")) == NULL) {
		printf("Block \"children\" not found!\n");
		throw InvalidXMLException();
	}

	TiXmlElement *child = NULL;
	while ((child = (TiXmlElement *) children->IterateChildren(child))) {
		char child_type[MAX_STRING_LEN];
		strdup(child_type, child->Value());

		if (strcmp(child_type, "rectangle") == 0) {
			char tmp_str[MAX_STRING_LEN];
			double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
			if (strdup(tmp_str, child->Attribute("xy1")) == NULL) {
				printf("Error reading \"xy1\" attribute!\n");
				throw InvalidXMLException();
			}
			if (sscanf(tmp_str, "%lf %lf", &x1, &y1) != 2) {
				printf("Error parsing \"xy1\" attribute!\n");
				throw InvalidXMLException();
			}

			if (strdup(tmp_str, child->Attribute("xy2")) == NULL) {
				printf("Error reading \"xy2\" attribute!\n");
				throw InvalidXMLException();
			}
			if (sscanf(tmp_str, "%lf %lf", &x2, &y2) != 2) {
				printf("Error parsing \"xy2\" attribute!\n");
				throw InvalidXMLException();
			}

			MyRectangle *rect = new MyRectangle(x1, y1, x2, y2);
			n->addPrimitive(rect);

			printf("Rectangle\nxy1: (%f,%f)\nxy2: (%f,%f)\n", x1, y1, x2, y2);

		} else if (strcmp(child_type, "triangle") == 0) {
			char tmp_str[MAX_STRING_LEN];
			double x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0, z1 = 0, z2 = 0, z3 = 0;
			if (strdup(tmp_str, child->Attribute("xyz1")) == NULL) {
				printf("Error reading \"xyz1\" attribute!\n");
				throw InvalidXMLException();
			}
			if (sscanf(tmp_str, "%lf %lf %lf", &x1, &y1, &z1) != 3) {
				printf("Error parsing \"xyz1\" attribute!\n");
				throw InvalidXMLException();
			}

			if (strdup(tmp_str, child->Attribute("xyz2")) == NULL) {
				printf("Error reading \"xyz2\" attribute!\n");
				throw InvalidXMLException();
			}
			if (sscanf(tmp_str, "%lf %lf %lf", &x2, &y2, &z2) != 3) {
				printf("Error parsing \"xyz2\" attribute!\n");
				throw InvalidXMLException();
			}

			if (strdup(tmp_str, child->Attribute("xyz3")) == NULL) {
				printf("Error reading \"xyz3\" attribute!\n");
				throw InvalidXMLException();
			}
			if (sscanf(tmp_str, "%lf %lf %lf", &x3, &y3, &z3) != 3) {
				printf("Error parsing \"xyz3\" attribute!\n");
				throw InvalidXMLException();
			}

			MyTriangle *tri = new MyTriangle(x1, y1, z1, x2, y2, z2, x3, y3, z3);
			n->addPrimitive(tri);

			printf("Triangle\nxyz1: (%f,%f,%f)\nxyz2: (%f,%f,%f)\nxyz3: (%f,%f,%f)\n", x1, y1, z1, x2, y2, z2, x3, y3,
					z3);

		} else if (strcmp(child_type, "cylinder") == 0) {
			double cyl_base = 0, cyl_top = 0, cyl_height = 0;
			unsigned int cyl_slices = 0, cyl_stacks = 0;

			if (child->QueryDoubleAttribute("base", &cyl_base) != TIXML_SUCCESS) {
				printf("Error parsing base attribute!\n");
				throw InvalidXMLException();
			}

			if (child->QueryDoubleAttribute("top", &cyl_top) != TIXML_SUCCESS) {
				printf("Error parsing slices attribute!\n");
				throw InvalidXMLException();
			}

			if (child->QueryDoubleAttribute("height", &cyl_height) != TIXML_SUCCESS) {
				printf("Error parsing slices attribute!\n");
				throw InvalidXMLException();
			}

			if (child->QueryUnsignedAttribute("slices", &cyl_slices) != TIXML_SUCCESS) {
				printf("Error parsing slices attribute!\n");
				throw InvalidXMLException();
			}

			if (child->QueryUnsignedAttribute("stacks", &cyl_stacks) != TIXML_SUCCESS) {
				printf("Error parsing stacks attribute!\n");
				throw InvalidXMLException();
			}

			MyCylinder *cyl = new MyCylinder(cyl_base, cyl_top, cyl_height, cyl_slices, cyl_stacks);
			n->addPrimitive(cyl);

			printf("Cylinder\nbase: %f\ntop: %f\nheight: %f\nslices: %d\nstacks: %d\n", cyl_base, cyl_top, cyl_height,
					cyl_slices, cyl_stacks);

		} else if (strcmp(child_type, "sphere") == 0) {
			double sph_rad = 0;
			unsigned int sph_slices = 0, sph_stacks = 0;

			if (child->QueryDoubleAttribute("radius", &sph_rad) != TIXML_SUCCESS) {
				printf("Error parsing radius attribute!\n");
			}

			if (child->QueryUnsignedAttribute("slices", &sph_slices) != TIXML_SUCCESS) {
				printf("Error parsing slices attribute!\n");
			}

			if (child->QueryUnsignedAttribute("stacks", &sph_stacks) != TIXML_SUCCESS) {
				printf("Error parsing stacks attribute!\n");
			}

			MySphere *sph = new MySphere(sph_rad, sph_slices, sph_stacks);
			n->addPrimitive(sph);

			printf("Sphere\nradius: %f\nslices: %d\nstacks: %d\n", sph_rad, sph_slices, sph_stacks);

		} else if (strcmp(child_type, "torus") == 0) {
			double tor_inner = 0, tor_out = 0;
			unsigned int tor_slices = 0, tor_loops = 0;

			if (child->QueryDoubleAttribute("inner", &tor_inner) != TIXML_SUCCESS) {
				printf("Error parsing inner attribute!\n");
			}

			if (child->QueryDoubleAttribute("outer", &tor_out) != TIXML_SUCCESS) {
				printf("Error parsing outer attribute!\n");
			}

			if (child->QueryUnsignedAttribute("slices", &tor_slices) != TIXML_SUCCESS) {
				printf("Error parsing slices attribute!\n");
			}

			if (child->QueryUnsignedAttribute("loops", &tor_loops) != TIXML_SUCCESS) {
				printf("Error parsing loops attribute!\n");
			}

			MyTorus *tor = new MyTorus(tor_inner, tor_out, tor_slices, tor_loops);
			n->addPrimitive(tor);

			printf("Torus\ninner: %f\nouter: %f\nslices: %d\nloops: %d\n", tor_inner, tor_out, tor_slices, tor_loops);
		} else if (strcmp(child_type, "plane") == 0) {
			int parts = 0;

			if (child->QueryIntAttribute("parts", &parts) != TIXML_SUCCESS) {
				printf("Error parsing \"parts\" attribute on plane!\n");
				throw InvalidXMLException();
			}

			if (parts <= 0) {
				printf("Invalid value on parts attribute of plane!\n");
				throw InvalidXMLException();
			}

			printf("Plane\nparts: %i\n", parts);

			Plane *p = new Plane(parts);
			n->addPrimitive(p);
		} else if (strcmp(child_type, "patch") == 0) {
			int order = 0;
			int parts_u = 0;
			int parts_v = 0;
			char compute[MAX_STRING_LEN];

			if (child->QueryIntAttribute("order", &order) != TIXML_SUCCESS) {
				printf("Error parsing \"order\" attribute on patch!\n");
				throw InvalidXMLException();
			}

			if (child->QueryIntAttribute("partsU", &parts_u) != TIXML_SUCCESS) {
				printf("Error parsing \"partsU\" attribute on patch!\n");
				throw InvalidXMLException();
			}

			if (child->QueryIntAttribute("partsV", &parts_v) != TIXML_SUCCESS) {
				printf("Error parsing \"partsV\" attribute on patch!\n");
				throw InvalidXMLException();
			}

			if (strdup(compute, child->Attribute("compute")) == NULL) {
				printf("Error parsing \"compute\" attribute on patch!\n");
				throw InvalidXMLException();
			}

			printf("Patch\norder: %d\npartsU: %d\npartsV: %d\ncompute: %s\n", order, parts_u, parts_v, compute);

			MyPatch *patch = new MyPatch(order, parts_u, parts_v, compute);
			n->addPrimitive(patch);

			TiXmlElement *ctrl_p = child->FirstChildElement("controlpoint");
			do {
				float x = 0;
				float y = 0;
				float z = 0;

				if (ctrl_p->QueryFloatAttribute("x", &x) != TIXML_SUCCESS) {
					printf("Error parsing \"x\" attribute on patch!\n");
					throw InvalidXMLException();
				}

				if (ctrl_p->QueryFloatAttribute("y", &y) != TIXML_SUCCESS) {
					printf("Error parsing \"y\" attribute on patch!\n");
					throw InvalidXMLException();
				}
				if (ctrl_p->QueryFloatAttribute("z", &z) != TIXML_SUCCESS) {
					printf("Error parsing \"z\" attribute on patch!\n");
					throw InvalidXMLException();
				}

				printf("controlpoint: (%f %f %f)\n", x, y, z);

				patch->addControlPoint(x, y, z);

			} while ((ctrl_p = ctrl_p->NextSiblingElement("controlpoint")) != NULL);
		} else if (strcmp(child_type, "waterline") == 0) {
			char heightmap[MAX_STRING_LEN];
			char texturemap[MAX_STRING_LEN];
			char vert_shader[MAX_STRING_LEN];
			char frag_shader[MAX_STRING_LEN];

			if (is_inside_dl || is_dl) {
				printf("Waterline defined in \"%s\" is inside a display list!\n", node_id);
				throw InvalidXMLException();
			}

			if (strdup(heightmap, child->Attribute("heightmap")) == NULL) {
				printf("Error parsing \"heightmap\" attribute of waterline!");
				throw InvalidXMLException();
			}

			if (strdup(texturemap, child->Attribute("texturemap")) == NULL) {
				printf("Error parsing \"texturemap\" attribute of waterline!");
				throw InvalidXMLException();
			}

			if (strdup(frag_shader, child->Attribute("fragmentshader")) == NULL) {
				printf("Error parsing \"fragmentshader\" attribute of waterline!");
				throw InvalidXMLException();
			}

			if (strdup(vert_shader, child->Attribute("vertexshader")) == NULL) {
				printf("Error parsing \"vertexshader\" attribute of waterline!");
				throw InvalidXMLException();
			}

			MyWaterLine *wl = new MyWaterLine(heightmap, texturemap, vert_shader, frag_shader);
			n->addPrimitive(wl);

		} else if (strcmp(child_type, "vehicle") == 0) {
			MyVehicle *v = new MyVehicle();
			n->addPrimitive(v);

		} else if (strcmp(child_type, "noderef") == 0) {
			char next_node_id[MAX_STRING_LEN];
			if (strdup(next_node_id, child->Attribute("id")) == NULL) {
				printf("Error reading noderef's id!\n");
				throw InvalidXMLException();
			}
			if (find(nodes_being_processed.begin(), nodes_being_processed.end(), next_node_id)
					!= nodes_being_processed.end()) {
				if (find(nodes_finished_processing.begin(), nodes_finished_processing.end(), next_node_id)
						!= nodes_finished_processing.end()) {
					printf("Node has already been processed.\n");
					string last_node_name = Scene::getInstance()->findLastNameAvail(next_node_id);
					if (Scene::getInstance()->getNode(last_node_name)->getType() != DISPLAY_LIST) { // normal node
						n->addRef(next_node_id);
					} else {
						TiXmlElement *next_node = NULL;
						if ((next_node = findChildByAttribute(graphElement, "id", next_node_id))) {
							printf("\n\n");
							parseNode(next_node, is_dl || is_inside_dl);
							n->addRef(Scene::getInstance()->findLastNameAvail(next_node_id));
						}
					}
					continue;
				} else {
					printf("Cyclic definition found in node \"%s\"", next_node_id);
					throw InvalidXMLException();
				}
			} else {
				TiXmlElement *next_node = NULL;
				if ((next_node = findChildByAttribute(graphElement, "id", next_node_id))) {
					printf("\n\n");
					parseNode(next_node, is_dl || is_inside_dl);
					string last_node_name = Scene::getInstance()->findLastNameAvail(next_node_id);
					if (Scene::getInstance()->getNode(last_node_name)->getType() == DISPLAY_LIST) {
						n->addRef(last_node_name);
					} else {
						n->addRef(next_node_id);
					}

				} else {
					printf("Node %s does not exist!\n", next_node_id);
					throw InvalidXMLException();
				}
			}
		} else {
			printf("Invalid block inside children of node %s\n", node_id);
			throw InvalidXMLException();
		}
	}
	printf("Finished processing %s node children.\n\n", node_id);

	if (is_dl) {
		Scene::getInstance()->addNode(dl_node_id, n);
	} else {
		Scene::getInstance()->addNode(node_id, n);
	}
	printf("closing %s\n", node_id);
	n->closeDefinition(app_stck);
	printf("closed %s\n", node_id);
	app_stck.pop();
	nodes_finished_processing.push_back(node_id);
	return true;
}
Example #14
0
// get the configuration file using hobbit protocol config
void		AgentBBWinUpdate::RunUpdate(std::string & configFile) {
	TiXmlDocument		* update, * toUpdate;

	DeleteFile(m_bbwinupdateTmpFilePath.c_str());
	m_mgr.Config(configFile.c_str(), m_bbwinupdateTmpFilePath.c_str());
	update = new TiXmlDocument(m_bbwinupdateTmpFilePath.c_str());
	bool loadUpdateOkay = update->LoadFile();
	if ( !loadUpdateOkay ) {
		string err = (string)" failed to get the update " + configFile + (string)" or the update file is not correct";
		m_mgr.ReportEventError(err.c_str());
	}
	toUpdate = new TiXmlDocument(m_bbwinCfgTmpPath.c_str());
	bool loadToUpdateOkay = toUpdate->LoadFile();
	if ( !loadToUpdateOkay ) {
		delete update;
		string err = (string)" failed to open " + m_bbwinCfgTmpPath;
		m_mgr.ReportEventError(err.c_str());
	}
	TiXmlElement *root = update->FirstChildElement( "configuration" );
	TiXmlElement *toUpdateRoot = toUpdate->FirstChildElement( "configuration" );
	if ( root && toUpdateRoot) {
		for (TiXmlNode * nameSpaceNode = root->FirstChild(); nameSpaceNode != NULL; nameSpaceNode = root->IterateChildren(nameSpaceNode)) {
			// we never update bbwin namespace (too dangerous)
			if (strcmp(nameSpaceNode->Value(), "bbwin") != 0) {
				TiXmlNode * destNameSpaceNode = toUpdateRoot->FirstChild(nameSpaceNode->Value());
				if ( destNameSpaceNode ) {
					toUpdateRoot->ReplaceChild(destNameSpaceNode, *nameSpaceNode);
				} else {
					toUpdateRoot->InsertEndChild(*nameSpaceNode);
				}
			} else {
				string err = (string)" bbwin namespace update is not permitted. Please check the " + (string)configFile + (string)" on your hobbit server.";
				m_mgr.ReportEventError(err.c_str());
			}
		}
	}
	if (toUpdate->SaveFile() != true) {
		string err = (string)" failed to save " + m_bbwinCfgTmpPath;
		m_mgr.ReportEventError(err.c_str());
	}
	delete update;
	delete toUpdate;
}
Example #15
0
OsStatus
PluginXmlParser::loadPlugins (
    const UtlString configFileName,
    Notifier* notifier )
{
    OsStatus currentStatus = OS_SUCCESS;
    int index = 0;

    mDoc = new TiXmlDocument( configFileName.data() );

    if( mDoc->LoadFile() )
    {
        OsSysLog::add(FAC_SIP, PRI_DEBUG, "PluginXmlParser::loadMappings "
            "- Loaded %s", configFileName.data() );
    }
    else
    {
        OsSysLog::add(FAC_SIP, PRI_ERR, "PluginXmlParser::loadMappings "
            "- Unable to Open XML file %s", configFileName.data() );

        return OS_NOT_FOUND;
    }

    // start loading plugins from the configuration file
    // Get the "subscribe-server-plugins" element.
    // It is a child of the document, and can be selected by name.
    TiXmlNode* mMainPluginsNode =
        mDoc->FirstChild( XML_TAG_SUBSCRIBE_SERVER_PLUGINS );

    if ( !mMainPluginsNode )
    {
        OsSysLog::add(FAC_SIP, PRI_ERR, "PluginXmlParser::loadMappings "
            "- No child Node for subscribe-server-plugins");

        return OS_FILE_READ_FAILED;
    }

    TiXmlElement* mMainPluginsElement = mMainPluginsNode->ToElement();

    // get <SUBSCRIBE-PLUGIN> Nodes
    TiXmlNode* pluginNode = NULL;
    UtlString eventType;

    while ((pluginNode = mMainPluginsElement->IterateChildren(pluginNode)))
    {
        eventType = "";

        // Skip over comments etc, only interested in ELEMENTS
        if( pluginNode->Type() == TiXmlNode::ELEMENT )
        {
            TiXmlElement* pluginElement = pluginNode->ToElement();
            UtlString value;
            value.append( pluginElement->Value() );
            if( value.compareTo(XML_TAG_SUBSCRIBE_PLUGINS) == 0 )
            {
                index ++;

                TiXmlNode* attibuteNode = NULL;
                SubscribeServerPluginBase* newPlugin = NULL;

                // get event type associated with this plug in
                // create a new plugin for this event type
                attibuteNode = pluginElement->FirstChild(XML_TAG_EVENT_TYPE);
                if(attibuteNode)
                {
                    TiXmlNode* eventTypeValue = attibuteNode->FirstChild();
                    if(eventTypeValue && eventTypeValue->Type() == TiXmlNode::TEXT)
                    {
                        TiXmlText* eventTypeText = eventTypeValue->ToText();
                        if (eventTypeText)
                        {
                            eventType = eventTypeText->Value();

                            // MWI is built in so we do not load a library for now.
                            // Eventually we should remove this if block so it looks
                            // for DLL and entry point
                            if(eventType.compareTo(SIP_EVENT_MESSAGE_SUMMARY,
                                UtlString::ignoreCase ) == 0)
                            {
                                // create new plugin with the specific attributes defined in the node
                                newPlugin = MwiPluginFactory( *pluginNode,
                                                             notifier );
                            }

                            // load DLL and find entry point defined in XML
			    else
                            {
			      // OPINION: make fail-fast; so we fail if one plugin fails
			      currentStatus = loadPlugin(*pluginElement, notifier, &newPlugin);
			      if (currentStatus != OS_SUCCESS)
				return OS_SUCCESS;//:TODO: ???
                            }
                        }
                    }
                }

                if( newPlugin)
                {
                    StatusPluginReference* pluginContainer =
                        new StatusPluginReference(*newPlugin,
                                                  eventType,
                                                  *pluginNode);

                    addPluginToList( pluginContainer );
                }
		else
                {
                    OsSysLog::add(FAC_SIP, PRI_ERR, "PluginXmlParser::loadMappings "
                        "- No Plugin for Node number %d event type: %s",
                        index, eventType.data());
                }
            }
        }
    }
    return currentStatus;
}
Example #16
0
void TextureControl::LoadSupportedSets() {
	TiXmlDocument* doc;
	TiXmlElement* setElem;
	TiXmlElement* subSetElem;
	TiXmlElement* chanElem;
	TiXmlElement* elem;
	TiXmlNode* prevChan;
	TiXmlNode* prevSubSet;
	
	string fileSetName;
	string setName;
	string subSetName;
	string chanName;
	string setPath;
	string fileName;
	string fileFormat;
	string buf;
	int size;
	int compress;
	int alpha;
	unsigned int Flags;
	TargetTextureSet* ptts;

	WIN32_FIND_DATA findData;
	HANDLE hFind;
	hFind = FindFirstFile("SetDefs\\*.xml",&findData);
	do {
		fileSetName = "SetDefs\\";
		fileSetName += findData.cFileName;	

		doc = new TiXmlDocument(fileSetName.c_str());
		bool loadOkay = doc->LoadFile();
		if(!loadOkay) {
			delete doc;
			continue;
		}

		setElem = doc->FirstChildElement("TextureSet");
		while(setElem) {
			setName = setElem->Attribute("Name");
			elem = setElem->FirstChildElement("Path");
			if(elem) setPath = elem->GetText();

			ptts = new TargetTextureSet(setName,setPath);

			prevSubSet = NULL;
			while(prevSubSet = setElem->IterateChildren("SubSet",prevSubSet)) {
				subSetElem = prevSubSet->ToElement();
				subSetName = subSetElem->Attribute("Name");

				prevChan = NULL;
				while( prevChan = subSetElem->IterateChildren("Channel",prevChan) ){
					chanElem = prevChan->ToElement();
					chanName = chanElem->Attribute("Name");

					elem = chanElem->FirstChildElement("FileName");
					if(elem) fileName = elem->GetText();
					elem = chanElem->FirstChildElement("FileFormat");
					if(elem) fileFormat = elem->GetText();
					elem = chanElem->FirstChildElement("Size");
					if(elem) size = atoi(elem->GetText());

					Flags = 0; compress = 0; alpha = 0;
					elem = chanElem->FirstChildElement("CompressTex");
					if(elem) compress = atoi(elem->GetText());
					if(!compress) 
						Flags = TTS_FLAG_DDSUNCOMPRESSED;
					elem = chanElem->FirstChildElement("HasAlpha");
					if(elem) alpha = atoi(elem->GetText());
					if(alpha)
						Flags |= TTS_FLAG_HASALPHA;

					ptts->AddSetFile(subSetName, chanName, fileName,fileFormat,size,Flags);
				}
			}
			supportedSets.push_back(ptts);
			setElem = setElem->NextSiblingElement("TextureSet");
		}
		delete doc;
	} while(FindNextFile(hFind,&findData)) ;
}
bool CWebBrowserDownloadHandler::LoadDownloadHistory(bool initial)
{
  TiXmlDocument xmlDoc;
  std::string strSettingsFile = kodi::GetBaseUserPath("download_history.xml");

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    if (initial)
    {
      if (!SaveDownloadHistory())
      {
        kodi::Log(ADDON_LOG_ERROR, "failed to create initial settings data file at '%s'", strSettingsFile.c_str());
        return false;
      }
      return true;
    }
    else
      kodi::Log(ADDON_LOG_ERROR, "invalid settings data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "downloadhistory") != 0)
  {
    if (!initial)
      kodi::Log(ADDON_LOG_ERROR, "invalid download history data (no <downloadhistory> tag found)");
    return false;
  }

  /* load history */
  TiXmlElement *pElement = pRootElement->FirstChildElement("histories");
  if (pElement)
  {
    TiXmlNode *pChannelNode = nullptr;
    while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != nullptr)
    {
      std::string name;
      if (!XMLUtils::GetString(pChannelNode, "name", name))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without name");
        continue;
      }

      std::string url;
      if (!XMLUtils::GetString(pChannelNode, "url", url))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without url (%s)", name.c_str());
        continue;
      }

      std::string path;
      if (!XMLUtils::GetString(pChannelNode, "path", path))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without path (%s)", name.c_str());
        continue;
      }

      long time;
      if (!XMLUtils::GetLong(pChannelNode, "time", time))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without time (%s)", name.c_str());
        continue;
      }

      std::shared_ptr<CDownloadItem> downloadItem = std::make_shared<CDownloadItem>(name, url, path, time);
      m_finishedDownloads[url] = downloadItem;
    }
  }

  return true;
}
Example #18
0
/**
 * Parse the theme map if the mPathMap is empty, else use the mPathMap parsed before.
 */
void MTKThemeManager::parseThemeMapIfNeeded()
{
    if (mPathMap != NULL) {
        ALOGV("The path has already parsed.");
        return;
    }

    /* Load theme map xml file. */
    TiXmlDocument* pDoc = new TiXmlDocument(kThemeMapFile);
    if (pDoc == NULL) {
        ALOGE("Read theme map xml file failed!");
        return;
    }
    pDoc->LoadFile();

    /* Get the root node(thememap) and the first module child node.*/
    TiXmlElement *pRootElement = pDoc->RootElement();
    TiXmlElement *pFirstModuleElement = pRootElement->FirstChildElement(kThemeModuleName);
    ALOGV("Module element is %s, path = %s.", pFirstModuleElement->Value(), pFirstModuleElement->Attribute(kThemePathAttr));

    /* Get module node count to create the path map array.*/
    int moduleCnt = getChildNodeCount(kThemeModuleName, pRootElement, pFirstModuleElement);
    ALOGV("Total element count is %d.", moduleCnt);

    mPathMap = new ThemePathMap[moduleCnt];
    if (mPathMap == NULL) {
        ALOGE("Failed to allocate memory for theme path map.");
        return;
    }
    MTKThemeManager::mModuleCount = moduleCnt;

    TiXmlNode *pModuleNode = pFirstModuleElement;
    TiXmlNode *pItemNode = NULL;
    TiXmlNode *pFirstItemElement = NULL;
    int itemCnt = 0;
    int moduleIndex = 0;
    int tempIndex = 0;

    /* Parse the whole xml by module. */
    while (pModuleNode != NULL) {
        mPathMap[moduleIndex].path = ((TiXmlElement *)pModuleNode)->Attribute(kThemePathAttr);
        ALOGV("parseThemeMap while start moduleIndex = %d, pModuleNode = %d, path = %s.",
                moduleIndex, pModuleNode, mPathMap[moduleIndex].path);

        pFirstItemElement = pModuleNode->FirstChildElement(kThemeItemName);
        itemCnt = getChildNodeCount(kThemeItemName, pModuleNode, pFirstItemElement);
        mPathMap[moduleIndex].fileCount = itemCnt;
        if (itemCnt == 0) {
            ALOGD("There is no item in apk %s.", ((TiXmlElement *)pModuleNode)->Attribute(kThemePathAttr));
            mPathMap[moduleIndex].fileList = NULL;
            continue;
        }

        ThemeFileList *itemFileList = new ThemeFileList[itemCnt];
        if (itemFileList == NULL) {
            ALOGE("Failed to allocate memory for item file list array.");
            return;
        }

        pItemNode = pFirstItemElement;
        tempIndex = 0;
        /* Parse all items in the current module pModuleNode. */
        while (pItemNode != NULL) {
            itemFileList[tempIndex++].fileName = ((TiXmlElement *)pItemNode)->GetText();
            ALOGV("parseThemeMap pItemNode->GetText() = %s, itemFileList[tempIndex].fileName = %s.",
                    ((TiXmlElement *)pItemNode)->GetText(), itemFileList[tempIndex-1].fileName);
            pItemNode = (TiXmlElement *)pModuleNode->IterateChildren(kThemeItemName, pItemNode);
        }

        mPathMap[moduleIndex].fileList = itemFileList;
        ALOGV("parseThemeMap moduleIndex = %d, itemCnt = %d, mPathMap[moduleIndex].fileList = %d,"
                "itemFileList = %d, filename0 = %s, itemFileList filename0 = %s.",
                moduleIndex, itemCnt, mPathMap[moduleIndex].fileList, itemFileList,
                (mPathMap[moduleIndex].fileList)[0].fileName, itemFileList[0].fileName);
        moduleIndex++;

        pModuleNode = (TiXmlElement *)pRootElement->IterateChildren(kThemeModuleName, pModuleNode);
    }
    ALOGV("Theme path map parsed completely.");
}
Example #19
0
bool PVRDemoData::LoadDemoData(void)
{
  TiXmlDocument xmlDoc;

  if (!xmlDoc.LoadFile(GetSettingsFile()))
  {
    XBMC->Log(LOG_ERROR, "invalid demo data (no/invalid data file found)");
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "demo") != 0)
  {
    XBMC->Log(LOG_ERROR, "invalid demo data (no <demo> tag found)");
    return false;
  }

  /* load channels */
  int iUniqueChannelId = 0;
  TiXmlElement *pElement = pRootElement->FirstChildElement("channels");
  if (pElement)
  {
    TiXmlNode *pChannelNode = NULL;
    while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoChannel channel;
      channel.iUniqueId = ++iUniqueChannelId;

      /* channel name */
      if (!XMLUtils::GetString(pChannelNode, "name", strTmp))
        continue;
      channel.strChannelName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pChannelNode, "radio", channel.bRadio);

      /* channel number */
      if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
        channel.iChannelNumber = iUniqueChannelId;

      /* CAID */
      if (!XMLUtils::GetInt(pChannelNode, "encryption", channel.iEncryptionSystem))
        channel.iEncryptionSystem = 0;

      /* icon path */
      if (!XMLUtils::GetString(pChannelNode, "icon", strTmp))
        channel.strIconPath = m_strDefaultIcon;
      else
        channel.strIconPath = strTmp;

      /* stream url */
      if (!XMLUtils::GetString(pChannelNode, "stream", strTmp))
        channel.strStreamURL = m_strDefaultMovie;
      else
        channel.strStreamURL = strTmp;

      m_channels.push_back(channel);
    }
  }

  /* load channel groups */
  int iUniqueGroupId = 0;
  pElement = pRootElement->FirstChildElement("channelgroups");
  if (pElement)
  {
    TiXmlNode *pGroupNode = NULL;
    while ((pGroupNode = pElement->IterateChildren(pGroupNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoChannelGroup group;
      group.iGroupId = ++iUniqueGroupId;

      /* group name */
      if (!XMLUtils::GetString(pGroupNode, "name", strTmp))
        continue;
      group.strGroupName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pGroupNode, "radio", group.bRadio);

      /* members */
      TiXmlNode* pMembers = pGroupNode->FirstChild("members");
      TiXmlNode *pMemberNode = NULL;
      while (pMembers != NULL && (pMemberNode = pMembers->IterateChildren(pMemberNode)) != NULL)
      {
        int iChannelId = atoi(pMemberNode->FirstChild()->Value());
        if (iChannelId > -1)
          group.members.push_back(iChannelId);
      }

      m_groups.push_back(group);
    }
  }

  /* load EPG entries */
  pElement = pRootElement->FirstChildElement("epg");
  if (pElement)
  {
    TiXmlNode *pEpgNode = NULL;
    while ((pEpgNode = pElement->IterateChildren(pEpgNode)) != NULL)
    {
      CStdString strTmp;
      int iTmp;
      PVRDemoEpgEntry entry;

      /* broadcast id */
      if (!XMLUtils::GetInt(pEpgNode, "broadcastid", entry.iBroadcastId))
        continue;

      /* channel id */
      if (!XMLUtils::GetInt(pEpgNode, "channelid", iTmp))
        continue;
      PVRDemoChannel &channel = m_channels.at(iTmp - 1);
      entry.iChannelId = channel.iUniqueId;

      /* title */
      if (!XMLUtils::GetString(pEpgNode, "title", strTmp))
        continue;
      entry.strTitle = strTmp;

      /* start */
      if (!XMLUtils::GetInt(pEpgNode, "start", iTmp))
        continue;
      entry.startTime = iTmp;

      /* end */
      if (!XMLUtils::GetInt(pEpgNode, "end", iTmp))
        continue;
      entry.endTime = iTmp;

      /* plot */
      if (XMLUtils::GetString(pEpgNode, "plot", strTmp))
        entry.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pEpgNode, "plotoutline", strTmp))
        entry.strPlotOutline = strTmp;

      /* icon path */
      if (XMLUtils::GetString(pEpgNode, "icon", strTmp))
        entry.strIconPath = strTmp;

      /* genre type */
      XMLUtils::GetInt(pEpgNode, "genretype", entry.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pEpgNode, "genresubtype", entry.iGenreSubType);

      XBMC->Log(LOG_DEBUG, "loaded EPG entry '%s' channel '%d' start '%d' end '%d'", entry.strTitle.c_str(), entry.iChannelId, entry.startTime, entry.endTime);
      channel.epg.push_back(entry);
    }
  }

  return true;
}
	bool PostProcessingPass::load(TiXmlElement *xml)
	{
		ShaderVersion psversion = ESV_None;
		std::string pscode;
		ShaderVersion vsversion = ESV_None;
		std::string vscode;
		// Load pixel shader
		TiXmlNode *psnode = xml->FirstChild("pixelshader");
		while (psnode)
		{
			TiXmlElement *psdata = psnode->ToElement();
			if (psdata)
			{
				// Get shader code
				std::string code;
				TiXmlNode *textnode = psdata->FirstChild();
				while (textnode)
				{
					TiXmlText *text = textnode->ToText();
					if (text && text->Value())
					{
						code += text->Value();
					}
					textnode = psdata->IterateChildren(textnode);
				}
				while (isspace(code[0]))
					code = code.substr(1);
				// Get version
				ShaderVersion version = ESV_None;
				if (psdata->Attribute("type"))
				{
					if (!strcmp(psdata->Attribute("type"), "arbfp1.0")
						&& GLEW_ARB_fragment_program)
						version = ESV_ARBFP10;
				}
				// Set shader to the best supported version
				if (version > psversion)
				{
					psversion = version;
					pscode = code;
				}
			}
			psnode = xml->IterateChildren("pixelshader", psnode);
		}
		if (psversion == ESV_None)
		{
			std::cerr << "No usable shader!" << std::endl;
			return false;
		}
		else if (psversion == ESV_ARBFP10)
		{
			// Build shader
			this->psversion = psversion;
			glGenProgramsARB(1, &ps);
			glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ps);
			glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB,
				GL_PROGRAM_FORMAT_ASCII_ARB, pscode.size(),
				pscode.c_str());
			unsigned int error = glGetError();
			if (error == GL_INVALID_OPERATION)
			{
				std::cout << glGetString(GL_PROGRAM_ERROR_STRING_ARB) << std::endl;
				std::cout << "Code: \"" << pscode << "\"" << std::endl;
				return false;
			}
		}
		else
		{
			std::cerr << "Unimplemented shader version!" << std::endl;
			return false;
		}
		// Load vertex shader
		TiXmlNode *vsnode = xml->FirstChild("vertexshader");
		while (vsnode)
		{
			TiXmlElement *vsdata = vsnode->ToElement();
			if (vsdata)
			{
				// Get shader code
				std::string code;
				TiXmlNode *textnode = vsdata->FirstChild();
				while (textnode)
				{
					TiXmlText *text = textnode->ToText();
					if (text && text->Value())
					{
						code += text->Value();
					}
					textnode = vsdata->IterateChildren(textnode);
				}
				while (isspace(code[0]))
					code = code.substr(1);
				// Get version
				ShaderVersion version = ESV_None;
				if (vsdata->Attribute("type"))
				{
					if (!strcmp(vsdata->Attribute("type"), "arbvp1.0")
						&& GLEW_ARB_vertex_program)
						version = ESV_ARBVP10;
				}
				// Set shader to the best supported version
				if (version > vsversion)
				{
					vsversion = version;
					vscode = code;
				}
			}
			vsnode = xml->IterateChildren("vertexshader", vsnode);
		}
		if (vsversion == ESV_None)
		{
			std::cerr << "No usable shader!" << std::endl;
			return false;
		}
		else if (vsversion == ESV_ARBVP10)
		{
			// Build shader
			this->vsversion = vsversion;
			glGenProgramsARB(1, &vs);
			glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vs);
			glProgramStringARB(GL_VERTEX_PROGRAM_ARB,
				GL_PROGRAM_FORMAT_ASCII_ARB, vscode.size(),
				vscode.c_str());
			unsigned int error = glGetError();
			if (error == GL_INVALID_OPERATION)
			{
				std::cout << glGetString(GL_PROGRAM_ERROR_STRING_ARB) << std::endl;
				std::cout << "Code: \"" << vscode << "\"" << std::endl;
				return false;
			}
		}
		else
		{
			std::cerr << "Unimplemented shader version!" << std::endl;
			return false;
		}
		return true;
	}
Example #21
0
OsStatus ForwardRules::parseRouteMatchContainer(const Url& requestUri,
                                              const SipMessage& request,
                                              UtlString& routeToString,
                                              UtlString& mappingType,
                                              bool& authRequired,
                                              TiXmlNode* routesNode,
                                              TiXmlNode* previousRouteMatchNode)
{
   UtlString testHost;
   requestUri.getHostAddress(testHost);
   int testPort = requestUri.getHostPort();
   if(testPort == SIP_PORT)
   {
      testPort = PORT_NONE;
   }
   
   UtlBoolean routeMatchFound = false;
   OsStatus methodMatchFound = OS_FAILED;
   
  	TiXmlElement* routesElement = routesNode->ToElement();

   TiXmlNode* routeMatchNode = previousRouteMatchNode;
   // Iterate through routes container children looking for 
   // route tags
   while ( (routeMatchNode = routesElement->IterateChildren(routeMatchNode)) 
      && methodMatchFound != OS_SUCCESS)
   {
      // Skip non-elements
      if(routeMatchNode && routeMatchNode->Type() != TiXmlNode::ELEMENT)
      {
         continue;
      }

      // Skip non-route elements
      TiXmlElement* routeMatchElement = routeMatchNode->ToElement();
      UtlString tagValue =  routeMatchElement->Value();
      if(tagValue.compareTo(XML_TAG_ROUTEMATCH) != 0 )
      {
         continue;
      }

      mappingType.remove(0);
      routeToString.remove(0);
      const char* mappingTypePtr = 
          routeMatchElement->Attribute(XML_ATT_MAPPINGTYPE);

      //get the mapping Type attribute
      mappingType.append(mappingTypePtr ? mappingTypePtr : "");

      // Iterate through the route container's children looking
      // for routeFrom, routeIPv4subnet, or routeDnsWildcard elements
      TiXmlNode* routeFromPatternNode = NULL;
      for( routeFromPatternNode = routeMatchElement->FirstChildElement();
         routeFromPatternNode;
         routeFromPatternNode = routeFromPatternNode->NextSiblingElement() )
      {
         // Skip elements that aren't of the "domainMatches" family 
         enum {ret_from, ret_ip, ret_dns} routeElementType ;

         const char *name = routeFromPatternNode->Value() ;
         if (strcmp(name, XML_TAG_ROUTEFROM) == 0)
         {
            routeElementType = ret_from;
         }
         else if (strcmp(name, XML_TAG_ROUTEIPV4SUBNET) == 0)
         {
            routeElementType = ret_ip;
         }
         else if (strcmp(name, XML_TAG_ROUTEDNSWILDCARD) == 0)
         {
            routeElementType = ret_dns;
         }
         else
         {
            continue ;
         }


         //found "domainMatches" pattern tag
         TiXmlElement* routeFromPatternElement = routeFromPatternNode->ToElement();
         //get the text value from it
         TiXmlNode* routeFromPatternText = routeFromPatternElement->FirstChild();
         if(routeFromPatternText && routeFromPatternText->Type() == TiXmlNode::TEXT)
         {
            TiXmlText* Xmlpattern = routeFromPatternText->ToText();
            if (Xmlpattern)
            {
               UtlString pattern = Xmlpattern->Value();

               switch(routeElementType)
               {
                  case ret_from: // a routeFrom element matches host and port
                  {
                     Url xmlUrl(pattern.data());
                     UtlString xmlHost;
                     xmlUrl.getHostAddress(xmlHost);
                     int xmlPort = xmlUrl.getHostPort();

                     // See if the host and port of the routeFrom elelment
                     // match that of the URI
                     if( (xmlHost.compareTo(testHost, UtlString::ignoreCase) == 0) &&
                        ((xmlPort == SIP_PORT && testPort == PORT_NONE) ||
                         xmlPort == testPort) )
                     {
                        routeMatchFound = true;
                        Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "ForwardRules::parseRouteMatchContainer - routeFrom %s matches %s", testHost.data(), pattern.data());
                     }
                  }
                  break ;

                  case ret_ip: // a routeIPv4subnet matches if the subnet does
                  {
                     // "pattern" is a subnet in CIDR notation (x.y.z.q/size)
                     // "testHost is supposed to be an IPv4 dotted quad

                     routeMatchFound = mPatterns->
                                          IPv4subnet(testHost, pattern);
                  }
                  break ;

                  case ret_dns: // a routeDnsWildcard matches if the domain name does
                  {
                     // "pattern" is a wildcard DNS (*.pingtel.com)
                     // "testHost is a FQDN
                     routeMatchFound = mPatterns->
                                          DnsWildcard(testHost, pattern);
  
                  }
                  break ;
               }

               if (routeMatchFound)
               {
                  previousRouteMatchNode = routeMatchNode;
                  // Find a match to the request method and recurse
                  // to find child element field(s) matches  and
                  // get the routeTo value
                  methodMatchFound = parseMethodMatchContainer(request,
                     routeToString,
                     authRequired,
                     routeMatchNode);

                  if( methodMatchFound == OS_SUCCESS)
                     break;
               }
            }
         }
      }
   }
   return methodMatchFound;
}
Example #22
0
bool CDSPSettings::LoadSettingsData(int settingId, bool initial)
{
  TiXmlDocument xmlDoc;
  string strSettingsFile = GetSettingsFile();

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    if (initial)
    {
      if (!SaveSettingsData())
      {
        XBMC->Log(LOG_ERROR, "failed to create initial settings data file at '%s')", strSettingsFile.c_str());
        return false;
      }
      return true;
    }
    else
      XBMC->Log(LOG_ERROR, "invalid settings data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "demo") != 0)
  {
    if (!initial)
      XBMC->Log(LOG_ERROR, "invalid settings data (no <demo> tag found)");
    return false;
  }

  TiXmlElement *pElement = NULL;
  if (settingId < 0 || settingId == ID_MENU_SPEAKER_GAIN_SETUP || settingId == ID_MENU_SPEAKER_DISTANCE_SETUP)
  {
    pElement = pRootElement->FirstChildElement("channels");
    if (pElement)
    {
      TiXmlNode *pChannelNode = NULL;
      while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != NULL)
      {
        CStdString strTmp;
        sDSPSettings::sDSPChannel channel;

        if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
          continue;

        if (XMLUtils::GetString(pChannelNode, "name", strTmp))
          channel.strName = strTmp;
        else
          channel.strName = "";

        if (!XMLUtils::GetInt(pChannelNode, "volume", channel.iVolumeCorrection))
          channel.iVolumeCorrection = 0;

        if (!XMLUtils::GetInt(pChannelNode, "distance", channel.iDistanceCorrection))
          channel.iDistanceCorrection = 0;

        m_Settings.m_channels[channel.iChannelNumber].iChannelNumber          = channel.iChannelNumber;
        m_Settings.m_channels[channel.iChannelNumber].iVolumeCorrection       = channel.iVolumeCorrection;
        m_Settings.m_channels[channel.iChannelNumber].iOldVolumeCorrection    = channel.iVolumeCorrection;
        m_Settings.m_channels[channel.iChannelNumber].strName                 = channel.strName;
        m_Settings.m_channels[channel.iChannelNumber].iDistanceCorrection     = channel.iDistanceCorrection;
        m_Settings.m_channels[channel.iChannelNumber].iOldDistanceCorrection  = channel.iDistanceCorrection;
      }
    }
  }

  return true;
}
Example #23
0
bool PVRDemoData::LoadDemoData(void)
{
  TiXmlDocument xmlDoc;
  string strSettingsFile = GetSettingsFile();

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    XBMC->Log(LOG_ERROR, "invalid demo data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "demo") != 0)
  {
    XBMC->Log(LOG_ERROR, "invalid demo data (no <demo> tag found)");
    return false;
  }

  /* load channels */
  int iUniqueChannelId = 0;
  TiXmlElement *pElement = pRootElement->FirstChildElement("channels");
  if (pElement)
  {
    TiXmlNode *pChannelNode = NULL;
    while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoChannel channel;
      channel.iUniqueId = ++iUniqueChannelId;

      /* channel name */
      if (!XMLUtils::GetString(pChannelNode, "name", strTmp))
        continue;
      channel.strChannelName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pChannelNode, "radio", channel.bRadio);

      /* channel number */
      if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
        channel.iChannelNumber = iUniqueChannelId;

      /* sub channel number */
      if (!XMLUtils::GetInt(pChannelNode, "subnumber", channel.iSubChannelNumber))
        channel.iSubChannelNumber = 0;

      /* CAID */
      if (!XMLUtils::GetInt(pChannelNode, "encryption", channel.iEncryptionSystem))
        channel.iEncryptionSystem = 0;

      /* icon path */
      if (!XMLUtils::GetString(pChannelNode, "icon", strTmp))
        channel.strIconPath = m_strDefaultIcon;
      else
        channel.strIconPath = strTmp;

      /* stream url */
      if (!XMLUtils::GetString(pChannelNode, "stream", strTmp))
        channel.strStreamURL = m_strDefaultMovie;
      else
        channel.strStreamURL = strTmp;

      m_channels.push_back(channel);
    }
  }

  /* load channel groups */
  int iUniqueGroupId = 0;
  pElement = pRootElement->FirstChildElement("channelgroups");
  if (pElement)
  {
    TiXmlNode *pGroupNode = NULL;
    while ((pGroupNode = pElement->IterateChildren(pGroupNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoChannelGroup group;
      group.iGroupId = ++iUniqueGroupId;

      /* group name */
      if (!XMLUtils::GetString(pGroupNode, "name", strTmp))
        continue;
      group.strGroupName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pGroupNode, "radio", group.bRadio);
      
      /* sort position */
      XMLUtils::GetInt(pGroupNode, "position", group.iPosition);

      /* members */
      TiXmlNode* pMembers = pGroupNode->FirstChild("members");
      TiXmlNode *pMemberNode = NULL;
      while (pMembers != NULL && (pMemberNode = pMembers->IterateChildren(pMemberNode)) != NULL)
      {
        int iChannelId = atoi(pMemberNode->FirstChild()->Value());
        if (iChannelId > -1)
          group.members.push_back(iChannelId);
      }

      m_groups.push_back(group);
    }
  }

  /* load EPG entries */
  pElement = pRootElement->FirstChildElement("epg");
  if (pElement)
  {
    TiXmlNode *pEpgNode = NULL;
    while ((pEpgNode = pElement->IterateChildren(pEpgNode)) != NULL)
    {
      CStdString strTmp;
      int iTmp;
      PVRDemoEpgEntry entry;

      /* broadcast id */
      if (!XMLUtils::GetInt(pEpgNode, "broadcastid", entry.iBroadcastId))
        continue;

      /* channel id */
      if (!XMLUtils::GetInt(pEpgNode, "channelid", iTmp))
        continue;
      PVRDemoChannel &channel = m_channels.at(iTmp - 1);
      entry.iChannelId = channel.iUniqueId;

      /* title */
      if (!XMLUtils::GetString(pEpgNode, "title", strTmp))
        continue;
      entry.strTitle = strTmp;

      /* start */
      if (!XMLUtils::GetInt(pEpgNode, "start", iTmp))
        continue;
      entry.startTime = iTmp;

      /* end */
      if (!XMLUtils::GetInt(pEpgNode, "end", iTmp))
        continue;
      entry.endTime = iTmp;

      /* plot */
      if (XMLUtils::GetString(pEpgNode, "plot", strTmp))
        entry.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pEpgNode, "plotoutline", strTmp))
        entry.strPlotOutline = strTmp;

      /* icon path */
      if (XMLUtils::GetString(pEpgNode, "icon", strTmp))
        entry.strIconPath = strTmp;

      /* genre type */
      XMLUtils::GetInt(pEpgNode, "genretype", entry.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pEpgNode, "genresubtype", entry.iGenreSubType);

      if (!XMLUtils::GetInt(pEpgNode, "season", entry.iSeriesNumber))
        entry.iSeriesNumber = -1;

      if (!XMLUtils::GetInt(pEpgNode, "episode", entry.iEpisodeNumber))
       entry.iEpisodeNumber = -1;

      XBMC->Log(LOG_DEBUG, "loaded EPG entry '%s' channel '%d' start '%d' end '%d'", entry.strTitle.c_str(), entry.iChannelId, entry.startTime, entry.endTime);
      channel.epg.push_back(entry);
    }
  }

  /* load recordings */
  iUniqueGroupId = 0; // reset unique ids
  pElement = pRootElement->FirstChildElement("recordings");
  if (pElement)
  {
    TiXmlNode *pRecordingNode = NULL;
    while ((pRecordingNode = pElement->IterateChildren(pRecordingNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoRecording recording;

      /* recording title */
      if (!XMLUtils::GetString(pRecordingNode, "title", strTmp))
        continue;
      recording.strTitle = strTmp;

      /* episode name (sub-title)*/
      if (XMLUtils::GetString(pRecordingNode, "episodename", strTmp))
        recording.strEpisodeName = strTmp;

      /* recording url */
      if (!XMLUtils::GetString(pRecordingNode, "url", strTmp))
        recording.strStreamURL = m_strDefaultMovie;
      else
        recording.strStreamURL = strTmp;

      /* recording path */
      if (XMLUtils::GetString(pRecordingNode, "directory", strTmp))
        recording.strDirectory = strTmp;

      iUniqueGroupId++;
      strTmp.Format("%d", iUniqueGroupId);
      recording.strRecordingId = strTmp;

      /* channel name */
      if (XMLUtils::GetString(pRecordingNode, "channelname", strTmp))
        recording.strChannelName = strTmp;

      /* plot */
      if (XMLUtils::GetString(pRecordingNode, "plot", strTmp))
        recording.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pRecordingNode, "plotoutline", strTmp))
        recording.strPlotOutline = strTmp;

      /* genre type */
      XMLUtils::GetInt(pRecordingNode, "genretype", recording.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pRecordingNode, "genresubtype", recording.iGenreSubType);

      if (!XMLUtils::GetInt(pRecordingNode, "season", recording.iSeriesNumber))
        recording.iSeriesNumber = -1;

      if (!XMLUtils::GetInt(pRecordingNode, "episode", recording.iEpisodeNumber))
        recording.iEpisodeNumber = -1;

      /* duration */
      XMLUtils::GetInt(pRecordingNode, "duration", recording.iDuration);

      /* recording time */
      if (XMLUtils::GetString(pRecordingNode, "time", strTmp))
      {
        time_t timeNow = time(NULL);
        struct tm* now = localtime(&timeNow);

        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);
          now->tm_mday--; // yesterday

          recording.recordingTime = mktime(now);
        }
      }

      m_recordings.push_back(recording);
    }
  }

  /* load deleted recordings */
  pElement = pRootElement->FirstChildElement("recordingsdeleted");
  if (pElement)
  {
    TiXmlNode *pRecordingNode = NULL;
    while ((pRecordingNode = pElement->IterateChildren(pRecordingNode)) != NULL)
    {
      CStdString strTmp;
      PVRDemoRecording recording;

      /* recording title */
      if (!XMLUtils::GetString(pRecordingNode, "title", strTmp))
        continue;
      recording.strTitle = strTmp;

      /* recording url */
      if (!XMLUtils::GetString(pRecordingNode, "url", strTmp))
        recording.strStreamURL = m_strDefaultMovie;
      else
        recording.strStreamURL = strTmp;

      /* recording path */
      if (XMLUtils::GetString(pRecordingNode, "directory", strTmp))
        recording.strDirectory = strTmp;

      iUniqueGroupId++;
      strTmp.Format("%d", iUniqueGroupId);
      recording.strRecordingId = strTmp;

      /* channel name */
      if (XMLUtils::GetString(pRecordingNode, "channelname", strTmp))
        recording.strChannelName = strTmp;

      /* plot */
      if (XMLUtils::GetString(pRecordingNode, "plot", strTmp))
        recording.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pRecordingNode, "plotoutline", strTmp))
        recording.strPlotOutline = strTmp;

      /* genre type */
      XMLUtils::GetInt(pRecordingNode, "genretype", recording.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pRecordingNode, "genresubtype", recording.iGenreSubType);

      /* duration */
      XMLUtils::GetInt(pRecordingNode, "duration", recording.iDuration);

      /* recording time */
      if (XMLUtils::GetString(pRecordingNode, "time", strTmp))
      {
        time_t timeNow = time(NULL);
        struct tm* now = localtime(&timeNow);

        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);
          now->tm_mday--; // yesterday

          recording.recordingTime = mktime(now);
        }
      }

      m_recordingsDeleted.push_back(recording);
    }
  }

  /* load timers */
  pElement = pRootElement->FirstChildElement("timers");
  if (pElement)
  {
    TiXmlNode *pTimerNode = NULL;
    while ((pTimerNode = pElement->IterateChildren(pTimerNode)) != NULL)
    {
      CStdString strTmp;
      int iTmp;
      PVRDemoTimer timer;
      time_t timeNow = time(NULL);
      struct tm* now = localtime(&timeNow);

      /* channel id */
      if (!XMLUtils::GetInt(pTimerNode, "channelid", iTmp))
        continue;
      PVRDemoChannel &channel = m_channels.at(iTmp - 1);
      timer.iChannelId = channel.iUniqueId;

      /* state */
      if (XMLUtils::GetInt(pTimerNode, "state", iTmp))
        timer.state = (PVR_TIMER_STATE) iTmp;

      /* title */
      if (!XMLUtils::GetString(pTimerNode, "title", strTmp))
        continue;
      timer.strTitle = strTmp;

      /* summary */
      if (!XMLUtils::GetString(pTimerNode, "summary", strTmp))
        continue;
      timer.strSummary = strTmp;

      /* start time */
      if (XMLUtils::GetString(pTimerNode, "starttime", strTmp))
      {
        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);

          timer.startTime = mktime(now);
        }
      }

      /* end time */
      if (XMLUtils::GetString(pTimerNode, "endtime", strTmp))
      {
        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);

          timer.endTime = mktime(now);
        }
      }

      XBMC->Log(LOG_DEBUG, "loaded timer '%s' channel '%d' start '%d' end '%d'", timer.strTitle.c_str(), timer.iChannelId, timer.startTime, timer.endTime);
      m_timers.push_back(timer);
    }
  }

  return true;
}
Example #24
0
OsStatus ForwardRules::parseMethodMatchContainer(const SipMessage& request,
                                                 UtlString& routeToString,
                                                 bool& authRequired,
                                                 TiXmlNode* routeMatchNode,
                                                 TiXmlNode* previousMethodMatchNode)
{
 
   OsStatus fieldMatchFound = OS_FAILED;
   UtlString method;
   request.getRequestMethod(&method);

   TiXmlNode* methodMatchNode = previousMethodMatchNode;
   TiXmlElement* routeMatchElement = routeMatchNode->ToElement();

   // Iterate through the children of the routeFrom container
   // looking for methodMatch elements
   while ( (methodMatchNode = routeMatchElement->IterateChildren( methodMatchNode)) 
      && (fieldMatchFound != OS_SUCCESS) ) 
   {
       // Skip non-elements
      if(methodMatchNode && methodMatchNode->Type() != TiXmlNode::ELEMENT)
      {
         continue;
      }

      // Skip non-methodMatch elements
      UtlString tagValue = methodMatchNode->Value();
      if(tagValue.compareTo(XML_TAG_METHODMATCH) != 0 )
      {
         continue;
      }

      //found methodPattern tag
      TiXmlElement* methodMatchElement = methodMatchNode->ToElement();
      TiXmlNode* methodPatternNode = NULL;
      // Iteratore through the children of the methodMatch element
      // looking for the first methodPattern element that matches
      for( methodPatternNode = methodMatchElement->FirstChild( XML_TAG_METHODPATTERN);
         methodPatternNode;
         methodPatternNode = methodPatternNode->NextSibling(XML_TAG_METHODPATTERN ) )
      {
         // Skip non-elements
         if(methodPatternNode && methodPatternNode->Type() != TiXmlNode::ELEMENT)
         {
            continue;
         }

         TiXmlElement* methodPatternElement = methodPatternNode->ToElement();

         // Get the value contained in the methodPattern element
         TiXmlNode* methodPatternText = methodPatternElement->FirstChild();
         if(methodPatternText && methodPatternText->Type() == TiXmlNode::TEXT)
         {
            TiXmlText* XmlMethod = methodPatternText->ToText();
            if (XmlMethod)
            {
                // If the method of the request matches the method in
                // the methodMatch element
               UtlString methodString = XmlMethod->Value();
               if (methodString.compareTo(method, UtlString::ignoreCase) == 0 )
               {
                  // Found a matching method, see if there is a fieldMatch
                  // with a fieldName attribute that matches the fields
                  // in the message
                  fieldMatchFound = parseFieldMatchContainer(request,
                     routeToString,
                     authRequired,
                     methodMatchNode);

                  if(fieldMatchFound == OS_SUCCESS)
                  {
                     break;
                  }

                  // None of the fields matched, see if the methodMatch
                  // element has an immediate child routeTo element.
                  // This is the "default" if none of the fieldMatches
                  // matched.
                  else
                  {
                      fieldMatchFound = getRouteTo(routeToString, 
                          authRequired,
                          methodMatchElement);
                      if(fieldMatchFound == OS_SUCCESS)
                      {
                          break;
                      }
                  }
               }
            }
         }
      }
   }

   if(fieldMatchFound == OS_FAILED)
   {
      // if none of the method match were successfull or if no methodMatch node present
      // get the default routeTo for this routeNode.
      fieldMatchFound = getRouteTo(routeToString, authRequired,
            routeMatchNode);
   }
   return fieldMatchFound;
}
bool CDSPSettings::LoadSettingsData(int settingId, bool initial)
{
  TiXmlDocument xmlDoc;
  string strSettingsFile = GetSettingsFile();

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    if (initial)
    {
      if (!SaveSettingsData())
      {
        KODI->Log(LOG_ERROR, "failed to create initial settings data file at '%s')", strSettingsFile.c_str());
        return false;
      }
      return true;
    }
    else
      KODI->Log(LOG_ERROR, "invalid settings data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "demo") != 0)
  {
    if (!initial)
      KODI->Log(LOG_ERROR, "invalid settings data (no <demo> tag found)");
    return false;
  }

  TiXmlElement *pElement = NULL;
  if (settingId < 0 || settingId == ID_MENU_SPEAKER_GAIN_SETUP || settingId == ID_MENU_SPEAKER_DISTANCE_SETUP)
  {
    pElement = pRootElement->FirstChildElement("channels");
    if (pElement)
    {
      TiXmlNode *pChannelNode = NULL;
      while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != NULL)
      {
        CStdString strTmp;
        sDSPSettings::sDSPChannel channel;

        if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
          continue;

        if (XMLUtils::GetString(pChannelNode, "name", strTmp))
          channel.strName = strTmp;
        else
          channel.strName = "";

        if (!XMLUtils::GetInt(pChannelNode, "volume", channel.iVolumeCorrection))
          channel.iVolumeCorrection = 0;

        if (!XMLUtils::GetInt(pChannelNode, "distance", channel.iDistanceCorrection))
          channel.iDistanceCorrection = 0;

        m_Settings.m_channels[channel.iChannelNumber].iChannelNumber          = channel.iChannelNumber;
        m_Settings.m_channels[channel.iChannelNumber].iVolumeCorrection       = channel.iVolumeCorrection;
        m_Settings.m_channels[channel.iChannelNumber].iOldVolumeCorrection    = channel.iVolumeCorrection;
        m_Settings.m_channels[channel.iChannelNumber].strName                 = channel.strName;
        m_Settings.m_channels[channel.iChannelNumber].iDistanceCorrection     = channel.iDistanceCorrection;
        m_Settings.m_channels[channel.iChannelNumber].iOldDistanceCorrection  = channel.iDistanceCorrection;
      }
    }
  }

  if (settingId < 0 || settingId == ID_MASTER_PROCESS_FREE_SURROUND)
  {
    pElement = pRootElement->FirstChildElement("freesurround");
    if (pElement)
    {
      if (!XMLUtils::GetFloat(pElement, "inputgain", m_Settings.m_FreeSurround.fInputGain))
        m_Settings.m_FreeSurround.fInputGain = 0.70794576;
      if (!XMLUtils::GetFloat(pElement, "circularwrap", m_Settings.m_FreeSurround.fCircularWrap))
        m_Settings.m_FreeSurround.fCircularWrap = 90;
      if (!XMLUtils::GetFloat(pElement, "shift", m_Settings.m_FreeSurround.fShift))
        m_Settings.m_FreeSurround.fShift = 0.0f;
      if (!XMLUtils::GetFloat(pElement, "depth", m_Settings.m_FreeSurround.fDepth))
        m_Settings.m_FreeSurround.fDepth = 1.0f;
      if (!XMLUtils::GetFloat(pElement, "centerimage", m_Settings.m_FreeSurround.fCenterImage))
        m_Settings.m_FreeSurround.fCenterImage = 1.0f;
      if (!XMLUtils::GetFloat(pElement, "focus", m_Settings.m_FreeSurround.fFocus))
        m_Settings.m_FreeSurround.fFocus = 0.0f;
      if (!XMLUtils::GetFloat(pElement, "frontseparation", m_Settings.m_FreeSurround.fFrontSeparation))
        m_Settings.m_FreeSurround.fFrontSeparation = 1.0;
      if (!XMLUtils::GetFloat(pElement, "rearseparation", m_Settings.m_FreeSurround.fRearSeparation))
        m_Settings.m_FreeSurround.fRearSeparation = 1.0;
      if (!XMLUtils::GetBoolean(pElement, "bassredirection", m_Settings.m_FreeSurround.bLFE))
        m_Settings.m_FreeSurround.bLFE = false;
      if (!XMLUtils::GetFloat(pElement, "lowcutoff", m_Settings.m_FreeSurround.fLowCutoff))
        m_Settings.m_FreeSurround.fLowCutoff = 40.0;
      if (!XMLUtils::GetFloat(pElement, "highcutoff", m_Settings.m_FreeSurround.fHighCutoff))
        m_Settings.m_FreeSurround.fHighCutoff = 90.0;
    }
  }

  return true;
}
void CSettingsManager::read_SettingsXML()
{
  TiXmlDocument xmlDoc;
  if(!xmlDoc.LoadFile(m_XMLFilename))
  {
    KODI->Log(LOG_NOTICE, "No initial settings XML file found.");
    return;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if(!pRootElement)
  {
    KODI->Log(LOG_NOTICE, "Settings XML file is empty.");
    return;
  }

  string mainCategory = pRootElement->Value();
  for(TiXmlNode *pGroupNode = pRootElement->FirstChild(); pGroupNode != NULL; pGroupNode = pRootElement->IterateChildren(pGroupNode))
  {
    if(pGroupNode->ValueStr() == "settings_group")
    {
      ATTRIBUTES_LIST groupAttributesList;
      if(pGroupNode && pGroupNode->Type() == TiXmlNode::TINYXML_ELEMENT)
      {
        getAttributesAsList(pGroupNode->ToElement(), groupAttributesList);
      }

      if(pGroupNode && pGroupNode->Type() == TiXmlNode::TINYXML_ELEMENT && groupAttributesList.size() == 2 && pGroupNode->ValueStr() == "settings_group")
      {
        string subCategory = "";
        string groupName = "";
        for(ATTRIBUTES_LIST::iterator iter = groupAttributesList.begin(); iter != groupAttributesList.end(); iter++)
        {
          if(iter->first == "sub_category")
          {
            subCategory = iter->second;
          }

          if(iter->first == "group_name")
          {
            groupName = iter->second;
          }
        }

        for(TiXmlNode *pKeyNode = pGroupNode->FirstChild(); pKeyNode != NULL; pKeyNode = pGroupNode->IterateChildren(pKeyNode))
        {
          if(pKeyNode && pKeyNode->Type() == TiXmlNode::TINYXML_ELEMENT && pKeyNode->ValueStr() == "setting")
          {
            ATTRIBUTES_LIST settingAttributesList;
            if(getAttributesAsList(pKeyNode->ToElement(), settingAttributesList) == 2)
            {
              string key = "";
              ISettingsElement::SettingsTypes type = ISettingsElement::UNKNOWN_SETTING;
              string value = "";
              for(ATTRIBUTES_LIST::iterator iter = settingAttributesList.begin(); iter != settingAttributesList.end(); iter++)
              {
                if(iter->first == "key")
                {
                  key = iter->second;
                }
                else
                {
                  type = CSettingsHelpers::TranslateTypeStrToEnum(iter->first);
                  value = iter->second;
                }
              }

              ISettingsElement *setting = find_Setting(mainCategory, subCategory, groupName, key);
              if(setting && setting->get_Type() == type)
              {
                switch(type)
                  {
                    case ISettingsElement::STRING_SETTING:
                      STRING_SETTINGS(setting)->set_Setting(value);
                    break;

                    case ISettingsElement::UNSIGNED_INT_SETTING:
                      {
                        unsigned int val = stringToVal<unsigned int>(value);
                        UNSIGNED_INT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::INT_SETTING:
                      {
                        int val = stringToVal<int>(value);
                        INT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::FLOAT_SETTING:
                      {
                        float val = stringToVal<float>(value);
                        FLOAT_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::DOUBLE_SETTING:
                      {
                        double val = stringToVal<double>(value);
                        DOUBLE_SETTINGS(setting)->set_Setting(val);
                      }
                    break;

                    case ISettingsElement::BOOL_SETTING:
                      if(value == "true" || value == "TRUE" || value == "True")
                      {
                        bool val = true;
                        BOOL_SETTINGS(setting)->set_Setting(val);
                      }
                      else if(value == "false" || value == "FALSE" || value == "False")
                      {
                        bool val = false;
                        BOOL_SETTINGS(setting)->set_Setting(val);
                      }
                      else
                      {
                        KODI->Log(LOG_ERROR, "CSettingsManager: Failed reading bool setting");
                      }
                    break;

                    default:
                      KODI->Log(LOG_ERROR, "CSettingsManager: Unknown settings type!");
                    break;
                  }
              }
              else
              {
                KODI->Log(LOG_ERROR, "CSettingsManager: Read settings element does not match the created settings element type!");
              }
            }
          }
        }
      }
    }
  }
}