Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AdvancedSubscribe.cpp (1 of 9 files). Show all
Unified · Split
| @@ -35,7 +35,7 @@ DataSubscriber Subscriber; · 34 unmodified lines | |||
| 35 | SubscriptionInfo Info; | 35 | SubscriptionInfo Info; |
| 36 | 36 | ||
| 37 | // Create helper objects for subscription. | 37 | // Create helper objects for subscription. |
| 38 | SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port); | 38 | void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, uint16_t port); |
| 39 | SubscriptionInfo CreateSubscriptionInfo(); | 39 | SubscriptionInfo CreateSubscriptionInfo(); |
| 40 | 40 | ||
| 41 | // Handlers for subscriber callbacks. | 41 | // Handlers for subscriber callbacks. |
| @@ -96,12 +96,10 @@ int main(int argc, char* argv[]) · 54 unmodified lines | |||
| 96 | // - Subscribe | 96 | // - Subscribe |
| 97 | void RunSubscriber(string hostname, uint16_t port) | 97 | void RunSubscriber(string hostname, uint16_t port) |
| 98 | { | 98 | { |
| 99 | // The connector is declared here because it | 99 | SubscriberConnector& connector = Subscriber.GetSubscriberConnector(); |
| 100 | // is only needed for the initial connection | ||
| 101 | SubscriberConnector connector; | ||
| 102 | 100 | ||
| 103 | // Set up helper objects | 101 | // Set up helper objects |
| 104 | connector = CreateSubscriberConnector(hostname, port); | 102 | SetupSubscriberConnector(connector, hostname, port); |
| 105 | Info = CreateSubscriptionInfo(); | 103 | Info = CreateSubscriptionInfo(); |
| 106 | 104 | ||
| 107 | // Register callbacks | 105 | // Register callbacks |
| @@ -169,12 +167,10 @@ SubscriptionInfo CreateSubscriptionInfo() · 61 unmodified lines | |||
| 169 | return info; | 167 | return info; |
| 170 | } | 168 | } |
| 171 | 169 | ||
| 172 | SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port) | 170 | void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, uint16_t port) |
| 173 | { | 171 | { |
| 174 | // SubscriberConnector is another helper object which allows the | 172 | // SubscriberConnector is another helper object which allows the |
| 175 | // user to modify settings for auto-reconnects and retry cycles. | 173 | // user to modify settings for auto-reconnects and retry cycles. |
| 176 | SubscriberConnector connector; | ||
| 177 | |||
| 178 | connector.RegisterErrorMessageCallback(&DisplayErrorMessage); | 174 | connector.RegisterErrorMessageCallback(&DisplayErrorMessage); |
| 179 | connector.RegisterReconnectCallback(&Resubscribe); | 175 | connector.RegisterReconnectCallback(&Resubscribe); |
| 180 | 176 | ||
| @@ -183,8 +179,6 @@ SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port) · 2 unmodified lines | |||
| 183 | connector.SetMaxRetries(5); | 179 | connector.SetMaxRetries(5); |
| 184 | connector.SetRetryInterval(1500); | 180 | connector.SetRetryInterval(1500); |
| 185 | connector.SetAutoReconnect(true); | 181 | connector.SetAutoReconnect(true); |
| 186 | |||
| 187 | return connector; | ||
| 188 | } | 182 | } |
| 189 | 183 | ||
| 190 | // Callback which is called when the subscriber has | 184 | // Callback which is called when the subscriber has |