Skip to content
Merged
1 change: 1 addition & 0 deletions agent_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ set(AGENT_SOURCES
"${SOURCE_DIR}/sink/rest_sink/session_impl.hpp"
"${SOURCE_DIR}/sink/rest_sink/tls_dector.hpp"
"${SOURCE_DIR}/sink/rest_sink/websocket_session.hpp"
"${SOURCE_DIR}/sink/rest_sink/websocket_request_manager.hpp"

# src/sink/rest_sink SOURCE_FILES_ONLY

Expand Down
2 changes: 1 addition & 1 deletion src/mtconnect/configuration/async_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace mtconnect::configuration {
/// @brief io_context::poll
auto poll() { return m_context.poll(); }

/// @brief io_context::poll
/// @brief io_context::get_executor
auto get_executor() BOOST_ASIO_NOEXCEPT { return m_context.get_executor(); }

/// @}
Expand Down
1 change: 0 additions & 1 deletion src/mtconnect/entity/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ namespace mtconnect::entity {
try
{
xmlInitParser();
xmlXPathInit();
xmlSetGenericErrorFunc(nullptr, entityXMLErrorFunc);

unique_ptr<xmlDoc, function<void(xmlDocPtr)>> doc(
Expand Down
2 changes: 0 additions & 2 deletions src/mtconnect/parser/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ namespace mtconnect::parser {
try
{
xmlInitParser();
xmlXPathInit();
xmlSetGenericErrorFunc(nullptr, agentXMLErrorFunc);

THROW_IF_XML2_NULL(m_doc = xmlReadFile(filePath.c_str(), nullptr, XML_PARSE_NOBLANKS));
Expand Down Expand Up @@ -302,7 +301,6 @@ namespace mtconnect::parser {
try
{
xmlInitParser();
xmlXPathInit();
xmlSetGenericErrorFunc(nullptr, agentXMLErrorFunc);

THROW_IF_XML2_NULL(m_doc = xmlReadMemory(doc.c_str(), int32_t(doc.length()), "Devices.xml",
Expand Down
2 changes: 0 additions & 2 deletions src/mtconnect/pipeline/response_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ namespace mtconnect::pipeline {
const std::optional<std::string> &device,
const std::optional<std::string> &uuid)
{
// xmlInitParser();
// xmlXPathInit();
unique_ptr<xmlDoc, function<void(xmlDocPtr)>> doc(
xmlReadMemory(content.data(), static_cast<int>(content.length()), "incoming.xml", nullptr,
XML_PARSE_NOBLANKS),
Expand Down
53 changes: 33 additions & 20 deletions src/mtconnect/sink/rest_sink/rest_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,23 +521,8 @@ namespace mtconnect {
void RestService::createAssetRoutings()
{
using namespace rest_sink;
auto handler = [&](SessionPtr session, RequestPtr request) -> bool {
auto removed = *request->parameter<bool>("removed");
auto count = *request->parameter<int32_t>("count");
auto pretty = request->parameter<bool>("pretty").value_or(false);
auto format = request->parameter<string>("format");
auto printer = getPrinter(request->m_accepts, format);

request->m_request = "MTConnectAssets";

respond(session,
assetRequest(printer, count, removed, request->parameter<string>("type"),
request->parameter<string>("device"), pretty, request->m_requestId),
request->m_requestId);
return true;
};

auto idHandler = [&](SessionPtr session, RequestPtr request) -> bool {
auto idHandler = [this](SessionPtr session, RequestPtr request) -> bool {
auto asset = request->parameter<string>("assetIds");
request->m_request = "MTConnectAssets";

Expand All @@ -564,17 +549,41 @@ namespace mtconnect {
return true;
};

auto handler = [this, idHandler](SessionPtr session, RequestPtr request) -> bool {
auto assets = request->parameter<string>("assetIds");
if (assets)
{
return idHandler(session, request);
}

auto removed = *request->parameter<bool>("removed");
auto count = *request->parameter<int32_t>("count");
auto pretty = request->parameter<bool>("pretty").value_or(false);
auto format = request->parameter<string>("format");
auto printer = getPrinter(request->m_accepts, format);

request->m_request = "MTConnectAssets";

respond(session,
assetRequest(printer, count, removed, request->parameter<string>("type"),
request->parameter<string>("device"), pretty, request->m_requestId),
request->m_requestId);
return true;
};

string qp(
"type={string}&removed={bool:false}&"
"count={integer:100}&device={string}&pretty={bool:false}&format={string}");
m_server->addRouting({boost::beast::http::verb::get, "/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets for deivce `device`")
.command("assets");
m_server->addRouting({boost::beast::http::verb::get, "/asset?" + qp, handler})
.document("MTConnect asset request", "Returns up to `count` assets");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/assets?" + qp, handler})
.document("MTConnect assets request", "Returns up to `count` assets for deivce `device`");
m_server->addRouting({boost::beast::http::verb::get, "/{device}/asset?" + qp, handler})
.document("MTConnect asset request", "Returns up to `count` assets for deivce `device`");
.document("MTConnect asset request", "Returns up to `count` assets for deivce `device`")
.command("asset");
m_server->addRouting({boost::beast::http::verb::get, "/assets/{assetIds}", idHandler})
.document(
"MTConnect assets request",
Expand Down Expand Up @@ -727,9 +736,13 @@ namespace mtconnect {
void RestService::createSampleRoutings()
{
using namespace rest_sink;

auto handler = [&](SessionPtr session, RequestPtr request) -> bool {
request->m_request = "MTConnectStreams";

if (!request->parameter<int32_t>("count"))
request->m_parameters["count"] = 100;

auto interval = request->parameter<int32_t>("interval");
if (interval)
{
Expand Down Expand Up @@ -959,7 +972,7 @@ namespace mtconnect {
}
else
{
LOG(debug) << "Sink close when failing sample respone: " << message;
LOG(debug) << "Sink close when failing sample response: " << message;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/mtconnect/sink/rest_sink/routing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ namespace mtconnect::sink::rest_sink {
errors.emplace_back(error);
}
}
else if (!std::holds_alternative<std::monostate>(p.m_default))
{
request->m_parameters.emplace(make_pair(p.m_name, p.m_default));
}
}

if (!errors.empty())
Expand Down
3 changes: 3 additions & 0 deletions src/mtconnect/sink/rest_sink/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ namespace mtconnect::sink::rest_sink {
/// @brief Start the http server
void start();

/// @brief Simulate running the server for testing
void simulateRun() { m_run = true; }

/// @brief Shutdown the http server
void stop()
{
Expand Down
Loading