Test.cpp

test program - J. Moringen, 09/16/2011 10:55 PM

Download (1.49 KB)

 
1

    
2
#include <rsb/Listener.h>
3
#include <rsb/Factory.h>
4

    
5
#include <rsb/CommException.h>
6
#include <rsc/misc/IllegalStateException.h>
7

    
8
using namespace std;
9

    
10
class TestCallback: public rsb::patterns::Server::Callback<string, string> {
11
public:
12

    
13
  virtual ~TestCallback() {
14
  }
15

    
16
  string methodName;
17

    
18
  TestCallback(const string &methodName) :
19
    methodName(methodName) {
20
  }
21

    
22
  boost::shared_ptr<string> call(const string &methodName,
23
                                 boost::shared_ptr<string> input) {
24
    assert(methodName == this->methodName);
25

    
26
    if (methodName == "methodError") {
27
      throw runtime_error("Intentionally failing.");
28
    }
29

    
30
    return boost::shared_ptr<string>(new string("reply to '" + *input + "' (method is '" + methodName + "')"));
31
  }
32

    
33
};
34

    
35
int main(){
36
  try{
37
    /*rsb::patterns::ServerPtr server = rsb::Factory::getInstance().createServer(rsb::Scope("/some/scope"));
38

39
    rsb::patterns::Server::CallbackPtr m1(new TestCallback("bla"));
40
    server->registerMethod("bla", m1);
41
    sleep(10);*/
42

    
43
    rsb::patterns::RemoteServerPtr server = rsb::Factory::getInstance().createRemoteServer(rsb::Scope("/some/scope"));
44

    
45
    server->call<string>("foo", boost::shared_ptr<string>(new string("bla")));
46
  }
47
  catch(rsb::CommException &e){
48
    std::cerr << "\t Caught rsb::CommException: " << e.what() << std::endl;
49
  }
50
  catch(rsc::misc::IllegalStateException &e){
51
    std::cerr << "\t Caught rsc::misc::IllegalStateException: " << e.what() << std::endl;
52
  }
53
  catch(...){
54
    std::cerr << "\t Caught unknown exception." << std::endl;
55
  }
56
}