Exemple #1
0
static int hop_addEvent(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    int fd = luaL_checknumber(L, 2);
    const char *chFilter = luaL_checkstring(L, 3);
    if (! lua_isfunction(L, 4)) return luaL_error(L, "Function was expected.");

    if (fd > SN_SETSIZE) {
        return luaL_error(L, "File descriptor outside SN_SETSIZE");
    }
    
    int mask = getMask(chFilter);
    if (mask == -1) return luaL_error(L, "Invalid event mask.");
    
    if (hloop->api->addEvent(hloop, fd, mask) == -1) {
        return luaL_error(L, "Could not add event listener.");
    }
    
    int clbref = luaL_ref(L, LUA_ENVIRONINDEX);
    hloop->events[fd].L = L;
    hloop->events[fd].mask |= mask;
    if (mask & SN_READABLE) hloop->events[fd].rcallback = clbref;
    if (mask & SN_WRITABLE) hloop->events[fd].wcallback = clbref;
    
    return 0;
}
Exemple #2
0
void SpriteAnimation::animate(int name)
{
	if (needSetup()) { return; }

	if (name == mCurrentAnimation) return;
	this->animate(name, checkLoop(name));
}
Exemple #3
0
void QueueManager::setupConnections()
{
  // opt connections
  connect(this, SIGNAL(needNewStructure()), m_opt, SLOT(generateNewStructure()),
          Qt::QueuedConnection);

  // re-emit connections
  connect(this, SIGNAL(structureStarted(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureSubmitted(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureKilled(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));
  connect(this, SIGNAL(structureFinished(GlobalSearch::Structure*)), this,
          SIGNAL(structureUpdated(GlobalSearch::Structure*)));

  // internal connections
  connect(this, SIGNAL(structureStarted(GlobalSearch::Structure*)), this,
          SLOT(addStructureToSubmissionQueue(GlobalSearch::Structure*)),
          Qt::QueuedConnection);

// Work around bug in Qt 4.6.3:
#if QT_VERSION == 0x040603
  connect(this, SIGNAL(newStructureQueued()), this, SLOT(unlockForNaming_()),
          Qt::QueuedConnection);
#endif // QT_VERSION == 4.6.3

  QTimer::singleShot(0, this, SLOT(checkLoop()));
}
Exemple #4
0
void ofxTLTrack::play(){
	if(!isPlaying && !timeline->getIsPlaying()){
		isPlaying = true;
		currentTime = ofClamp(timeline->getCurrentTimeMillis(), timeline->getInTimeInMillis(), timeline->getOutTimeInMillis());
		playbackStartTime = timeline->getTimer().getAppTimeMillis() - currentTime;
		checkLoop();
	}
}
Exemple #5
0
static int hop_poll(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    struct timeval *tv = NULL;
    double usec_total = 0;
    
    if (lua_istable(L, 2)) {
        usec_total = table_to_usec(L, 2);
        
        if (usec_total > 0) {
            tv = malloc(sizeof(struct timeval));
            tv->tv_sec = (long int) (usec_total / SIM);
            tv->tv_usec = (long int) fmod(usec_total, SIM);
        }
    }
    
    int nevents = hloop->api->poll(hloop, tv);
    if (tv != NULL) free(tv);
    
    int i = 0;
    for (i=0; i<nevents; i++) {
        snFiredEvent fevent = hloop->fired[i];
        int mask = fevent.mask;
        int fd = fevent.fd;
        
        if (mask & SN_TIMER) { /* timer event */
            snTimerEvent *timerEvent = &hloop->timers[fd];
            lua_State *ctx = timerEvent->L;
            
            if (timerEvent->mask & mask & SN_TIMER) {
                int callback = timerEvent->callback;
                run_callback(L, ctx, callback, fd, mask, hloop);
                
                if (timerEvent->mask & SN_ONCE) {
                    _clearTimer(L, hloop, fd);
                }
            }
        } else { /* <file event> */
            snFileEvent *evData = &hloop->events[fd];
            lua_State *ctx = evData->L;
            int rcallback = evData->rcallback;
            int wcallback = evData->wcallback;
            int rfired = 0;
            
            if (evData->mask & mask & SN_READABLE) {
                rfired = 1;
                run_callback(L, ctx, rcallback, fd, mask, NULL);
            }
            if (evData->mask & mask & SN_WRITABLE) {
                if (!rfired || evData->wcallback != evData->rcallback) {
                    run_callback(L, ctx, wcallback, fd, mask, NULL);
                }
            }
        } /* </file event> */
    }
    
    return 0;
}
Exemple #6
0
static int hop_gc(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    closeLoop(hloop);
    
    /* free only those members; hloop itself is freed by Lua */
    free(hloop->api);
    free(hloop->state);
    
    return 0;
}
Exemple #7
0
static int hop_loop(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    hloop->shouldStop = 0;
    
    while (hloop->shouldStop == 0) {
        hop_poll(L);
    }
    
    return 0;
}
Exemple #8
0
static int hop_removeEvent(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    int fd = luaL_checknumber(L, 2);
    const char *chFilter = luaL_checkstring(L, 3);
    
    int mask = getMask(chFilter);
    if (mask == -1) return luaL_error(L, "Invalid event mask.");
    
    return _removeEvent(L, fd, mask, hloop);
}
Exemple #9
0
unsigned long ofxTLTrack::currentTrackTime(){
	if(isPlaying){
		currentTime = timeline->getTimer().getAppTimeMillis() - playbackStartTime;
		checkLoop();
		return currentTime;
		//return timeline->getInTimeInMillis() + (timeline->getTimer().getAppTimeMillis() - playbackStartTime) % timeline->getInOutRangeMillis().span() ;
	}
	else{
		return timeline->getCurrentTimeMillis();
	}
}
Exemple #10
0
void QueueManager::checkLoop()
{
  // Ensure that this is only called from the QM thread:
  Q_ASSERT_X(QThread::currentThread() == m_thread, Q_FUNC_INFO,
             "Attempting to run QueueManager::checkLoop "
             "from a thread other than the QM thread. ");

  // Update runtime options by reading a file if we are not using the GUI
  // This needs to be here first because sometimes, our CLI settings are
  // over-written from somewhere else when starting.
  if (!m_opt->usingGUI())
    m_opt->readRuntimeOptions();

  if (!m_opt->readOnly && !m_opt->isStarting) {
    checkPopulation();
    checkRunning();
  }

  QTimer::singleShot(1000, this, SLOT(checkLoop()));
}
Exemple #11
0
static int _setTimer(lua_State *L, int timerType) {
    snHopLoop *hloop = checkLoop(L);
    luaL_checktype(L, 2, LUA_TTABLE);
    if (! lua_isfunction(L, 3)) return luaL_error(L, "Function was expexted.");
    int fd = 0;
    
    struct timeval tv;
    int usec_total = table_to_usec(L, 2);
    
    tv.tv_sec = (long int) (usec_total / SIM);
    tv.tv_usec = (long int) fmod(usec_total, SIM);
    
    int clbref = luaL_ref(L, LUA_ENVIRONINDEX);
    
    if (timerType & SN_ONCE)
        fd = hloop->api->setTimeout(hloop, &tv);
    else
        fd = hloop->api->setInterval(hloop, &tv);
    
    if (fd == -1) {
        lua_pushnumber(L, -1);
        lua_pushstring(L, "Could not create a new timer (internal error)");
        
        lua_pushnil(L);
        lua_rawseti(L, LUA_ENVIRONINDEX, clbref);
        
        return 2;
    }
    
    hloop->timers[fd].L = L;
    hloop->timers[fd].callback = clbref;
    hloop->timers[fd].mask = SN_TIMER;
    if (timerType & SN_ONCE) hloop->timers[fd].mask |= SN_ONCE;
    
    lua_pushnumber(L, fd);
    
    return 1;
}
Exemple #12
0
static int hop_repr(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    lua_pushfstring(L, "<Hop Loop: %s>", hloop->api->name);
    
    return 1;
}
Exemple #13
0
static int hop_stop(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    hloop->shouldStop = 1;
    
    return 0;
}
Exemple #14
0
static int hop_clearTimer(lua_State *L) {
    snHopLoop *hloop = checkLoop(L);
    int fd = luaL_checknumber(L, 2);
    
    return _clearTimer(L, hloop, fd);
}