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