summaryrefslogtreecommitdiff
path: root/cesar/maximus/usertest/src/main_example.cpp
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /cesar/maximus/usertest/src/main_example.cpp
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/maximus/usertest/src/main_example.cpp')
-rw-r--r--cesar/maximus/usertest/src/main_example.cpp166
1 files changed, 166 insertions, 0 deletions
diff --git a/cesar/maximus/usertest/src/main_example.cpp b/cesar/maximus/usertest/src/main_example.cpp
new file mode 100644
index 0000000000..90e2ba570e
--- /dev/null
+++ b/cesar/maximus/usertest/src/main_example.cpp
@@ -0,0 +1,166 @@
+
+#include "Maximus.h"
+#include "Sta.h"
+#include "Msg.h"
+
+#include <signal.h> // for 'raise()' and 'SIGTERM'
+#include <iostream> // for 'cout', 'cerr' and 'clog'
+using namespace std;
+
+typedef struct my_struct
+{
+ int i1;
+ int i2;
+ bool b;
+} my_struct_t;
+
+typedef long long my_type_t;
+
+bool receive_fc1_rsp;
+
+void
+my_cb (Msg & msg)
+{
+ cout << __PRETTY_FUNCTION__ << endl;
+
+ unsigned long length = sizeof(my_type_t);
+ my_type_t result2;
+ my_type_t * p_result2 = &result2;
+ if (NULL != msg.bind_param("result_2", length, (unsigned char *)p_result2))
+ {
+ cout << "result 2 = " << result2 << endl;
+ }
+ receive_fc1_rsp = true;
+
+ p_result2 = NULL;
+}
+
+int
+main ( int argc, char * argv[] )
+{
+ try
+ {
+ /* Instantiate a Maximus object and initialize it. */
+ Maximus maximus;
+ maximus.init(argc, argv);
+
+ /* Create three stations. */
+ Sta stationA = maximus.create_sta();
+ Sta stationB = maximus.create_sta();
+ Sta stationC = maximus.create_sta();
+
+ /* Launch a debugger attached to station B. */
+ stationB.debug();
+
+ /* Send an asynchronous function message to station A. */
+
+ /** Create a function message and set the name of the function to call of station A. **/
+ Msg fc1 = maximus.create_fc("function_1");
+
+ /** Add a first parameter to the created message. **/
+ my_struct_t param1 = { 1, 2, true };
+ fc1.add_param("param_1", sizeof(my_struct_t), (unsigned char *)&param1);
+
+ /** Add a second parameter to the created message. **/
+ int param2[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ fc1.add_param("param_2", 10*sizeof(int), (unsigned char *)param2);
+
+ /** Add a third parameter to the created message. **/
+ string param3("hello");
+ fc1.add_param("param_3", param3);
+
+ /** Add a fourth parameter to the created message. **/
+ my_type_t param4 = 123;
+ fc1.add_param("param_4", sizeof(my_type_t), (unsigned char *)&param4);
+
+ /** Register a callback function which will be called at message response reception. **/
+ fc1.set_cb(&my_cb);
+
+ /** Set destination station of message 1. **/
+ fc1.set_sta(stationA);
+
+ /** Send the configured message in an asynchronous mode. **/
+ receive_fc1_rsp = false;
+ fc1.send_async();
+
+ /* Send a synchronous function message to station B. */
+
+ /** Create a function message and set the name of the function to call into station B. **/
+ Msg fc2 = maximus.create_fc("function_2");
+
+ /** Add a first parameter to the created message. **/
+ fc2.add_param("param_5", true);
+
+ /** Send the configured message to station B in a synchronous mode. **/
+ fc2.send(stationB);
+
+ /** Get the function result. **/
+ char result1[FUNCTION_CALL_PARAM_MAX_SIZE];
+ unsigned long length = FUNCTION_CALL_PARAM_MAX_SIZE*sizeof(char);
+ fc2.bind_param("result_1", length, (unsigned char *)result1);
+ cout << "result1 = " << result1 << endl;
+
+ /* Set a parameter value of station B. */
+ Msg probe1 = maximus.create_probe();
+ unsigned int param6 = 789;
+ probe1.add_param("param_6", param6);
+ probe1.send(stationB);
+
+ /* Get a parameter value from station B. */
+ Msg probe2 = maximus.create_probe()
+ .add_param("param_7")
+ .send(stationB);
+ unsigned int param7 = probe2.bind_param<unsigned int>("param_7");
+ cout << "param 7 = " << param7 << endl;
+
+ /* Get the same parameter value from station C, re-using existing message. */
+ probe2.send(stationC);
+
+ /* Send asynchronous function message(s) to station B. */
+ if (456 == param7)
+ {
+ Msg fc3 = maximus.create_fc("function_3");
+ fc3.send_async(stationC);
+ }
+ Msg fc4 = maximus.create_fc("function_4");
+ fc4.send_async(stationC);
+
+ /* Wait for station A response. */
+ while(!receive_fc1_rsp)
+ {
+ maximus.process();
+ }
+
+ /* Send an asynchronous function message to station C. */
+ Msg fc5 = maximus.create_fc("function_5");
+ fc5.send_async(stationC);
+
+ /* Wait for responses to all sent messages in asynchronous mode. */
+ maximus.wait();
+
+ /* Get list of all registered parameters of stations C. */
+ Msg probe3 = maximus.create_probe();
+ probe3.send(stationC);
+ if (probe3.is_param("param_8"))
+ {
+ /* Get parameter 8 value and set parameter 9 value of station C. */
+ Msg probe4 = maximus.create_probe();
+ probe4.add_param("param_8");
+ probe4.add_param("param_9", false);
+ probe4.send(stationC);
+ bool param8 = probe4.bind_param<bool>("param_8");
+ cout << "param 8 = " << param8 << endl;
+ }
+
+ /* Wait during 10000 ticks before terminating the program. */
+ maximus.wait(10000);
+ }
+ catch (...)
+ {
+ cerr << "Catch an exception" << endl;
+ raise(SIGTERM);
+ }
+
+ cout << endl << "*** END ***" << endl;
+ return 0;
+}