Skip to main content

Adding RPC and Task Actions

SS RPC (service-to-service)

  1. Add a method to an existing service (or a new service) in the proto:
service MyService {
option (atframework.service_options) = {module_name: "my_module"};
rpc my_method(MyMethodReq) returns (MyMethodRsp) {
option (atframework.rpc_options) = {api_name: "my_method" allow_no_wait: false};
}
}
  1. Rebuild: protoc + mako-generator automatically produce:
    • the server-side task action skeleton task_action_my_method.{h,cpp} (existing handwritten parts are preserved within marked regions);
    • updated handler registration handle_ss_rpc_<service>.atfw.gen.*;
    • the caller-side API rpc_call_api (<service>.atfw.gen.*).
  2. Implement the business logic in the skeleton's operator():
task_action_my_method::result_type task_action_my_method::operator()() {
MyMethodRsp &rsp = get_response_body();
// ... business logic; may use RPC_AWAIT_CODE_RESULT(rpc::db::xxx(...))
RPC_RETURN_CODE(0);
}
  1. Caller side:
MyMethodReq req;
// ... fill in the request
auto res = RPC_AWAIT_CODE_RESULT(rpc::MyService::my_method(ctx, req, /*target*/...));

CS RPC (client)

Define messages and services in com.protocol*.proto (public), and declare the handle_cs_rpc / task_action_cs_rpc templates in CMake; the generated action base class is task_action_cs_req_base, which comes with session validation and downstream packing built in. The downstream push API is generated by session_downstream_api_for_cs.*.mako.

Messageless Tasks

Scheduled/self-driven tasks use the task_action_no_msg.*.mako template, or use src/generate-nomsg-task.sh (.in) to quickly generate a skeleton; an in-framework example: task_action_auto_save_objects.

Common Options

rpc_optionsEffect
allow_no_wait: trueThe caller only sends without waiting for a response (no co_await result)
stream return (returns (stream X))Server-side streaming downstream push (e.g., player_dirty_chg_sync in com.protocol.proto)
stream request (rpc x(stream Req) returns (...))Caller-side streaming upload / response-free calls (e.g., dtmq channel_event_sync)
api_nameThe generated caller-side function name