Skip to content

Commit

Permalink
further evert portions of e118bd2
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Feb 22, 2024
1 parent cb61b46 commit d4c1df6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
25 changes: 8 additions & 17 deletions src/tateyama/endpoint/ipc/ipc_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#include <atomic>
#include <functional>

#include "tateyama/endpoint/common/response.h"
#include <tateyama/api/server/response.h>

#include "tateyama/endpoint/common/pointer_comp.h"
#include "server_wires.h"
#include "ipc_request.h"
Expand Down Expand Up @@ -77,30 +78,18 @@ class ipc_data_channel : public tateyama::api::server::data_channel {
/**
* @brief response object for ipc_endpoint
*/
class ipc_response : public tateyama::endpoint::common::response {
class ipc_response : public tateyama::api::server::response {
friend ipc_data_channel;

public:
ipc_response(std::shared_ptr<server_wire_container> server_wire, std::size_t index, std::function<void(void)> clean_up) :
ipc_response(std::shared_ptr<server_wire_container> server_wire, std::size_t index) :
server_wire_(std::move(server_wire)),
index_(index),
garbage_collector_(server_wire_->get_garbage_collector()),
clean_up_(std::move(clean_up)) {
garbage_collector_(server_wire_->get_garbage_collector()) {
// do dump here
garbage_collector_->dump();
}
ipc_response(std::shared_ptr<server_wire_container> server_wire, std::size_t index) :
ipc_response(std::move(server_wire), index, [](){}) {
}
ipc_response() = delete;
~ipc_response() override {
clean_up_();
}

ipc_response(ipc_response const&) = delete;
ipc_response(ipc_response&&) = delete;
ipc_response& operator = (ipc_response const&) = delete;
ipc_response& operator = (ipc_response&&) = delete;

tateyama::status body(std::string_view body) override;
tateyama::status body_head(std::string_view body_head) override;
Expand All @@ -112,11 +101,13 @@ class ipc_response : public tateyama::endpoint::common::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_;
garbage_collector* garbage_collector_;
const std::function<void(void)> clean_up_;

std::string message_{};

Expand Down
5 changes: 5 additions & 0 deletions src/tateyama/endpoint/stream/stream_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ namespace tateyama::endpoint::stream {
// class stream_response
class stream_request;

// class stream_response
stream_response::stream_response(std::shared_ptr<stream_socket> stream, std::uint16_t index)
: stream_(std::move(stream)), index_(index) {
}

tateyama::status stream_response::body(std::string_view body) {
if (!completed_.test_and_set()) {
VLOG_LP(log_trace) << static_cast<const void*>(stream_.get()) << " length = " << body.length(); //NOLINT
Expand Down
23 changes: 7 additions & 16 deletions src/tateyama/endpoint/stream/stream_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <condition_variable>
#include <atomic>

#include <tateyama/endpoint/common/response.h>
#include <tateyama/api/server/response.h>
#include "tateyama/endpoint/common/pointer_comp.h"
#include "stream.h"

Expand Down Expand Up @@ -73,24 +73,12 @@ class stream_data_channel : public tateyama::api::server::data_channel {
/**
* @brief response object for stream_endpoint
*/
class stream_response : public tateyama::endpoint::common::response {
class stream_response : public tateyama::api::server::response {
friend stream_data_channel;

public:
stream_response(std::shared_ptr<stream_socket> stream, std::uint16_t index, std::function<void(void)> clean_up) :
stream_(std::move(stream)), index_(index), clean_up_(std::move(clean_up)) {
}
stream_response(std::shared_ptr<stream_socket> stream, std::uint16_t index) : stream_response(std::move(stream), index, [](){}) {
}
stream_response(std::shared_ptr<stream_socket> stream, std::uint16_t index);
stream_response() = delete;
~stream_response() override {
clean_up_();
}

stream_response(stream_response const&) = delete;
stream_response(stream_response&&) = delete;
stream_response& operator = (stream_response const&) = delete;
stream_response& operator = (stream_response&&) = delete;

tateyama::status body(std::string_view body) override;
tateyama::status body_head(std::string_view body_head) override;
Expand All @@ -101,10 +89,13 @@ class stream_response : public tateyama::endpoint::common::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_;
const std::function<void(void)> clean_up_;

std::string message_{};

Expand Down

0 comments on commit d4c1df6

Please sign in to comment.