Exemplo n.º 1
0
  TaskResult Char(const KeyInfo& info) override{
    auto handleKeyPress = [&](){
      m_autoComplete.Forget();
      return handle_key_press(info.key, m_textObject->GetTextBuffer()) ?
        TaskResult::DRAW : TaskResult::NONE;
    };

    if (is_exit_key(info.key)){
      return Commit(info.layerType);
    }
    else if (info.key.Is(key::tab) && m_settings.Get(ts_ParseExpressions)){
      return handle_completion(m_autoComplete, m_textObject->GetTextBuffer()) ?
        TaskResult::DRAW :
        handleKeyPress();
    }

    return handle_command_key(info.key, m_textObject).Visit(
      [&](TextChange& cmd){
        m_autoComplete.Forget();
        // Fixme: Need to support undo
        cmd.Do();
        m_states.Did(cmd);
        return TaskResult::DRAW;
      },
      handleKeyPress);
  }
Exemplo n.º 2
0
        void nfs_client_impl::local_write_callback(error_code err, size_t sz, dsn::ref_ptr<copy_request_ex> reqc)
        {
            //dassert(reqc->local_write_task == task::get_current_task(), "");
            --_concurrent_local_write_count;

            // clear all content to release memory quickly
            reqc->response.file_content = blob();

            continue_write();

            bool completed = false;
            if (err != ERR_OK)
            {
                completed = true;
            }
            else
            {
                zauto_lock l(reqc->file_ctx->user_req->user_req_lock);
                if (++reqc->file_ctx->finished_segments == (int)reqc->file_ctx->copy_requests.size())
                {
                    if (++reqc->file_ctx->user_req->finished_files == (int)reqc->file_ctx->user_req->file_context_map.size())
                    {
                        completed = true;
                    }
                }
            }

            if (completed)
            {   
                handle_completion(reqc->file_ctx->user_req, err);
            }
        }
Exemplo n.º 3
0
        void nfs_client_impl::end_copy(
            ::dsn::error_code err,
            const copy_response& resp,
            void* context)
        {
            //dinfo("*** call RPC_NFS_COPY end, return (%d, %d) with %s", resp.offset, resp.size, err.to_string());

            dsn::ref_ptr<copy_request_ex> reqc;
            reqc = (copy_request_ex*)context;
            reqc->release_ref();

            continue_copy(1);
            
            if (err == ERR_OK)
            {
                err = resp.error;
            }

            if (err != ::dsn::ERR_OK)
            {
                handle_completion(reqc->file_ctx->user_req, err);
                return;
            }
            
            reqc->response = resp;
            reqc->response.error.end_tracking(); // always ERR_OK
            reqc->is_ready_for_write = true;

            auto& fc = reqc->file_ctx;

            // check write availability
            {
                zauto_lock l(fc->user_req->user_req_lock);
                if (fc->current_write_index != reqc->index - 1)
                    return;
            }

            // check readies for local writes
            {
                zauto_lock l(fc->user_req->user_req_lock);
                for (int i = reqc->index; i < (int)(fc->copy_requests.size()); i++)
                {
                    if (fc->copy_requests[i]->is_ready_for_write)
                    {
                        fc->current_write_index++;

                        {
                            zauto_lock l(_local_writes_lock);
                            _local_writes.push(fc->copy_requests[i]);
                        }
                    }
                    else
                        break;
                }
            }

            continue_write();
        }
Exemplo n.º 4
0
static void aio_event(struct iothread *t, void *priv, eventfd_t val)
{
	struct io_event ev[in_flight];
	struct timespec tmo;
	int ret, i;

	memset(&tmo, 0, sizeof(tmo));

	dprintf("aio_event ready, %"PRIu64"/%u in flight\n", val, in_flight);

	ret = io_getevents(aio_ctx, 1, in_flight, ev, &tmo);
	if ( ret < 0 ) {
		fprintf(stderr, "io_getevents: %s\n", os_err());
		return;
	}

	for(i = 0; i < ret; i++)
		handle_completion(t, ev[i].obj, ev[i].data, ev[i].res);
}
Exemplo n.º 5
0
void ts::scene::Loading_sequence::load_scripts_if_ready()
{
    if (scene_loader_.finished() && audio_loader_.finished())
    {
        try
        {
            loaded_scene_.action_scene = scene_loader_.transfer_result();
            loaded_scene_.sound_controller = audio_loader_.transfer_result();

            auto callback = [this]()
            {
                handle_completion();
            };

            script_loader_.async_load_scripts(stage_->stage_data().script_resources, callback);
        }

        catch (...)
        {
            exception_ptr_ = std::current_exception();            
        }
    }
}
Exemplo n.º 6
0
        void nfs_client_impl::continue_write()
        {
            // check write quota
            if (++_concurrent_local_write_count > _opts.max_concurrent_local_writes)
            {
                --_concurrent_local_write_count;
                return;
            }

            // get write
            dsn::ref_ptr<copy_request_ex> reqc;
            while (true)
            {
                {
                    zauto_lock l(_local_writes_lock);
                    if (!_local_writes.empty())
                    {
                        reqc = _local_writes.front();
                        _local_writes.pop();
                    }
                    else
                    {
                        reqc = nullptr;
                        break;
                    }   
                }

                {
                    zauto_lock l(reqc->lock);
                    if (reqc->is_valid)
                        break;
                }
            }

            if (nullptr == reqc)
            {
                --_concurrent_local_write_count;
                return;
            }   

            // real write
            std::string file_path = dsn::utils::filesystem::path_combine(reqc->copy_req.dst_dir, reqc->file_ctx->file_name);
            std::string path = dsn::utils::filesystem::remove_file_name(file_path.c_str());
            if (!dsn::utils::filesystem::create_directory(path))
            {
                dassert(false, "Fail to create directory %s.", path.c_str());
            }

            dsn_handle_t hfile = reqc->file_ctx->file.load();
            if (!hfile)
            {
                zauto_lock l(reqc->file_ctx->user_req->user_req_lock);
                hfile = reqc->file_ctx->file.load();
                if (!hfile)
                {
                    hfile = dsn_file_open(file_path.c_str(), O_RDWR | O_CREAT | O_BINARY, 0666);
                    reqc->file_ctx->file = hfile;
                }
            }

            if (!hfile)
            {
                derror("file open %s failed", file_path.c_str());
                error_code err = ERR_FILE_OPERATION_FAILED;
                handle_completion(reqc->file_ctx->user_req, err);
                --_concurrent_local_write_count;
                continue_write();
                return;
            }

            {
                zauto_lock l(reqc->lock);
                auto& reqc_save = *reqc.get();
                reqc_save.local_write_task = file::write(
                    hfile,
                    reqc_save.response.file_content.data(),
                    reqc_save.response.size,
                    reqc_save.response.offset,
                    LPC_NFS_WRITE,
                    this,
                    [this, reqc_cap = std::move(reqc)] (error_code err, int sz)
                    {
                        local_write_callback(err, sz, std::move(reqc_cap));
                    }
                );
            }
        }
Exemplo n.º 7
0
        void nfs_client_impl::continue_write()
        {
            // check write quota
            if (++_concurrent_local_write_count > _opts.max_concurrent_local_writes)
            {
                --_concurrent_local_write_count;
                return;
            }

            // get write
            boost::intrusive_ptr<copy_request_ex> reqc;
            while (true)
            {
                {
                    zauto_lock l(_local_writes_lock);
                    if (!_local_writes.empty())
                    {
                        reqc = _local_writes.front();
                        _local_writes.pop();
                    }
                    else
                    {
                        reqc = nullptr;
                        break;
                    }   
                }

                {
                    zauto_lock l(reqc->lock);
                    if (reqc->is_valid)
                        break;
                }
            }

            if (nullptr == reqc)
            {
                --_concurrent_local_write_count;
                return;
            }   

            // real write
            std::string file_path = reqc->copy_req.dst_dir + reqc->file_ctx->file_name;

            boost::filesystem::path path(file_path); // create directory recursively if necessary
            path = path.remove_filename();
            if (!boost::filesystem::exists(path))
            {
                boost::filesystem::create_directories(path);
            }

            handle_t hfile = reqc->file_ctx->file.load();
            if (!hfile)
            {
                zauto_lock l(reqc->file_ctx->user_req->user_req_lock);
                hfile = reqc->file_ctx->file.load();
                if (!hfile)
                {
                    hfile = file::open(file_path.c_str(), O_RDWR | O_CREAT | O_BINARY, 0666);
                    reqc->file_ctx->file = hfile;
                }
            }

            if (!hfile)
            {
                derror("file open %s failed", file_path.c_str());
                error_code err = ERR_FILE_OPERATION_FAILED;
                handle_completion(reqc->file_ctx->user_req, err);
                --_concurrent_local_write_count;
                continue_write();
                return;
            }

            {
                zauto_lock l(reqc->lock);

                reqc->local_write_task = file::write(
                    hfile,
                    reqc->response.file_content.data(),
                    reqc->response.size,
                    reqc->response.offset,
                    LPC_NFS_WRITE,
                    this,
                    std::bind(
                    &nfs_client_impl::local_write_callback,
                    this,
                    std::placeholders::_1,
                    std::placeholders::_2,
                    reqc
                    ),
                    0);
            }
        }