void ConditionInputButton::onInputChanged(HWInput* hw)
{
    pi_assert(m_hw == hw && m_hw->getType() == HWInput::Button);

    bool isFulfilled = false;

    if(m_trigger == Pressed)
    {
        if(((HWInputButton*)hw)->getValue() == true)
            isFulfilled = true;
    }
    else if(m_trigger == Released)
    {
        if(((HWInputButton*)hw)->getValue() == false)
            isFulfilled = true;
    }
    else // m_trigger == Toggle
    {
        // we have to trick here, so that we do not have to change the part below
        // todo: find a better way to do this
        m_isFulfilled = false;
        isFulfilled = true; // we cannot compare with earlier values, so we have to believe that something has indeed changed
    }

    if(m_isFulfilled != isFulfilled)
    {
        m_isFulfilled = isFulfilled;

        // only call conditionChanged if there is the possibility that all conditons are true
        // if this conditon is not true there is no point in telling anyone
        // if the condition did not change, we MUST NOT tell anyone, because otherwise we could start a rule multiple times
        if(isFulfilled)
            this->conditionChanged();
    }
}
Beispiel #2
0
/**     call is used by ActionCallRule to call another rule.
 *      The conditions in this rule must be true, otherwise it is not going to be executed
 */
void Rule::call()
{
    pi_assert(m_type == MustBeCalled);

    if(this->conditionsTrue())
        this->executeActions();
}
Beispiel #3
0
/**
 * @brief BTClassicThread::start starts this bluetooth thread.
 * The thread is automatically killed as soon as it is deleted, or it can be killed manually by BTClassicThread::kill
 */
void
BLEThread::start()
{
    pi_assert(m_thread == 0);

    // create and run thread
    pthread_create(&m_thread, NULL, BLEThread::run_internal, (void*)this);
}
Beispiel #4
0
int PipeImpl::writeBytes(const void* buffer, int length)
{
    pi_assert (_writeHandle != INVALID_HANDLE_VALUE);

	DWORD bytesWritten = 0;
	if (!WriteFile(_writeHandle, buffer, length, &bytesWritten, NULL))
		throw WriteFileException("anonymous pipe");
	return bytesWritten;
}
Beispiel #5
0
void Rule::executeActions(unsigned int start)
{
    pi_assert(start <= m_listActions.size());

    // start executing at start-element
    for(; start < m_listActions.size(); start++)
    {
        if( !(m_listActions.at(start)->execute(start) ) )
            break; // Action said we should stop executing other actions
    }
}
Beispiel #6
0
int PipeImpl::readBytes(void* buffer, int length)
{
    pi_assert (_readHandle != INVALID_HANDLE_VALUE);

	DWORD bytesRead = 0;
	BOOL ok = ReadFile(_readHandle, buffer, length, &bytesRead, NULL);
	if (ok || GetLastError() == ERROR_BROKEN_PIPE)
		return bytesRead;
	else
		throw ReadFileException("anonymous pipe");
}
Beispiel #7
0
void SocketImpl::initSocket(int af, int type, int proto)
{
    pi_assert (_sockfd == PIL_INVALID_SOCKET);

    _sockfd = ::socket(af, type, proto);
    if (_sockfd == PIL_INVALID_SOCKET)
        error();

#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__)
    // SIGPIPE sends a signal that if unhandled (which is the default)
    // will crash the process. This only happens on UNIX, and not Linux.
    //
    // In order to have PIL sockets behave the same across platforms, it is
    // best to just ignore SIGPIPE all together.
    setOption(SOL_SOCKET, SO_NOSIGPIPE, 1);
#endif
}
Beispiel #8
0
void ConditionVariable::onVariableChanged(Variable *var)
{
    pi_assert(m_var == var);

    bool isFulfilled = false;

    if(m_trigger == Equal)
        isFulfilled = var->getValue() == m_triggerValue;
    else if(m_trigger == NoLongerEqual)
        isFulfilled = var->getValue() != m_triggerValue;
    else if(m_trigger == GreaterThan)
        isFulfilled = var->getValue() > m_triggerValue;
    else if(m_trigger == LessThan)
        isFulfilled = var->getValue() < m_triggerValue;

    if(m_isFulfilled != isFulfilled)
    {
        m_isFulfilled = isFulfilled;

        if(m_isFulfilled)
            this->conditionChanged();
    }
}