示例#1
0
    // Function:     waitForNewFriend
    // Inputs:       NA
    // Outputs:      true if executed to fruition, false if no user active.
    // Description:  This function wait for a user to input the name of a frined they
    //               want to add then stores the friendship in the user list.
    //
    bool Menu::waitForNewFriend()
    {
        // Check to see if there is an active user.
        if (users.hasNoActiveUser())
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_NO_USER_ACTIVE;
            return false;
        }
        
        // Display prompt for a new friend.
        std::cout << NEW_LINE + TAB + TAB + STRING_ENTER_NEW_FRIEND;
        
        // Read a line from the console.
        std::string newFriend;
        std::getline(std::cin, newFriend);
        
        // Check if username is empty.
        if ( newFriend.length() == 0)
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_USER_NOT_BLANK;
            return waitForNewFriend();
        }
        // Check if username is formatted correctly.
        else if ( newFriend.find(" ") != std::string::npos)
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_USER_FORMAT;
            return waitForNewFriend();
        }
        else
        {
        
            // Check to see if the name entered is a valid user.
            if ( !users.isUser(User(newFriend)) )
            {
                std::cout << NEW_LINE + TAB + TAB + STRING_NO_USER;
                return waitForCommand();
            }
        
            // Check to see if the name belongs to the current user.
            if ( users.getCurrentUser().getUsername().compare(newFriend) == 0 )
            {
                std::cout << NEW_LINE + TAB + TAB + STRING_CANNOT_FRIEND_SELF;
                return waitForCommand();
            }
        
            // Check to see if the current user is already friends with newFriend.
            if ( users.isFriend(users.getCurrentUser(), users.findUserByName(newFriend)) )
            {
                std::cout << NEW_LINE + TAB + TAB + STRING_ALREADY_FRIENDS;
                return waitForCommand();
            }
        
            std::cout << NEW_LINE << TAB << TAB << STRING_NOW_FRIENDS << newFriend << NEW_LINE;
        
            // Add the friend to the current user's friends list.
            users.setFriends(users.getCurrentUser(),users.findUserByName(newFriend));

            return true;
        }
    }
示例#2
0
void Simulation::start()
{
	iteration++;
	populate();
	display.show(geodata);
	waitForCommand();
}
示例#3
0
// Get the debugger API version
DebuggerApiVersions dbgPgConn::DebuggerApiVersion()
{
	if (m_debuggerApiVersion > 0)
		return m_debuggerApiVersion;

	// The v1 protocol didn't have pldbg_get_proxy_info()
	wxString result;

	PGresult *res = waitForCommand(wxT( "SELECT count(*) FROM pg_proc WHERE proname = 'pldbg_get_proxy_info';"));

	if (PQresultStatus(res) == PGRES_TUPLES_OK)
	{
		// Retrieve the query result and return it.
		if (wxString(PQgetvalue(res, 0, 0), wxConvUTF8) == wxT("0"))
		{
			PQclear(res);
			m_debuggerApiVersion = DEBUGGER_V1_API;
			return DEBUGGER_V1_API;
		}

		PQclear(res);
	}
	else
	{
		wxLogError(wxT("%s"), wxString(PQerrorMessage(m_pgConn), wxConvUTF8).c_str());
		return DEBUGGER_UNKNOWN_API;
	}

	// We have pldbg_get_proxy_info, so use it to get the API version
	res = waitForCommand(wxT( "SELECT proxyapiver FROM pldbg_get_proxy_info();"));

	if (PQresultStatus(res) == PGRES_TUPLES_OK)
	{
		// Retrieve the query result and return it.
		m_debuggerApiVersion = (DebuggerApiVersions)atoi(wxString(PQgetvalue(res, 0, 0), wxConvUTF8).ToAscii());
		PQclear(res);
	}
	else
	{
		wxLogError(wxT("%s"), wxString(PQerrorMessage(m_pgConn), wxConvUTF8).c_str());
		return DEBUGGER_UNKNOWN_API;
	}

	return m_debuggerApiVersion;
}
示例#4
0
 // Function:     waitForAlternateUser
 // Inputs:       NA
 // Outputs:      true if executed to fruition
 // Description:  This function waits for a user to enter the name of another
 //               existing user whose account they want to switch to.
 //
 bool Menu::waitForAlternateUser()
 {
     // Check to see if there is are any users enrolled in the system.
     if (users.hasNoUsersEnrolled() )
     {
         std::cout << NEW_LINE << TAB << TAB << STRING_NO_USERS;
         return false;
     }
     
     // Query for the username to switch to.
     std::cout << NEW_LINE + TAB + TAB + STRING_CHANGE_USER;
     
     // Input a string for a username.
     std::string altUser;
     std::getline(std::cin, altUser);
     
     // Check if username is empty.
     if ( altUser.length() == 0)
     {
         std::cout << NEW_LINE << TAB << TAB << STRING_USER_NOT_BLANK;
         return waitForAlternateUser();
     }
     // Check if username is formatted correctly.
     else if ( altUser.find(" ") != std::string::npos)
     {
         std::cout << NEW_LINE << TAB << TAB << STRING_USER_FORMAT;
         return waitForAlternateUser();
     }
     else
     {
     
         // Check to see if the name entered is a valid user.
         if ( !users.isUser(User(altUser)) )
         {
             std::cout << NEW_LINE + TAB + TAB + STRING_NO_USER;
             return waitForCommand();
         }
     
         // Change to the specified user.
         users.setCurrentUser(User(altUser));
     
         // Display the new user's message board header.
         std::cout << users.getCurrentUser().getBoardHeader();
     
         return true;
     }
 }
示例#5
0
wxString dbgPgConn::GetVersionString()
{
	PGresult *res;
	wxString result;

	res = waitForCommand(wxT( "SELECT version();"));

	if (PQresultStatus(res) == PGRES_TUPLES_OK)
	{
		// Retrieve the query result and return it.
		result = wxString(PQgetvalue(res, 0, 0), wxConvUTF8);

		// Cleanup & exit
		PQclear(res);
	}

	return result;
}
示例#6
0
 // Function:     waitForNewTweet
 // Inputs:       NA
 // Outputs:      true if executed to fruition
 // Description:  This function prompts the user for a new tweet. If there
 //               is no user logged in it displays an error and returns.
 //               If there is a user it stores the tweet in the board.
 //
 bool Menu::waitForNewTweet()
 {
     // Check to see if there is an active user.
     if (users.hasNoActiveUser())
     {
         std::cout << NEW_LINE << TAB << TAB << STRING_NO_USER_ACTIVE;
         return false;
     }
     
     // Display prompt for a new tweet.
     std::cout << NEW_LINE + TAB + TAB + STRING_ENTER_TWEET;
     
     std::string currentTweet;    // The current line of input.
     std::string totalTweet;      // The concatenation of input lines so far.
     
     // collect multiple lines of input until a line containing only TERMINATE_MESSAGE is detected.
     while (true)
     {
         std::getline(std::cin, currentTweet);
         
         if (currentTweet.compare(TERMINATE_MESSAGE) == 0)
             break;
         totalTweet += currentTweet + NEW_LINE + TAB + TAB + TAB ;
         std::cout << TAB << TAB << TAB;
     }
     
     // If message is blank throw an error.
     if (totalTweet.length() == 0)
     {
         std::cout << NEW_LINE << TAB << TAB << STRING_EMPTY_MESSAGE;
         return waitForCommand();
     }
     
     // Add the tweet to the stream.
     board.addTweetToStream(users.getCurrentUser(), totalTweet, systemTime.getTime());
     systemTime.incrementTime();
     
     // Display new tweet added message.
     std::cout << NEW_LINE << TAB << TAB << STRING_TWEET_ADDED << NEW_LINE;
     
     return true;
 }
示例#7
0
    // Function:     waitForNewUser
    // Inputs:       NA
    // Outputs:      true if executed to fruition
    // Description:  This function prompts for a new user then waits for user to input a name.
    //
    bool Menu::waitForNewUser()
    {
        // Display prompt for new username.
        std::cout << NEW_LINE + TAB + TAB + STRING_ENTER_USER_NAME;
        
        // Read an input from the console.
        std::string newUsername;
        std::getline(std::cin, newUsername);

        // Check if username is empty.
        if ( newUsername.length() == 0)
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_USER_NOT_BLANK;
            return waitForNewUser();
        }
        // Check if username is formatted correctly.
        else if ( newUsername.find(" ") != std::string::npos)
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_USER_FORMAT;
            return waitForNewUser();
        }
        else
        {
            // Create a new User from the newUsername input.
            User newUser = *new User(newUsername);
        
            // Check to see if user already exists.
            if ( users.isUser(newUser) )
            {
                std::cout << NEW_LINE << TAB << TAB << STRING_USER_EXISTS << std::endl;
                return waitForCommand();
            }

            // Adds the new user to the UserList and sets as the active user.
            users.addUser(newUser);
        
            // Display the new user's board header.
            std::cout << users.getCurrentUser().getBoardHeader();
        
            return true;
        }
    }
示例#8
0
bool VideoDemuxerThread::work() 
{
    if (m_bEOF) {
        waitForCommand();
    } else {
        map<int, VideoMsgQueuePtr>::iterator it;
        int shortestQ = -1;
        int shortestLength = INT_MAX;
        for (it = m_PacketQs.begin(); it != m_PacketQs.end(); it++) {
            if (it->second->size() < shortestLength && 
                    it->second->size() < it->second->getMaxSize() &&
                    !m_PacketQEOFMap[it->first])
            {
                shortestLength = it->second->size();
                shortestQ = it->first;
            }
        }
        
        if (shortestQ < 0) {
            // All queues are at their max capacity. Take a nap and try again later.
            // Note that we can't wait on the queue. If decoding is paused, the queues can
            // remain full indefinitely and commands from the application (seek() and 
            // close() must still be processed.
            msleep(10);
            return true;
        }

        AVPacket * pPacket = m_pDemuxer->getPacket(shortestQ);
        VideoMsgPtr pMsg(new VideoMsg);
        if (pPacket == 0) {
            onStreamEOF(shortestQ);
            pMsg->setEOF();
        } else {
            pMsg->setPacket(pPacket);
        }
        m_PacketQs[shortestQ]->push(pMsg);
        msleep(0);
    }
    return true;
}
示例#9
0
// Check the backend version
bool dbgPgConn::BackendMinimumVersion(int major, int minor)
{
	if (!m_majorVersion)
	{
		wxString version = GetVersionString();
		sscanf(version.ToAscii(), "%*s %d.%d", &m_majorVersion, &m_minorVersion);
		m_isEdb = version.Upper().Matches(wxT("ENTERPRISEDB*"));

		// EnterpriseDB 8.3 beta 1 & 2 and possibly later actually have PostgreSQL 8.2 style
		// catalogs. This is expected to change either before GA, but in the meantime we
		// need to check the catalogue version in more detail, and if we don't see what looks
		// like a 8.3 catalog, force the version number back to 8.2. Yuck.
		if (m_isEdb && m_majorVersion == 8 && m_minorVersion == 3)
		{
			PGresult *res;
			wxString result;

			res = waitForCommand(wxT( "SELECT count(*) FROM pg_attribute WHERE attname = 'proconfig' AND attrelid = 'pg_proc'::regclass"));

			if (PQresultStatus(res) == PGRES_TUPLES_OK)
			{
				// Retrieve the query result and return it.
				result = wxString(PQgetvalue(res, 0, 0), wxConvUTF8);

				// Cleanup & exit
				PQclear(res);
			}
			if (result == wxT("0"))
				m_minorVersion = 2;
		}
		else
			m_isGreenplum = version.Upper().Matches(wxT("*GREENPLUM DATABASE*"));
	}

	return m_majorVersion > major || (m_majorVersion == major && m_minorVersion >= minor);
}
示例#10
0
文件: Task.cpp 项目: posilva/dune
      void
      task(void)
      {
        // Set servo positions.
        uint8_t data[c_servo_count + 1];

        data[0] = 0;
        for (unsigned i = 0; i < c_servo_count; ++i)
        {
          unsigned nr = m_args.servo_renumbering[i];
          float value = m_set_position[nr];

          // compute elapsed time to trim according to max rotation rate
          double elapsedtime = Clock::get() - m_last_timestamp[nr];
          if (elapsedtime > 0 && m_args.limit_servo_rate)
          {
            elapsedtime = trimValue(elapsedtime, 0, (m_args.servo_max - m_args.servo_min) / m_args.servo_rate_max);

            if (value - m_last_ref[nr] >= 0)
              value = std::min((double)value, m_last_ref[nr] + m_args.servo_rate_max * elapsedtime);
            else
              value = std::max((double)value, m_last_ref[nr] - m_args.servo_rate_max * elapsedtime);
          }

          // trim according to max and min rotation
          value = trimValue(value, m_args.servo_min, m_args.servo_max);

          // update variables used as previous
          m_last_ref[nr] = value;
          m_last_timestamp[nr] = Clock::get();

          int ticks = (int)(256 + m_args.servo_orient[nr] * (value + m_args.servo_middle[nr]) * (400.0 / DUNE::Math::c_pi));
          m_servo_ref[nr] = trimValue(ticks, 0, 511);

          data[0] |= (m_servo_ref[nr] & 0x100) >> (8 - i);
          data[i + 1] = m_servo_ref[nr] & 0xFF;
        }

        m_proto.sendCommand(CMD_SERVO_SET, data, c_servo_count + 1);
        if (!waitForCommand(CMD_SERVO_SET))
        {
          setEntityState(IMC::EntityState::ESTA_ERROR, Status::CODE_COM_ERROR);
          throw RestartNeeded(DTR(Status::getString(Status::CODE_COM_ERROR)), 5);
        }
        else
        {
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE);
        }

        if (!m_last_adc.overflow())
          return;

        m_last_adc.reset();

        // Request state.
        m_proto.sendCommand(CMD_STATE);
        if (!waitForCommand(CMD_STATE))
        {
          setEntityState(IMC::EntityState::ESTA_ERROR, Status::CODE_COM_ERROR);
        }
        else
        {
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE);
        }
      }
示例#11
0
OMX_ERRORTYPE Component::setState(OMX_STATETYPE state)
{
    if(!handle) 
    {
        ofLogError(__func__) << getName() << " NO HANDLE";
        return OMX_ErrorNone;
    }
    
    lock();
    ofLogVerbose(__func__) << getName() << " state requested " << GetOMXStateString(state)  << " BEGIN";
    OMX_ERRORTYPE error = OMX_ErrorNone;
    OMX_STATETYPE state_actual;
    error = OMX_GetState(handle, &state_actual);
    OMX_TRACE(error);
    
    //ofLogVerbose(__func__) << getName() << " state requested " << GetOMXStateString(state) << " state_actual: " << GetOMXStateString(state_actual);
    
    
    if(state == state_actual)
    {
        ofLogVerbose(__func__) << getName() << " state requested " << GetOMXStateString(state)  << " END SAME STATE";
        unlock();
        return OMX_ErrorNone;
    }
    
    error = OMX_SendCommand(handle, OMX_CommandStateSet, state, 0);
    OMX_TRACE(error);
    
    if(error == OMX_ErrorNone)
    {
        OMX_ERRORTYPE waitResult = waitForCommand(OMX_CommandStateSet, state);
        OMX_TRACE(waitResult);
        if(waitResult == OMX_ErrorSameState)
        {
            error = waitResult;
        } 
    }
    else
    {
        
        if(componentName == "OMX.broadcom.audio_mixer")
        {
            error = OMX_ErrorNone;
        }
    }
  
#define DEBUG_STATE_INFO 1
    
#ifdef DEBUG_STATE_INFO    
    OMX_STATETYPE currentState;
    OMX_GetState(handle, &currentState);
    string result = "FAIL";
    if(error == OMX_ErrorNone)
    {
        result = "SUCCESS";
        if(currentState != state)
        {
            result = "MIXED";
            ofLogVerbose(__func__) << GetOMXStateString(state) << " IS NOT " << GetOMXStateString(currentState);

        }
    }
    stringstream info;
    info << endl;
    info << getName() << endl;
    info << "currentState: " <<  GetOMXStateString(currentState) << endl;
    info << "requestedState: " <<  GetOMXStateString(state) << endl;
    info << "error: " <<  GetOMXErrorString(error) << endl;
    ofLogVerbose(__func__) << info.str() << " END BLOCK " << result << endl;    
#endif   
    unlock();
    

    return error;
}
示例#12
0
    // Function:     waitForCommand
    // Inputs:       NA
    // Outputs:      False if user wants to quit, true otherwise
    // Description:  This function displays the available commands and waits
    //               for the user to input an integer [1,8]. If the value entered
    //               is not an integer or is outside of the defined range, it
    //               displays an error message.
    //
    bool Menu::waitForCommand()
    {
        // The value that the user input command is stored into.
        int whichCommand;
        
        // Display the command options available.
        std::cout << NEW_LINE << TAB << INPUT_NEW_USER << STRING_CREATE_USER;
        std::cout << TAB << INPUT_NEW_MESSAGE << STRING_POST_MESSAGE;
        std::cout << TAB << INPUT_NEW_TWEET << STRING_POST_TWEET;
        std::cout << TAB << INPUT_DISPLAY_WALL << STRING_DISPLAY_WALL;
        std::cout << TAB << INPUT_DISPLAY_HOME << STRING_DISPLAY_HOME;
        std::cout << TAB << INPUT_ADD_FRIEND << STRING_ADD_FRIEND;
        std::cout << TAB << INPUT_SWITCH_USER << STRING_SWITCH_USER;
        std::cout << TAB << INPUT_EXIT << STRING_QUIT;
        std::cout << TAB + TAB + STRING_CHOOSE_OPTION;
        
        // Read an input from the command line as a string.
        std::string inputString;
        std::getline(std::cin,inputString);
        
        // If string is not one char, throw an error.
        if ( inputString.length() > 1 )
        {
            std::cout << NEW_LINE << TAB << TAB << STRING_INVALID_COMMAND;
            return waitForCommand();
        }
        
        // Convert the string to an integer.
        whichCommand = std::atoi(inputString.c_str());

        // Check to see if whichCommand is [1,8], if not display an error
        switch ( whichCommand )
        {
            case INPUT_NEW_USER:
                waitForNewUser();
                break;
                
            case INPUT_NEW_MESSAGE:
                waitForNewMessage();
                break;
                
            case INPUT_NEW_TWEET:
                waitForNewTweet();
                break;
                
            case INPUT_DISPLAY_HOME:
                displayPage(board.toHomeVector(users.getCurrentUser()), true);
                break;
                
            case INPUT_DISPLAY_WALL:
                displayPage(board.toWallVector(users.getCurrentUser()), false);
                break;
                
            case INPUT_ADD_FRIEND:
                waitForNewFriend();
                break;
                
            case INPUT_SWITCH_USER:
                waitForAlternateUser();
                break;
                
            case INPUT_EXIT:
                return false;
                
            default:
                std::cout << NEW_LINE + TAB + TAB + STRING_INVALID_COMMAND;
                return waitForCommand();
                
                
        }
        
        return true;
    }
bool VideoWriterThread::work()
{
    waitForCommand();
    return true;
}