void AbstractPipeline::run() {
        std::unique_lock<std::mutex> lock(*cgt::GlContextManager::getRef().getGlMutexForContext(_canvas));
        cgt::GlContextManager::getRef().acquireContext(_canvas, false);

        while (! _stopExecution) {
            if (_enabled && _pipelineDirty) {
                // mark pipeline as not dirty
                _pipelineDirty = false;

                // execute pipeline
                executePipeline();

                // paint on canvas
                _canvas->getPainter()->paint();
            }

            if (!_stopExecution && (!_enabled || !_pipelineDirty)) {
                cgt::GlContextManager::getRef().releaseContext(_canvas, false);
                _evaluationCondition.wait(lock);
                cgt::GlContextManager::getRef().acquireContext(_canvas, false);
            }
        }

        cgt::GlContextManager::getRef().releaseContext(_canvas, false);
    }
Exemplo n.º 2
0
    bool PipelineCommand::runExecute(
        BSONObjBuilder &result, string &errmsg,
        const string &ns, const string &db,
        intrusive_ptr<Pipeline> &pPipeline,
        intrusive_ptr<ExpressionContext> &pCtx) {

        // The DocumentSourceCursor manages a read lock internally, see SERVER-6123.
        intrusive_ptr<DocumentSourceCursor> pSource(
            PipelineD::prepareCursorSource(pPipeline, db, pCtx));
        return executePipeline(result, errmsg, ns, pPipeline, pSource, pCtx);
    }
Exemplo n.º 3
0
Arquivo: digenv.c Projeto: pagr/id2200
/** executePipeline
 *
 * executePipeline returns 0 if ok error code if not
 *
 * Def:
 *     Execute all programs with parameters and connects their stdout to the next programs stdin.
 *     The first programs STDIN is fin and thlast programs stdout is stdout.
 *
 */
int
executePipeline(
	int fin, 		/* Filedescriptor number to redirect stdin to */
	char** programs[])	/* list of list of strings. The inner list contains a program and it's arguments */
{
	char * program = *programs[0];
	char ** args = programs[0];

	/*  Check if this is the last program. This is inportant for the last pipe  */
	int lastProgram = 0;
	if (programs[1]==NULL) lastProgram=1;

	int fd[2];
	int ret=pipe(fd);
	if (ret) { fprintf(stderr, "Failed to create pipe\n"); return 1;}


	int childPid=fork();
	if (childPid==-1){ fprintf(stderr, "Could not fork\n"); return 1;}
	if (!childPid)
	{
		/*  Child process - Close and duplicate pipes for reading and writing then execute program  */
		ret = close(fd[0]);
		if (ret == -1) { fprintf(stderr, "Failed to close pipe(non critical)\n");}
		ret = dup2(fin,STDIN_FILENO);
		if (ret == -1) { fprintf(stderr, "Failed to duplicate pipe(STDIN)\n"); return 1;}

		if (!lastProgram)
		{
			ret = dup2(fd[1],STDOUT_FILENO);
			if (ret == -1) { fprintf(stderr, "failed to duplicate pipe(STDOUT)\n"); return 1;}
		}
		ret = close(fd[1]);
		if (ret == -1) { fprintf(stderr, "Failed to close pipe(non critical");}
		execvp(program,args); /* Finds program path(in $PATH) and executes it */
	}
	else
	{
		/* Main process - Wait for return value then recurse  */
		int statval;

		ret = wait(&statval); 	/* wait for child to exit */
		//if (!ret) {printf("Wait failed"); return 1;}
		if (statval!=0) { fprintf(stderr, "Error with code %d from %s\n",statval,program);close(fd[0]); return 1;}
		ret = close(fd[1]);
		if (ret == -1) { fprintf(stderr, "failed to close pipe(non critical)\n");}

		if (!lastProgram)
			return executePipeline(fd[0],programs+1);
	}
	return 0;
}
Exemplo n.º 4
0
Arquivo: digenv.c Projeto: pagr/id2200
int 
main(
	int argc,	/* Number of arguments passed in argv*/
	char *argv[])	/* Command line arguments*/
{
	char * pager=getenv("PAGER");
	if (pager==NULL) pager="less";

	char * printenv[] = {"printenv",NULL};
	char * sort[] = {"sort",NULL};
	char * less[] = {pager,NULL};

	int result;
	if (argc>1)
	{
		argv[0] = "grep";
		char ** programs[] = {printenv,argv,sort,less,NULL};
		result = executePipeline(STDIN_FILENO, programs);
	}else{
		char ** programs[] = {printenv,sort,less,NULL};
		result = executePipeline(STDIN_FILENO, programs);
	}
	return result;
}
Exemplo n.º 5
0
// ****************************************************************************
// Constructor:  ELPipelineBuilder::ELPipelineBuilder
//
// Programmer:  Jeremy Meredith
// Creation:    August  2, 2012
//
// Modifications:
// ****************************************************************************
ELPipelineBuilder::ELPipelineBuilder(QWidget *parent)
    : QWidget(parent)
{
    currentPipeline = -1;

    // Top layout
    QGridLayout *topLayout = new QGridLayout(this);
    pipelineChooser = new QComboBox(this);
    connect(pipelineChooser, SIGNAL(activated(int)), 
            this, SLOT(activatePipeline(int)));
    topLayout->addWidget(new QLabel("Pipeline: ", this), 0,0, 1,1);
    topLayout->addWidget(pipelineChooser, 0,1, 1,1);

    QPushButton *newPipelineBtn = new QPushButton("New Pipeline", this);
    topLayout->addWidget(newPipelineBtn, 1,0, 1,2);
    connect(newPipelineBtn, SIGNAL(clicked()),
            this, SLOT(NewPipeline()));

    QSplitter *topSplitter = new QSplitter(Qt::Vertical, this);
    topLayout->addWidget(topSplitter, 3, 0, 1, 2);

    QGroupBox *pipelineGroup = new QGroupBox("Pipeline",
                                             topSplitter);

    QGridLayout *pipelineLayout = new QGridLayout(pipelineGroup);

    //
    // The pipeline tree
    //
    tree = new QTreeWidget(pipelineGroup);
    tree->setHeaderLabels(QStringList() << "Operation" << "Settings");
    //tree->setHeaderHidden(true);
    pipelineLayout->addWidget(tree, 0,0);
    connect(tree, SIGNAL(itemSelectionChanged()),
            this, SLOT(rowSelected()));

    //
    // The operator menu
    //
    QMenu *opMenu = new QMenu();
    ///\todo: these choice names must currently match the exact text in
    /// Operation::GetOperationName.  We should loosed this restriction.
    const char *operations[] = {
        "Isosurface",
        "Elevate",
        "ExternalFace",
        "Histogram",
        "SurfaceNormals",
        "Transform",
        NULL
    };
    for (int i=0; operations[i] != NULL; i++)
    {
        QAction *op= opMenu->addAction(operations[i]);
        op->setData(QString(operations[i]));
        connect(op, SIGNAL(triggered()), this, SLOT(newOperation()));
    }
    QPushButton *addOpButton = new QPushButton("Add Operation", pipelineGroup);
    addOpButton->setMenu(opMenu);
    pipelineLayout->addWidget(addOpButton, 1,0);

    //
    // add execute button (probably not the best place for it)
    //
    QPushButton *deleteOpButton = new QPushButton("Delete Operation", pipelineGroup);
    pipelineLayout->addWidget(deleteOpButton, 2, 0);
    connect(deleteOpButton, SIGNAL(clicked()),
            this, SLOT(deleteCurrentOp()));


    //
    // add execute button (probably not the best place for it)
    //
    QPushButton *executeButton = new QPushButton("Execute", pipelineGroup);
    pipelineLayout->addWidget(executeButton, 3, 0);
    connect(executeButton, SIGNAL(clicked()),
            this, SLOT(executePipeline()));

    //
    // Settings
    //
    settingsGroup = new QGroupBox("Settings", topSplitter);
    QGridLayout *settingsLayout = new QGridLayout(settingsGroup);

    //
    // sources widgets
    //
    sourceSettings = new ELSources(settingsGroup);
    connect(sourceSettings, SIGNAL(sourceChanged()),
            this, SLOT(sourceUpdated()));
    settingsLayout->addWidget(sourceSettings);

    topSplitter->setStretchFactor(0,30);
    topSplitter->setStretchFactor(1,50);

    // add one pipeline
    Pipeline::allPipelines.push_back(new Pipeline);
    activatePipeline(0);
    pipelineChooser->addItem("");
}