Example #1
0
bool ObjectDataIStream::getNextBuffer( uint32_t* compressor, uint32_t* nChunks,
                                       const void** chunkData, uint64_t* size )
{
    const Command* command = getNextCommand();
    if( !command )
        return false;

    const ObjectDataPacket* packet = command->get< ObjectDataPacket >();
    LBASSERT( packet->command == CMD_OBJECT_INSTANCE ||
              packet->command == CMD_OBJECT_DELTA ||
              packet->command == CMD_OBJECT_SLAVE_DELTA );

    if( packet->dataSize == 0 ) // empty packet
        return getNextBuffer( compressor, nChunks, chunkData, size );

    *size = packet->dataSize;
    *compressor = packet->compressorName;
    *nChunks = packet->nChunks;
    *size = packet->dataSize;
    switch( packet->command )
    {
      case CMD_OBJECT_INSTANCE:
        *chunkData = command->get< ObjectInstancePacket >()->data;
        break;
      case CMD_OBJECT_DELTA:
        *chunkData = command->get< ObjectDeltaPacket >()->data;
        break;
      case CMD_OBJECT_SLAVE_DELTA:
        *chunkData = command->get< ObjectSlaveDeltaPacket >()->data;
        break;
    }
    return true;
}
Example #2
0
int main(int argc, char *argv[]){

	if(argc <= 1){
		printProgramInfo();
		return 0;
	}

	initData();
	dataIndex = 0;
	
	pSourceCodeFile = fopen(argv[1], "rb");
	int cmd = 0;
	if (pSourceCodeFile==NULL){
		fatalError(FILE_OPEN_FAILED_ERROR_MSG);
	}
	while(!feof(pSourceCodeFile)){
		cmd = getNextCommand();
		if(cmd!=EOF){
			execCommand(cmd);
		}
	}
	fclose(pSourceCodeFile);
	msg(EXECUTION_FINISHED_MSG);
	return 0;
}
Example #3
0
void Console::start()
{
	CommandAndArguments commandAndArguments;
	while (commandAndArguments.command().toLower() != ExitCommand) {
		commandAndArguments = getNextCommand();

		checkCommand(commandAndArguments);
	}
	emit exitConsole();
}
std::string DatabaseReader::getNextText()
{
	std::string result = "";
	if (currentPos_ >= fileContents_.length())
		return "";
	if (fileContents_.at(currentPos_) == '#')
	{
		result = getNextCommand();
		currentPos_ += result.length();
	}
	else
	{
		result = getNextDisplayText();
		currentPos_ += result.length() + 1;
	}
	return result;
}
Example #5
0
void interfaceLoop() {
    Puzzle *puzzle = NULL;
    char command = '\0';
    
    showSolution = false;
    
    createDirectionKeys();
    createOptionKeys();
    
    do {
        puzzle = createPuzzle(getPuzzleSize());
        shuffleCount = getShuffleCount();
        shufflePuzzle(puzzle, shuffleCount);
        
        showSolution = false;
        
        while( !isSolved(puzzle) ){
            printHeader();
            printPuzzle(puzzle);
            command = getNextCommand(puzzle);
            
            if(command == INVERT_KEY) {
                puzzle->inverted = (puzzle->inverted) ? false : true;
                invertSolution(puzzle);
                setDirectionVectors(puzzle);
            }
            else if(command == SOLVE_KEY)
                showSolution = (showSolution) ? false : true;
            else if(command == QUIT_KEY || command == RESTART_KEY)
                break;
            else
                applyDirection(puzzle, getData(directionKeys, command));
        }
        
        if( isSolved(puzzle) ) {
            printPuzzle(puzzle);
            printWinner();
        }
        
        destroyPuzzle(&puzzle);
    } while(command == RESTART_KEY);
    
    destroyOptionKeys();
    destroyDirectionKeys();
}
void ExecutorCommon::main(){
    shouldStop = false;
    while(!shouldStop){

        Instruction inst = getNextCommand();

        if(inst.type == Instruction::STOP){
            return;
        }

        ActuatorCommand* newCommand = (ActuatorCommand*) inst.command;
        if (newCommand!= NULL && currentActuatorCommand!= NULL){
            //send error to old command
            debug("Newer command recived seding error to old one");
            sendResponseFromCommand(currentActuatorCommand, ERROR);
        }

        if (newCommand!=NULL){
            debug("executing new command");
            (this->*actuatorHandles[newCommand->getActuatorType()])(newCommand); // do new command ( map static cast )

        }
    }
}
Example #7
0
//This Function allows the user to run a batchfile containing several commands on mothur
bool ScriptEngine::getInput(){
	try {
			
		string input = "";
		string commandName = "";
		string options = "";
		
		
		//CommandFactory cFactory;
		int quitCommandCalled = 0;
	
		while(quitCommandCalled != 1){
			
			#ifdef USE_MPI
				int pid, processors;
				MPI_Status status;
				MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
				MPI_Comm_size(MPI_COMM_WORLD, &processors);
				
				if (pid == 0) {
				//cout << pid << " is here " << processors << endl;
			#endif
			
			input = getNextCommand(listOfCommands);	
			
			if (input == "") { input = "quit()"; }
                    
            if (mout->changedSeqNames) { mout->mothurOut("[WARNING]: your sequence names contained ':'.  I changed them to '_' to avoid problems in your downstream analysis.\n"); }
			
			if (mout->gui) {
				if ((input.find("quit") != string::npos) || (input.find("set.logfile") != string::npos)) {}
				else if ((input.find("get.current") != string::npos) && (!mout->hasCurrentFiles())) {}
				else {  mout->mothurOut("\nmothur > " + input + "\n");  }
			}else{
				mout->mothurOut("\nmothur > " + input + "\n");
			}
			
			#ifdef USE_MPI
				//send commandName
				for(int i = 1; i < processors; i++) {
                    //cout << pid << " is here " << input << endl;
						int length = input.length();
						MPI_Send(&length, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
                    //cout << pid << " is here " << length << '\t' << input << endl;
						MPI_Send(&input[0], length, MPI_CHAR, i, 2001, MPI_COMM_WORLD);
	//cout << pid << " is here " << length << '\t' << input << endl;
					}
				}else {
					int length;
					MPI_Recv(&length, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
                    //cout << pid << " is here " << length << endl;
					//recieve container
					char* tempBuf = new char[length];
					MPI_Recv(&tempBuf[0], length, MPI_CHAR, 0, 2001, MPI_COMM_WORLD, &status);
					//cout << pid << " is here " << length << '\t' << tempBuf << endl;
					input = tempBuf;
					if (input.length() > length) { input = input.substr(0, length);  }
					delete tempBuf;	
				}

			
			#endif
			
			
			if (mout->control_pressed) { input = "quit()"; }
				
			//allow user to omit the () on the quit command
			if (input == "quit") { input = "quit()"; }

			CommandOptionParser parser(input);
			commandName = parser.getCommandString();
			options = parser.getOptionString();
										
			if (commandName != "") {
					mout->executing = true;
					#ifdef USE_MPI
						int pid, numProcesses;
						
						MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
						MPI_Comm_size(MPI_COMM_WORLD, &numProcesses); 
					
//cout << pid << " is here " << commandName  << endl;
						if ((cFactory->MPIEnabled(commandName)) || (pid == 0)) {
							//cout << pid << " is in execute" << endl;
					#endif
					//executes valid command
                    mout->changedSeqNames = false;
					mout->runParse = true;
					mout->clearGroups();
					mout->clearAllGroups();
					mout->Treenames.clear();
					mout->saveNextLabel = "";
                    mout->commandInputsConvertError = false;
                    mout->printedSharedHeaders = false;
                    mout->currentSharedBinLabels.clear();
                    mout->sharedBinLabelsInFile.clear();
                    mout->printedListHeaders = false;
                    mout->listBinLabelsInFile.clear();

					Command* command = cFactory->getCommand(commandName, options);
					if (mout->commandInputsConvertError) { quitCommandCalled = 2; }
					else { quitCommandCalled = command->execute(); }
					
					//if we aborted command
					if (quitCommandCalled == 2) {  mout->mothurOut("[ERROR]: did not complete " + commandName + ".\n");  }
							
					mout->control_pressed = 0;
					mout->executing = false;
									
					#ifdef USE_MPI
					//cout << pid << " is done in execute" << endl;
						}
                        MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
					#endif
				}else {		
					mout->mothurOut("Invalid.\n");
				}

			
		}
		
		return 1;
	}
	catch(exception& e) {
		mout->errorOut(e, "ScriptEngine", "getInput");
		exit(1);
	}
}
Example #8
0
int main(int argc, char** argv) {
    if (argc == 1) {
        return 0;
    }

    // Check input for validity.
    if (!validateInput(argc - 1, &argv[1])) {
        return -1;
    }

    // Count number of processes on the pipeline.
    for (int i = 0; argv[i] != 0; ++i) {
        if (!strcmp(argv[i], "|")) {
            ++numProcesses;
        }
    }

    // Open files as needed for I/O redirection.
    int bound = argc - 1;
    for (int i = 0; i < bound; ++i) {
        int erase_redirect = 0;
        // Find output redirect if it exists and open the pipe.
        if (!strcmp(argv[i], ">")) {
            write_fd = open(argv[i+1], O_CREAT | O_WRONLY);
            if (write_fd < 0) {
                perror(argv[i+1]);
                exit(-1);
            }
            dup2(write_fd, 1);
            close(write_fd);
            erase_redirect = 1;
        }
        // Find input redirect if it exists and get the file descriptor for it.
        if (!strcmp(argv[i], "<")) {
            read_fd = open(argv[i+1], O_RDONLY);
            if (read_fd < 0) {
                perror(argv[i+1]);
                exit(-1);
            }
            erase_redirect = 1;
        }

        // If a redirect is detected, eliminate the arguments and continue
        // processing.
        if (erase_redirect) {
            for (int j = i; j < bound - 1; ++j) {
                argv[j] = argv[j+2];
            }
            argc -= 2;
            bound -= 2;
            erase_redirect = 0;
            --i;
        }
    }

    // Get first command to execute.
    curIndex = argc - 1;
    prevIndex = curIndex;
    curIndex = nextSpecial(curIndex, argv);
    if (curIndex == -1) curIndex = 0;
    getNextCommand(curIndex + 1, prevIndex, argv);

    // If there are multiple processes, enter function to execute all processes.
    if (numProcesses > 1) {
        executeNext(argc, argv);
    }
    // Otherwise, redirect stdin if needed and execute the command.
    else {
        if (read_fd != -1) {
            dup2(read_fd, 0);
            close(read_fd);
        }
        execvp(command[0], command);
    }

    freeCommand();
}
Example #9
0
//This Function allows the user to run a batchfile containing several commands on Dotur
bool BatchEngine::getInput(){
	try {
		//check if this is a valid batchfile
		if (openedBatch == 1) {  
			mout->mothurOut("unable to open batchfile");  
			mout->mothurOutEndLine();
			return 1; 
		}
	
		string input = "";
		string commandName = "";
		string options = "";
		
		//CommandFactory cFactory;
		int quitCommandCalled = 0;
	    int count = 0;
		while(quitCommandCalled != 1){
			
			#ifdef USE_MPI
				int pid, processors;
				MPI_Status status;
				MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
				MPI_Comm_size(MPI_COMM_WORLD, &processors);
				
				if (pid == 0) {
				
			#endif
			
			input = getNextCommand(inputBatchFile);
			count++;
			
			#ifdef USE_MPI
				//send commandName
				for(int i = 1; i < processors; i++) { 
						int length = input.length();
						MPI_Send(&length, 1, MPI_INT, i, 2001, MPI_COMM_WORLD);
						MPI_Send(&input[0], length, MPI_CHAR, i, 2001, MPI_COMM_WORLD);
	
					}
				}else {
					int length;
					MPI_Recv(&length, 1, MPI_INT, 0, 2001, MPI_COMM_WORLD, &status);
					//recieve container
					char* tempBuf = new char[length];
					MPI_Recv(&tempBuf[0], length, MPI_CHAR, 0, 2001, MPI_COMM_WORLD, &status);
					
					input = tempBuf;
					if (input.length() > length) { input = input.substr(0, length);  }
					delete tempBuf;	
				}

			
			#endif

			
			
			if (input[0] != '#') {
				
				mout->mothurOutEndLine();
				mout->mothurOut("mothur > " + input);
				mout->mothurOutEndLine();
							
				if (mout->control_pressed) { input = "quit()"; }
				
				//allow user to omit the () on the quit command
				if (input == "quit") { input = "quit()"; }

				CommandOptionParser parser(input);
				commandName = parser.getCommandString();
				options = parser.getOptionString();
										
				if (commandName != "") {
					mout->executing = true;
					#ifdef USE_MPI
						int pid;
						MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
						
//cout << pid << " is here " << commandName << '\t' << count << endl;
						if ((cFactory->MPIEnabled(commandName)) || (pid == 0)) {
					#endif
					//executes valid command
					mout->runParse = true;
					mout->clearGroups();
					mout->clearAllGroups();
					mout->Treenames.clear();
					mout->names.clear();
					mout->saveNextLabel = "";
					mout->printedHeaders = false;
					mout->commandInputsConvertError = false;
					mout->currentBinLabels.clear();
					mout->binLabelsInFile.clear();

							
					Command* command = cFactory->getCommand(commandName, options);
					if (mout->commandInputsConvertError) { quitCommandCalled = 2; }
					else { quitCommandCalled = command->execute(); }
							
					//if we aborted command
					if (quitCommandCalled == 2) {  mout->mothurOut("[ERROR]: did not complete " + commandName + "."); mout->mothurOutEndLine(); }

					mout->control_pressed = 0;
					mout->executing = false;
										
					#ifdef USE_MPI
						}
					#endif
				}else {		
					mout->mothurOut("Invalid."); 
					mout->mothurOutEndLine();
				}
				
			}
			mout->gobble(inputBatchFile);
		}
		
		inputBatchFile.close();
		return 1;
	}
	catch(exception& e) {
		mout->errorOut(e, "BatchEngine", "getInput");
		exit(1);
	}
}
Example #10
0
static void
outlineObject(path *           const pathP,
              struct fillobj * const fillObjP) {
/*----------------------------------------------------------------------------
  Create a fill object, which contains and outline of the object and
  can be used with ppmd_fill() to fill the figure.  The outline is as
  described by *pathP.
-----------------------------------------------------------------------------*/
    pathReader * pathReaderP;
    bool endOfPath;
    point currentPos;
    point subpathStart;
        /* Point at which the current subpath starts */

    endOfPath = false;
    subpathStart = makePoint(0,0);
    currentPos = subpathStart;

    createPathReader(pathP, &pathReaderP);

    while (!endOfPath) {
        pathCommand pathCommand;
        getNextCommand(pathReaderP, &pathCommand, &endOfPath);
        if (!endOfPath) {
            switch (pathCommand.verb) {
            case PATH_MOVETO:
                if (traceDraw)
                    pm_message("Moving to (%u, %u)",
                               pathCommand.args.moveto.dest.x,
                               pathCommand.args.moveto.dest.y);
                subpathStart = pathCommand.args.moveto.dest;
                currentPos = subpathStart;
                break;
            case PATH_LINETO: {
                point const dest = pathCommand.args.lineto.dest;
                if (traceDraw)
                    pm_message("Lining to (%u, %u)", dest.x, dest.y);
                ppmd_line(NULL, 0, 0, 0,
                          currentPos.x, currentPos.y, dest.x, dest.y,
                          ppmd_fill_drawproc, fillObjP);
                currentPos = dest;
            } break;
            case PATH_CLOSEPATH:
                if (traceDraw)
                    pm_message("Closing.");
                ppmd_line(NULL, 0, 0, 0,
                          currentPos.x, currentPos.y,
                          subpathStart.x, subpathStart.y,
                          ppmd_fill_drawproc, fillObjP);
                currentPos = subpathStart;
                break;
            case PATH_CUBIC: {
                point const dest = pathCommand.args.cubic.dest;
                point const ctl1 = pathCommand.args.cubic.ctl1;
                point const ctl2 = pathCommand.args.cubic.ctl2;
                if (traceDraw)
                    pm_message("Doing cubic spline to (%u, %u)",
                               dest.x, dest.y);
                /* We need to write ppmd_spline4() */
                ppmd_spline4p(NULL, 0, 0, 0,
                              makePpmdPoint(currentPos),
                              makePpmdPoint(dest),
                              makePpmdPoint(ctl1),
                              makePpmdPoint(ctl2),
                              ppmd_fill_drawprocp, fillObjP);
                currentPos = dest;
            } break;
            }
        }
    }
    destroyPathReader(pathReaderP);
}
Example #11
0
void *dbgPgThread::Entry( void )
{

	wxLogInfo( wxT( "worker thread waiting for some work to do..." ));

	// This thread should hang at the call to m_condition.Wait()
	// When m_condition is signaled, we wake up, send a command
	// to the PostgreSQL server, and wait for a result.

	while( m_queueCounter.Wait() == wxSEMA_NO_ERROR && !die && !TestDestroy() )
	{
		m_owner.setNoticeHandler( noticeHandler, this );

		m_currentCommand = getNextCommand();
		wxString command = m_currentCommand->getCommand();

		wxLogInfo( wxT( "Executing: %s" ), command.c_str());

		// This call to PQexec() will hang until we've received
		// a complete result set from the server.
		PGresult *result = 0;

#if defined (__WXMSW__) || (EDB_LIBPQ)
		// If we have a set of params, and we have the required functions...
		dbgPgParams *params = m_currentCommand->getParams();
		bool use_callable = true;

		// we do not need all of PQi stuff AS90 onwards
		if (m_owner.EdbMinimumVersion(9, 0))
			use_callable = false;

#ifdef EDB_LIBPQ
		if (params && use_callable)
#else
		if (PQiGetOutResult && PQiPrepareOut && PQiSendQueryPreparedOut && params && use_callable)
#endif
		{
			wxLogInfo(wxT("Using an EnterpriseDB callable statement"));
			wxString stmt = wxString::Format(wxT("DebugStmt-%d-%d"), this->GetId(), ++run);
			PGresult *res = PQiPrepareOut(m_owner.getConnection(),
			                              stmt.mb_str(wxConvUTF8),
			                              command.mb_str(wxConvUTF8),
			                              params->nParams,
			                              params->paramTypes,
			                              params->paramModes);

			if( PQresultStatus(res) != PGRES_COMMAND_OK)
			{
				wxLogError(_( "Could not prepare the callable statement: %s, error: %s" ), stmt.c_str(), wxString(PQresultErrorMessage(res), *conv).c_str());
				PQclear(res);
				return this;
			}

			int ret = PQiSendQueryPreparedOut(m_owner.getConnection(),
			                                  stmt.mb_str(wxConvUTF8),
			                                  params->nParams,
			                                  params->paramValues,
			                                  NULL, // Can be null - all params are text
			                                  NULL, // Can be null - all params are text
			                                  1);
			if (ret != 1)
			{
				wxLogError(_( "Couldn't execute the callable statement: %s" ), stmt.c_str());
				PQclear(res);
				return this;
			}

			// We need to call PQgetResult before we can call PQgetOutResult
			// Note that this is all async code as far as libpq is concerned to
			// ensure we can always bail out when required, without leaving threads
			// hanging around.
			PGresult *dummy;
			while(true)
			{
				if (die || TestDestroy())
				{
					PQrequestCancel(m_owner.getConnection());
					return this;
				}

				PQconsumeInput(m_owner.getConnection());

				if (PQisBusy(m_owner.getConnection()))
				{
					Yield();
					wxMilliSleep(10);
					continue;
				}

				dummy = PQgetResult(m_owner.getConnection());

				// There should be 2 results - the first is the dummy, the second
				// contains our out params.
				if (dummy)
					break;
			}

			if((PQresultStatus(dummy) == PGRES_NONFATAL_ERROR) || (PQresultStatus(dummy) == PGRES_FATAL_ERROR))
				result = dummy;
			else
			{
				PQclear(dummy);
				result = PQiGetOutResult(m_owner.getConnection());
			}
		}
		else
		{
#endif
			// This is the normal case for a pl/pgsql function, or if we don't
			// have access to PQgetOutResult.
			// Note that this is all async code as far as libpq is concerned to
			// ensure we can always bail out when required, without leaving threads
			// hanging around.
			int ret = PQsendQuery(m_owner.getConnection(), command.mb_str(wxConvUTF8));

			if (ret != 1)
			{
				wxLogError(_( "Couldn't execute the query (%s): %s" ), command.c_str(), wxString(PQerrorMessage(m_owner.getConnection()), *conv).c_str());
				return this;
			}

			PGresult *part;
			while(true)
			{
				if (die || TestDestroy())
				{
					PQrequestCancel(m_owner.getConnection());
					return this;
				}

				PQconsumeInput(m_owner.getConnection());

				if (PQisBusy(m_owner.getConnection()))
				{
					Yield();
					wxMilliSleep(10);
					continue;
				}

				// In theory we should only get one result here, but we'll loop
				// anyway until we get the last one.
				part = PQgetResult(m_owner.getConnection());

				if (!part)
					break;

				result = part;
			}

#if defined (__WXMSW__) || (EDB_LIBPQ)
		}
#endif

		if(!result)
		{
			wxLogInfo(wxT( "NULL PGresult - user abort?" ));
			return this;
		}

		wxLogInfo(wxT( "Complete: %s" ), wxString(PQresStatus(PQresultStatus(result)), *conv).c_str());

		// Notify the GUI thread that a result set is ready for display

		if( m_currentCommand->getEventType() == wxEVT_NULL )
		{
			wxCommandEvent resultEvent( wxEVT_COMMAND_MENU_SELECTED, RESULT_ID_DIRECT_TARGET_COMPLETE );
			resultEvent.SetClientData( result );
			m_currentCommand->getCaller()->AddPendingEvent( resultEvent );
		}
		else
		{
			wxCommandEvent resultEvent( wxEVT_COMMAND_MENU_SELECTED, m_currentCommand->getEventType());
			resultEvent.SetClientData( result );
			m_currentCommand->getCaller()->AddPendingEvent( resultEvent );
		}
	}

	return this;
}
Example #12
0
Dispatcher::~Dispatcher()
{
	// flush the command buffer to release all memory
	while (getNextCommand((char*)0, 0));
}