Skip to content

Commit

Permalink
add dummy response::check_chancel() API to ipc, stream, and loopback …
Browse files Browse the repository at this point in the history
…responses
  • Loading branch information
t-horikawa committed Feb 23, 2024
1 parent 1d6c8f3 commit e049601
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 1 deletion.
19 changes: 18 additions & 1 deletion include/tateyama/api/server/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ class response {
virtual void session_id(std::size_t id) = 0;

/**
* @brief report error with diagnostics information
* @brief report error with diagnostics information.
* @param record the diagnostic record to report
* @details report an error with diagnostics information for client. When this function is called, no more
* body_head() or body() is expected to be called.
* @attention this function is not thread-safe and should be called from single thread at a time.
* @attention After calling this for cancelling the current job, the job must not use the related resources.
* This includes the below:
*
* - request object
* - response object
* - resources underlying session context
*/
virtual void error(proto::diagnostics::Record const& record) = 0;

Expand Down Expand Up @@ -105,6 +111,17 @@ class response {
*/
virtual status release_channel(data_channel& ch) = 0;

/**
* @brief returns whether or not cancellation was requested to the corresponding job.
* @details To cancel the job, first you must shutdown the operation of this job, and then call error().
* At this time, `OPERATION_CANCELED` is recommended as the diagnostic code for cancelling the job.
* Or, to avoid inappropriate conditions, you can omit the cancel request and complete the job.
* @return true if the job is calling for a cancel
* @return false otherwise
* @see error()
*/
[[nodiscard]] virtual bool check_cancel() const = 0;

};

}
4 changes: 4 additions & 0 deletions src/tateyama/endpoint/ipc/ipc_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class ipc_response : public tateyama::api::server::response {
session_id_ = id;
}

[[nodiscard]] bool check_cancel() const override {
return false;
}

private:
std::shared_ptr<server_wire_container> server_wire_;
std::size_t index_;
Expand Down
7 changes: 7 additions & 0 deletions src/tateyama/endpoint/loopback/loopback_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class loopback_response: public tateyama::api::server::response {
*/
tateyama::status release_channel(tateyama::api::server::data_channel &ch) override;

/**
* @see tateyama::server::response::check_cancel()
*/
[[nodiscard]] bool check_cancel() const override {
return false;
}

// just for unit test
[[nodiscard]] std::map<std::string, std::vector<std::string>, std::less<>> const& all_committed_data() const noexcept {
return committed_data_map_;
Expand Down
5 changes: 5 additions & 0 deletions src/tateyama/endpoint/stream/stream_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class stream_response : public tateyama::api::server::response {
void session_id(std::size_t id) override {
session_id_ = id;
}

[[nodiscard]] bool check_cancel() const override {
return false;
}

private:
std::shared_ptr<stream_socket> stream_;
std::uint16_t index_;
Expand Down
1 change: 1 addition & 0 deletions test/tateyama/datastore/datastore_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class datastore_test :
void error(proto::diagnostics::Record const& record) override {}
status acquire_channel(std::string_view name, std::shared_ptr<api::server::data_channel>& ch) override { return status::ok; }
status release_channel(api::server::data_channel& ch) override { return status::ok; }
bool check_cancel() const override { return false; }

std::size_t session_id_{};
std::string body_{};
Expand Down
1 change: 1 addition & 0 deletions test/tateyama/framework/router_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class router_test :
}
status acquire_channel(std::string_view name, std::shared_ptr<api::server::data_channel>& ch) override { return status::ok; }
status release_channel(api::server::data_channel& ch) override { return status::ok; }
bool check_cancel() const override { return false; }

std::size_t session_id_{};
std::string body_{};
Expand Down
1 change: 1 addition & 0 deletions test/tateyama/session/session_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class session_test :
void error(proto::diagnostics::Record const& record) override {}
status acquire_channel(std::string_view name, std::shared_ptr<api::server::data_channel>& ch) override { return status::ok; }
status release_channel(api::server::data_channel& ch) override { return status::ok; }
bool check_cancel() const override { return false; }

std::size_t session_id_{};
std::string body_{};
Expand Down

0 comments on commit e049601

Please sign in to comment.