replicode
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_node_h
77 #define mBrane_node_h
78 
79 #include "mBrane.h"
80 #include "../Core/payload.h"
81 #include "../Core/list.h"
82 
83 #include "networking.h"
84 #include "messaging.h"
85 #include "executing.h"
86 
87 
88 using namespace mBrane::sdk;
89 using namespace mBrane::sdk::module;
90 using namespace mBrane::sdk::mdaemon;
91 
92 
93 namespace mBrane
94 {
95 
96 class mbrane_dll Node:
97  public Networking,
98  public Executing
99 {
100 private:
101  class NoStream:
102  public std::ostream
103  {
104  public:
105  NoStream(): std::ostream(NULL) {}
106  template<typename T> NoStream &operator <<(T &t)
107  {
108  return *this;
109  }
110  };
111  // CONFIG
113  Node *loadConfigXML(const char *configXML);
114  Node *loadConfigFile(const char *configFileName);
115  // NETWORKING
116  void start(uint8_t assignedNID, NetworkID *networkID, bool isTimeReference);
117  void notifyNodeJoined(uint8_t NID, NetworkID *networkID);
118  void notifyNodeLeft(uint8_t NID);
119  // MESSAGING
120  void startReceivingThreads(uint8_t NID);
121  // SHARED MEMORY
122  // Array<Array<uint8_t>,65535> sharedMemorySegments; // FUTURE DEVELOPMENT
123  // NODE
124  // Array<Host::host_name,32> nodeNames;
125  // Array<int32_t,32> nodeStatus;
126  Node(uint8_t traceLevels);
127  bool loadApplication(const char *fileName);
128 public:
129  // uint8_t nodeCount;
130  // uint8_t nodeJoined;
131  // uint8_t getNID(const char *name);
132  // bool allNodesJoined();
133  // bool allNodesReady();
134  const char *name();
135  // main() NODE API
136  static Node *New(const char *configFileName, SharedLibrary &userLibrary, uint8_t traceLevels);
137  static Node *NewXML(const char *configXML, SharedLibrary &userLibrary, uint8_t traceLevels);
138  ~Node();
139  void run();
140  void ready();
141  //void systemReady();
142  void shutdown();
143  // MODULE NODE API
144  void send(const _Module *sender, _Payload *message, module::Node::Network network = module::Node::PRIMARY);
145  void send(const _Module *sender, _Payload *message, uint8_t nodeID, Network network = module::Node::PRIMARY);
146  void send(const _Module *sender, _Payload *message, Array<uint8_t, 128> *nodeIDs, Network network);
147  uint64_t time() const;
148  void newSpace(const _Module *sender, Network network = PRIMARY);
149  void newModule(const _Module *sender, uint16_t CID, Network network = PRIMARY, const char *hostName = "local");
150  void deleteSpace(uint16_t ID, Network network = PRIMARY);
151  void deleteModule(uint16_t CID, uint16_t ID, Network network = PRIMARY);
152  void activateModule(const _Module *sender, uint16_t module_cid, uint16_t module_id, uint16_t space_id, float activationLevel, Network network = PRIMARY);
153  void activateSpace(const _Module *sender, uint16_t space_id, uint16_t target_sid, float activationLevel, Network network = PRIMARY);
154  void setSpaceThreshold(const _Module *sender, uint16_t space_id, float threshold, Network network = PRIMARY);
155  void subscribeMessage(const _Module *sender, uint16_t module_cid, uint16_t module_id, uint16_t space_id, uint16_t message_cid, Network network = PRIMARY);
156  void unsubscribeMessage(const _Module *sender, uint16_t module_cid, uint16_t module_id, uint16_t space_id, uint16_t message_cid, Network network = PRIMARY);
157  void subscribeStream(const _Module *sender, uint16_t module_cid, uint16_t module_id, uint16_t space_id, uint16_t stream_id, Network network = PRIMARY);
158  void unsubscribeStream(const _Module *sender, uint16_t module_cid, uint16_t module_id, uint16_t space_id, uint16_t stream_id, Network network = PRIMARY);
159  const char *getSpaceName(uint16_t hostID, uint16_t ID);
160  const char *getModuleName(uint16_t CID);
161  void markUnused(_Payload *p);
162  void addConstantObject(_Payload *c, const std::string &name);
163  _Payload *getConstantObject(uint32_t OID);
164  _Payload *getConstantObject(const std::string &name); // usage: call once and retain a pointer to the result.
165  void addLookup(uint8_t sourceNID, uint32_t OID);
166  bool hasLookup(uint8_t destinationNID, uint32_t OID);
167  void addSharedObject(_Payload *o);
168  _Payload *getSharedObject(uint32_t OID);
169  void consolidate(_Payload *p);
170  // DAEMON NODE API
171  void dump(const char *fileName);
172  void load(const char *fileName);
173  void migrate(uint16_t CID, uint16_t ID, uint8_t NID);
174  //Array<uint8_t,65535> &sharedMemorySegment(uint8_t segment); // FUTURE DEVELOPMENT
175  _Module *getModule(uint8_t hostID, uint16_t CID, uint16_t ID);
176 };
177 }
178 
179 
180 #endif
static thread_ret thread_function_call run(void *args)
Definition: RR.h:375
Definition: array.h:84
Definition: network_id.h:101
Network
Definition: module_node.h:104
Definition: module.cpp:85
Definition: dynamic_class_loader.h:89
Definition: array.h:86
Definition: payload.h:122
Definition: utils.h:138
Definition: node.h:101
SharedLibrary * userLibrary
Definition: node.h:112
Definition: executing.h:110
void start()
Definition: Perf_modules.h:96
NoStream()
Definition: node.h:105
Definition: node.h:96
Definition: networking.h:175
Definition: array.h:162
Definition: module.h:99
Definition: module_node.h:105