Esempio n. 1
0
	void RSSManager::updateFeed(int feedId, RSSManagerCallback callback, void * data)
	{
		RSSFeedItemVector result;

		RSSDocument doc;

		RSSFeed & feed = getFeed(feedId);
		if (feed.url.empty())
		{
			if (callback)
				callback(feedId, false, result, data, "Empty feed url");
			return;
		}

		// for debugging things
#ifdef _DEBUG
		//
		if (feed.url.at(0) == 0x7f)
		{
			doc.LoadFile(feed.url.substr(1, std::string::npos).c_str());
		}
		else
#endif
		{
			bool success = false;
			std::vector<char> & file = manager.downloadSingle(feed.url, success);

			if (success)
			{
				doc.Parse(file.data(), file.size());
			}
			else
			{
				if (callback)
				{
					callback(feedId, false, result, data, manager.getLastError());
				}
				return;
			}
		}
		
		result = updateFeedFromDoc(&doc, feedId);

		if (callback)
		{
			callback(feedId, true, result, data, "Success");
		}
	}
void AdafruitIO_Group::subCallback(char *val, uint16_t len)
{

  char *line;
  char *name;
  char *value;

  if(_groupCallback == NULL)
    return;

  while((line = strtok_r(val, "\n", &val)) != NULL) {

    name = strtok_r(line, ",", &line);

    // couldn't grab name from line, move on
    if(! name)
      continue;

    // don't handle location for now
    if(strcmp(name, "location") == 0)
      continue;

    value = strtok_r(line, ",", &line);

    // no value? move on
    if(! value)
      continue;

    AdafruitIO_Data *feed = getFeed(name);

    // we couldn't get the data, move on
    if(! feed)
      continue;

    feed->setValue(value);
    call(feed);

  }

}
void AdafruitIO_Group::set(const char *feed, double value)
{
  AdafruitIO_Data *f = getFeed(feed);
  f->setValue(value);
}
void AdafruitIO_Group::set(const char *feed, unsigned long value)
{
  AdafruitIO_Data *f = getFeed(feed);
  f->setValue(value);
}