Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AverageFrequencyCalculator.cpp (1 of 9 files). Show all
Unified · Split
| @@ -36,7 +36,7 @@ DataSubscriber Subscriber; · 35 unmodified lines | |||
| 36 | SubscriptionInfo Info; | 36 | SubscriptionInfo Info; |
| 37 | 37 | ||
| 38 | // Create helper objects for subscription. | 38 | // Create helper objects for subscription. |
| 39 | SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port); | 39 | void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, uint16_t port); |
| 40 | SubscriptionInfo CreateSubscriptionInfo(); | 40 | SubscriptionInfo CreateSubscriptionInfo(); |
| 41 | 41 | ||
| 42 | // Handlers for subscriber callbacks. | 42 | // Handlers for subscriber callbacks. |
| @@ -88,12 +88,10 @@ int main(int argc, char* argv[]) · 45 unmodified lines | |||
| 88 | // - Subscribe | 88 | // - Subscribe |
| 89 | void RunSubscriber(string hostname, uint16_t port) | 89 | void RunSubscriber(string hostname, uint16_t port) |
| 90 | { | 90 | { |
| 91 | // The connector is declared here because it | 91 | SubscriberConnector& connector = Subscriber.GetSubscriberConnector(); |
| 92 | // is only needed for the initial connection | ||
| 93 | SubscriberConnector connector; | ||
| 94 | 92 | ||
| 95 | // Set up helper objects | 93 | // Set up helper objects |
| 96 | connector = CreateSubscriberConnector(hostname, port); | 94 | SetupSubscriberConnector(connector, hostname, port); |
| 97 | Info = CreateSubscriptionInfo(); | 95 | Info = CreateSubscriptionInfo(); |
| 98 | 96 | ||
| 99 | // Register callbacks | 97 | // Register callbacks |
| @@ -139,12 +137,10 @@ SubscriptionInfo CreateSubscriptionInfo() · 39 unmodified lines | |||
| 139 | return info; | 137 | return info; |
| 140 | } | 138 | } |
| 141 | 139 | ||
| 142 | SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port) | 140 | void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, uint16_t port) |
| 143 | { | 141 | { |
| 144 | // SubscriberConnector is another helper object which allows the | 142 | // SubscriberConnector is another helper object which allows the |
| 145 | // user to modify settings for auto-reconnects and retry cycles. | 143 | // user to modify settings for auto-reconnects and retry cycles. |
| 146 | SubscriberConnector connector; | ||
| 147 | |||
| 148 | connector.RegisterErrorMessageCallback(&DisplayErrorMessage); | 144 | connector.RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 149 | connector.RegisterReconnectCallback(&Resubscribe); | 145 | connector.RegisterReconnectCallback(&Resubscribe); |
| 150 | 146 | ||
| @@ -153,8 +149,6 @@ SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port) · 2 unmodified lines | |||
| 153 | connector.SetMaxRetries(-1); | 149 | connector.SetMaxRetries(-1); |
| 154 | connector.SetRetryInterval(2000); | 150 | connector.SetRetryInterval(2000); |
| 155 | connector.SetAutoReconnect(true); | 151 | connector.SetAutoReconnect(true); |
| 156 | |||
| 157 | return connector; | ||
| 158 | } | 152 | } |
| 159 | 153 | ||
| 160 | // Callback which is called when the subscriber has | 154 | // Callback which is called when the subscriber has |