コード例 #1
0
AREXPORT void ArClientHandlerConfig::handleGetConfigData(ArNetPacket *packet,
                                                         bool isMultiplePackets)
{
  char name[32000];
  char comment[32000];
  char type;
  std::string section;
  
  // The multiple packets method also sends display hints with the parameters;
  // the old single packet method does not.
  ArClientArg clientArg(isMultiplePackets, 
                        ArPriority::LAST_PRIORITY);
  bool isEmptyPacket = true;

  myDataMutex.lock();

  while (packet->getDataReadLength() < packet->getDataLength())
  {
    isEmptyPacket = false;

    type = packet->bufToByte();

    if (type == 'S')
    {
      packet->bufToStr(name, sizeof(name));
      packet->bufToStr(comment, sizeof(name));
      //printf("%c %s %s\n", type, name, comment);

      ArLog::log(ArLog::Verbose, "%sReceiving config section %s...", 
                 myLogPrefix.c_str(), name);
      
      section = name;
      myConfig.setSectionComment(name, comment);
    }
    else if (type == 'P')
    {
		  ArConfigArg configArg;

		  bool isSuccess = clientArg.createArg(packet,
											                     configArg);

		  if (isSuccess) {
        
			  myConfig.addParam(configArg,
							            section.c_str(),
							            configArg.getConfigPriority(),
                          configArg.getDisplayHint());
		  }
		  else
		  {
			  ArLog::log(ArLog::Terse, "ArClientHandlerConfig unknown param type");
		  }
    }
    else // unrecognized header
    {
      ArLog::log(ArLog::Terse, "ArClientHandlerConfig unknown type");
    }
  
  } // end while more to read

  if (!isMultiplePackets || isEmptyPacket) {

    ArLog::log(ArLog::Normal, "%sGot config from server.", myLogPrefix.c_str());
    IFDEBUG(myConfig.log());

    myHaveGottenConfig = true;
  }

  myDataMutex.unlock();



  if (myHaveGottenConfig) {

    myCallbackMutex.lock();

    for (std::list<ArFunctor *>::iterator it = myGotConfigCBList.begin(); 
        it != myGotConfigCBList.end(); 
        it++) {
      (*it)->invoke();
    }
    myCallbackMutex.unlock();

  } // end if config received

} // end method handleGetConfigData
コード例 #2
0
/** 
    @internal

    doesn't delete the old one, do that if you're going to call this
    yourself and make sure you lock around all that (okay, it deletes
    it now, but the stuff that calls it should still take care of it)
**/
void ArServerHandlerConfig::createDefaultConfig(const char *defaultFileBaseDir)
{
  if (myDefault != NULL)
  {
    delete myDefault;
    myDefault = NULL;
  }
  // copy that config (basedir will be NULL if we're not loading from
  // a file)... don't have the default save unknown values
  myDefault = new ArConfig(defaultFileBaseDir, false, false, false, false);

  std::list<ArConfigSection *>::iterator sectionIt;
  std::list<ArConfigArg>::iterator paramIt;
  ArConfigSection *section = NULL;
  std::list<ArConfigArg> *params = NULL;
  ArConfigArg param;
  for (sectionIt = myConfig->getSections()->begin(); 
       sectionIt != myConfig->getSections()->end(); 
       sectionIt++)
  {
    section = (*sectionIt);
    params = section->getParams();
    for (paramIt = params->begin(); paramIt != params->end(); paramIt++)
    {
      param = (*paramIt);
      switch (param.getType()) {
      case ArConfigArg::INT:
	myDefault->addParam(
		ArConfigArg(param.getName(), param.getInt(), 
			    param.getDescription(), 
			    param.getMinInt(), param.getMaxInt()), 
		section->getName(), 
		param.getConfigPriority(),
		param.getDisplayHint());
	break;
      case ArConfigArg::DOUBLE:
	myDefault->addParam(
		ArConfigArg(param.getName(), param.getDouble(), 
			    param.getDescription(),
			    param.getMinDouble(), param.getMaxDouble()), 
		section->getName(), 
		param.getConfigPriority(),
		param.getDisplayHint());
	break;
	
      case ArConfigArg::BOOL:
	myDefault->addParam(
		ArConfigArg(param.getName(), param.getBool(), 
			    param.getDescription()),
		section->getName(), 
		param.getConfigPriority(),
		param.getDisplayHint());
	break;
	
      case ArConfigArg::STRING:
	myDefault->addParam(
		ArConfigArg(param.getName(), (char *)param.getString(), 
			    param.getDescription(), 0),
		section->getName(), 
		param.getConfigPriority(),
		param.getDisplayHint());
	break;
	
      case ArConfigArg::SEPARATOR:
	myDefault->addParam(
		ArConfigArg(ArConfigArg::SEPARATOR),
		section->getName(), 
		param.getConfigPriority(),
		param.getDisplayHint());
	break;
      default:
	break;
      } // end switch param type
    } // end for each param
  } // end for each section
}