Esempio n. 1
1
bool Timer::start()
{
    if(mTimer.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::start could not get timer lock!");

    if(time == 0 || !hasCallers())
        return false;

    DWORD period = 0;
    if(repeat)
        period = time;

    if(!CreateTimerQueueTimer(&timerHandle,  // our handle
                             NULL,          // handle to the queue
                             timerCallback, // the shared callback function for timers
                             this,          // pass along a pointer to the timer object
                             time,          // how long until first trigger
                             period,        // how long the period is
                             0
                            ))
    {
        timerHandle = NULL;
        mTimer.unlock();
        return false;
    }

    mTimer.unlock();

    return true;
}
Esempio n. 2
0
ClassCaller<ToCall, retType, paramType...>::ClassCaller(ToCall* obj, retType (ToCall::*member)(paramType...)) : object(obj), funcPtr(member)
{
    if(!object)
        throw RobotException("Allocated ClassCaller without object to call!");

    if(!funcPtr)
        throw RobotException("Allocated ClassCaller with NULL pointer!");

}
Esempio n. 3
0
Caller<void>* Timer::giveCaller(UINT id)
{
    if(mHook.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::giveCaller could not get lock!");

    if(!hasCallers() || id == 0)
    {
        mHook.unlock();
        return 0;
    }

    Caller<void>* tmp = 0;

    std::list<PAIRDEF>::iterator iter = callerList.begin();
    while(iter != callerList.end())
    {
        if(iter->first == id)
        {
            tmp = iter->second;
            callerList.erase(iter);
            break;
        }
        ++iter;
    }

    mHook.unlock();
    return tmp;
}
Esempio n. 4
0
Timer::~Timer()
{
    if(mTimer.lock() != WAIT_OBJECT_0 || mHook.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer destructor could not get locks!");;

    stop();
    disconnect();
}
Esempio n. 5
0
VOID CALLBACK timerCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
    Timer* triggered = (Timer*) lpParameter;
    if(!lpParameter)
        throw RobotException("timerCallback was passed lpParameter of 0!");

    triggered->doCallback();
}
Esempio n. 6
0
//接受网络事件主循环
void Robot::startAndWaitForExit() 
{
	if(getTCPServerIsBuilded() || getUDPServerIsBuilded())
	{
		processNetEpoll();
	}
	else
		throw RobotException("未建立任何网络服务器,异常退出");
}
Esempio n. 7
0
void Drawer::redraw()
{
    if(disconnected())
        throw RobotException("Drawer::startDrawing called without connected window!");

    HDC canvas = GetDC(drawTo);

    if(canvas == NULL)
        throw RobotException("Tried to call Drawer::startDrawing but couldn't get canvas!");

    // Select and draw into our buffer
    HDC bufCanvas = CreateCompatibleDC(canvas);
    HBITMAP oldBuf = (HBITMAP)SelectObject(bufCanvas, buffer);
    onRedraw(bufCanvas, bufSize);

/* THIS IS CODE FOR SOME SEEMINGLY CLEVER ANTIALIASING - BUT IT DEPENDS A LOT ON BEING ABLE TO
    REPRODUCE AN IDENTICAL IMAGE SCALED UP, SO I MIGHT NOT USE IT

    // select and draw into the aliasing buffer
    HDC aliasCanvas = CreateCompatibleDC(canvas);
    HBITMAP oldAlBuf = (HBITMAP)SelectObject(aliasCanvas, aliasBuffer);
    onRedraw(aliasCanvas, alBufSize);

    // StretchBlit the aliasing buffer into the standard buffer
    SetStretchBltMode(bufCanvas, HALFTONE);
    StretchBlt(bufCanvas, 0, 0, bufSize.right, bufSize.bottom,
    aliasCanvas, 0, 0, alBufSize.right, alBufSize.bottom, SRCINVERT);
*/
    // Blit out the buffer onto the screen
    BitBlt(canvas, 0, 0, bufSize.right, bufSize.bottom, bufCanvas, 0, 0, SRCCOPY);

    // unselect the buffer from bufCanvas
    SelectObject(bufCanvas, oldBuf);
    DeleteObject(bufCanvas);

/* MORE ANTIALIASING CODE
    SelectObject(aliasCanvas, oldAlBuf);
    DeleteObject(aliasCanvas);
*/

    ReleaseDC(drawTo, canvas);
}
Esempio n. 8
0
void Timer::setRepeating(bool repeating)
{
    if(mTimer.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::setRepeating could not get lock!");

    repeat = repeating;
    if(timerHandle)
        ChangeTimerQueueTimer(NULL, timerHandle, time, time);

    mTimer.unlock();
}
Esempio n. 9
0
UINT Timer::takeCaller(Caller<void>* newCaller)
{
    if(!newCaller)
        return 0;

    if(mHook.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::takeCaller could not get lock!");

    callerList.push_front(PAIRDEF(nextID, newCaller));

    mHook.unlock();
    return nextID++;
}
Esempio n. 10
0
void Timer::stop()
{
    if(timerHandle != NULL)
    {
        if(mTimer.lock() != WAIT_OBJECT_0)
            throw RobotException("Timer::stop could not get lock!");

        DeleteTimerQueueTimer(NULL, timerHandle, INVALID_HANDLE_VALUE);
        timerHandle = NULL;

        mTimer.unlock();
    }
}
Esempio n. 11
0
void Timer::doCallback()
{
    if(mHook.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::doCallback could not get lock!");

    std::list<PAIRDEF>::iterator iter = callerList.begin();
    while(iter != callerList.end())
    {
        iter->second->doCall();
        ++iter;
    }

    mHook.unlock();
}
Esempio n. 12
0
void Timer::setTimer(DWORD setTime)
{
    if(mTimer.lock() != WAIT_OBJECT_0)
        throw RobotException("Timer::setTimer could not get lock!");

    time = setTime;
    if(timerHandle)
    {
        DWORD period = 0;
        if(repeat)
            period = time;

        ChangeTimerQueueTimer(NULL, timerHandle, time, period);
    }

    mTimer.unlock();
}
Esempio n. 13
0
void Drawer::renewBuffer()
{
    if(!drawTo)
        throw RobotException("Calling Drawer::RenewBuffer without a connected window!");

    GetClientRect(drawTo, &bufSize);

/*
    alBufSize.right = bufSize.right * ALIASFACTOR;
    alBufSize.bottom = bufSize.bottom * ALIASFACTOR;
*/

    HDC tmpDC = GetDC(drawTo);
    buffer = CreateCompatibleBitmap(tmpDC, bufSize.right, bufSize.bottom);
//    aliasBuffer = CreateCompatibleBitmap(tmpDC, alBufSize.right, alBufSize.bottom);
    ReleaseDC(drawTo, tmpDC);
}
Esempio n. 14
0
void Timer::disconnect()
{
    // aquiring mTimer might seem agressive but we need to prevent
    // users from starting the clock while we disconnect everything
    if(mTimer.lock() != WAIT_OBJECT_0 || mHook.lock() != WAIT_OBJECT_0)
        throw RobotException("disconnect could not get both locks!");

    stop();

    while(hasCallers())
    {
        Caller<void>* tmp = callerList.front().second;
        callerList.pop_front();

        delete tmp;
    }

    mTimer.unlock();
    mHook.unlock();
}
Esempio n. 15
0
FuncCaller<retType, paramType...>::FuncCaller(retType (*toCall)(paramType...)) : funcPtr(toCall)
{
    if(funcPtr == 0)
        throw RobotException("Allocated FuncCaller with NULL pointer");
}