Subordination
A framework for distributed programming
api.hh
1 #ifndef SUBORDINATION_API_HH
2 #define SUBORDINATION_API_HH
3 
4 #include <subordination/config.hh>
5 #include <subordination/ppl/basic_factory.hh>
6 
7 namespace sbn {
8 
9  typedef SUBORDINATION_KERNEL_TYPE kernel;
10 
11  enum Target {
12  Local,
13  Remote,
14  Child
15  };
16 
17  template <Target t=Target::Local>
18  inline void
19  send(kernel* k) {
20  factory.send(k);
21  }
22 
23  template <>
24  inline void
25  send<Local>(kernel* k) {
26  factory.send(k);
27  }
28 
29  template <>
30  inline void
31  send<Remote>(kernel* k) {
32  factory.send_remote(k);
33  }
34 
35  template<Target target=Target::Local>
36  void
37  upstream(kernel* lhs, kernel* rhs) {
38  rhs->parent(lhs);
39  send<target>(rhs);
40  }
41 
42  template<Target target=Target::Local>
43  void
44  commit(kernel* rhs, exit_code ret) {
45  if (!rhs->parent()) {
46  delete rhs;
47  sbn::graceful_shutdown(static_cast<int>(ret));
48  } else {
49  rhs->return_to_parent(ret);
50  send<target>(rhs);
51  }
52  }
53 
54  template<Target target=Target::Local>
55  void
56  commit(kernel* rhs) {
57  exit_code ret = rhs->return_code();
58  commit<target>(
59  rhs,
60  ret == exit_code::undefined ? exit_code::success :
61  ret
62  );
63  }
64 
65  template<Target target=Target::Local>
66  void
67  send(kernel* lhs, kernel* rhs) {
68  lhs->principal(rhs);
69  send<target>(lhs);
70  }
71 
72  struct factory_guard {
73 
74  inline
75  factory_guard() {
76  ::sbn::factory.start();
77  }
78 
79  inline
80  ~factory_guard() {
81  ::sbn::factory.stop();
82  ::sbn::factory.wait();
83  }
84 
85  };
86 
87  template<class Pipeline>
88  void
89  upstream(Pipeline& ppl, kernel* lhs, kernel* rhs) {
90  rhs->parent(lhs);
91  ppl.send(rhs);
92  }
93 
94 }
95 
96 #endif // vim:filetype=cpp
Definition: api.hh:72
Definition: kernel.hh:12