eris 1.4.0
A WorldForge client library.
TypeBoundRedispatch.cpp
1#include <utility>
2
3#ifdef HAVE_CONFIG_H
4 #include "config.h"
5#endif
6
7#include "TypeBoundRedispatch.h"
8#include "Connection.h"
9#include "TypeService.h"
10#include "TypeInfo.h"
11#include "LogStream.h"
12
13#include <Atlas/Objects/Operation.h>
14#include <sigc++/slot.h>
15#include <sigc++/bind.h>
16
17using namespace Atlas::Objects::Operation;
18using Atlas::Objects::Root;
19using Atlas::Objects::Entity::RootEntity;
20using Atlas::Objects::smart_dynamic_cast;
21
22namespace Eris
23{
24
25
26TypeBoundRedispatch::TypeBoundRedispatch(Connection& con,
27 const Root& obj,
28 TypeInfo* unbound) :
29 Redispatch(con, obj),
30 m_con(con)
31{
32 m_unbound.insert(unbound);
33
34 assert(!unbound->isBound());
35 unbound->Bound.connect(sigc::bind(sigc::mem_fun(this, &TypeBoundRedispatch::onBound), unbound));
36
37 con.getTypeService().BadType.connect(sigc::mem_fun(this, &TypeBoundRedispatch::onBadType));
38}
39
40TypeBoundRedispatch::TypeBoundRedispatch(Connection& con,
41 const Root& obj,
42 TypeInfoSet unbound) :
43 Redispatch(con, obj),
44 m_con(con),
45 m_unbound(std::move(unbound))
46{
47 for (auto& item : m_unbound) {
48 assert(!item->isBound());
49 item->Bound.connect(sigc::bind(sigc::mem_fun(this, &TypeBoundRedispatch::onBound), item));
50 }
51
52 con.getTypeService().BadType.connect(sigc::mem_fun(this, &TypeBoundRedispatch::onBadType));
53}
54
55void TypeBoundRedispatch::onBound(TypeInfo* bound)
56{
57 assert(m_unbound.count(bound));
58 m_unbound.erase(bound);
59
60 if (m_unbound.empty()) {
61 post();
62 }
63}
64
65void TypeBoundRedispatch::onBadType(TypeInfo* bad)
66{
67 if (m_unbound.count(bad)) {
68 warning() << "TypeBoundRedispatch was waiting on bad type " << bad->getName();
69 fail();
70 }
71}
72
73} // of Eris namespace
Definition: Account.cpp:33