|
27 | 27 | #include "pipeline/duplicate_filter.hpp"
|
28 | 28 | #include "pipeline/period_filter.hpp"
|
29 | 29 | #include "pipeline/timestamp_extractor.hpp"
|
30 |
| -#include "pipeline/upcase_value.hpp" |
31 | 30 | #include "pipeline/topic_mapper.hpp"
|
| 31 | +#include "pipeline/upcase_value.hpp" |
32 | 32 |
|
33 | 33 | using namespace std;
|
34 | 34 | using namespace std::literals;
|
35 | 35 |
|
36 | 36 | namespace mtconnect {
|
37 |
| -using namespace observation; |
38 |
| -using namespace entity; |
39 |
| -using namespace pipeline; |
40 |
| - |
41 |
| -namespace adapter { |
42 |
| -std::unique_ptr<Handler> AdapterPipeline::makeHandler() |
43 |
| -{ |
44 |
| - auto handler = make_unique<Handler>(); |
45 |
| - |
46 |
| - // Build the pipeline for an adapter |
47 |
| - handler->m_connecting = [this](const std::string &id) { |
48 |
| - auto entity = make_shared<Entity>("ConnectionStatus", |
49 |
| - Properties {{"VALUE", "CONNECTING"s}, {"source", id}}); |
50 |
| - run(entity); |
51 |
| - }; |
52 |
| - handler->m_connected = [this](const std::string &id) { |
53 |
| - auto entity = make_shared<Entity>("ConnectionStatus", |
54 |
| - Properties {{"VALUE", "CONNECTED"s}, {"source", id}}); |
55 |
| - run(entity); |
56 |
| - }; |
57 |
| - handler->m_disconnected = [this](const std::string &id) { |
58 |
| - auto entity = make_shared<Entity>("ConnectionStatus", |
59 |
| - Properties {{"VALUE", "DISCONNECTED"s}, {"source", id}}); |
60 |
| - run(entity); |
61 |
| - }; |
62 |
| - handler->m_processData = [this](const std::string &data, const std::string &source) { |
63 |
| - auto entity = make_shared<Entity>("Data", Properties {{"VALUE", data}, {"source", source}}); |
64 |
| - run(entity); |
65 |
| - }; |
66 |
| - handler->m_processMessage = [this](const std::string &topic, const std::string &data, |
67 |
| - const std::string &source) { |
68 |
| - auto entity = make_shared<PipelineMessage>( |
69 |
| - "Message", Properties {{"VALUE", data}, {"topic", topic}, {"source", source}}); |
70 |
| - run(entity); |
71 |
| - }; |
72 |
| - handler->m_command = [this](const std::string &data, const std::string &source) { |
73 |
| - auto entity = make_shared<Entity>("Command", Properties {{"VALUE", data}, {"source", source}}); |
74 |
| - run(entity); |
75 |
| - }; |
76 |
| - |
77 |
| - return handler; |
78 |
| -} |
79 |
| - |
80 |
| -void AdapterPipeline::build(const ConfigOptions &options) |
81 |
| -{ |
82 |
| - clear(); |
83 |
| - m_options = options; |
84 |
| - |
85 |
| - m_identity = GetOption<string>(m_options, configuration::AdapterIdentity).value_or("unknown"); |
86 |
| -} |
87 |
| - |
88 |
| -void AdapterPipeline::buildDeviceList() |
89 |
| -{ |
90 |
| - m_identity = *GetOption<string>(m_options, configuration::AdapterIdentity); |
91 |
| - |
92 |
| - auto list = GetOption<StringList>(m_options, configuration::AdditionalDevices); |
93 |
| - if (list) |
94 |
| - m_devices = *list; |
95 |
| - m_device = GetOption<string>(m_options, configuration::Device); |
96 |
| - if (m_device) |
97 |
| - { |
98 |
| - m_devices.emplace_front(*m_device); |
99 |
| - auto dp = m_context->m_contract->findDevice(*m_device); |
100 |
| - if (dp) |
| 37 | + using namespace observation; |
| 38 | + using namespace entity; |
| 39 | + using namespace pipeline; |
| 40 | + |
| 41 | + namespace adapter { |
| 42 | + std::unique_ptr<Handler> AdapterPipeline::makeHandler() |
| 43 | + { |
| 44 | + auto handler = make_unique<Handler>(); |
| 45 | + |
| 46 | + // Build the pipeline for an adapter |
| 47 | + handler->m_connecting = [this](const std::string &id) { |
| 48 | + auto entity = make_shared<Entity>("ConnectionStatus", |
| 49 | + Properties {{"VALUE", "CONNECTING"s}, {"source", id}}); |
| 50 | + run(entity); |
| 51 | + }; |
| 52 | + handler->m_connected = [this](const std::string &id) { |
| 53 | + auto entity = make_shared<Entity>("ConnectionStatus", |
| 54 | + Properties {{"VALUE", "CONNECTED"s}, {"source", id}}); |
| 55 | + run(entity); |
| 56 | + }; |
| 57 | + handler->m_disconnected = [this](const std::string &id) { |
| 58 | + auto entity = make_shared<Entity>("ConnectionStatus", |
| 59 | + Properties {{"VALUE", "DISCONNECTED"s}, {"source", id}}); |
| 60 | + run(entity); |
| 61 | + }; |
| 62 | + handler->m_processData = [this](const std::string &data, const std::string &source) { |
| 63 | + auto entity = make_shared<Entity>("Data", Properties {{"VALUE", data}, {"source", source}}); |
| 64 | + run(entity); |
| 65 | + }; |
| 66 | + handler->m_processMessage = [this](const std::string &topic, const std::string &data, |
| 67 | + const std::string &source) { |
| 68 | + auto entity = make_shared<PipelineMessage>( |
| 69 | + "Message", Properties {{"VALUE", data}, {"topic", topic}, {"source", source}}); |
| 70 | + run(entity); |
| 71 | + }; |
| 72 | + handler->m_command = [this](const std::string &data, const std::string &source) { |
| 73 | + auto entity = |
| 74 | + make_shared<Entity>("Command", Properties {{"VALUE", data}, {"source", source}}); |
| 75 | + run(entity); |
| 76 | + }; |
| 77 | + |
| 78 | + return handler; |
| 79 | + } |
| 80 | + |
| 81 | + void AdapterPipeline::build(const ConfigOptions &options) |
| 82 | + { |
| 83 | + clear(); |
| 84 | + m_options = options; |
| 85 | + |
| 86 | + m_identity = GetOption<string>(m_options, configuration::AdapterIdentity).value_or("unknown"); |
| 87 | + } |
| 88 | + |
| 89 | + void AdapterPipeline::buildDeviceList() |
| 90 | + { |
| 91 | + m_identity = *GetOption<string>(m_options, configuration::AdapterIdentity); |
| 92 | + |
| 93 | + auto list = GetOption<StringList>(m_options, configuration::AdditionalDevices); |
| 94 | + if (list) |
| 95 | + m_devices = *list; |
| 96 | + m_device = GetOption<string>(m_options, configuration::Device); |
| 97 | + if (m_device) |
| 98 | + { |
| 99 | + m_devices.emplace_front(*m_device); |
| 100 | + auto dp = m_context->m_contract->findDevice(*m_device); |
| 101 | + if (dp) |
| 102 | + { |
| 103 | + dp->setOptions(m_options); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + void AdapterPipeline::buildCommandAndStatusDelivery() |
| 109 | + { |
| 110 | + bind(make_shared<DeliverConnectionStatus>( |
| 111 | + m_context, m_devices, IsOptionSet(m_options, configuration::AutoAvailable))); |
| 112 | + bind(make_shared<DeliverCommand>(m_context, m_device)); |
| 113 | + } |
| 114 | + |
| 115 | + void AdapterPipeline::buildAssetDelivery(pipeline::TransformPtr next) |
| 116 | + { |
| 117 | + // Go directly to asset delivery |
| 118 | + std::optional<string> assetMetrics; |
| 119 | + assetMetrics = m_identity + "_asset_update_rate"; |
| 120 | + |
| 121 | + next->bind(make_shared<DeliverAsset>(m_context, assetMetrics)); |
| 122 | + next->bind(make_shared<DeliverAssetCommand>(m_context)); |
| 123 | + } |
| 124 | + |
| 125 | + void AdapterPipeline::buildObservationDelivery(pipeline::TransformPtr next) |
101 | 126 | {
|
102 |
| - dp->setOptions(m_options); |
| 127 | + // Uppercase Events |
| 128 | + if (IsOptionSet(m_options, configuration::UpcaseDataItemValue)) |
| 129 | + next = next->bind(make_shared<UpcaseValue>()); |
| 130 | + |
| 131 | + // Filter dups, by delta, and by period |
| 132 | + next = next->bind(make_shared<DuplicateFilter>(m_context)); |
| 133 | + next = next->bind(make_shared<DeltaFilter>(m_context)); |
| 134 | + next = next->bind(make_shared<PeriodFilter>(m_context)); |
| 135 | + |
| 136 | + // Convert values |
| 137 | + if (IsOptionSet(m_options, configuration::ConversionRequired)) |
| 138 | + next = next->bind(make_shared<ConvertSample>()); |
| 139 | + |
| 140 | + // Deliver |
| 141 | + std::optional<string> obsMetrics; |
| 142 | + obsMetrics = m_identity + "_observation_update_rate"; |
| 143 | + next->bind(make_shared<DeliverObservation>(m_context, obsMetrics)); |
103 | 144 | }
|
104 |
| - } |
105 |
| -} |
106 |
| - |
107 |
| -void AdapterPipeline::buildCommandAndStatusDelivery() |
108 |
| -{ |
109 |
| - bind(make_shared<DeliverConnectionStatus>(m_context, m_devices, |
110 |
| - IsOptionSet(m_options, configuration::AutoAvailable))); |
111 |
| - bind(make_shared<DeliverCommand>(m_context, m_device)); |
112 |
| -} |
113 |
| - |
114 |
| -void AdapterPipeline::buildAssetDelivery(pipeline::TransformPtr next) |
115 |
| -{ |
116 |
| - // Go directly to asset delivery |
117 |
| - std::optional<string> assetMetrics; |
118 |
| - assetMetrics = m_identity + "_asset_update_rate"; |
119 |
| - |
120 |
| - next->bind(make_shared<DeliverAsset>(m_context, assetMetrics)); |
121 |
| - next->bind(make_shared<DeliverAssetCommand>(m_context)); |
122 |
| -} |
123 |
| - |
124 |
| -void AdapterPipeline::buildObservationDelivery(pipeline::TransformPtr next) |
125 |
| -{ |
126 |
| - // Uppercase Events |
127 |
| - if (IsOptionSet(m_options, configuration::UpcaseDataItemValue)) |
128 |
| - next = next->bind(make_shared<UpcaseValue>()); |
129 |
| - |
130 |
| - // Filter dups, by delta, and by period |
131 |
| - next = next->bind(make_shared<DuplicateFilter>(m_context)); |
132 |
| - next = next->bind(make_shared<DeltaFilter>(m_context)); |
133 |
| - next = next->bind(make_shared<PeriodFilter>(m_context)); |
134 |
| - |
135 |
| - // Convert values |
136 |
| - if (IsOptionSet(m_options, configuration::ConversionRequired)) |
137 |
| - next = next->bind(make_shared<ConvertSample>()); |
138 |
| - |
139 |
| - // Deliver |
140 |
| - std::optional<string> obsMetrics; |
141 |
| - obsMetrics = m_identity + "_observation_update_rate"; |
142 |
| - next->bind(make_shared<DeliverObservation>(m_context, obsMetrics)); |
143 |
| -} |
144 |
| -} // namespace adapter |
| 145 | + } // namespace adapter |
145 | 146 | } // namespace mtconnect
|
0 commit comments