5 #include "s2clientprotocol/sc2api.pb.h" 11 class ControlInterface;
13 const unsigned int kDefaultProtoInterfaceTimeout = 120000;
15 typedef std::shared_ptr<SC2APIProtocol::Request> GameRequestPtr;
16 typedef std::shared_ptr<const SC2APIProtocol::Response> GameResponsePtr;
18 template<
class MessageType>
25 void Set(GameResponsePtr response,
const MessageType* message) {
30 bool HasErrors()
const {
33 if (response_->error_size() > 0)
45 const MessageType* operator->()
const {
50 const MessageType*
get()
const {
55 GameResponsePtr GetResponse()
const {
59 bool HasResponse ()
const {
60 return response_.get() !=
nullptr;
63 bool HasMessage ()
const {
64 return message_ !=
nullptr;
68 const MessageType* message_;
69 GameResponsePtr response_;
72 #define SET_MESSAGE_RESPONSE(VAR, RESPONSE, MESSAGE_NAME) \ 73 if (RESPONSE.get() && RESPONSE->has_##MESSAGE_NAME()) \ 74 VAR.Set(RESPONSE, &RESPONSE->MESSAGE_NAME()); \ 76 VAR.Set(RESPONSE, nullptr); 78 #define SET_SUBMESSAGE_RESPONSE(VAR, MESSAGE, SUBMESSAGE_NAME) \ 79 if (!MESSAGE.HasErrors() && MESSAGE->has_##SUBMESSAGE_NAME()) \ 80 VAR.Set(MESSAGE.GetResponse(), &MESSAGE->SUBMESSAGE_NAME()); \ 82 VAR.Set(MESSAGE.GetResponse(), nullptr); 88 bool ConnectToGame(
const std::string& address,
int port,
int timeout_ms);
89 GameRequestPtr MakeRequest();
90 bool SendRequest(GameRequestPtr& request,
bool ignore_pending_requests =
false);
91 GameResponsePtr WaitForResponseInternal();
94 void SetErrorCallback(std::function<
void(
const std::string& error_str)> error_callback);
96 SC2APIProtocol::Status GetLastStatus()
const {
return latest_status_; }
97 bool HasResponsePending()
const;
98 SC2APIProtocol::Response::ResponseCase GetResponsePending()
const {
return response_pending_; }
99 int GetAssignedPort()
const {
return port_; }
101 const std::vector<uint32_t>& GetStats()
const {
return count_uses_; }
104 uint32_t GetBaseBuild()
const {
return base_build_; }
105 const std::string& GetDataVersion()
const {
return data_version_; }
109 std::string address_;
111 unsigned int default_timeout_ms_;
112 std::function<void(const std::string& error_str)> error_callback_;
113 SC2APIProtocol::Status latest_status_;
114 SC2APIProtocol::Response::ResponseCase response_pending_;
115 std::vector<uint32_t> count_uses_;
118 uint32_t base_build_;
119 std::string data_version_;
123 const char* RequestResponseIDToName(
int type);
Definition: sc2_connection.h:26
A basic websocket connection and queue wrapper.
Definition: sc2_action.h:9
Definition: sc2_proto_interface.h:19
Definition: sc2_control_interfaces.h:16
Definition: sc2_proto_interface.h:85