예제 #1
0
파일: shader.cpp 프로젝트: devnev/skyways
void Shader::setSource(const ShaderSource& source)
{
	std::list< std::string > sources = source.getSources();
	if ( sources.size() == 0 )
	{
		throw std::runtime_error("Attempted to create shader with empty sources");
	}
	if ( sources.size() == 1 )
	{
		const char * cstr = sources.front().c_str();
		glShaderSource(_shaderId, 1, &cstr, 0);
	}
	else
	{
		std::vector< const char* > strArray(sources.size(), 0);
		size_t i = 0;
		std::list< std::string >::iterator sourcestr = sources.begin();
		for ( ; sourcestr != sources.end(); ++sourcestr, ++i )
		{
			strArray[i] = sourcestr->c_str();
		}
		glShaderSource(_shaderId, i, &strArray[0], 0);
	}
}
예제 #2
0
파일: mod_ovs.c 프로젝트: sflow/host-sflow
  static int syncOVS(EVMod *mod)
  {
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    resetCmd(mod);
    resetExtras(mod);
    char line[SFVS_MAX_LINELEN];

    myDebug(1, "==== ovs-vsctl version ====");
    char *version_cmd[] = { SFVS_OVS_CMD, "--version", NULL};
    // don't abort if this fails: readVersion returns NO as an easy way
    // to only see the first line. (Line number should really be supplied to
    // callback from myExec)
    mdata->ovs10 = NO; // assume newer version
    mdata->usingAtVar = NO;
    myExec((void *)mod, version_cmd, readVersion, line, SFVS_MAX_LINELEN, NULL);
    // adapt if OVS is upgraded under our feet
    if(mdata->ovs10 == NO) mdata->useAtVar = YES;
    if(mdata->config.error
       || mdata->config.num_collectors == 0
       || (mdata->config.sampling_n == 0 && mdata->config.polling_secs == 0)) {
      // no config or no targets or no sampling/polling - clear everything
      myDebug(1, "no config found: clearing all OVS sFlow config");
      setStr(&mdata->sflowUUID, "[]");
      setState(mod, SFVSSTATE_SYNC_DESTROY);
    }
    else {
      // got config - assume here that we're going to create a new
      // sflow object, but if we find one we'll adopt it
      setStr(&mdata->sflowUUID, SFVS_NEW_SFLOW_ID);
      setState(mod, SFVSSTATE_SYNC_SEARCH);
    }
    myDebug(1, "==== list sflow ====");
    char *list_sflow_cmd[] = { SFVS_OVS_CMD, "list", "sflow", NULL };
    if(myExec((void *)mod, list_sflow_cmd, sFlowList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;

    if(mdata->useAtVar) {
      // we can add the create at the end
    }
    else {
      // create new sFlow object if there were none found (i.e. if
      // the sflowUUID has not changed from the initial setting we
      // gave it.
      if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) {
	addCreateSFlow(mod);
	logCmd(mod);
	strArrayAdd(mdata->cmd, NULL); // for execve(2)
	if(myExec((void *)mod, strArray(mdata->cmd), submitCreate, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
	resetCmd(mod);
      }
    }

    // make sure every bridge is using this sFlow entry
    myDebug(1, "==== list bridge ====");
    char *list_bridge_cmd[] = { SFVS_OVS_CMD, "list", "bridge", NULL};
    if(myExec((void *)mod, list_bridge_cmd, bridgeList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;

    // now it's safe to delete any extras that we found
    for(int ex = strArrayN(mdata->extras); --ex >= 0; ) {
      addDestroySFlow(mod, strArrayAt(mdata->extras, ex));
    }

    if(mdata->useAtVar) {
      // create new sFlow object if there were none found (i.e. if
      // the sflowUUID has not changed from the initial setting we
      // gave it.
      if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) {
	addCreateSFlow(mod);
      }
    }

    // if we decided to make any changes, submit them now
    mdata->cmdFailed = NO;
    if(strArrayN(mdata->cmd) > 1) {
      logCmd(mod);
      strArrayAdd(mdata->cmd, NULL); // for execve(2)
      if(myExec((void *)mod, strArray(mdata->cmd), submitChanges, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
      if(mdata->usingAtVar && mdata->cmdFailed == NO) {
        // remember that it worked at least once
        mdata->usedAtVarOK = YES;
      }
    }
    return mdata->cmdFailed ? NO : YES;
  }