History

TimeSeriesPlatFormLibrary: Improved auto-reconnect handling.

J. Ritchie Carroll committed 8 years ago

Commit b2b5ad51 parent 8d7dcfe9 files · +336 −292Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp (1 of 9 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp+40−10
@@ -34,7 +34,7 @@ using namespace GSF::TimeSeries::Transport; · 33 unmodified lines
34 34
35DataSubscriber Subscriber;35DataSubscriber Subscriber;
36 36
37void RunSubscriber(string hostname, uint16_t port);37bool RunSubscriber(string hostname, uint16_t port);
38void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements);38void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements);
39void DisplayStatusMessage(DataSubscriber* source, const string& message);39void DisplayStatusMessage(DataSubscriber* source, const string& message);
40void DisplayErrorMessage(DataSubscriber* source, const string& message);40void DisplayErrorMessage(DataSubscriber* source, const string& message);
@@ -67,11 +67,12 @@ int main(int argc, char* argv[]) · 26 unmodified lines
67 stringstream(argv[2]) >> port;67 stringstream(argv[2]) >> port;
68 68
69 // Run the subscriber.69 // Run the subscriber.
70 RunSubscriber(hostname, port);70 if (RunSubscriber(hostname, port))
71 71 {
72 // Wait until the user presses enter before quitting.72 // Wait until the user presses enter before quitting.
73 string line;73 string line;
74 getline(cin, line);74 getline(cin, line);
75 }
75 76
76 // Disconnect the subscriber to stop background threads.77 // Disconnect the subscriber to stop background threads.
77 Subscriber.Disconnect();78 Subscriber.Disconnect();
@@ -85,7 +86,7 @@ int main(int argc, char* argv[]) · 7 unmodified lines
85// - Register callbacks86// - Register callbacks
86// - Connect to publisher87// - Connect to publisher
87// - Subscribe88// - Subscribe
88void RunSubscriber(string hostname, uint16_t port)89bool RunSubscriber(string hostname, uint16_t port)
89{90{
90 // SubscriptionInfo is a helper object which allows the user91 // SubscriptionInfo is a helper object which allows the user
91 // to set up their subscription and reuse subscription settings.92 // to set up their subscription and reuse subscription settings.
@@ -98,10 +99,39 @@ void RunSubscriber(string hostname, uint16_t port) · 6 unmodified lines
98 Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);99 Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);
99 100
100 cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;101 cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;
101 Subscriber.Connect(hostname, port);
102 102
103 cout << "Connected! Subscribing to data..." << endl << endl;103 string errorMessage;
104 Subscriber.Subscribe(info);104 bool connected = false;
105
106 try
107 {
108 Subscriber.Connect(hostname, port);
109 connected = true;
110 }
111 catch (SubscriberException& ex)
112 {
113 errorMessage = ex.what();
114 }
115 catch (SystemError& ex)
116 {
117 errorMessage = ex.what();
118 }
119 catch (...)
120 {
121 errorMessage = current_exception_diagnostic_information(true);
122 }
123
124 if (connected)
125 {
126 cout << "Connected! Subscribing to data..." << endl << endl;
127 Subscriber.Subscribe(info);
128 }
129 else
130 {
131 cerr << "Failed to connect to \"" << hostname << ":" << port << "\": " << errorMessage;
132 }
133
134 return connected;
105}135}
106 136
107// Callback which is called when the subscriber has137// Callback which is called when the subscriber has

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t