Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/InstanceSubscribe.cpp (1 of 24 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | //****************************************************************************************************** |
| 2 | −// AdvancedSubscribe.cpp - Gbtc | |
| 2 | +// InstanceSubscribe.cpp - Gbtc | |
| 3 | 3 | // |
| 4 | 4 | // Copyright � 2010, Grid Protection Alliance. All Rights Reserved. |
| 5 | 5 | // |
| @@ -16,7 +16,7 @@ · 10 unmodified lines | ||
| 16 | 16 | // |
| 17 | 17 | // Code Modification History: |
| 18 | 18 | // ---------------------------------------------------------------------------------------------------- |
| 19 | −// 04/06/2012 - Stephen C. Wills | |
| 19 | +// 03/27/2018 - J. Ritchie Carroll | |
| 20 | 20 | // Generated original version of source code. |
| 21 | 21 | // |
| 22 | 22 | //****************************************************************************************************** |
| @@ -25,52 +25,70 @@ · 2 unmodified lines | ||
| 25 | 25 | |
| 26 | 26 | #include "SubscriberHandler.h" |
| 27 | 27 | |
| 28 | −SubscriberHandler* Subscriber1; | |
| 29 | −SubscriberHandler* Subscriber2; | |
| 28 | +#define TotalInstances 3 | |
| 29 | + | |
| 30 | +SubscriberHandler* Subscriber[TotalInstances]; | |
| 30 | 31 | |
| 31 | 32 | int main(int argc, char* argv[]) |
| 32 | 33 | { |
| 33 | − string hostname; | |
| 34 | − uint16_t port; | |
| 34 | + string hostname; | |
| 35 | + uint16_t port; | |
| 36 | + | |
| 37 | + // Ensure that the necessary | |
| 38 | + // command line arguments are given. | |
| 39 | + if (argc < 3) | |
| 40 | + { | |
| 41 | + cout << "Usage:" << endl; | |
| 42 | + cout << " InstanceSubscribe HOSTNAME PORT" << endl; | |
| 43 | + return 0; | |
| 44 | + } | |
| 45 | + | |
| 46 | + // Get hostname and port. | |
| 47 | + hostname = argv[1]; | |
| 48 | + stringstream(argv[2]) >> port; | |
| 35 | 49 | |
| 36 | − // Ensure that the necessary | |
| 37 | − // command line arguments are given. | |
| 38 | − if (argc < 3) | |
| 39 | − { | |
| 40 | − cout << "Usage:" << endl; | |
| 41 | − cout << " AdvancedSubscribe HOSTNAME PORT" << endl; | |
| 42 | − return 0; | |
| 43 | − } | |
| 50 | + // Initialize the subscribers. | |
| 51 | + for (size_t i = 0; i < TotalInstances; i++) | |
| 52 | + { | |
| 53 | + stringstream name; | |
| 54 | + | |
| 55 | + name << "Subscriber" << (i + 1); | |
| 44 | 56 | |
| 45 | − // Get hostname and port. | |
| 46 | − hostname = argv[1]; | |
| 47 | − stringstream(argv[2]) >> port; | |
| 57 | + SubscriberHandler* subscriber = new SubscriberHandler(name.str()); | |
| 48 | 58 | |
| 49 | − // Initialize the subscribers. | |
| 50 | − Subscriber1 = new SubscriberHandler("Subscriber1"); | |
| 51 | − Subscriber2 = new SubscriberHandler("Subscriber2"); | |
| 59 | + subscriber->Initialize(hostname, port); | |
| 52 | 60 | |
| 53 | − Subscriber1->Initialize(hostname, port); | |
| 54 | − Subscriber2->Initialize(hostname, port); | |
| 61 | + switch (i) | |
| 62 | + { | |
| 63 | + case 1: | |
| 64 | + subscriber->SetFilterExpression("FILTER TOP 5 ActiveMeasurements WHERE SignalType = 'FREQ'"); | |
| 65 | + break; | |
| 66 | + case 2: | |
| 67 | + subscriber->SetFilterExpression("FILTER TOP 10 ActiveMeasurements WHERE SignalType LIKE '%PHA'"); | |
| 68 | + break; | |
| 69 | + default: | |
| 70 | + subscriber->SetFilterExpression("FILTER TOP 10 ActiveMeasurements WHERE SignalType LIKE '%PHM'"); | |
| 71 | + break; | |
| 72 | + } | |
| 55 | 73 | |
| 56 | − Subscriber1->SetFilterExpression("FILTER TOP 5 ActiveMeasurements WHERE SignalType = 'FREQ'"); | |
| 57 | − Subscriber2->SetFilterExpression("FILTER TOP 10 ActiveMeasurements WHERE SignalType LIKE '%PHA'"); | |
| 74 | + subscriber->Connect(); | |
| 58 | 75 | |
| 59 | − Subscriber1->Connect(); | |
| 60 | − Subscriber2->Connect(); | |
| 76 | + Subscriber[i] = subscriber; | |
| 77 | + } | |
| 61 | 78 | |
| 62 | − // Wait until the user presses enter before quitting. | |
| 63 | − string line; | |
| 64 | − getline(cin, line); | |
| 79 | + // Wait until the user presses enter before quitting. | |
| 80 | + string line; | |
| 81 | + getline(cin, line); | |
| 65 | 82 | |
| 66 | − Subscriber1->Disconnect(); | |
| 67 | − Subscriber2->Disconnect(); | |
| 83 | + // Shutdown subscriber instances | |
| 84 | + for (size_t i = 0; i < TotalInstances; i++) | |
| 85 | + { | |
| 86 | + Subscriber[i]->Disconnect(); | |
| 87 | + delete Subscriber[i]; | |
| 88 | + } | |
| 68 | 89 | |
| 69 | − delete Subscriber1; | |
| 70 | − delete Subscriber2; | |
| 71 | − | |
| 72 | − // Disconnect the subscriber to stop background threads. | |
| 73 | − cout << "Disconnected." << endl; | |
| 90 | + // Disconnect the subscriber to stop background threads. | |
| 91 | + cout << "Disconnected." << endl; | |
| 74 | 92 | |
| 75 | − return 0; | |
| 93 | + return 0; | |
| 76 | 94 | } |