Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 'prepare' for server task too. #1686

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/factory/WFTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ class WFNetworkTask : public CommRequest
}
}

public:
void set_prepare(std::function<void (WFNetworkTask<REQ, RESP> *)> prep)
{
this->prepare = std::move(prep);
}

public:
void set_callback(std::function<void (WFNetworkTask<REQ, RESP> *)> cb)
{
Expand All @@ -226,6 +232,7 @@ class WFNetworkTask : public CommRequest
int watch_timeo;
REQ req;
RESP resp;
std::function<void (WFNetworkTask<REQ, RESP> *)> prepare;
std::function<void (WFNetworkTask<REQ, RESP> *)> callback;

protected:
Expand Down Expand Up @@ -749,6 +756,7 @@ class WFRepeaterTask : public WFGenericTask
this->create = std::move(create);
}

public:
void set_callback(std::function<void (WFRepeaterTask *)> cb)
{
this->callback = std::move(cb);
Expand Down
22 changes: 11 additions & 11 deletions src/factory/WFTask.inl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WFClientTask : public WFNetworkTask<REQ, RESP>
protected:
virtual CommMessageOut *message_out()
{
/* By using prepare function, users can modify request after
/* By using prepare function, users can modify the request after
* the connection is established. */
if (this->prepare)
this->prepare(this);
Expand Down Expand Up @@ -91,15 +91,6 @@ protected:
return series->pop();
}

public:
void set_prepare(std::function<void (WFNetworkTask<REQ, RESP> *)> prep)
{
this->prepare = std::move(prep);
}

protected:
std::function<void (WFNetworkTask<REQ, RESP> *)> prepare;

public:
WFClientTask(CommSchedObject *object, CommScheduler *scheduler,
std::function<void (WFNetworkTask<REQ, RESP> *)>&& cb) :
Expand All @@ -115,7 +106,16 @@ template<class REQ, class RESP>
class WFServerTask : public WFNetworkTask<REQ, RESP>
{
protected:
virtual CommMessageOut *message_out() { return &this->resp; }
virtual CommMessageOut *message_out()
{
/* By using prepare function, users can modify the response before
* replying to the client. */
if (this->prepare)
this->prepare(this);

return &this->resp;
}

virtual CommMessageIn *message_in() { return &this->req; }
virtual void handle(int state, int error);

Expand Down
Loading