예제 #1
0
void KRunnerApp::switchUser()
{
    const KService::Ptr service = KService::serviceByStorageId(QLatin1String("plasma-runner-sessions.desktop"));
    KPluginInfo info(service);

    if (info.isValid()) {
        SessList sessions;
        KDisplayManager dm;
        dm.localSessions(sessions);

        if (sessions.isEmpty()) {
            // no sessions to switch between, let's just start up another session directly
            Plasma::AbstractRunner *sessionRunner = m_runnerManager->runner(info.pluginName());
            if (sessionRunner) {
                Plasma::QueryMatch switcher(sessionRunner);
                sessionRunner->run(*m_runnerManager->searchContext(), switcher);
            }
        } else {
            m_runnerManager->setSingleModeRunnerId(info.pluginName());
            m_runnerManager->setSingleMode(true);
            m_interface->display();
            //TODO: ugh, magic strings. See sessions/sessionrunner.cpp
            m_runnerManager->launchQuery(QLatin1String("SESSIONS"), info.pluginName());
        }
    }
}
예제 #2
0
int main(int argc, char** argv) {
    init();
    while(true){
        switcher();
    }
    return (EXIT_SUCCESS);
}
예제 #3
0
osg::Group* createCharacterInstance(osg::Group* character, bool hardware)
{
    osg::ref_ptr<osg::Group> c ;
    if (hardware)
        c = osg::clone(character, osg::CopyOp::DEEP_COPY_ALL & ~osg::CopyOp::DEEP_COPY_PRIMITIVES & ~osg::CopyOp::DEEP_COPY_ARRAYS);
    else
        c = osg::clone(character, osg::CopyOp::DEEP_COPY_ALL);

    osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(c->getUpdateCallback());

    osgAnimation::BasicAnimationManager* anim = dynamic_cast<osgAnimation::BasicAnimationManager*>(animationManager);
    const osgAnimation::AnimationList& list = animationManager->getAnimationList();
    int v = getRandomValueinRange(list.size());
    if (list[v]->getName() == std::string("MatIpo_ipo")) {
        anim->playAnimation(list[v].get());
        v = (v + 1)%list.size();
    }

    anim->playAnimation(list[v].get());

    SetupRigGeometry switcher(hardware);
    c->accept(switcher);

    return c.release();
}
예제 #4
0
파일: parser.cpp 프로젝트: BulSV/DirList
void Parser::applyOptions()
{
#ifdef DEBUG
    qDebug() << "getCollectedOptions() =" << getCollectedOptions();
    qDebug() << "(int)getCollectedOptions() =" << (int)getCollectedOptions();
#endif
    switcher(parseOptions());

    emit finished();
}
예제 #5
0
파일: handle.cpp 프로젝트: Abioy/mordor
HandleStream::~HandleStream()
{
    if (m_hFile != INVALID_HANDLE_VALUE && m_own) {
        SchedulerSwitcher switcher(m_scheduler);
        BOOL result = CloseHandle(m_hFile);
        MORDOR_LOG_LEVEL(g_log, result ? Log::VERBOSE : Log::ERROR) << this
            << " CloseHandle(" << m_hFile << "): " << result << " ("
            << GetLastError() << ")";
    }
}
예제 #6
0
파일: handle.cpp 프로젝트: Abioy/mordor
size_t
HandleStream::write(const void *buffer, size_t length)
{
    if (m_cancelWrite)
        MORDOR_THROW_EXCEPTION(OperationAbortedException());
    SchedulerSwitcher switcher(m_ioManager ? NULL : m_scheduler);
    DWORD written;
    OVERLAPPED *overlapped = NULL;
    if (m_ioManager) {
        MORDOR_ASSERT(Scheduler::getThis());
        m_ioManager->registerEvent(&m_writeEvent);
        overlapped = &m_writeEvent.overlapped;
        if (supportsSeek()) {
            overlapped->Offset = (DWORD)m_pos;
            overlapped->OffsetHigh = (DWORD)(m_pos >> 32);
        }
    }
    length = (std::min)(length, m_maxOpSize);
    BOOL ret = WriteFile(m_hFile, buffer, (DWORD)length, &written, overlapped);
    Log::Level level = Log::DEBUG;
    if (!ret) {
        if (m_ioManager && GetLastError() == ERROR_IO_PENDING)
            level = Log::TRACE;
        else
            level = Log::ERROR;
    }
    DWORD error = GetLastError();
    MORDOR_LOG_LEVEL(g_log, level) << this << " WriteFile(" << m_hFile << ", "
        << length << "): " << ret << " - " << written << " (" << error << ")";
    if (m_ioManager) {
        if (!ret && error != ERROR_IO_PENDING) {
            m_ioManager->unregisterEvent(&m_writeEvent);
            MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("WriteFile");
        }
        if (m_skipCompletionPortOnSuccess && ret)
            m_ioManager->unregisterEvent(&m_writeEvent);
        else
            Scheduler::yieldTo();
        DWORD error = pRtlNtStatusToDosError((NTSTATUS)m_writeEvent.overlapped.Internal);
        MORDOR_LOG_LEVEL(g_log, error ? Log::ERROR : Log::VERBOSE) << this
            << " WriteFile(" << m_hFile << ", " << length << "): "
            << m_writeEvent.overlapped.InternalHigh << " (" << error << ")";
        if (error)
            MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "WriteFile");
        if (supportsSeek()) {
            m_pos = ((long long)overlapped->Offset | ((long long)overlapped->OffsetHigh << 32)) +
                m_writeEvent.overlapped.InternalHigh;
        }
        return m_writeEvent.overlapped.InternalHigh;
    }
    if (!ret)
        MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "WriteFile");
    return written;
}
예제 #7
0
파일: handle.cpp 프로젝트: Abioy/mordor
void
HandleStream::flush(bool flushParent)
{
    SchedulerSwitcher switcher(m_scheduler);
    BOOL ret = FlushFileBuffers(m_hFile);
    DWORD error = GetLastError();
    MORDOR_LOG_LEVEL(g_log, ret ? Log::VERBOSE : Log::ERROR) << this
        << " FlushFileBuffers(" << m_hFile << "): " << ret << " (" << error
        << ")";
    if (!ret)
        MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "FlushFileBuffers");
}
예제 #8
0
파일: handle.cpp 프로젝트: Abioy/mordor
long long
HandleStream::size()
{
    SchedulerSwitcher switcher(m_scheduler);
    long long size;
    BOOL ret = GetFileSizeEx(m_hFile, (LARGE_INTEGER*)&size);
    DWORD error = GetLastError();
    MORDOR_LOG_VERBOSE(g_log) << this << " GetFileSizeEx(" << m_hFile << ", "
        << size << "): " << ret << " (" << error << ")";
    if (!ret)
        MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "GetFileSizeEx");
    return size;
}
int main(int argc, const char *argv[]) {
  unsigned int x = 0xfffffff1;
  x >>= (argc - 1);  // force it to be unsigned for purpose of checking our
                     // switch comparison in signed/unsigned
  printf("*%d,%d,%d,%d,%d,%d*\n", switcher('a'), switcher('b'), switcher('c'),
         switcher(x), switcher(-15), switcher('e'));
  return 0;
}
예제 #10
0
int main(int argc, char **argv)
{
    FILE* fp;  // file pointer to input file
    char move = '\0';  // character depicting next move
    int direction[2];  // direction of the move in cartesian plane

    Position* head = NULL;  // head of set (linked list)
    Position santa_position;  // current santa position
    santa_position.x = 0;
    santa_position.y = 0;
    Position robot_position;  // current robot position
    robot_position.x = 0;
    robot_position.y = 0;
    mark_position_visited(&head, santa_position);

    // Since Santa goes first,
    // Robot would have been the one before that.
    // Current member will hold whoever is moving currently.
    Position* current_member = &robot_position;

    fp = fopen("./input.txt", "r");

    // Read the file one character at a time
    while((move=fgetc(fp)) != EOF) {

        // Get the next move
        parse_direction(move, direction);

        // Get position of currently active member
        current_member = switcher(current_member, &santa_position, &robot_position);

        // Add the next move to current position
        current_member->x += direction[0];
        current_member->y += direction[1];

        // Check if position has been previously visited.
        // If it hasn't been, mark it as visited.
        if (!position_was_visited(head, *current_member)) {
            mark_position_visited(&head, *current_member);
        }
    }

    printf("%ld\n", list_length(head));

    // Free the list and close the file.
    clear_memory(&head);
    fclose(fp);

    return 0;
}
예제 #11
0
파일: handle.cpp 프로젝트: Abioy/mordor
void
HandleStream::truncate(long long size)
{
    SchedulerSwitcher switcher(m_scheduler);
    long long pos = seek(0, CURRENT);
    seek(size, BEGIN);
    BOOL ret = SetEndOfFile(m_hFile);
    DWORD error = GetLastError();
    MORDOR_LOG_LEVEL(g_log, ret ? Log::VERBOSE : Log::ERROR) << this
        << " SetEndOfFile(" << m_hFile << "): " << ret << " ("
        << error << ")";
    seek(pos, BEGIN);
    if (!ret)
        MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "SetEndOfFile");
}
예제 #12
0
파일: handle.cpp 프로젝트: Abioy/mordor
void
HandleStream::close(CloseType type)
{
    MORDOR_ASSERT(type == BOTH);
    if (m_hFile != INVALID_HANDLE_VALUE && m_own) {
        SchedulerSwitcher switcher(m_scheduler);
        BOOL result = CloseHandle(m_hFile);
        DWORD error = GetLastError();
        MORDOR_LOG_LEVEL(g_log, result ? Log::VERBOSE : Log::ERROR) << this
            << " CloseHandle(" << m_hFile << "): " << result << " ("
            << error << ")";
        if (!result)
            MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "CloseHandle");
        m_hFile = INVALID_HANDLE_VALUE;
    }
}
예제 #13
0
void loop()
{
	if (timer.onRestart())
	{
		switcher();
		MeterWrite(temp_avg, atm_avg / 100.0, 1);
	}
	if (timerJSON.onRestart())
	{
		// Sending data in JSON via serial port
		Serial.print("{\"temp\":");
		Serial.print(temp_avg);
		Serial.print(", \"atm\":");
		Serial.print(atm_avg);
		Serial.println("}");
	}
}
예제 #14
0
파일: handle.cpp 프로젝트: Abioy/mordor
long long
HandleStream::seek(long long offset, Anchor anchor)
{
    SchedulerSwitcher switcher(m_ioManager ? NULL : m_scheduler);
    if (m_ioManager) {
        if (supportsSeek()) {
            switch (anchor) {
                case BEGIN:
                    if (offset < 0) {
                        MORDOR_THROW_EXCEPTION(std::invalid_argument("resulting offset is negative"));
                    }
                    return m_pos = offset;
                case CURRENT:
                    if (m_pos + offset < 0) {
                        MORDOR_THROW_EXCEPTION(std::invalid_argument("resulting offset is negative"));
                    }
                    return m_pos += offset;
                case END:
                    {
                        long long end = size();
                        if (end + offset < 0) {
                            MORDOR_THROW_EXCEPTION(std::invalid_argument("resulting offset is negative"));
                        }
                        return m_pos = end + offset;
                    }
                default:
                    MORDOR_ASSERT(false);
            }
        } else {
            MORDOR_ASSERT(false);
        }
    }

    long long pos;
    BOOL ret = SetFilePointerEx(m_hFile, *(LARGE_INTEGER*)&offset,
        (LARGE_INTEGER*)&pos, (DWORD)anchor);
    DWORD error = GetLastError();
    MORDOR_LOG_LEVEL(g_log, ret ? Log::VERBOSE : Log::ERROR) << this
        << " SetFilePointerEx(" << m_hFile << ", " << offset << ", " << pos
        << ", " << anchor << "): " << ret << " (" << error << ")";
    if (!ret)
        MORDOR_THROW_EXCEPTION_FROM_ERROR_API(error, "SetFilePointerEx");
    return pos;
}
예제 #15
0
Result
PreparedStatement::execute()
{
    PGconn *conn = m_conn.lock().get();
    boost::shared_ptr<PGresult> result, next;
    int nParams = (int)m_params.size();
    Oid *paramTypes = NULL;
    int *paramLengths = NULL, *paramFormats = NULL;
    const char **params = NULL;
    if (nParams) {
        if (m_name.empty())
            paramTypes = &m_paramTypes[0];
        params = &m_params[0];
        paramLengths = &m_paramLengths[0];
        paramFormats = &m_paramFormats[0];
    }
    const char *api = NULL;
#ifndef WINDOWS
    SchedulerSwitcher switcher(m_scheduler);
#endif
    if (m_name.empty()) {
#ifndef WINDOWS
        if (m_scheduler) {
            api = "PQsendQueryParams";
            if (!PQsendQueryParams(conn, m_command.c_str(),
                nParams, paramTypes, params, paramLengths, paramFormats, m_resultFormat))
                throwException(conn);
            flush(conn, m_scheduler);
            next.reset(nextResult(conn, m_scheduler), &PQclear);
            while (next) {
                result = next;
                next.reset(nextResult(conn, m_scheduler), &PQclear);
                if (next) {
                    ExecStatusType status = PQresultStatus(next.get());
                    MORDOR_LOG_VERBOSE(g_log) << conn << "PQresultStatus(" <<
                        next.get() << "): " << PQresStatus(status);
                    switch (status) {
                        case PGRES_COMMAND_OK:
                        case PGRES_TUPLES_OK:
                            break;
                        default:
                            throwException(next.get());
                            MORDOR_NOTREACHED();
                    }
                }
            }
        } else
#endif
        {
            api = "PQexecParams";
            result.reset(PQexecParams(conn, m_command.c_str(),
                nParams, paramTypes, params, paramLengths, paramFormats, m_resultFormat),
                &PQclear);
        }
    } else {
#ifndef WINDOWS
        if (m_scheduler) {
            api = "PQsendQueryPrepared";
            if (!PQsendQueryPrepared(conn, m_name.c_str(),
                nParams, params, paramLengths, paramFormats, 1))
                throwException(conn);
            flush(conn, m_scheduler);
            next.reset(nextResult(conn, m_scheduler), &PQclear);
            while (next) {
                result = next;
                next.reset(nextResult(conn, m_scheduler), &PQclear);
                if (next) {
                    ExecStatusType status = PQresultStatus(next.get());
                    MORDOR_LOG_VERBOSE(g_log) << conn << "PQresultStatus(" <<
                        next.get() << "): " << PQresStatus(status);
                    switch (status) {
                        case PGRES_COMMAND_OK:
                        case PGRES_TUPLES_OK:
                            break;
                        default:
                            throwException(next.get());
                            MORDOR_NOTREACHED();
                    }
                }
            }
        } else
#endif
        {
            api = "PQexecPrepared";
            result.reset(PQexecPrepared(conn, m_name.c_str(),
                nParams, params, paramLengths, paramFormats, m_resultFormat),
                &PQclear);
        }
    }
    if (!result)
        throwException(conn);
    ExecStatusType status = PQresultStatus(result.get());
    MORDOR_ASSERT(api);
    MORDOR_LOG_VERBOSE(g_log) << conn << " " << api << "(\"" << m_command
        << m_name << "\", " << nParams << "), PQresultStatus(" << result.get()
        << "): " << PQresStatus(status);
    switch (status) {
        case PGRES_COMMAND_OK:
        case PGRES_TUPLES_OK:
            return Result(result);
        default:
            throwException(result.get());
            MORDOR_NOTREACHED();
    }
}
예제 #16
0
파일: switch.c 프로젝트: SRI-CSL/llvm2smt
int main(int argc, char* argv[]){
  if(argc == 2){
    switcher(argv[1][0]);
  }
  return 0;
}
예제 #17
0
파일: parser.c 프로젝트: shenchi/mycc
int statement(){
    symbol_t id;
    if(sym->type==IF){
        nextSym();
        brancher();
    }else if(sym->type==WHILE){
        nextSym();
        looper();
    }else if(sym->type==LBRACE){
        nextSym();
        statementlist();
        if(sym->type!=RBRACE){
            msg(ERR, "missing \'}\'", line);
			ERROR_STATUS = 1;
        }
        nextSym();
    }else if(sym->type==ID){
        id = copySym(sym);
        nextSym();
        if(sym->type==LPAREN){
            nextSym();
            funccall(id);
        }else if(sym->type==ASN){
            nextSym();
            assign(id);
        }else{
            msg(ERR, "expect a \'=\' or \'(\'", line);
			ERROR_STATUS = 1;
        }
        mfree(id);
        if(sym->type!=SEMIC){
            msg(ERR, "missing \';\'", line);
			ERROR_STATUS = 1;
        }
        nextSym();
    }else if(sym->type==PRINTF){
        nextSym();
        printfcall();
        if(sym->type!=SEMIC){
            msg(ERR, "missing \';\'", line);
			ERROR_STATUS = 1;
        }
        nextSym();
    }else if(sym->type==SCANF){
        nextSym();
        scanfcall();
        if(sym->type!=SEMIC){
            msg(ERR, "missing \';\'", line);
			ERROR_STATUS = 1;
        }
        nextSym();
    }else if(sym->type==SWITCH){
        nextSym();
        switcher();
    }else if(sym->type==RETURN){
        nextSym();
        returns();
        if(sym->type!=SEMIC){
            msg(ERR, "missing \';\'", line);
			ERROR_STATUS = 1;
        }
        nextSym();
    }else return 0;// a 0 statement

    return 1;
}
예제 #18
0
파일: pve500.cpp 프로젝트: MASHinfo/mame
void pve500_state::pve500(machine_config &config)
{
	/* Main CPU */
	TMPZ84C015(config, m_maincpu, 12_MHz_XTAL / 2); // TMPZ84C015BF-6
	m_maincpu->set_addrmap(AS_PROGRAM, &pve500_state::maincpu_prg);
	m_maincpu->set_addrmap(AS_IO, &pve500_state::maincpu_io);
	m_maincpu->set_daisy_config(maincpu_daisy_chain);
	m_maincpu->out_dtra_callback().set(FUNC(pve500_state::GPI_w));
	m_maincpu->out_dtrb_callback().set(m_buzzer, FUNC(beep_device::set_state)).invert();
	m_maincpu->out_txda_callback().set("recorder", FUNC(rs232_port_device::write_txd));
	m_maincpu->out_txdb_callback().set("player1", FUNC(rs232_port_device::write_txd));

	z80ctc_device& ctc(Z80CTC(config, "external_ctc", 12_MHz_XTAL / 2));
	ctc.intr_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ0);

	z80sio0_device& sio(Z80SIO0(config, "external_sio", 12_MHz_XTAL / 2));
	sio.out_int_callback().set_inputline(m_maincpu, INPUT_LINE_IRQ0);
	sio.out_txda_callback().set("player2", FUNC(rs232_port_device::write_txd));
	sio.out_txdb_callback().set("edl_inout", FUNC(rs232_port_device::write_txd));

	/* Secondary CPU */
	TMPZ84C015(config, m_subcpu, 12_MHz_XTAL / 2); /* TMPZ84C015BF-6 */
	m_subcpu->set_addrmap(AS_PROGRAM, &pve500_state::subcpu_prg);
	m_subcpu->set_addrmap(AS_IO, &pve500_state::subcpu_io);
	m_subcpu->out_dtra_callback().set(FUNC(pve500_state::cxdio_reset_w));
	m_subcpu->out_dtrb_callback().set(FUNC(pve500_state::external_monitor_w));
	m_subcpu->out_txda_callback().set("switcher", FUNC(rs232_port_device::write_txd));
	m_subcpu->out_txdb_callback().set("serial_mixer", FUNC(rs232_port_device::write_txd));

	// PIO callbacks
	m_subcpu->in_pa_callback().set(FUNC(pve500_state::eeprom_r));
	m_subcpu->out_pa_callback().set(FUNC(pve500_state::eeprom_w));

	// ICG3: I/O Expander
	CXD1095(config, m_cxdio, 0);
	m_cxdio->out_porta_cb().set(FUNC(pve500_state::io_sc_w));
	m_cxdio->out_portb_cb().set(FUNC(pve500_state::io_le_w));
	m_cxdio->in_portc_cb().set(FUNC(pve500_state::io_ky_r));
	m_cxdio->out_portd_cb().set(FUNC(pve500_state::io_ld_w));
	m_cxdio->out_porte_cb().set(FUNC(pve500_state::io_sel_w));

	/* Search Dial MCUs */
	MB88201(config, "dial_mcu_left", 4_MHz_XTAL).set_disable(); /* PLAYER DIAL MCU */
	MB88201(config, "dial_mcu_right", 4_MHz_XTAL).set_disable(); /* RECORDER DIAL MCU */

	/* Serial EEPROM (128 bytes, 8-bit data organization) */
	/* The EEPROM stores the setup data */
	EEPROM_MSM16911_8BIT(config, "eeprom");

	/* FIX-ME: These are actually RS422 ports (except EDL IN/OUT which is indeed an RS232 port)*/
	rs232_port_device &recorder(RS232_PORT(config, "recorder", default_rs232_devices, nullptr));
	recorder.rxd_handler().set(m_maincpu, FUNC(tmpz84c015_device::rxa_w));

	rs232_port_device &player1(RS232_PORT(config, "player1", default_rs232_devices, nullptr));
	player1.rxd_handler().set(m_maincpu, FUNC(tmpz84c015_device::rxb_w));

	rs232_port_device &player2(RS232_PORT(config, "player2", default_rs232_devices, nullptr));
	player2.rxd_handler().set("external_sio", FUNC(z80dart_device::rxa_w));

	rs232_port_device &edl_inout(RS232_PORT(config, "edl_inout", default_rs232_devices, nullptr));
	edl_inout.rxd_handler().set("external_sio", FUNC(z80dart_device::rxb_w));

	rs232_port_device &switcher(RS232_PORT(config, "switcher", default_rs232_devices, nullptr));
	switcher.rxd_handler().set(m_subcpu, FUNC(tmpz84c015_device::rxa_w));

	rs232_port_device &serial_mixer(RS232_PORT(config, "serial_mixer", default_rs232_devices, nullptr));
	serial_mixer.rxd_handler().set(m_subcpu, FUNC(tmpz84c015_device::rxb_w));

	clock_device &clk1(CLOCK(config, "clk1", 12_MHz_XTAL / 20));
	clk1.signal_handler().set(m_maincpu, FUNC(tmpz84c015_device::rxca_w));
	clk1.signal_handler().append(m_maincpu, FUNC(tmpz84c015_device::txca_w));
	clk1.signal_handler().append(m_maincpu, FUNC(tmpz84c015_device::rxcb_w));
	clk1.signal_handler().append(m_maincpu, FUNC(tmpz84c015_device::txcb_w));
	clk1.signal_handler().append(m_subcpu, FUNC(tmpz84c015_device::rxca_w));
	clk1.signal_handler().append(m_subcpu, FUNC(tmpz84c015_device::txca_w));
	clk1.signal_handler().append(m_subcpu, FUNC(tmpz84c015_device::rxcb_w));
	clk1.signal_handler().append(m_subcpu, FUNC(tmpz84c015_device::txcb_w));

	/* ICF5: 2kbytes of RAM shared between the two CPUs (dual-port RAM)*/
	mb8421_device &mb8421(MB8421(config, "mb8421"));
	mb8421.intl_callback().set(FUNC(pve500_state::mb8421_intl));
	mb8421.intr_callback().set(FUNC(pve500_state::mb8421_intr));

	/* video hardware */
	config.set_default_layout(layout_pve500);

	/* audio hardware */
	SPEAKER(config, "mono").front_center();
	BEEP(config, "buzzer", 12_MHz_XTAL / 3200).add_route(ALL_OUTPUTS, "mono", 0.05); // 3.75 kHz CLK2 coming out of IC D4 (frequency divider circuitry)
}