Example #1
0
int
timer__cancel_impl(CORBA_Object _caller, objref_t timer_obj,
                   idl4_server_environment * _env)
{
    struct timer *timer = (struct timer *)timer_obj;
    struct driver *device = timer->timer_service->device;
    int is_start = (timer->prev == NULL);
    struct timer *next_timer = timer->next;

    if (timer->state == timer_cancelled_e)
        return 1;

    assert(is_start ? timer->timer_service->active == timer : 1);
    assert(next_timer == NULL ? timer->timer_service->active_end == timer : 1);

    /* Inactivate timer */
    deactivate_timer(timer);
    if (is_start) {
        if (next_timer) {
            /* Timeout at next registered time */
            if (timer_timeout
                (device, next_timer->timeout, timer_callback, 0,
                 (uintptr_t)next_timer)) {
                timer_callback(0, 0, NULL, (uintptr_t)timer);
            }
        } else {
            /* Never timeout -- nothing left in list */
            timer_timeout(device, -1, NULL, 0, (uintptr_t)0);
        }
    }

    return 0;
}
Example #2
0
void sploit_loop(void)
{
  int ret = 0;
  int64_t *timeout;
  int64_t remain = 0LL;
  
  while(ret >= 0)
  {
    /* Calculate timeout value */
    timeout = timer_timeout();
    
    /* Do I/O multiplexing and event handling */
#if (defined USE_SELECT)
    ret = io_select(&remain, timeout);
#elif (defined USE_POLL)
    ret = io_poll(&remain, timeout);
#endif
    
    /* Remaining time is 0msecs, we need to run a timer */
    if(remain == 0LL)
      timer_run();
    
    if(timeout)
      timer_drift(*timeout - remain);
    
    io_handle();
    
    timer_collect();
    /*    ircd_collect();*/
  }
}
Example #3
0
void pLineEdit::init()
{
	mMargin = sizeHint().height() -2;
	mSpacing = 0;
	
	tbSearch = new QToolButton( this );
	tbSearch->setIcon( pIconManager::icon( "search.png", ":/fresh" ) );
	tbSearch->setToolTip( tr( "Search Options" ) );
	tbSearch->setStyleSheet( "QToolButton { border: none; padding: 0px; } QToolButton::menu-indicator { right: -2px; bottom: -2px; }" );
	tbSearch->setCursor( Qt::ArrowCursor );
	tbSearch->setFocusPolicy( Qt::NoFocus );
	tbSearch->setPopupMode( QToolButton::InstantPopup );
	
	tbClear = new QToolButton( this );
	tbClear->setIcon( pIconManager::icon( "edit-clear-rtl.png", ":/fresh" ) );
	tbClear->setToolTip( tr( "Clear" ) );
	tbClear->setStyleSheet( "QToolButton { border: none; padding: 0px; }" );
	tbClear->setCursor( Qt::ArrowCursor );
	tbClear->setFocusPolicy( Qt::NoFocus );
	
	setSearchButtonVisible( true );
	setClearButtonVisible( false );
	setPromptText( "Search..." );
	
	mTimer = new QTimer( this );
	mTimer->setInterval( mTimeOut );
	mTimer->setSingleShot( true );
	
	connect( this, SIGNAL( textChanged( const QString& ) ), this, SLOT( _q_textChanged( const QString& ) ) );
	connect( tbSearch, SIGNAL( clicked() ), this, SIGNAL( searchButtonClicked() ) );
	connect( tbSearch, SIGNAL( triggered( QAction* ) ), this, SIGNAL( searchButtonActionTriggered( QAction* ) ) );
	connect( tbClear, SIGNAL( clicked() ), this, SLOT( clear() ) );
	connect( tbClear, SIGNAL( clicked() ), this, SIGNAL( clearButtonClicked() ) );
	connect( mTimer, SIGNAL( timeout() ), this, SLOT( timer_timeout() ) );
}
Example #4
0
MainWindow::MainWindow(Soccer *soccer, QWidget *parent) :
    QMainWindow(parent),
    timer(this),
    sc(soccer),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //ui->txtLog->append(QSerialPort::);
    _render = new RenderArea(soccer);
    ui->gridRender->addWidget(_render);
    QStringList indexses;
    indexses<<"0"<<"1"<<"2"<<"3"<<"4"<<"5"<<"6"<<"7"<<"8"<<"9"<<"10"<<"11"<<"All";
    ui->astarIndex_comboBox->addItems(indexses);
    QStringList output_types;
    output_types<<"1"<<"2";
    ui->debug_output_type->addItems(output_types);
    this->on_btnLoadVars_clicked();
    connect(&timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
    timer.start(100);

    logTimer = new QTimer();
    connect(logTimer, SIGNAL(timeout()), this, SLOT(logTimer_timeout()));

    //this->setWindowState(Qt::WindowFullScreen);

    this->counter = 0;
    this->logPlayer_status = "Stop";
    this->logIsPlayed = false;
}
Example #5
0
/* -------------------------------------------------------------------------- *
 * Loop around some timer stuff and the i/o multiplexer.                      *
 * -------------------------------------------------------------------------- */
void servauth_loop(void)
{
  int ret = 0;
  int64_t *timeout;
  int64_t remain = 0LL;

  while(ret >= 0)
  {
    /* Calculate timeout value */
    timeout = timer_timeout();

    /* Do I/O multiplexing and event handling */
#ifdef USE_POLL
    ret = io_poll(&remain, timeout);
#else
    ret = io_select(&remain, timeout);
#endif

    /* Remaining time is 0msecs, we need to run a timer */
    if(remain == 0LL)
      timer_run();

    if(timeout)
      timer_drift(*timeout - remain);

    io_handle();
  }
}
Example #6
0
QlipperModel::QlipperModel(QObject *parent) :
    QAbstractListModel(parent)
{
    m_network = new QlipperNetwork(this);

    m_boldFont.setBold(true);

    m_sticky = QlipperPreferences::Instance()->getStickyItems();
    m_dynamic = QlipperPreferences::Instance()->getDynamicItems();
    // a little hack-a-magic to have almost
    if (m_sticky.count() + m_dynamic.count() == 0)
    {
        clipboard_changed(QClipboard::Clipboard);
        if (m_dynamic.count() == 0)
        {
            clearHistory();
        }
    }

#ifdef Q_WS_MAC
    m_timer = new QTimer(this);
    connect(m_timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
    m_timer->start(1000);
#endif

    connect(ClipboardWrap::Instance(), &ClipboardWrap::changed, this, &QlipperModel::clipboard_changed);
}
Example #7
0
GameTimer::GameTimer(Minesweeper *minesweeper)
{
	m_main_window = minesweeper;
	m_timer = new QTimer();
	m_timer->setInterval(1000);
	m_timer->setSingleShot(false);
	connect(m_timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
}
Example #8
0
void blink ()
{
    unsigned int t;
    PWM1_Duty(24000);
    while(1)
    {
        LATAbits.LATA4 = 0;
        LATAbits.LATA0 = 1;
        LATBbits.LATB2 = 1;
        t = timer_start();
        while (!timer_timeout(t, 10000000));
        LATAbits.LATA4 = 1;
        LATAbits.LATA0 = 0;
        LATBbits.LATB2 = 0;
        t = timer_start();
        while (!timer_timeout(t, 10000000));
    }   
}
Example #9
0
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
	int erases = 0;
	if (event->key() == Qt::Key_P) {
		mode_switch();
		return;
	}
	switch (state) {
	case STATE_RUNNING:
		switch (event->key()) {
		case Qt::Key_Space:
			game->DropToBottom();
			finishJudge();
			drawNext(game->next);
			erases = game->EraseRows();
			for(int i = 0; i<erases; i++)
			{
				score += (i+1) * 100;
			}
			refreshScore();
			goto redraw;
		case Qt::Key_Left:
			game->MoveLeft();
			goto redraw;
		case Qt::Key_Right:
			game->MoveRight();
			goto redraw;
		case Qt::Key_Up:
			game->Rotate();
			goto redraw;
		case Qt::Key_Down:
			timer_timeout ();
			goto redraw;
		case Qt::Key_C:
			if (interval % 10 == 3)
				game->next = block(util::point(0, 0), block_shape::GetRandomBlockShape());
			drawNext(game->next);
			goto redraw;
		default:
			QMainWindow::keyReleaseEvent(event);
			return;
		}
		redraw:
		redraw ();
		return;
	case STATE_INIT:
		if (event->key() == Qt::Key_Space)
			mode_switch();
		else {
			QMainWindow::keyReleaseEvent(event);
			return;
		}
		return;
	case STATE_PAUSE:
		return;
	}
}
Example #10
0
File: clock.c Project: BruceYi/okl4
/* generate an interrupt after the specified time (in microseconds) */
void
clock_generate_interrupt(uint64_t time)
{
    uint64_t clock = clock_read();
    
    while(timer_timeout(timer_device.ti, us_to_ticks(timer_device.frequency, clock + time)))
        time *= 2;
        
}
Example #11
0
//! [0]
Window::Window(QString filename):run_animation(false),m_animation_number(0),anim_time(0.0)
{
  scene = new GraphSceneJM(filename,this);
  graph_view = new GraphViewJM(scene);
  m_shotbutton = new QPushButton("Shot", this);
  m_saveposbutton = new QPushButton("Save Pos", this);
  m_newposbutton = new QPushButton("New Pos", this);
  m_newposname_edit = new QLineEdit(this);
  m_delposbutton = new QPushButton("Delete this position", this);
  m_gotoposbutton = new QPushButton("Goto Pos:", this);
  m_pos_list = new QComboBox(this);
  m_destpos_list = new QComboBox(this);
  m_animfile_label = new QLabel("Save as:",this);
  m_animfile_edit = new QLineEdit(this);

  m_writefilebutton = new QPushButton("Write File", this);

  QGridLayout *mainLayout = new QGridLayout;
  mainLayout->addWidget(graph_view,1,1,10,2);
  mainLayout->addWidget(m_shotbutton,1,3,1,2);
  mainLayout->addWidget(m_saveposbutton,2,3,1,2);
  mainLayout->addWidget(m_pos_list,3,3,1,2);
  mainLayout->addWidget(m_delposbutton,4,3,1,2);

  mainLayout->addWidget(m_newposbutton,5,3,1,1);
  mainLayout->addWidget(m_newposname_edit,5,4,1,1);

  mainLayout->addWidget(m_gotoposbutton,6,3,1,1);
  mainLayout->addWidget(m_destpos_list,6,4,1,1);

  mainLayout->addWidget(m_animfile_label,7,3,1,1);
  mainLayout->addWidget(m_animfile_edit,7,4,1,1);

  mainLayout->addWidget(m_writefilebutton,8,3,1,2);

  setLayout(mainLayout);
  
  setWindowTitle(tr("QAnimDrawer"));
  QObject::connect(m_shotbutton, SIGNAL(clicked()), graph_view, SLOT(ask_shot()));
  QObject::connect(m_saveposbutton, SIGNAL(clicked()), this, SLOT(save_pos()));
  QObject::connect(m_delposbutton, SIGNAL(clicked()), this, SLOT(del_pos()));
  QObject::connect(m_gotoposbutton, SIGNAL(clicked()), this, SLOT(goto_pos()));
  QObject::connect(m_newposbutton, SIGNAL(clicked()), this, SLOT(new_pos()));

  QObject::connect(m_pos_list, SIGNAL(currentIndexChanged(int)), this, SLOT(change_pos(int)));

  QObject::connect(m_writefilebutton, SIGNAL(clicked()), this, SLOT(write_file()));

  scene->draw_skel();
  
  update_pos_list();

  timer=new QTimer(this);
  QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));

}
Example #12
0
ScrollText::ScrollText(QWidget *parent) :
    QWidget(parent), scrollPos(0)
{
    staticText.setTextFormat(Qt::PlainText);

    setFixedHeight(fontMetrics().height());
    leftMargin = height() / 3;

    setSeparator("   ---   ");

    connect(&timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
    timer.setInterval(50);
}
Example #13
0
Agent::Agent(int rid, OutputBuffer *outputbuffer, WorldModel *wm, QObject *parent) :
    QObject(parent),
    _timer(this),
    _outputbuffer(outputbuffer),
    _rid(rid),
    _wm(wm),
    _FLG(0),
    _ASK(0)
{
    qDebug() << "Agent Initialization... (ID=" << _rid <<")";
    _skill=0;
    _timer.setInterval(AGENT_TIMER);
    connect(&_timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
}
Example #14
0
/**
 * @brief Starts the TcpNetwork and UdpNetwork for Communication.
 *  if isConnected then sets the multicastInterface  UdpNetwork class and
 */
void wavrNetwork::start(void){
    wavrTrace::write("Network started");

    pTimer = new QTimer(this);
    connect(pTimer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
    pTimer->start(2000);

    if(isConnected) {
        pUdpNetwork->setMulticastInterface(networkInterface);
        pUdpNetwork->setIPAddress(ipAddress, subnetMask);
        pUdpNetwork->start();
        pTcpNetwork->setIPAddress(ipAddress);
        pTcpNetwork->start();
        canReceive = pUdpNetwork->canReceive;
    }
}
Example #15
0
File: clock.c Project: BruceYi/okl4
/*
 * Wait the given number of ticks for an interrupt. If the timeout was too
 * short such that we didn't need to receive an interrupt (because our setup
 * time exceeded the wait time), 'interrupt_received' will be 0. Otherwise,
 * it will be 1.
 */
static void
clock_pause(uint64_t ticks, int *interrupt_received)
{
    /* Wait for the timeout. */
    uint64_t time = timer_get_ticks(timer_device.ti);
    int already_passed = timer_timeout(timer_device.ti, time + ticks);
    if (already_passed) {
        /* If it happened while we were still setting up, just return. */
        *interrupt_received = 0;
        return;
    }

    /* Otherwise, wait for an interrupt. */
    while (!device_interrupt(timer_device.di, okn_syscall_interrupt_wait()));
    *interrupt_received = 1;
}
Example #16
0
ScrollText::ScrollText(QWidget *parent) :
    QWidget(parent), scrollPos(0)
{
    staticText.setTextFormat(Qt::PlainText);
    //staticText.setTextFormat(Qt::RichText);

    //staticText.setPerformanceHint(QStaticText::ModerateCaching);
    //staticText.setPerformanceHint(QStaticText::AggressiveCaching);

    setFixedHeight(fontMetrics().height());
    leftMargin = height() / 3;

    setSeparator("   ---   ");

    connect(&timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
    timer.setInterval(50);
}
Example #17
0
int service_timeout(uint32_t handle, int ti) {
	int session = service_session(handle);
	if (ti == 0) {
		struct message m;
		m.source = handle;
		m.session = session;
		m.data = 0;
		m.size = 0;
		m.proto = SERVICE_PROTO_RESP;
		session = service_send(handle, &m);
	} else {
		struct timer_event evt;
		evt.session = session;
		evt.handle = handle;
		timer_timeout(ti, &evt, sizeof(evt));
	}
	return session;
}
Example #18
0
uint64_t
timer__request_impl(CORBA_Object _caller, objref_t timer_obj,
                    uint64_t time, int flags, idl4_server_environment * _env)
{
    struct timer *timer = (struct timer *)timer_obj;
    struct driver *device = timer->timer_service->device;
    uint64_t abs_time;
    int is_earliest;

    if (timer->state != timer_cancelled_e) {
        /* We need to cancel the timer first */
        timer__cancel_impl(_caller, timer_obj, _env);
    }

    abs_time = time;

    if (!(flags & TIMER_ABSOLUTE)) {
        abs_time += timer_current_time(device);
    }

    if (flags & TIMER_PERIODIC) {
        if (flags & TIMER_ABSOLUTE) {
            return -1;
        }
        timer->state = timer_periodic_e;
        timer->period = time;
    } else {
        timer->state = timer_oneshot_e;
    }

    timer->timeout = abs_time;
    is_earliest = make_active(timer);
    // debug_active(timer);

    /* Set a request for that point in time */
    if (is_earliest) {
        if (timer_timeout
            (device, abs_time, timer_callback, 0, (uintptr_t)timer)) {
            timer_callback(0, 0, NULL, (uintptr_t)timer);
        }
    }

    return abs_time;
}
Example #19
0
File: clock.c Project: BruceYi/okl4
/* Wait for the specified time (in microseconds) */
void
clock_wait(uint64_t time)
{
    int error;
    uint64_t clock = clock_read();
    uint64_t timeout = clock + time;

    error = okn_syscall_interrupt_register(CLOCK_IRQ);
    assert(!error);
    if (timer_timeout(timer_device.ti, us_to_ticks(timer_device.frequency, timeout))) {
        error = okn_syscall_interrupt_deregister(CLOCK_IRQ);
        assert(!error);
        return; /* Already expired */
    }
    /* wait for the interrupt */
    while(!device_interrupt(timer_device.di, okn_syscall_interrupt_wait()));
    error = okn_syscall_interrupt_deregister(CLOCK_IRQ);
    assert(!error);
}
Example #20
0
void FileReceiver::receiveFile(void) {
	QDir dir = QFileInfo(filePath).dir();
	if(!dir.exists())
		dir.mkpath(dir.absolutePath());

	file = new QFile(filePath);

	if(file->open(QIODevice::WriteOnly)) {
		buffer = new char[bufferSize];
		active = true;

		timer = new QTimer(this);
		connect(timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
		timer->start(timeout);
	} else {
		socket->close();
		emit progressUpdated(FM_Receive, FO_Error, type, &id, &peerId, &filePath);
	}
}
Example #21
0
MainWindow::MainWindow (QWidget * parent):
QMainWindow (parent), ui (new Ui::MainWindow)
{
	ui->setupUi (this);
	scene = new QGraphicsScene (0, 0, BOARD_WIDTH * BOARD_TILE_SIZE,
		BOARD_HEIGHT * BOARD_TILE_SIZE);
	scene->setBackgroundBrush(QBrush(QColor(Qt::white)));
	ui->graphicsView->setScene (scene);
	nextScene = new QGraphicsScene (0, 0, 4*BOARD_TILE_SIZE, 4*BOARD_TILE_SIZE);
	nextScene->setBackgroundBrush(QBrush(QColor(Qt::black)));
	ui->nextView->setScene(nextScene);
	timer = new QTimer (this);
	connect(timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
	srand (std::time(NULL));
	game = new normal_game (BOARD_WIDTH, BOARD_HEIGHT);
	state = STATE_INIT;
	setWindowState(Qt::WindowMaximized);
	settings = new QSettings(SETTINGS_ORGNIZATION, SETTINGS_APPLICATION);
	refreshSettings();
}
Example #22
0
	void unlink(SockJsSession *ext)
	{
		Session *s = sessionsByExt.value(ext);
		assert(s);

		sessionsByExt.remove(s->ext);
		s->ext = 0;

		if(s->closeValue.isValid())
		{
			// if there's a close value, hang around for a little bit
			s->timer = new QTimer(this);
			connect(s->timer, SIGNAL(timeout()), SLOT(timer_timeout()));
			s->timer->setSingleShot(true);
			sessionsByTimer.insert(s->timer, s);
			s->timer->start(5000);
		}
		else
			removeSession(s);
	}
Example #23
0
void FileSender::sendFile(void) {
	file = new QFile(filePath);

	if(file->open(QIODevice::ReadOnly)) {
		buffer = new char[bufferSize];
		active = true;

		timer = new QTimer(this);
		connect(timer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
		timer->start(timeout);

		qint64 unsentBytes = fileSize - file->pos();
		qint64 bytesToSend = (bufferSize < unsentBytes) ? bufferSize : unsentBytes;
		qint64 bytesRead = file->read(buffer, bytesToSend);
		socket->write(buffer, bytesRead);
	} else {
		socket->close();
        QString data;
		emit progressUpdated(FM_Send, FO_Error, type, &id, &peerId, &data);
	}
}
Example #24
0
struct timeval *NS_CLASS timer_age_queue()
{
    struct timeval now;
    static struct timeval remaining;

    gettimeofday(&now, NULL);

    timer_timeout(&now);

    if (!TQ)
	return NULL;

    remaining.tv_usec = (TQ->timeout.tv_usec - now.tv_usec);
    remaining.tv_sec = (TQ->timeout.tv_sec - now.tv_sec);

    if (remaining.tv_usec < 0) {
	remaining.tv_usec += 1000000;
	remaining.tv_sec -= 1;
    }
    return (&remaining);
}
Example #25
0
void lmcMessaging::init(XmlMessage *pInitParams) {
	lmcTrace::write("Messaging initialized");

	pNetwork->init(pInitParams);

    QString logonName = Helper::getLogonName();
    QString szAddress = pNetwork->physicalAddress();
    QString userId = createUserId(&szAddress, &logonName);

	pNetwork->setLocalId(&userId);
	
	pSettings = new lmcSettings();
	QString userStatus = pSettings->value(IDS_STATUS, IDS_STATUS_VAL).toString();
	int sIndex = Helper::statusIndexFromCode(userStatus);
	//	if status not recognized, default to available
	if(sIndex < 0)
		userStatus = statusCode[0];
	QString userName = getUserName();

	int nAvatar = pSettings->value(IDS_AVATAR, IDS_AVATAR_VAL).toInt();
	QString userNote = pSettings->value(IDS_NOTE, IDS_NOTE_VAL).toString();
    uint userCaps = UC_File | UC_GroupMessage | UC_Folder;
    localUser = new User(userId, IDA_VERSION, pNetwork->ipAddress, userName, userStatus,
                         QString::null, nAvatar, userNote, StdLocation::avatarFile(),
                         QString::number(userCaps));

	loadGroups();

	nTimeout = pSettings->value(IDS_TIMEOUT, IDS_TIMEOUT_VAL).toInt() * 1000;
	nMaxRetry = pSettings->value(IDS_MAXRETRIES, IDS_MAXRETRIES_VAL).toInt();

	pTimer = new QTimer(this);
	connect(pTimer, SIGNAL(timeout()), this, SLOT(timer_timeout()));
	pTimer->start(1000);

	msgId = 1;
}
Example #26
0
static void
timer_callback(callback_data_t data, int ignored, struct data *ignored_data,
               uintptr_t key)
{
    struct timer *timer = (struct timer *)key;
    struct timer *next_timer;
    struct driver *device = timer->timer_service->device;

    do {
        L4_Notify(timer->thread, timer->mask);

        /* The timer should be at the start of the list! */
        assert(timer->timer_service->active == timer);
        assert(timer->prev == NULL);

        if (timer->state == timer_oneshot_e) {
            /* Remove timer from active list */
            next_timer = timer->next;
            deactivate_timer(timer);
        } else {
            /*
             * Period timer -- needs to be put straight back in the active
             * queue
             */
            timer->timeout += timer->period;
            if (timer->next == NULL || timer->next->timeout > timer->timeout) {
                /*
                 * Special case -- we are still at the front of the list so we
                 * don't need to do very much... XXX: Periodic timers should
                 * cost a lot of quota, this could easily DOS a system if
                 * someone request a short periodic timeout
                 */
                next_timer = timer;
            } else {
                /* Ok, so we are not going to be at the front this time */
                struct timer *back = timer->timer_service->active_end;

                next_timer = timer->next;
                timer->timer_service->active = next_timer;
                next_timer->prev = NULL;
                while (back->timeout > timer->timeout) {
                    back = back->prev;
                    assert(back != NULL);
                    /*
                     * This could only happen if we are next, which we can't be
                     * because we already checked that!
                     */
                }
                /* Now we insert behind back */
                timer->next = back->next;
                timer->prev = back;
                back->next = timer;
                if (timer->next) {
                    timer->next->prev = timer;
                }
                if (timer->timer_service->active_end == back) {
                    timer->timer_service->active_end = timer;
                }
            }
        }

        timer = NULL;
        if (next_timer) {
            /* We need to add the next timer */
            if (timer_timeout
                (device, next_timer->timeout, timer_callback, 0,
                 (uintptr_t)next_timer)) {
                timer = next_timer;
            }
        }
    } while (timer);
}
Example #27
0
	void start(const QVariant &vrequest, Mode mode)
	{
		outSeq = 0;

		ZurlRequestPacket request;
		if(!request.fromVariant(vrequest))
		{
			log_warning("failed to parse zurl request");

			QVariantHash vhash = vrequest.toHash();
			rid = vhash.value("id").toByteArray();
			assert(!rid.isEmpty()); // app layer ensures this
			receiver = vhash.value("sender").toByteArray();
			bool cancel = vhash.value("cancel").toBool();
			if(!receiver.isEmpty() && !cancel)
			{
				QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
			}
			else
			{
				cleanup();
				QMetaObject::invokeMethod(q, "finished", Qt::QueuedConnection);
			}

			return;
		}

		rid = request.id;
		receiver = request.sender;
		outCredits = 0;
		userData = request.userData;
		quiet = false;
		sentHeader = false;
		stuffToRead = false;
		bytesReceived = 0;

		ignorePolicies = request.ignorePolicies;

		// streaming only allowed on streaming interface
		if(mode == Worker::Stream)
			outStream = request.stream;
		else
			outStream = false;

		// some required fields
		if(request.method.isEmpty() || request.uri.isEmpty())
		{
			log_warning("missing request method or missing uri");

			QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
			return;
		}

		log_info("IN id=%s, %s %s", request.id.data(), qPrintable(request.method), request.uri.toEncoded().data());

		// inbound streaming must start with sequence number of 0
		if(mode == Worker::Stream && request.more && request.seq != 0)
		{
			log_warning("streamed input must start with seq 0");

			QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
			return;
		}

		// fire and forget
		if(mode == Worker::Stream && receiver.isEmpty())
			quiet = true;

		// can't use these two together
		if(mode == Worker::Single && request.more)
		{
			log_warning("cannot use streamed input on router interface");

			QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "bad-request"));
			return;
		}

		bodySent = false;

		inSeq = request.seq;

		if(!isAllowed(request.uri.host()) || (!request.connectHost.isEmpty() && !isAllowed(request.connectHost)))
		{
			QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "policy-violation"));
			return;
		}

		hreq = new HttpRequest(dns, this);
		connect(hreq, SIGNAL(nextAddress(const QHostAddress &)), SLOT(req_nextAddress(const QHostAddress &)));
		connect(hreq, SIGNAL(readyRead()), SLOT(req_readyRead()));
		connect(hreq, SIGNAL(bytesWritten(int)), SLOT(req_bytesWritten(int)));
		connect(hreq, SIGNAL(error()), SLOT(req_error()));
		maxResponseSize = request.maxSize;
		if(!request.connectHost.isEmpty())
			hreq->setConnectHost(request.connectHost);

		hreq->setIgnoreTlsErrors(request.ignoreTlsErrors);

		if(request.credits != -1)
			outCredits += request.credits;

		HttpHeaders headers = request.headers;
		// ensure content-length (or overwrite it, if not streaming input)
		if((request.method == "POST" || request.method == "PUT") && (!headers.contains("content-length") || !request.more))
			headers += HttpHeader("Content-Length", QByteArray::number(request.body.size()));

		timer = new QTimer(this);
		connect(timer, SIGNAL(timeout()), SLOT(timer_timeout()));
		timer->setSingleShot(true);
		timer->start(config->sessionTimeout * 1000);

		hreq->start(request.method, request.uri, headers);

		// note: unlike follow-up requests, the initial request is assumed to have a body.
		//   if no body field is present, we act as if it is present but empty.

		if(!request.body.isEmpty())
		{
			if(request.more && !request.headers.contains("content-length"))
			{
				log_warning("streamed input requires content-length");
				QMetaObject::invokeMethod(this, "respondError", Qt::QueuedConnection, Q_ARG(QByteArray, "length-required"));
				return;
			}

			hreq->writeBody(request.body);
		}

		if(!request.more)
		{
			bodySent = true;
			hreq->endBody();
		}
		else
		{
			// send cts
			ZurlResponsePacket resp;
			resp.credits = config->sessionBufferSize;
			writeResponse(resp);
		}
	}
bool process_record_userspace(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
  case CU_GAME:
    if(record->event.pressed) {
      game = !game;
    }
    return false;
  case KC_LGUI:
  case KC_RGUI:
    if (game)
      return false;
    else
      return true;
  case CU_NAV:
    if(record->event.pressed) {
      navesc = true;
      navesc_timer = timer_read();
      layer_on(_NAV);
    } else {
      if (timer_elapsed(navesc_timer) < 200 && navesc) {
        register_code(KC_ESC);
        unregister_code(KC_ESC);
      }
      layer_off(_NAV);
    }
  return false;

  #ifdef RGBLIGHT_ENABLE
  case CU_RGBV:
    if(record->event.pressed) {
      if (rgblight_get_val()+32>255)
        rgblight_sethsv(rgblight_get_hue(), rgblight_get_sat(), 31);
      else
        rgblight_sethsv(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val()+32);
    }
    return false;
  #endif

  #ifdef GERMAN_ENABLE
  case CU_LSFT:
    if(record->event.pressed) {
      lshiftp = true;
      lshift_timer = timer_read();
      unregister_code(KC_LSFT);
      register_code(KC_LSFT);
      lshift = true;
    } else {
      if (timer_elapsed(lshift_timer) < 200 && lshiftp && !game) {
        register_code(KC_LSFT);
        register_code(KC_8);
        unregister_code(KC_8);
        unregister_code(KC_LSFT);
      }
      unreg_prev();
      if (!rshift)
        unregister_code(KC_LSFT);
      lshift = false;
    }
    return false;
  case CU_RSFT:
    if(record->event.pressed) {
      rshiftp = true;
      rshift_timer = timer_read();
      unregister_code(KC_LSFT);
      register_code(KC_LSFT);
      rshift = true;
    } else {
      if (timer_elapsed(rshift_timer) < 200 && rshiftp && !game) {
        register_code(KC_LSFT);
        register_code(KC_9);
        unregister_code(KC_9);
        unregister_code(KC_LSFT);
      }
      unreg_prev();
      if (!lshift)
        unregister_code(KC_LSFT);
      rshift = false;
    }
    return false;
  case CU_ESCT:
    if(record->event.pressed) {
      esct = !esct;
    }
    return false;
  case CU_AE:
    UML(DE_AE)
  case CU_OE:
    UML(DE_OE)
  case CU_UE:
    UML(DE_UE)
  case CU_SS:
    if(record->event.pressed) {
      timer_timeout();
      unregister_code(KC_LSFT);
      register_code(DE_SS);
      unregister_code(DE_SS);
      if (lshift || rshift)
        register_code(KC_LSFT);
      layer_off(_DEADKEY);
    }
    return false;
  case CU_DDQ:
    if(record->event.pressed) {
      timer_timeout();
      register_code(KC_LSFT);
      register_code(KC_2);
      unregister_code(KC_2);
      if (!lshift && !rshift)
        unregister_code(KC_LSFT);
      layer_off(_DEADKEY);
    }
    return false;
  case CU_ED:
    if(record->event.pressed) {
      timer_timeout();
      layer_off(_DEADKEY);
    }
    return false;
  case CU_GRV:
    if(record->event.pressed) {
      timer_timeout();
      if (lshift || rshift){
        unregister_code(KC_LSFT);
        register_code(DE_ALGR);
        unregister_code(DE_PLUS);
        register_code(DE_PLUS);
        unregister_code(DE_PLUS);
        unregister_code(DE_ALGR);
        register_code(KC_LSFT);
      } else {
        register_code(KC_LSFT);
        unregister_code(DE_ACUT);
        register_code(DE_ACUT);
        unregister_code(DE_ACUT);
        unregister_code(KC_LSFT);
        if (!esct) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
      }
    }
    return false;
  case CU_CIRC:
    if(record->event.pressed) {
      timer_timeout();
      unregister_code(KC_LSFT);
      unregister_code(DE_CIRC);
      register_code(DE_CIRC);
      unregister_code(DE_CIRC);
      if (!esct) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
      }
      if (lshift || rshift)
        register_code(KC_LSFT);
    }
    return false;
  case CU_QUOT:
    if(record->event.pressed){
      timer_timeout();
      register_code(KC_LSFT);
      if (lshift || rshift){
        layer_on(_DEADKEY);
      } else {
        unregister_code(DE_HASH);
        register_code(DE_HASH);
        add_to_prev(DE_HASH);
      }
    } else {
      unregister_code(DE_HASH);
      unreg_prev();
      if (lshift || rshift)
        register_code(KC_LSFT);
      else
        unregister_code(KC_LSFT);
    }
    return false;
  case CU_6:
    if(record->event.pressed){
      timer_timeout();
      unregister_code(KC_LSFT);
      if (lshift || rshift){
        unregister_code(DE_CIRC);
        register_code(DE_CIRC);
        unregister_code(DE_CIRC);
        if (!esct) {
          register_code(KC_SPC);
          unregister_code(KC_SPC);
        }
        register_code(KC_LSFT);
      } else {
        register_code(DE_6);
      }
    } else {
      unregister_code(DE_6);
    }
    return false;
  case CU_COMM:
    SHIFT_NO(DE_COMM, DE_LESS)
  case CU_DOT:
    SHIFT_NORM(DE_DOT, DE_LESS)
  case CU_SLSH:
    SHIFT_ALL(DE_7, DE_SS)
  case CU_SCLN:
    SHIFT_ALL(DE_COMM, DE_DOT)
  case CU_3:
    SHIFT_NO(DE_3, DE_HASH)
  case CU_7:
    SHIFT_NORM(DE_7, DE_6)
  case CU_8:
    SHIFT_NORM(DE_8, DE_PLUS)
  case CU_9:
    SHIFT_NORM(DE_9, DE_8)
  case CU_0:
    SHIFT_NORM(DE_0, DE_9)
  case CU_EQL:
    SHIFT_SWITCH(DE_0, DE_PLUS)
  case CU_LBRC:
    SHIFT_ALGR(DE_8, DE_7)
  case CU_RBRC:
    SHIFT_ALGR(DE_9, DE_0)
  case CU_BSLS:
    SHIFT_ALGR(DE_SS, DE_LESS)
  case CU_Z:
    CTRL(DE_Z, KC_Z)
  case CU_Y:
    CTRL(DE_Y, KC_Y)
  case KC_LCTL:
  case KC_RCTL:
    if(!record->event.pressed) {
      unregister_code(KC_Z);
      unregister_code(KC_Y);
    }
    return true;
  #endif

  default:
    if(record->event.pressed) {
      timer_timeout();

      #ifdef GERMAN_ENABLE
      if (lshift || rshift)
        register_code(KC_LSFT);
      else
        unregister_code(KC_LSFT);
      #endif

    }
    return true;
  }
}
Example #29
0
AppDBWidget::AppDBWidget(QWidget *parent) : QWidget(parent)
{

    // Loading libq4wine-core.so
#ifdef RELEASE
    libq4wine.setFileName(_CORELIB_PATH_);
#else
    libq4wine.setFileName("../q4wine-lib/libq4wine-core");
#endif

    if (!libq4wine.load()){
          libq4wine.load();
    }

    // Getting corelib calss pointer
    CoreLibClassPointer = (CoreLibPrototype *) libq4wine.resolve("createCoreLib");
    CoreLib.reset((corelib *)CoreLibClassPointer(true));

    //Init AppDB Core Classes
    xmlparser.reset(new XmlParser());
    httpcore.reset(new HttpCore());

    //Init delay timer
    timer.reset(new QTimer(this));

    this->createActions();

    std::auto_ptr<QToolBar> toolbar (new QToolBar());
    toolbar->setIconSize(QSize(24, 24));
    toolbar->addAction(appdbOpen.get());
    toolbar->addAction(appdbAppPage.get());
    toolbar->addSeparator();
    toolbar->addAction(appdbCat.get());
    toolbar->addSeparator();
    toolbar->addAction(appdbClear.get());
    toolbar->addAction(appdbClearSearch.get());
    searchField.reset (new QLineEdit(this));
    connect(searchField.get(), SIGNAL(returnPressed()), this, SLOT(appdbSearch_Click()));

    toolbar->addWidget(searchField.get());
    toolbar->addAction(appdbSearch.get());

    //Init custom widgets
    appdbHeader.reset(new AppDBHeaderWidget());
    connect(appdbHeader.get(), SIGNAL(itemTrigged(short int, QString, int, int, int)), this, SLOT(itemTrigged(short int, QString, int, int, int)));
    appdbScrollArea.reset(new AppDBScrollWidget());
    connect(appdbScrollArea.get(), SIGNAL(itemTrigged(short int, QString, int, int, int)), this, SLOT(itemTrigged(short int, QString, int, int, int)));

    //Add custom widgets to mail layout
    std::auto_ptr<QVBoxLayout> contentLayout(new QVBoxLayout(this));
    contentLayout->setMargin(0);
    contentLayout->setSpacing(0);
    contentLayout->addWidget(toolbar.release());
    contentLayout->addWidget(appdbHeader.get());
    contentLayout->addWidget(appdbScrollArea.get());
    this->setLayout(contentLayout.release());

    //Connect slots and signals
    connect(timer.get(), SIGNAL(timeout()), this, SLOT(timer_timeout()));
    connect(httpcore.get(), SIGNAL(pageReaded()), this, SLOT(httpcore_pageDownloaded()));
    connect(httpcore.get(), SIGNAL(requestError(QString)), this, SLOT(requestError(QString)));
    connect(httpcore.get(), SIGNAL(updateDataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
    connect(httpcore.get(), SIGNAL(stateChanged(int)), this, SLOT(stateChanged(int)));

    this->appdbHeader->addLabel(tr("Status: Ready"));
    timer->stop();

    return;
}
Example #30
0
void timer_busysleep(timer_t *t, uint32_t timeout)
{
	timer_start(t,timeout);
	while (!timer_timeout(t)) {};
}