Revision 0c8d22a5 src/client/middleware_rsb.cpp

View differences:

src/client/middleware_rsb.cpp
28 28
#include "client/middleware_rsb.h"
29 29

  
30 30
#ifdef RSB_SUPPORT
31

  
31 32
#define BOOST_SIGNALS_NO_DEPRECATION_WARNING 1
32
#include <rsb/Listener.h>
33
#include <rsb/patterns/RemoteServer.h>
34
#include <rsb/MetaData.h>
35
#include <rsb/converter/Repository.h>
36 33
#include <rsb/converter/ProtocolBufferConverter.h>
34
#include <rsb/converter/Repository.h>
37 35
#include <rsb/Factory.h>
36
#include <rsb/Listener.h>
37
#include <rsb/MetaData.h>
38
#include <rsb/patterns/RemoteServer.h>
39
#include <string>
38 40

  
39
#include <humotion/mouth.h>
40
#include <humotion/gaze.h>
41
#include "humotion/gaze.h"
42
#include "humotion/mouth.h"
41 43

  
42
using namespace std;
43
using namespace rsb;
44
using namespace boost;
45
using namespace humotion;
46
using namespace humotion::client;
44
// using namespace std;
45
// using namespace rsb;
46
// using namespace boost;
47
// using namespace humotion;
48
using humotion::client::MiddlewareRSB;
47 49

  
48 50
//! constructor
49
MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope){
51
MiddlewareRSB::MiddlewareRSB(string scope) : Middleware(scope) {
50 52
    printf("> registering converters\n");
51 53

  
52
    try{
53
        //converter for GazeTarget
54
        rsb::converter::Converter<string>::Ptr gazeTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
54
    try {
55
        // converter for GazeTarget
56
        rsb::converter::Converter<string>::Ptr gazeTargetConverter(
57
                    new rsb::converter::ProtocolBufferConverter<rst::robot::HumotionGazeTarget>());
55 58
        rsb::converter::converterRepository<string>()->registerConverter(gazeTargetConverter);
56
    }catch (std::invalid_argument e){
57
        printf("> it seems like a converter for rst::robot::HumotionGazeTarget is already registered. fine, will not add another converter\n");
59
    } catch (std::invalid_argument e) {
60
        printf("> it seems like a converter for rst::robot::HumotionGazeTarget "
61
               "is already registered. fine, will not add another converter\n");
58 62
    }
59 63

  
60
    try{
61
        //converter for MouthTarget
62
        rsb::converter::Converter<string>::Ptr mouthTargetConverter(new rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
63
        rsb::converter::converterRepository<string>()->registerConverter(mouthTargetConverter);
64
    }catch (std::invalid_argument e){
65
        printf("> it seems like a converter for rst::robot::MouthTarget is already registered. fine, will not add another converter\n");
64
    try {
65
        // converter for MouthTarget
66
        rsb::converter::Converter<string>::Ptr mouthTargetConverter(
67
                    new rsb::converter::ProtocolBufferConverter<rst::robot::MouthTarget>());
68
        rsb::converter::converterRepository<std::string>()->registerConverter(mouthTargetConverter);
69
    } catch (std::invalid_argument e) {
70
        printf("> it seems like a converter for rst::robot::MouthTarget is "
71
               "already registered. fine, will not add another converter\n");
66 72
    }
67 73

  
68 74

  
69
    //first get a factory instance that is used to create RSB domain objects
75
    // first get a factory instance that is used to create RSB domain objects
70 76
    Factory &factory = getFactory();
71 77

  
72
    //create informer
73
    mouth_target_informer = factory.createInformer<rst::robot::MouthTarget> (base_scope + "/humotion/mouth/target");
74
    gaze_target_informer  = factory.createInformer<rst::robot::HumotionGazeTarget> (base_scope + "/humotion/gaze/target");
78
    // create informer
79
    mouth_target_informer = factory.createInformer<rst::robot::MouthTarget>
80
            (base_scope + "/humotion/mouth/target");
81
    gaze_target_informer  = factory.createInformer<rst::robot::HumotionGazeTarget>
82
            (base_scope + "/humotion/gaze/target");
75 83

  
76 84
    printf("> MiddlewareRSB initialised\n");
77 85
}
78 86

  
79 87
//! destructor
80
MiddlewareRSB::~MiddlewareRSB(){
88
MiddlewareRSB::~MiddlewareRSB() {
81 89
}
82 90

  
83 91
//! connection ok?
84 92
//! \return true if conn is alive
85
bool MiddlewareRSB::ok(){
93
bool MiddlewareRSB::ok() {
86 94
    return true;
87 95
}
88 96

  
89 97
//! do a single tick
90
void MiddlewareRSB::tick(){
91
    //nothing to do
98
void MiddlewareRSB::tick() {
99
    // nothing to do
92 100
}
93 101

  
94 102

  
95 103
//! send mouth target to server
96
void MiddlewareRSB::send_mouth_target(){
97
    //build target packet:
104
void MiddlewareRSB::send_mouth_target() {
105
    // build target packet
98 106
    boost::shared_ptr<rst::robot::MouthTarget> request(new rst::robot::MouthTarget());
99 107

  
100 108
    request->set_position_left(mouth_state.position_left);
......
110 118
}
111 119

  
112 120
//! send mouth target to server
113
void MiddlewareRSB::send_gaze_target(int gaze_type){
114
    //build target packet:
121
void MiddlewareRSB::send_gaze_target(int gaze_type) {
122
    // build target packet
115 123
    boost::shared_ptr<rst::robot::HumotionGazeTarget> request(new rst::robot::HumotionGazeTarget());
116 124

  
117 125
    request->set_pan(gaze_state.pan);
118 126
    request->set_tilt(gaze_state.tilt);
119
    request->set_roll (gaze_state.roll);
127
    request->set_roll(gaze_state.roll);
120 128
    request->set_vergence(gaze_state.vergence);
121 129

  
122 130
    request->set_pan_offset(gaze_state.pan_offset);
......
132 140
    request->set_eyeblink_request_left(gaze_state.eyeblink_request_left);
133 141
    request->set_eyeblink_request_right(gaze_state.eyeblink_request_right);
134 142

  
135
    if (gaze_state.type == GazeState::ABSOLUTE){
143
    if (gaze_state.type == GazeState::ABSOLUTE) {
136 144
        request->set_type(rst::robot::HumotionGazeTarget::ABSOLUTE);
137
    }else{
145
    } else {
138 146
        request->set_type(rst::robot::HumotionGazeTarget::RELATIVE);
139 147
    }
140 148

  
141 149

  
142
    //add position to send queue
150
    // add position to send queue
143 151
    gaze_target_informer->publish(request);
144 152
}
145 153

  

Also available in: Unified diff