+ class mesh {
+ public:
+ mesh() : handle(0) {}
+
+ virtual ~mesh() {
+ this->close();
+ }
+
+ bool isOpen() const {
+ return (handle!=0);
+ }
+
+// TODO: please enable C++11 in autoconf to enable "move constructors":
+// mesh(mesh&& other)
+// : handle(other.handle)
+// {
+// if(handle)
+// handle->priv = this;
+// other.handle = 0;
+// }
+
+ /// Initialize MeshLink's configuration directory.
+ /** This function causes MeshLink to initialize its configuration directory,
+ * if it hasn't already been initialized.
+ * It only has to be run the first time the application starts,
+ * but it is not a problem if it is run more than once, as long as
+ * the arguments given are the same.
+ *
+ * This function does not start any network I/O yet. The application should
+ * first set callbacks, and then call meshlink_start().
+ *
+ * @param confbase The directory in which MeshLink will store its configuration files.
+ * @param name The name which this instance of the application will use in the mesh.
+ * @param appname The application name which will be used in the mesh.
+ * @param dclass The device class which will be used in the mesh.
+ *
+ * @return This function will return a pointer to a meshlink::mesh if MeshLink has succesfully set up its configuration files, NULL otherwise.
+ */
+ bool open(const char *confbase, const char *name, const char* appname, dev_class_t devclass) {
+ handle = meshlink_open(confbase, name, appname, devclass);
+ if(handle)
+ handle->priv = this;
+
+ return isOpen();
+ }
+
+ mesh(const char *confbase, const char *name, const char* appname, dev_class_t devclass) {
+ open(confbase, name, appname, devclass);
+ }
+
+ /// Close the MeshLink handle.
+ /** This function calls meshlink_stop() if necessary,
+ * and frees all memory allocated by MeshLink.
+ * Afterwards, the handle and any pointers to a struct meshlink_node are invalid.
+ */
+ void close() {
+ if(handle)
+ meshlink_close(handle);
+ handle=0;
+ }
+
+ /** instead of registerin callbacks you derive your own class and overwrite the following abstract member functions.
+ * These functions are run in MeshLink's own thread.
+ * It is therefore important that these functions use apprioriate methods (queues, pipes, locking, etc.)
+ * to hand the data over to the application's thread.
+ * These functions should also not block itself and return as quickly as possible.
+ * The default member functions are no-ops, so you are not required to overwrite all these member functions
+ */
+
+ /// This function is called whenever another node sends data to the local node.
+ virtual void receive(node* source, const void* data, size_t length) { /* do nothing */ }
+
+ /// This functions is called whenever another node's status changed.
+ virtual void node_status(node* peer, bool reachable) { /* do nothing */ }
+
+ /// This functions is called whenever MeshLink has some information to log.
+ virtual void log(log_level_t level, const char* message) { /* do nothing */ }
+