-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJSONInstruction.cpp
34 lines (27 loc) · 1.17 KB
/
JSONInstruction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// source tree.
#include "JSONInstruction.h"
#include "JSONInterface.h"
#include "handleOperation.h"
#include <mumble/json_bridge/messages/Message.h>
namespace Mumble {
namespace JsonBridge {
namespace CLI {
JSONInstruction::JSONInstruction(const nlohmann::json &msg) : m_msg(msg) {}
nlohmann::json JSONInstruction::execute(const JSONInterface &jsonInterface) {
MESSAGE_ASSERT_FIELD(m_msg, "message_type", string);
if (m_msg["message_type"].get< std::string >() == "api_call") {
return jsonInterface.process(m_msg);
} else if (m_msg["message_type"].get< std::string >() == "operation") {
return handleOperation(m_msg["message"],
[&jsonInterface](nlohmann::json &msg) { return jsonInterface.process(msg); });
} else {
throw Messages::InvalidMessageException(std::string("Unknown \"message_type\" option \"")
+ m_msg["message_type"].get< std::string >() + "\"");
}
}
}; // namespace CLI
}; // namespace JsonBridge
}; // namespace Mumble