mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 03:38:09 +00:00
Issue #262: function GetQuotes load data from MT instead of using cached quotes
This commit is contained in:
@@ -38,7 +38,7 @@ std::unique_ptr<MtCommand> MtCommand::Parse(const std::string& msg)
|
||||
return command;
|
||||
}
|
||||
|
||||
std::unique_ptr<MtNotification> MtNotification::Parse(const std::string& msg)
|
||||
std::unique_ptr<MtServiceRequest> MtServiceRequest::Parse(const std::string& msg)
|
||||
{
|
||||
std::string::size_type pos = msg.find(';');
|
||||
|
||||
@@ -47,17 +47,17 @@ std::unique_ptr<MtNotification> MtNotification::Parse(const std::string& msg)
|
||||
using rule = qi::rule<std::string::const_iterator>;
|
||||
|
||||
std::string message_type;
|
||||
std::string notification_type;
|
||||
std::string request_type;
|
||||
|
||||
rule_s word_p = qi::as_string[+(qi::char_ - qi::char_(';'))];
|
||||
rule message_type_p = word_p[boost::phoenix::ref(message_type) = qi::_1];
|
||||
rule notification_type_p = +qi::char_(';') >> word_p[boost::phoenix::ref(notification_type) = qi::_1];
|
||||
rule notification_type_p = +qi::char_(';') >> word_p[boost::phoenix::ref(request_type) = qi::_1];
|
||||
|
||||
std::unique_ptr<MtNotification> command;
|
||||
std::unique_ptr<MtServiceRequest> request;
|
||||
|
||||
bool ok = qi::parse(msg.begin(), msg.end(), message_type_p >> -notification_type_p);
|
||||
if (ok)
|
||||
command = std::make_unique<MtNotification>((NotificationType)std::stoi(notification_type));
|
||||
request = std::make_unique<MtServiceRequest>((ServiceRequestType)std::stoi(request_type));
|
||||
|
||||
return command;
|
||||
return request;
|
||||
}
|
||||
+11
-11
@@ -14,12 +14,12 @@ enum MessageType
|
||||
EXPERT_LIST = 3,
|
||||
EXPERT_ADDED = 4,
|
||||
EXPERT_REMOVED = 5,
|
||||
NOTIFICATION = 6
|
||||
SERVICE_REQUEST = 6
|
||||
};
|
||||
|
||||
enum NotificationType
|
||||
enum ServiceRequestType
|
||||
{
|
||||
CLIENT_READY = 0
|
||||
EXPERTS = 0
|
||||
};
|
||||
|
||||
class MtMessage
|
||||
@@ -111,25 +111,25 @@ private:
|
||||
std::string payload_;
|
||||
};
|
||||
|
||||
class MtNotification : public MtMessage
|
||||
class MtServiceRequest : public MtMessage
|
||||
{
|
||||
public:
|
||||
MtNotification(NotificationType type)
|
||||
: notification_type_(type)
|
||||
MtServiceRequest(ServiceRequestType type)
|
||||
: request_type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
NotificationType GetNotificationType() const
|
||||
ServiceRequestType GetServiceRequestType() const
|
||||
{
|
||||
return notification_type_;
|
||||
return request_type_;
|
||||
}
|
||||
|
||||
static std::unique_ptr<MtNotification> Parse(const std::string& msg);
|
||||
static std::unique_ptr<MtServiceRequest> Parse(const std::string& msg);
|
||||
|
||||
private:
|
||||
MessageType GetType() const override
|
||||
{
|
||||
return MessageType::NOTIFICATION;
|
||||
return MessageType::SERVICE_REQUEST;
|
||||
}
|
||||
|
||||
std::string GetBody() const override
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
return "";
|
||||
}
|
||||
|
||||
NotificationType notification_type_;
|
||||
ServiceRequestType request_type_;
|
||||
};
|
||||
|
||||
class MtEvent : public MtMessage
|
||||
|
||||
@@ -288,12 +288,12 @@ void MtServer::ProcessMessage(const std::string& msg, std::weak_ptr<MtConnection
|
||||
else
|
||||
log_.Warning("%s: Failed to parse command from message: %s", __FUNCTION__, msg.c_str());
|
||||
}
|
||||
else if (msg_type == MessageType::NOTIFICATION)
|
||||
else if (msg_type == MessageType::SERVICE_REQUEST)
|
||||
{
|
||||
auto notification = MtNotification::Parse(msg);
|
||||
if (notification)
|
||||
auto request = MtServiceRequest::Parse(msg);
|
||||
if (request)
|
||||
{
|
||||
if (notification->GetNotificationType() == NotificationType::CLIENT_READY)
|
||||
if (request->GetServiceRequestType() == ServiceRequestType::EXPERTS)
|
||||
{
|
||||
std::vector<int> expert_list;
|
||||
for (const auto& e : experts_)
|
||||
@@ -306,7 +306,7 @@ void MtServer::ProcessMessage(const std::string& msg, std::weak_ptr<MtConnection
|
||||
}
|
||||
}
|
||||
else
|
||||
log_.Warning("%s: Failed to parse notification from message: %s", __FUNCTION__, msg.c_str());
|
||||
log_.Warning("%s: Failed to parse service request from message: %s", __FUNCTION__, msg.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user