File tree Expand file tree Collapse file tree 1 file changed +79
-0
lines changed
Expand file tree Collapse file tree 1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change 3030  ;
3131
3232
33+ ## Sample application
3334
35+ Sample use of the library is done in following simple application:
36+
37+ ``` cpp
38+ #include < iostream>
39+ #include < string>
40+ #include < exception>
41+
42+ #include < stdio.h>
43+
44+ #include " ddsconnector.h"
45+
46+ using namespace std ;
47+ using namespace dds ::net::connector;
48+
49+
50+ void wait_for_exit_key();
51+ void my_double_consumer(std::string& variableName, double variableValue);
52+
53+
54+ int main()
55+ {
56+ string appName = "DDS.Net C++ Connected App";
57+ string serverIP = "127.0.0.1";
58+ unsigned short serverPort = 44556;
59+
60+ cout << appName << endl;
61+ cout << "-----" << endl;
62+ cout << "Press Ctrl+C / input 'C' to exit." << endl << endl;
63+
64+ try
65+ {
66+ DdsConnector connector(
67+ appName,
68+ serverIP, serverPort,
69+ new ConsoleLogger());
70+
71+ connector.registerDoubleConsumer("TESTX", my_double_consumer, ON_CHANGE);
72+ connector.registerDoubleConsumer("TESTY", my_double_consumer, ON_CHANGE);
73+
74+ connector.start();
75+
76+ wait_for_exit_key ();
77+
78+ connector.stop();
79+ }
80+ catch (exception& ex)
81+ {
82+ cout << "Error! " << ex.what() << endl;
83+ }
84+
85+ cout << endl << endl << endl;
86+ }
87+
88+
89+ void wait_for_exit_key ()
90+ {
91+ char ch;
92+ while ((ch = getc(stdin)) != 'C');
93+ }
94+
95+
96+ static double x, y;
97+
98+ void my_double_consumer (std::string& variableName, double variableValue)
99+ {
100+ if (variableName == "TESTX")
101+ {
102+ x = variableValue;
103+ }
104+ else if (variableName == "TESTY")
105+ {
106+ y = variableValue;
107+
108+ cout << x << ", " << y << endl;
109+ }
110+ }
111+
112+ ```
You can’t perform that action at this time.
0 commit comments