forked from Maelic/libqi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_object_holder.cpp
More file actions
59 lines (49 loc) · 1.34 KB
/
service_object_holder.cpp
File metadata and controls
59 lines (49 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <qi/anyobject.hpp>
#include <qi/applicationsession.hpp>
#include <ka/errorhandling.hpp>
#include <iostream>
using namespace qi;
class ObjectHolder
{
public:
void emit()
{
signal(_obj);
}
void setObject(AnyObject newObj)
{
_obj = newObj;
}
void resetObject()
{
_obj = {};
}
AnyObject getObject() const
{
return _obj;
}
Signal<AnyObject> signal;
private:
AnyObject _obj;
};
QI_REGISTER_OBJECT(ObjectHolder, emit, setObject, resetObject, getObject, signal)
int main(int argc, char** argv)
{
return ka::invoke_catch(
ka::compose([] { return EXIT_FAILURE; },
qi::ExceptionLogError<const char*>{ "service_object_holder.main",
"Terminating because of unhandled error" }),
[&] {
ApplicationSession app{ argc, argv };
app.startSession();
auto sess = app.session();
if (!sess || !sess->isConnected())
throw std::runtime_error{ "Session is not connected." };
const auto serviceName = "ObjectHolder";
std::cout << "service_name=" << serviceName << std::endl;
std::cout << "endpoint=" << sess->endpoints()[0].str() << std::endl;
sess->registerService(serviceName, boost::make_shared<ObjectHolder>());
app.run();
return EXIT_SUCCESS;
});
}