Пример #1
0
void MessageFolder::openMailbox()
{
    if (QMailStore* store = QMailStore::instance()) {
        if (!mFolder.id().isValid()) {
            QMailFolderKey key(QMailFolderKey::Name,mailbox());
            key &= QMailFolderKey(QMailFolderKey::ParentId,QMailFolderId());
            
            QMailFolderIdList folderIdList = QMailStore::instance()->queryFolders(key);
            if(folderIdList.isEmpty()) {
                // create folder
                QMailFolder newFolder(mailbox());
                if(!QMailStore::instance()->addFolder(&newFolder))
                    qWarning() << "Failed to add folder " << mailbox();
                mFolder = newFolder;
            } else { 
                // load folder
                QMailFolderId folderId = folderIdList.first();
                mFolder = QMailFolder(folderId);
            }

            //set the folder key   
            mParentFolderKey = QMailMessageKey(QMailMessageKey::ParentFolderId,mFolder.id());
        }

        // notify when our content is reported to have changed
        connect(store, SIGNAL(folderContentsModified(QMailFolderIdList)), this, SLOT(folderContentsModified(QMailFolderIdList)));
    } 
}
Пример #2
0
void arena::free_arena () {
    __TBB_ASSERT( !my_num_threads_active, "There are threads in the dying arena" );
    poison_value( my_guard );
    intptr_t drained = 0;
    for ( unsigned i = 1; i <= my_num_slots; ++i )
        drained += mailbox(i).drain();
#if __TBB_TASK_PRIORITY && TBB_USE_ASSERT
    for ( intptr_t i = 0; i < num_priority_levels; ++i )
        __TBB_ASSERT(my_task_stream[i].empty() && my_task_stream[i].drain()==0, "Not all enqueued tasks were executed");
#elif !__TBB_TASK_PRIORITY
    __TBB_ASSERT(my_task_stream.empty() && my_task_stream.drain()==0, "Not all enqueued tasks were executed");
#endif /* !__TBB_TASK_PRIORITY */
#if __TBB_COUNT_TASK_NODES
    my_market->update_task_node_count( -drained );
#endif /* __TBB_COUNT_TASK_NODES */
    my_market->release();
#if __TBB_TASK_GROUP_CONTEXT
    __TBB_ASSERT( my_master_default_ctx, "Master thread never entered the arena?" );
    my_master_default_ctx->~task_group_context();
    NFS_Free(my_master_default_ctx);
#endif /* __TBB_TASK_GROUP_CONTEXT */
#if __TBB_STATISTICS
    for( unsigned i = 0; i < my_num_slots; ++i )
        NFS_Free( my_slots[i].my_counters );
#endif /* __TBB_STATISTICS */
    void* storage  = &mailbox(my_num_slots);
    __TBB_ASSERT( my_num_threads_active == 0, NULL );
    __TBB_ASSERT( my_pool_state == SNAPSHOT_EMPTY || !my_max_num_workers, NULL );
    this->~arena();
#if TBB_USE_ASSERT > 1
    memset( storage, 0, allocation_size(my_max_num_workers) );
#endif /* TBB_USE_ASSERT */
    NFS_Free( storage );
}
Пример #3
0
arena::arena ( market& m, unsigned max_num_workers ) {
    __TBB_ASSERT( !my_guard, "improperly allocated arena?" );
    __TBB_ASSERT( sizeof(slot[0]) % NFS_GetLineSize()==0, "arena::slot size not multiple of cache line size" );
    __TBB_ASSERT( (uintptr_t)this % NFS_GetLineSize()==0, "arena misaligned" );
    my_market = &m;
    my_limit = 1;
    // Two slots are mandatory: for the master, and for 1 worker (required to support starvation resistant tasks).
    my_num_slots = max(2u, max_num_workers + 1);
    my_max_num_workers = max_num_workers;
    my_num_threads_active = 1; // accounts for the master
    __TBB_ASSERT ( my_max_num_workers < my_num_slots, NULL );
    // Construct mailboxes. Mark internal synchronization elements for the tools.
    for( unsigned i = 0; i < my_num_slots; ++i ) {
        __TBB_ASSERT( !slot[i].my_scheduler && !slot[i].task_pool, NULL );
        ITT_SYNC_CREATE(slot + i, SyncType_Scheduler, SyncObj_WorkerTaskPool);
        mailbox(i+1).construct();
        ITT_SYNC_CREATE(&mailbox(i+1), SyncType_Scheduler, SyncObj_Mailbox);
#if __TBB_STATISTICS
        slot[i].my_counters = new ( NFS_Allocate(sizeof(statistics_counters), 1, NULL) ) statistics_counters;
#endif /* __TBB_STATISTICS */
    }
    my_task_stream.initialize(my_num_slots);
    ITT_SYNC_CREATE(&my_task_stream, SyncType_Scheduler, SyncObj_TaskStream);
    my_mandatory_concurrency = false;
#if __TBB_TASK_GROUP_CONTEXT
    my_master_default_ctx = NULL;
#endif
}
Пример #4
0
int main(int argc, char *argv[])
{
	const int port = 8888;

	QApplication app(argc, argv);
	app.setApplicationName("TrikServer");
	trikKernel::ApplicationInitHelper initHelper(app);

	if (!initHelper.parseCommandLine()) {
		return 0;
	}

	initHelper.init();

	QLOG_INFO() << "TrikServer started on port" << port;
	qDebug() << "Running TrikServer on port" << port;

	QScopedPointer<trikControl::BrickInterface> brick(trikControl::BrickFactory::create(
			initHelper.configPath(), trikKernel::Paths::mediaPath()));

	trikKernel::Configurer configurer(
			initHelper.configPath() + "/system-config.xml"
			, initHelper.configPath() + "/model-config.xml"
			);

	QScopedPointer<trikNetwork::MailboxInterface> mailbox(trikNetwork::MailboxFactory::create(configurer));

	trikCommunicator::TrikCommunicator communicator(*brick, mailbox.data());
	communicator.startServer(port);

	return app.exec();
}
Пример #5
0
void arena::free_arena () {
    // Drain mailboxes
    // TODO: each scheduler should plug-and-drain its own mailbox when it terminates.
    intptr_t drain_count = 0;
    for( unsigned i=1; i<=prefix().number_of_slots; ++i )
        drain_count += mailbox(i).drain();
#if __TBB_COUNT_TASK_NODES
    prefix().task_node_count -= drain_count;
    if( prefix().task_node_count ) {
        runtime_warning( "Leaked %ld task objects\n", long(prefix().task_node_count) );
    }
#endif /* __TBB_COUNT_TASK_NODES */
    void* storage  = &mailbox(prefix().number_of_slots);
    delete[] prefix().worker_list;
    prefix().~ArenaPrefix();
    NFS_Free( storage );
}
Пример #6
0
Файл: delete.cpp Проект: aox/aox
void Delete::parse()
{
    space();
    d->m = mailbox();
    end();
    if ( ok() )
        log( "Delete mailbox: " + d->m->name().ascii() );
}
Пример #7
0
MailboxPtr MailboxRepository::select(const Mailbox& obj)
{
	soci::row row;
	MailboxPtr mailbox(new Mailbox);
	dataBase << "SELECT  mailbox.username as Mailbox_username, mailbox.password as Mailbox_password, mailbox.name as Mailbox_name, mailbox.home as Mailbox_home, mailbox.maildir as Mailbox_maildir, mailbox.quota as Mailbox_quota, mailbox.domain as Mailbox_domain, mailbox.create_date as Mailbox_create_date, mailbox.change_date as Mailbox_change_date, mailbox.active as Mailbox_active, mailbox.passwd_expire as Mailbox_passwd_expire, mailbox.uid as Mailbox_uid, mailbox.gid as Mailbox_gid, mailbox.id_mentor as Mailbox_id_mentor, mailbox.tipo_conta as Mailbox_tipo_conta, mailbox.assina as Mailbox_assina, mailbox.matricula as Mailbox_matricula"
	" FROM mailbox "
	"WHERE mailbox.username = :Mailbox_username", into(row), use(obj);
	if(!dataBase.got_data())
		mailbox.reset();
	else
		type_conversion<Mailbox>::from_base(row, i_ok, *mailbox);
	return mailbox;
}
Пример #8
0
void abstract_broker::launch(execution_unit* eu, bool is_lazy, bool is_hidden) {
  CAF_ASSERT(eu != nullptr);
  CAF_ASSERT(eu == &backend());
  // add implicit reference count held by middleman/multiplexer
  if (!is_hidden)
    register_at_system();
  CAF_PUSH_AID(id());
  CAF_LOG_TRACE("init and launch broker:" << CAF_ARG(id()));
  if (is_lazy && mailbox().try_block())
    return;
  intrusive_ptr_add_ref(ctrl());
  eu->exec_later(this);
}
Пример #9
0
MailboxList MailboxRepository::select(const string& where)
{
	soci::rowset<row> rs = 	dataBase.prepare << "SELECT  mailbox.username as Mailbox_username, mailbox.password as Mailbox_password, mailbox.name as Mailbox_name, mailbox.home as Mailbox_home, mailbox.maildir as Mailbox_maildir, mailbox.quota as Mailbox_quota, mailbox.domain as Mailbox_domain, mailbox.create_date as Mailbox_create_date, mailbox.change_date as Mailbox_change_date, mailbox.active as Mailbox_active, mailbox.passwd_expire as Mailbox_passwd_expire, mailbox.uid as Mailbox_uid, mailbox.gid as Mailbox_gid, mailbox.id_mentor as Mailbox_id_mentor, mailbox.tipo_conta as Mailbox_tipo_conta, mailbox.assina as Mailbox_assina, mailbox.matricula as Mailbox_matricula "
	" FROM mailbox" 
	<< (where.size()?" WHERE "+where:"");
	MailboxList mailboxList;
	for(row& r: rs)
	{
		MailboxPtr mailbox(new Mailbox);
		type_conversion<Mailbox>::from_base(r, i_ok, *mailbox);
		mailboxList.push_back(mailbox);
	}
	return mailboxList;
}
Пример #10
0
void arena::free_arena () {
    __TBB_ASSERT( !my_num_threads_active, "There are threads in the dying arena" );
    poison_value( my_guard );
    intptr_t drained = 0;
    for ( unsigned i = 1; i <= my_num_slots; ++i )
        drained += mailbox(i).drain();
    __TBB_ASSERT(my_task_stream.empty() && my_task_stream.drain()==0, "Not all enqueued tasks were executed");
#if __TBB_COUNT_TASK_NODES
    my_market->update_task_node_count( -drained );
#endif /* __TBB_COUNT_TASK_NODES */
    my_market->release();
#if __TBB_TASK_GROUP_CONTEXT
    __TBB_ASSERT( my_master_default_ctx, "Master thread never entered the arena?" );
    my_master_default_ctx->~task_group_context();
    NFS_Free(my_master_default_ctx);
#endif /* __TBB_TASK_GROUP_CONTEXT */
#if __TBB_STATISTICS
    for( unsigned i = 0; i < my_num_slots; ++i )
        NFS_Free( slot[i].my_counters );
#endif /* __TBB_STATISTICS */
    void* storage  = &mailbox(my_num_slots);
    this->~arena();
    NFS_Free( storage );
}
Пример #11
0
MailBox Accounts::makeMailBox_(TiXmlElement const * mailBoxXML) {
    std::string login = mailBoxXML->Attribute("login");
    std::string password = mailBoxXML->Attribute("password");
    std::string server = mailBoxXML->Attribute("server");
    
    std::vector<std::string> ignoredMailBox;
    ignoredMailBox.push_back("Spam");
    ignoredMailBox.push_back("Trash");
    ignoredMailBox.push_back("Sent");

    MailBoxSetting mailBoxSetting(login, password, server, ignoredMailBox);
    
    MailBox mailbox(mailBoxSetting);
    return mailbox;
}
Пример #12
0
Файл: status.cpp Проект: aox/aox
void Status::parse()
{
    space();
    d->mailbox = mailbox();
    space();
    require( "(" );

    EString l( "Status " );
    if ( d->mailbox ) {
        l.append(  d->mailbox->name().ascii() );
        l.append( ":" );
    }
    bool atEnd = false;
    while ( !atEnd ) {
        EString item = letters( 1, 13 ).lower();
        l.append( " " );
        l.append( item );

        if ( item == "messages" )
            d->messages = true;
        else if ( item == "recent" )
            d->recent = true;
        else if ( item == "uidnext" )
            d->uidnext = true;
        else if ( item == "uidvalidity" )
            d->uidvalidity = true;
        else if ( item == "unseen" )
            d->unseen = true;
        else if ( item == "highestmodseq" )
            d->modseq = true;
        else
            error( Bad, "Unknown STATUS item: " + item );

        if ( nextChar() == ' ' )
            space();
        else
            atEnd = true;
    }

    require( ")" );
    end();
    if ( !ok() )
        return;

    log( l );
    requireRight( d->mailbox, Permissions::Read );
}
Пример #13
0
void Builder<TaskTraits, Entity, MailboxType>::run_(Args&&... args) {
    using Traits = TraitsFor<Args...>;
    assert(!invalidated);
    invalidated = true;

    FiberSystem* system = Scheduler::current()->system();
    if (!system->shuttingDown()) {
        /**
         * Create and schedule the task
         */
        Path path = PrefixedPath(system->uuid(), ident());
        std::unique_ptr<Mailbox> mailbox(new MailboxType(std::move(mailbox_)));
        auto task = Traits::newTask(std::move(path), std::move(mailbox), pin_,
            detail::bind<Entity, Args...>(std::move(task_), std::forward<Args>(args)...));
        runner_(task);
    }
}
Пример #14
0
IMAP_RESULTS DeleteHandler::execute(void) {
    IMAP_RESULTS result = IMAP_MBOX_ERROR;
    // SYZYGY -- check to make sure that the argument list has just the one argument
    // SYZYGY -- parsingAt should point to '\0'
    std::string mailbox(m_parseBuffer->arguments());
    switch (m_session->mboxErrorCode(m_session->store()->deleteMailbox(mailbox))) {
    case MailStore::SUCCESS:
	result = IMAP_OK;
	break;

    case MailStore::CANNOT_COMPLETE_ACTION:
	result = IMAP_TRY_AGAIN;
	break;

    default:
	break;
    }
    return result;
}
Пример #15
0
void
GMApp::OpenMailbox
	(
	const JCharacter*	filename,
	const JBoolean		beep,
	const JBoolean		iconify
	)
{
	if (JDirectoryExists(filename))
		{
		const JCharacter* map[] =
			{
			"dir", filename
			};
		const JString msg = JGetString("NameIsDirectoryNotFile::GMApp", map, sizeof(map));
		JGetUserNotification()->ReportError(msg);
		return;
		}
		
	if (MailboxOpen(filename, !iconify))
		{
		return;
		}

	JString mailbox(filename);
	JBoolean locked = FileLocked(mailbox, kJFalse);
	GMessageTableDir* dir;

	if (!locked)
		{
		if (GLockFile(mailbox) && GMessageTableDir::Create(this, mailbox, &dir, iconify))
			{
			itsTableDirs->Append(dir);
			GUnlockFile(mailbox);
			Broadcast(MailboxOpened(mailbox));
			if (beep && GGetPrefsMgr()->IsBeepingOnNewMail())
				{
				GetCurrentDisplay()->Beep();
				}
			}
		}
}
Пример #16
0
void Search::saveSettings(QSettings *config)
{
    config->setValue("mailbox", mailbox() );
    config->setValue("name", name() );
    config->setValue("from", getFrom() );
    config->setValue("to", getTo() );
    config->setValue("subject", getSubject() );
    config->setValue("body", getBody() );
    config->setValue("status", status() );
    if ( !getBeforeDate().isNull() ) {
        config->setValue("datebefore", getBeforeDate().toString() );
    } else {
        config->setValue("datebefore", "" );
    }
    if ( !getAfterDate().isNull() ) {
        config->setValue("dateafter", getAfterDate().toString() );
    } else {
        config->setValue("dateafter", "" );
    }
}
void NmFwaStoreEnvelopesOperation::doRunAsyncOperation()
{
    NM_FUNCTION;
    
    const TFSMailMsgId mailboxId(mMailboxId.pluginId32(), mMailboxId.id32());
    CFSMailBox *mailbox(NULL);
    TRAP_IGNORE( mailbox = mMailClient.GetMailBoxByUidL(mailboxId) );
    // no possibility to leave; no need for CleanupStack
    if ( mailbox && mMessages.Count() ) {
        TRAPD(err, mRequestId = mailbox->UpdateMessageFlagsL( mailboxId, mMessages, *this ));
        if (err != KErrNone) {
            completeOperation(NmGeneralError);
        }
    }
    else {
        completeOperation(NmNotFoundError);
    }
    // cleanup
    if (mailbox) {
        delete mailbox;
        mailbox = NULL;
    }
}
Пример #18
0
void Select::parse()
{
    space();
    d->mailbox = mailbox();
    if ( present( " (" ) ) {
        bool more = true;
        while ( ok() && more ) {
            // select-param can be a list or an astring. in our case,
            // only astring is legal, since we advertise no extension
            // that permits the list.
            EString param = astring().lower();
            if ( param == "annotate" )
                d->annotate = true;
            else if ( param == "condstore" )
                d->condstore = true;
            else
                error( Bad, "Unknown select-param: " + param );
            more = present( " " );
        }
        require( ")" );
    }
    end();
}
Пример #19
0
void MessageFolder::externalChange()
{
    emit externalEdit( mailbox() );
}
Пример #20
0
int main(int argc, char *argv[])
{
	qsrand(QDateTime::currentMSecsSinceEpoch());
	QApplication app(argc, argv);
	QStringList args = app.arguments();

	if (args.count() < 2) {
		printUsage();
		return 1;
	}

	QString configPath = "./";
	if (app.arguments().contains("-c")) {
		const int index = app.arguments().indexOf("-c");
		if (app.arguments().count() <= index + 1) {
			printUsage();
			return 1;
		}

		configPath = app.arguments()[index + 1];
		if (configPath.right(1) != "/") {
			configPath += "/";
		}
	}

	QString startDirPath = QDir::currentPath();
	if (app.arguments().contains("-d")) {
		const int index = app.arguments().indexOf("-d");
		if (app.arguments().count() <= index + 1) {
			printUsage();
			return 1;
		}

		startDirPath = app.arguments()[index + 1];
	}

	if (startDirPath.right(1) != "/") {
		startDirPath += "/";
	}

	trikKernel::coreDumping::initCoreDumping(startDirPath);

#ifdef Q_WS_QWS
	QWSServer * const server = QWSServer::instance();
	if (server) {
		server->setCursorVisible(false);
	}
#endif

	trikKernel::LoggingHelper loggingHelper(startDirPath);
	Q_UNUSED(loggingHelper);

	QLOG_INFO() << "TrikRun started";

	QScopedPointer<trikControl::BrickInterface> brick(trikControl::BrickFactory::create(configPath, startDirPath));

	trikKernel::Configurer configurer(configPath + "/system-config.xml", configPath + "/model-config.xml");
	QScopedPointer<trikNetwork::GamepadInterface> gamepad(trikNetwork::GamepadFactory::create(configurer));
	QScopedPointer<trikNetwork::MailboxInterface> mailbox(trikNetwork::MailboxFactory::create(configurer));
	trikScriptRunner::TrikScriptRunner runner(*brick, mailbox.data(), gamepad.data(), startDirPath);

	QObject::connect(&runner, SIGNAL(completed(QString, int)), &app, SLOT(quit()));

	if (app.arguments().contains("-s")) {
		runner.run(args[app.arguments().indexOf("-s") + 1]);
	} else {
		args.removeAll("-qws");
		if (args.contains("-c")) {
			args.removeAt(args.indexOf("-c") + 1);
			args.removeAll("-c");
		}

		if (args.contains("-d")) {
			args.removeAt(args.indexOf("-d") + 1);
			args.removeAll("-d");
		}

		if (args.count() != 2) {
			printUsage();
			return 1;
		}

		runner.run(trikKernel::FileUtils::readFromFile(args[1]));
	}

	return app.exec();
}
Пример #21
0
IMAP_RESULTS AppendHandler::receiveData(INPUT_DATA_STRUCT &input) {
    IMAP_RESULTS result = IMAP_OK;

    switch (m_parseStage) {
    case 0:
	switch (m_parseBuffer->astring(input, false, NULL)) {
	case ImapStringGood:
	    m_parseStage = 2;
	    result = execute(input);
	    break;

	case ImapStringBad:
	    m_session->responseText("Malformed Command");
	    result = IMAP_BAD;
	    break;

	case ImapStringPending:
	    result = IMAP_NOTDONE;
	    m_parseStage = 1;
	    break;

	default:
	    m_session->responseText("Failed -- internal error");
	    result = IMAP_NO;
	    break;
	}
	break;

    case 1:
	// It's the mailbox name that's arrived
    {
	size_t dataUsed = m_parseBuffer->addLiteralToParseBuffer(input);
	if (0 == m_parseBuffer->literalLength()) {
	    m_parseStage = 2;
	    if (2 < (input.dataLen - dataUsed)) {
		// Get rid of the CRLF if I have it
		input.dataLen -= 2;
		input.data[input.dataLen] = '\0';  // Make sure it's terminated so strchr et al work
	    }
	    result = execute(input);
	}
	else {
	    result = IMAP_IN_LITERAL;
	}
    }
    break;

    case 2:
    {
	result = execute(input);
    }
    break;

    case 3:
    {
	size_t residue;
	// It's the message body that's arrived
	size_t len = MIN(m_parseBuffer->literalLength(), input.dataLen);
	if (m_parseBuffer->literalLength() > input.dataLen) {
	    result = IMAP_IN_LITERAL;
	    residue = m_parseBuffer->literalLength() - input.dataLen;
	}
	else {
	    residue = 0;
	}
	m_parseBuffer->literalLength(residue);
	std::string mailbox(m_parseBuffer->arguments());
	switch (m_store->appendDataToMessage(mailbox, m_appendingUid, input.data, len)) {
	case MailStore::SUCCESS:
	    if (0 == m_parseBuffer->literalLength()) {
		m_parseStage = 4;
		switch(m_store->doneAppendingDataToMessage(mailbox, m_appendingUid)) {
		case MailStore::SUCCESS:
		    if (MailStore::SUCCESS == m_store->unlock(m_tempMailboxName)) {
			result = IMAP_OK;
		    }
		    else {
			m_store->deleteMessage(mailbox, m_appendingUid);
			result = IMAP_MBOX_ERROR;
		    }
		    m_appendingUid = 0;
		    result = IMAP_OK;
		    break;

		case MailStore::CANNOT_COMPLETE_ACTION:
		    result = IMAP_TRY_AGAIN;
		    break;

		default:
		    m_store->deleteMessage(mailbox, m_appendingUid);
		    m_appendingUid = 0;
		    result = IMAP_MBOX_ERROR;
		}
	    }
	    break;

	case MailStore::CANNOT_COMPLETE_ACTION:
	    result = IMAP_TRY_AGAIN;
	    break;

	default:
	    m_store->doneAppendingDataToMessage(mailbox, m_appendingUid);
	    m_store->deleteMessage(mailbox, m_appendingUid);
	    m_store->unlock(m_tempMailboxName);
	    result = IMAP_MBOX_ERROR;
	    m_appendingUid = 0;
	    m_parseBuffer->literalLength(0);
	    break;
	}
    }
    break;

    case 4:
	// I've got the last of the data, and I'm retrying the done appending code
    {
	std::string mailbox(m_parseBuffer->arguments());
	switch(m_store->doneAppendingDataToMessage(mailbox, m_appendingUid)) {
	case MailStore::SUCCESS:
	    if (MailStore::SUCCESS == m_store->unlock(m_tempMailboxName)) {
		result = IMAP_OK;
	    }
	    else {
		m_store->deleteMessage(mailbox, m_appendingUid);
		result = IMAP_MBOX_ERROR;
	    }
	    m_appendingUid = 0;
	    break;

	case MailStore::CANNOT_COMPLETE_ACTION:
	    result = IMAP_TRY_AGAIN;
	    break;

	default:
	    m_store->deleteMessage(mailbox, m_appendingUid);
	    m_appendingUid = 0;
	    result = IMAP_MBOX_ERROR;
	}
	m_tempMailboxName = "";
    }
    break;

    default:
	m_session->responseText("Failed -- internal error");
	result = IMAP_NO;
	break;
    }
    return result;
}
 resumable::resume_result resume(execution_unit* new_host,
                                 size_t max_throughput) override {
   CAF_REQUIRE(max_throughput > 0);
   auto d = static_cast<Derived*>(this);
   CAF_LOG_TRACE("id = " << d->id());
   d->host(new_host);
   auto done_cb = [&]() -> bool {
     CAF_LOG_TRACE("");
     d->bhvr_stack().clear();
     d->bhvr_stack().cleanup();
     d->on_exit();
     if (!d->bhvr_stack().empty()) {
       CAF_LOG_DEBUG("on_exit did set a new behavior");
       d->planned_exit_reason(exit_reason::not_exited);
       return false; // on_exit did set a new behavior
     }
     auto rsn = d->planned_exit_reason();
     if (rsn == exit_reason::not_exited) {
       rsn = exit_reason::normal;
       d->planned_exit_reason(rsn);
     }
     d->cleanup(rsn);
     return true;
   };
   auto actor_done = [&]() -> bool {
     if (d->bhvr_stack().empty()
         || d->planned_exit_reason() != exit_reason::not_exited) {
       return done_cb();
     }
     return false;
   };
   // actors without behavior or that have already defined
   // an exit reason must not be resumed
   CAF_REQUIRE(!d->is_initialized()
               || (!d->bhvr_stack().empty()
                   && d->planned_exit_reason() == exit_reason::not_exited));
   std::exception_ptr eptr = nullptr;
   try {
     if (!d->is_initialized()) {
       CAF_LOG_DEBUG("initialize actor");
       d->is_initialized(true);
       auto bhvr = d->make_behavior();
       CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior, "
                               << "bhvr_stack().empty() = "
                               << std::boolalpha << d->bhvr_stack().empty());
       if (bhvr) {
         // make_behavior() did return a behavior instead of using become()
         CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
         d->become(std::move(bhvr));
       }
       if (actor_done()) {
         CAF_LOG_DEBUG("actor_done() returned true right "
                       << "after make_behavior()");
         return resume_result::done;
       }
     }
     // max_throughput = 0 means infinite
     for (size_t i = 0; i < max_throughput; ++i) {
       auto ptr = d->next_message();
       if (ptr) {
         if (d->invoke_message(ptr)) {
           if (actor_done()) {
             CAF_LOG_DEBUG("actor exited");
             return resume_result::done;
           }
           // continue from cache if current message was
           // handled, because the actor might have changed
           // its behavior to match 'old' messages now
           while (d->invoke_message_from_cache()) {
             if (actor_done()) {
               CAF_LOG_DEBUG("actor exited");
               return resume_result::done;
             }
           }
         }
         // add ptr to cache if invoke_message
         // did not reset it (i.e. skipped, but not dropped)
         if (ptr) {
           CAF_LOG_DEBUG("add message to cache");
           d->push_to_cache(std::move(ptr));
         }
       } else {
         CAF_LOG_DEBUG("no more element in mailbox; going to block");
         if (d->mailbox().try_block()) {
           return resumable::awaiting_message;
         }
         CAF_LOG_DEBUG("try_block() interrupted by new message");
       }
     }
     if (!d->has_next_message() && d->mailbox().try_block()) {
       return resumable::awaiting_message;
     }
     // time's up
     return resumable::resume_later;
   }
   catch (actor_exited& what) {
     CAF_LOG_INFO("actor died because of exception: actor_exited, "
                  "reason = " << what.reason());
     if (d->exit_reason() == exit_reason::not_exited) {
       d->quit(what.reason());
     }
   }
   catch (std::exception& e) {
     CAF_LOG_INFO("actor died because of an exception: "
                  << detail::demangle(typeid(e))
                  << ", what() = " << e.what());
     if (d->exit_reason() == exit_reason::not_exited) {
       d->quit(exit_reason::unhandled_exception);
     }
     eptr = std::current_exception();
   }
   catch (...) {
     CAF_LOG_INFO("actor died because of an unknown exception");
     if (d->exit_reason() == exit_reason::not_exited) {
       d->quit(exit_reason::unhandled_exception);
     }
     eptr = std::current_exception();
   }
   if (eptr) {
     auto opt_reason = d->handle(eptr);
     if (opt_reason) {
       // use exit reason defined by custom handler
       d->planned_exit_reason(*opt_reason);
     }
   }
   if (!actor_done()) {
     // actor has been "revived", try running it again later
     return resumable::resume_later;
   }
   return resumable::done;
 }
Пример #23
0
 resumable::resume_result resume(detail::cs_thread*,
                                 execution_unit* host) override {
     auto d = static_cast<Derived*>(this);
     d->m_host = host;
     CPPA_LOG_TRACE("id = " << d->id());
     auto done_cb = [&]() -> bool {
         CPPA_LOG_TRACE("");
         d->bhvr_stack().clear();
         d->bhvr_stack().cleanup();
         d->on_exit();
         if (!d->bhvr_stack().empty()) {
             CPPA_LOG_DEBUG("on_exit did set a new behavior in on_exit");
             d->planned_exit_reason(exit_reason::not_exited);
             return false; // on_exit did set a new behavior
         }
         auto rsn = d->planned_exit_reason();
         if (rsn == exit_reason::not_exited) {
             rsn = exit_reason::normal;
             d->planned_exit_reason(rsn);
         }
         d->cleanup(rsn);
         return true;
     };
     auto actor_done = [&] {
         return    d->bhvr_stack().empty()
                || d->planned_exit_reason() != exit_reason::not_exited;
     };
     // actors without behavior or that have already defined
     // an exit reason must not be resumed
     CPPA_REQUIRE(!d->m_initialized || !actor_done());
     if (!d->m_initialized) {
         d->m_initialized = true;
         auto bhvr = d->make_behavior();
         if (bhvr) d->become(std::move(bhvr));
         // else: make_behavior() might have just called become()
         if (actor_done() && done_cb()) return resume_result::done;
         // else: enter resume loop
     }
     try {
         for (;;) {
             auto ptr = d->next_message();
             if (ptr) {
                 if (d->invoke_message(ptr)) {
                     if (actor_done() && done_cb()) {
                         CPPA_LOG_DEBUG("actor exited");
                         return resume_result::done;
                     }
                     // continue from cache if current message was
                     // handled, because the actor might have changed
                     // its behavior to match 'old' messages now
                     while (d->invoke_message_from_cache()) {
                         if (actor_done() && done_cb()) {
                             CPPA_LOG_DEBUG("actor exited");
                             return resume_result::done;
                         }
                     }
                 }
                 // add ptr to cache if invoke_message
                 // did not reset it (i.e. skipped, but not dropped)
                 if (ptr) {
                     CPPA_LOG_DEBUG("add message to cache");
                     d->push_to_cache(std::move(ptr));
                 }
             }
             else {
                 CPPA_LOG_DEBUG("no more element in mailbox; "
                                "going to block");
                 if (d->mailbox().try_block()) {
                     return resumable::resume_later;
                 }
                 // else: try again
             }
         }
     }
     catch (actor_exited& what) {
         CPPA_LOG_INFO("actor died because of exception: actor_exited, "
                       "reason = " << what.reason());
         if (d->exit_reason() == exit_reason::not_exited) {
             d->quit(what.reason());
         }
     }
     catch (std::exception& e) {
         CPPA_LOG_WARNING("actor died because of exception: "
                          << detail::demangle(typeid(e))
                          << ", what() = " << e.what());
         if (d->exit_reason() == exit_reason::not_exited) {
             d->quit(exit_reason::unhandled_exception);
         }
     }
     catch (...) {
         CPPA_LOG_WARNING("actor died because of an unknown exception");
         if (d->exit_reason() == exit_reason::not_exited) {
             d->quit(exit_reason::unhandled_exception);
         }
     }
     done_cb();
     return resumable::done;
 }
Пример #24
0
QSoftMenuBar::StandardLabel Folder::menuLabel() const
{
    if (mailbox() == MailboxList::DraftsString)
        return QSoftMenuBar::Edit;
    return QSoftMenuBar::View;
}
Пример #25
0
bool Recipient::operator <=( const Recipient &b )
{
    if ( mailbox() && b.mailbox() )
        return mailbox()->id() <= b.mailbox()->id();
    return false;
}
Пример #26
0
nfsreadlinkres *
nfsproc_readlink_2_svc(am_nfs_fh *argp, struct svc_req *rqstp)
{
  static nfsreadlinkres res;
  uid_t userid = (uid_t) INVALIDID;
  gid_t groupid = hlfs_gid + 1;	/* anything not hlfs_gid */
  int retval = 0;
  char *path_val = NULL;
  char *username;
  static uid_t last_uid = (uid_t) INVALIDID;

  if (eq_fh(argp, &root)) {
    res.rlr_status = NFSERR_ISDIR;
  } else if (eq_fh(argp, &slink)) {
    if (getcreds(rqstp, &userid, &groupid, nfsxprt) < 0)
      return (nfsreadlinkres *) NULL;

    clocktime(&slinkfattr.na_atime);

    res.rlr_status = NFS_OK;
    if (groupid == hlfs_gid) {
      res.rlr_u.rlr_data_u = DOTSTRING;
    } else if (!(res.rlr_u.rlr_data_u = path_val = homedir(userid, groupid))) {
      /*
       * parent process (fork in homedir()) continues
       * processing, by getting a NULL returned as a
       * "special".  Child returns result.
       */
      return NULL;
    }

  } else {			/* check if asked for user mailbox */

    if (getcreds(rqstp, &userid, &groupid, nfsxprt) < 0) {
      return (nfsreadlinkres *) NULL;
    }

    if (groupid == hlfs_gid) {
      u_int xuserid;
      memcpy(&xuserid, argp->fh_data, sizeof(xuserid));
      userid = xuserid;
      username = (char *) &argp->fh_data[sizeof(xuserid)];
      if (!(res.rlr_u.rlr_data_u = mailbox(userid, username)))
	return (nfsreadlinkres *) NULL;
    } else {
      res.rlr_status = NFSERR_STALE;
    }
  }

  /* print info, but try to avoid repetitions */
  if (userid != last_uid) {
    plog(XLOG_USER, "mailbox for uid=%ld, gid=%ld is %s",
	 (long) userid, (long) groupid, (char *) res.rlr_u.rlr_data_u);
    last_uid = userid;
  }

  /* I don't think it will pass this if -D fork */
  if (serverpid == getpid())
    return &res;

  if (!svc_sendreply(nfsxprt, (XDRPROC_T_TYPE) xdr_readlinkres, (SVC_IN_ARG_TYPE) &res))
    svcerr_systemerr(nfsxprt);

  /*
   * Child exists here.   We need to determine which
   * exist status to return.  The exit status
   * is gathered using wait() and determines
   * if we returned $HOME/.hlfsspool or $ALTDIR.  The parent
   * needs this info so it can update the lookup table.
   */
  if (path_val && alt_spooldir && STREQ(path_val, alt_spooldir))
    retval = 1;		/* could not get real home dir (or uid 0 user) */
  else
    retval = 0;

  /*
   * If asked for -D nofork, then must return the value,
   * NOT exit, or else the main hlfsd server exits.
   * If -D fork (default), then we do want to exit from the process.
   * Bug: where is that status information being collected?
   */
  if (amuDebug(D_FORK))
    exit(retval);
  else
    return &res;
}
Пример #27
0
int main(int argc, char *argv[])
{
	QStringList params;
	for (int i = 1; i < argc; ++i) {
		params << QString(argv[i]);
	}

	QScopedPointer<QCoreApplication> app;

	if (params.contains("--no-display") || params.contains("-no-display")) {
		app.reset(new QCoreApplication(argc, argv));
	} else {
		app.reset(new QApplication(argc, argv));
	}

	app->setApplicationName("TrikRun");

	// RAII-style code to ensure that after brick gets destroyed there will be an event loop that cleans it up.
	trikKernel::DeinitializationHelper helper;
	Q_UNUSED(helper);

	trikKernel::ApplicationInitHelper initHelper(*app);

	initHelper.commandLineParser().addPositionalArgument("file", QObject::tr("File with script to execute")
			+ " " + QObject::tr("(optional of -js or -py option is specified)"));

	initHelper.commandLineParser().addOption("js", "js-script"
			, QObject::tr("JavaScript script to be executed directly from command line.") + "\n\t"
							+ QObject::tr("Example:") + " ./trikRun -js \"brick.smile(); script.wait(2000);\"");

	initHelper.commandLineParser().addOption("py", "py-script"
			, QObject::tr("Python script to be executed directly from command line.") + "\n\t"
							+ QObject::tr("Example:") + " ./trikRun -py \""
										  "brick.display().showImage('media/trik_smile_normal.png'); "
										  "script.wait(2000)\"");

	initHelper.commandLineParser().addFlag("no-display", "no-display"
			, QObject::tr("Disable display support. When this flag is active, trikRun can work without QWS or even "
								"physical display"));

	initHelper.commandLineParser().addApplicationDescription(QObject::tr("Runner of JavaScript and Python files."));

	if (!initHelper.parseCommandLine()) {
		return 0;
	}

	initHelper.init();

	QLOG_INFO() << "TrikRun started";

	const auto run = [&](const QString &script, const QString &fileName, trikScriptRunner::ScriptType stype) {
		QScopedPointer<trikControl::BrickInterface> brick(
					trikControl::BrickFactory::create(initHelper.configPath(), trikKernel::Paths::mediaPath())
					);

		trikKernel::Configurer configurer(initHelper.configPath() + "/system-config.xml"
										  , initHelper.configPath() + "/model-config.xml");

		QScopedPointer<trikNetwork::MailboxInterface> mailbox(trikNetwork::MailboxFactory::create(configurer));
		trikScriptRunner::TrikScriptRunner result(*brick, mailbox.data());

		QObject::connect(&result, SIGNAL(completed(QString, int)), app.data(), SLOT(quit()));

		if (fileName.isEmpty()) { // from command line
			result.run(script, stype);
		} else { // from file
			result.run(script, fileName);
		}

		return app->exec();
	};

	if (initHelper.commandLineParser().isSet("js")) {
		return run(initHelper.commandLineParser().value("js"), "", trikScriptRunner::ScriptType::JAVASCRIPT);
	} else if (initHelper.commandLineParser().isSet("py")) {
		return run(initHelper.commandLineParser().value("py"), "", trikScriptRunner::ScriptType::PYTHON);
	} else {
		const QStringList positionalArgs = initHelper.commandLineParser().positionalArgs();
		if (positionalArgs.size() == 1) {
			return run(trikKernel::FileUtils::readFromFile(positionalArgs[0]),
					positionalArgs[0], trikScriptRunner::ScriptType::JAVASCRIPT);
		} else {
			initHelper.commandLineParser().showHelp();
			return 1;
		}
	}
}