1
|
#include "ResultPublisher.h"
|
2
|
|
3
|
ResultPublisher::ResultPublisher ( string outScopeOccupiedFields,
|
4
|
string outScopeFixatedField) {
|
5
|
|
6
|
this->outScopeOccupiedFields = outScopeOccupiedFields;
|
7
|
this->outScopeFixatedField = outScopeFixatedField;
|
8
|
this->alreadySetupRSB = false;
|
9
|
|
10
|
|
11
|
}
|
12
|
|
13
|
ResultPublisher::~ResultPublisher(void)
|
14
|
{
|
15
|
}
|
16
|
|
17
|
int ResultPublisher::setupRSB() {
|
18
|
|
19
|
if (alreadySetupRSB)
|
20
|
return 0;
|
21
|
rsb::Factory& factory = rsb::Factory::getInstance();
|
22
|
|
23
|
boost::shared_ptr< rsb::converter::ProtocolBufferConverter<rst::generic::ListFloat> >
|
24
|
converter(new rsb::converter::ProtocolBufferConverter<rst::generic::ListFloat>());
|
25
|
rsb::converter::converterRepository<std::string>()->registerConverter(converter);
|
26
|
|
27
|
try {
|
28
|
occFieldsInformer = factory.createInformer<rst::generic::ListFloat>(rsb::Scope(outScopeOccupiedFields));
|
29
|
fixatedFieldInformer = factory.createInformer<string>(rsb::Scope(outScopeFixatedField));
|
30
|
} catch( std::exception& e) {
|
31
|
cout << "Sorry, RSB could not be initialized. Maybe Spread is not running?" << endl;
|
32
|
cout << e.what() << endl;
|
33
|
return -1;
|
34
|
}
|
35
|
alreadySetupRSB = true;
|
36
|
cout << "rsb successful setup" << endl;
|
37
|
|
38
|
return 0;
|
39
|
|
40
|
}
|
41
|
|
42
|
int ResultPublisher::sendResultOccFields(vector<float> result) {
|
43
|
cout << "About to publish occFields" << endl;
|
44
|
rst::generic::ListFloat floatArrayRes;
|
45
|
for(vector<float>::iterator it = result.begin() ; it != result.end(); ++it)
|
46
|
{
|
47
|
cout << *it << " |";
|
48
|
floatArrayRes.add_x(*it);
|
49
|
}
|
50
|
cout << endl;
|
51
|
boost::shared_ptr<rst::generic::ListFloat> resultOut(new rst::generic::ListFloat(floatArrayRes), rsc::misc::NullDeleter());
|
52
|
occFieldsInformer->publish(resultOut);
|
53
|
|
54
|
cout << "Published Occfields" << endl;
|
55
|
return 0;
|
56
|
|
57
|
}
|
58
|
|
59
|
int ResultPublisher::sendResultFixatedField(float field){
|
60
|
cout << "About to publish fixated Field" << endl;
|
61
|
stringstream s;
|
62
|
s << field;
|
63
|
string t = s.str();
|
64
|
rsb::Informer<string>::DataPtr dataPtr(new string(t));
|
65
|
|
66
|
|
67
|
fixatedFieldInformer->publish(dataPtr);
|
68
|
|
69
|
cout << "Published fixated Field" << endl;
|
70
|
return 0;
|
71
|
}
|
72
|
|
73
|
|
74
|
|