replicode
mdaemon_node.h
Go to the documentation of this file.
1 /*
2 * HUMANOBS - mBrane
3 *
4 * Eric Nivel
5 * Center for Analysis and Design of Intelligent Agents
6 * Reykjavik University, Menntavegur 1, 101 Reykjavik, Iceland
7 * http://cadia.ru.is
8 * Copyright(c)2012
9 *
10 * This software was developed by the above copyright holder as part of
11 * the HUMANOBS EU research project, in collaboration with the
12 * following parties:
13 *
14 * Autonomous Systems Laboratory
15 * Technical University of Madrid, Spain
16 * http://www.aslab.org/
17 *
18 * Communicative Machines
19 * Edinburgh, United Kingdom
20 * http://www.cmlabs.com/
21 *
22 * Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
23 * University of Lugano and SUPSI, Switzerland
24 * http://www.idsia.ch/
25 *
26 * Institute of Cognitive Sciences and Technologies
27 * Consiglio Nazionale delle Ricerche, Italy
28 * http://www.istc.cnr.it/
29 *
30 * Dipartimento di Ingegneria Informatica
31 * University of Palermo, Italy
32 * http://roboticslab.dinfo.unipa.it/index.php/Main/HomePage
33 *
34 *
35 * --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, is permitted provided that the following conditions
39 * are met:
40 *
41 * - Redistributions of source code must retain the above copyright
42 * and collaboration notice, this list of conditions and the
43 * following disclaimer.
44 *
45 * - Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following
47 * disclaimer in the documentation and/or other materials provided
48 * with the distribution.
49 *
50 * - Neither the name of its copyright holders nor the names of its
51 * contributors may be used to endorse or promote products
52 * derived from this software without specific prior written permission.
53 *
54 * - CADIA Clause: The license granted in and to the software under this
55 * agreement is a limited-use license. The software may not be used in
56 * furtherance of:
57 * (i) intentionally causing bodily injury or severe emotional distress
58 * to any person;
59 * (ii) invading the personal privacy or violating the human rights of
60 * any person; or
61 * (iii) committing or preparing for any act of war.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
64 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
65 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
66 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
67 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
68 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
69 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
70 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
71 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
73 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 */
75 
76 #ifndef mBrane_sdk_mdaemon_node_h
77 #define mBrane_sdk_mdaemon_node_h
78 
79 #include "module_node.h"
80 #include <CoreLibrary/xml_parser.h>
81 #include "dynamic_class_loader.h"
82 
83 #include <thread>
84 
85 #pragma warning( disable : 4251 )
86 
87 namespace mBrane
88 {
89 class RecvThread;
90 class PushThread;
91 class XThread;
92 class Executing;
93 namespace sdk
94 {
95 namespace mdaemon
96 {
97 
98 class Daemon;
99 // Node API, as seen from the daemons
100 class mBrane_dll Node:
101  public module::Node
102 {
103  friend class RecvThread;
104  friend class PushThread;
105  friend class XThread;
106  friend class Executing;
107 protected:
108  bool volatile _shutdown;
112  Node(uint8_t ID = NoID);
113  bool loadConfig(XMLNode &n);
114  void start();
115  virtual void shutdown();
116  ~Node();
117 public:
118  bool isRunning();
119  virtual void dump(const char *fileName) = 0; // dumps the current system state; module dump fileNames: module_class_ID.bin: ex: CR1_123.bin
120  virtual void load(const char *fileName) = 0; // initializes itself from a previously saved system state
121  virtual void migrate(uint16_t CID, uint16_t ID, uint8_t NID) = 0; // identifies the module and the target node
122  //virtual Array<uint8_t,65535> &sharedMemorySegment(uint8_t segment)=0; // FUTURE DEVELOPMENT: pinned down RAM for RDMA, 16KB-1
123  virtual module::_Module *getModule(uint8_t hostID, uint16_t CID, uint16_t ID) = 0; // so that the daemons can write module internals and use modules as interfaces to the pub-sub network
124  // TODO: define API as pure virtual functions
125  // -> node map (an array of mBrane::Networking::NetworkID)
126  // -> profiling data
127  // - msg throughput
128  // - routing latencies (send_ts/recv_ts, node_send_ts/node_recv_ts)
129  // - runtime per module, and its ratio wrt total node runtime, routing time consumption/module runtime
130  // - logical topology, i.e. affinities between modules; traffic between nodes in light of traffic between modules
131 };
132 
133 class mBrane_dll Daemon
134 {
135 protected:
136  Node *const node;
137  Daemon(Node *node);
138 public:
139  typedef Daemon *(*Load)(XMLNode &, Node *); // function exported by the shared library
140  static void Run(Daemon *daemon); // args=this daemon
141  virtual ~Daemon();
142  virtual void init() = 0; // called once, before looping
143  virtual uint32_t run() = 0; // called in a loop: while(!node->_shutdown); returns error code (or 0 if none)
144  virtual void shutdown() = 0; // called when run returns an error, and when the node shutsdown
145 };
146 }
147 }
148 }
149 
150 
151 #endif
Definition: executing.h:93
static thread_ret thread_function_call run(void *args)
Definition: RR.h:375
StaticArray< DynamicClassLoader< Daemon > * > daemonLoaders
Definition: mdaemon_node.h:109
Definition: messaging.h:107
Definition: array.h:84
Node *const node
Definition: mdaemon_node.h:136
Definition: messaging.h:120
StaticArray< std::thread > daemonThreads
Definition: mdaemon_node.h:111
bool volatile _shutdown
Definition: mdaemon_node.h:108
Definition: xml_parser.h:172
Definition: executing.h:110
void start()
Definition: Perf_modules.h:96
Definition: mdaemon_node.h:100
Definition: mdaemon_node.h:133
Definition: module_node.h:93
Definition: module.h:99
StaticArray< Daemon * > daemons
Definition: mdaemon_node.h:110
Definition: array.h:89