operations_fixture.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 operations_fixture.cpp
3 
4  operations_fixture.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #define BOOST_FUSION_INVOKE_MAX_ARITY 8
21 #define BOOST_FUSION_UNFUSED_MAX_ARITY 7
22 
23 #include "operations_fixture.hpp"
24 #include <iostream>
25 #include <TaskContext.hpp>
26 #include <OperationCaller.hpp>
27 #include <Operation.hpp>
28 #include <Service.hpp>
29 
30 using namespace std;
31 using namespace boost;
32 using namespace RTT;
33 using namespace RTT::detail;
34 
36 {
38 public:
39  OperationCallerComponent(TaskContext* tc) : TaskContext("caller"), mtc(tc) {
40 
41  // calls own thread operations :
42  opc0 = tc->provides("methods")->getOperation("o0");
43  opc0.setCaller( this->engine() );
44  opc1 = tc->provides("methods")->getOperation("o1");
45  opc1.setCaller( this->engine() );
46  // client thread :
47  opc2 = tc->provides("methods")->getOperation("m2");
48  opc2.setCaller( this->engine() );
49  opc3 = tc->provides("methods")->getOperation("m3");
50  opc3.setCaller( this->engine() );
51 
52  // four combinations are possible:
53  this->addOperation("o0", &OperationCallerComponent::m0, this, OwnThread);
54  this->addOperation("o1", &OperationCallerComponent::m1, this, ClientThread);
55  this->addOperation("o2", &OperationCallerComponent::m2, this, OwnThread);
56  this->addOperation("o3", &OperationCallerComponent::m3, this, ClientThread);
57 
58  }
59 
60  void updateHook() {
61  // m0 and m2 are executed in OwnThread
62  // where m0 calls an OwnThread op of 'tc' and m2 calls a ClientThread op of 'tc'.
63 
64  // m1 and m3 are executed in ClientThread (so in GlobalEE when being sent),
65  // where m1 calls an OwnThread op of 'tc' and m3 calls a ClientThread op of 'tc'.
66  // but do set the caller to this component.
67  }
68 
69  bool ready() {
70  BOOST_REQUIRE( opc0.ready() );
71  BOOST_REQUIRE( opc1.ready() );
72  BOOST_REQUIRE( opc2.ready() );
73  BOOST_REQUIRE( opc3.ready() );
74  return opc0.ready() &&
75  opc1.ready() &&
76  opc2.ready() &&
77  opc3.ready();
78  }
79 
80  // plain argument tests:
81  double m0(void) { return opc0(); }
82  double m1(int i) { return opc1(i); }
83  double m2(int i, double d) { return opc2(i,d); }
84  double m3(int i, double d, bool c) { return opc3(i,d,c); }
85 
90 
91 };
92 
93 
95 {
96  ret = 0.0;
97  i = -1;
98  tc = new TaskContext("root");
99  this->createOperationCallerFactories(tc);
100  tc->provides()->addAttribute("ret", ret );
101  caller = new OperationCallerComponent(tc);
102  caller->start();
103  tc->start();
104 }
105 
107 {
108  tc->stop();
109  delete tc;
110  delete caller;
111 }
112 
114 {
115  Service::shared_ptr dat = Service::Create("test", target);
116  dat->addAttribute("i", i);
117  dat->addOperation("assert", &OperationsFixture::assertBool, this).doc("assert").arg("b", "bd");
118  dat->addOperation("assertEqual", &OperationsFixture::assertEqual, this);
119  dat->addOperation("increase", &OperationsFixture::increase, this).doc("Return increasing i");
120  dat->addOperation("increaseCmd", &OperationsFixture::increase, this, OwnThread).doc("Return increasing i");
121  dat->addOperation("resetI", &OperationsFixture::resetI, this).doc("ResetI i");
122  dat->addOperation("assertMsg", &OperationsFixture::assertMsg, this).doc("Assert message").arg("bool", "").arg("text", "text");
123  dat->addOperation("isTrue", &OperationsFixture::isTrue, this).doc("Identity function").arg("bool", "");
124  dat->addOperation("fail", &OperationsFixture::fail, this).doc("Fails by throwing.");
125  dat->addOperation("good", &OperationsFixture::good, this).doc("Returns true.");
126  dat->addOperation("print", &OperationsFixture::print, this).doc("Print message");
127  dat->addOperation("printNumber", &OperationsFixture::printNumber, this).doc("Print message + number");
128 
129  createOperationCallerFactories0(target);
130  createOperationCallerFactories1(target);
131  createOperationCallerFactories2(target);
132  createOperationCallerFactories3(target);
133  createOperationCallerFactories4(target);
134  createOperationCallerFactories5(target);
135  createOperationCallerFactories6(target);
136  createOperationCallerFactories7(target);
137 
138 }
double m3(int i, double d, bool c)
double m2(int i, double d)
OperationCaller< double(int)> opc1
void print(const std::string &what)
Service::shared_ptr provides()
OperationCaller< double(int, double)> opc2
bool assertMsg(bool b, const std::string &msg)
Definition: mystd.hpp:163
void createOperationCallerFactories(TaskContext *target)
void printNumber(const std::string &what, int n)
OperationCaller< double(void)> opc0
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
OperationCallerComponent(TaskContext *tc)
bool assertEqual(int a, int b)
OperationCaller< double(int, double, bool)> opc3
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:34