Merge authors: Rick Stovall (fpstovall) Rick Stovall (fpstovall) Rick Stovall <fpstovall> Related merge proposals: https://code.launchpad.net/~fpstovall/nrtb/D_prototype/+merge/130093 proposed by: Rick Stovall (fpstovall) review: Approve - Rick Stovall (fpstovall) ------------------------------------------------------------ revno: 12 [merge] committer: Rick Stovall <fpstovall> branch nick: alpha timestamp: Mon 2012-10-22 22:03:27 -0400 message: Refactored and added started code to begin our reboot of the core portions of this project to D. added: D_lang/ D_lang/Makefile D_lang/bin/ D_lang/common/ D_lang/common/Makefile D_lang/common/common.d D_lang/common/docs/ D_lang/common/docs/common.html D_lang/common/docs/vect3d.html D_lang/common/nrtb/ D_lang/common/nrtb/common/ D_lang/common/nrtb/common/GPB_transceiver.d D_lang/common/nrtb/common/conf_manager.d D_lang/common/nrtb/common/vect3d.d D_lang/common/nrtb/common/zmq.d D_lang/common/nrtb/common/zmq_utils.d D_lang/lib/ D_lang/testing/ D_lang/testing/threads/ D_lang/testing/threads/Makefile D_lang/testing/threads/msg_passing.d obsolete/ obsolete/Cpp/ renamed: common/ => obsolete/Cpp/common/ plugins/ => obsolete/Cpp/plugins/ sim_engine/ => obsolete/Cpp/sim_engine/
-- lp:nrtb https://code.launchpad.net/~nrtb-core/nrtb/alpha Your team NRTB Core is subscribed to branch lp:nrtb. To unsubscribe from this branch go to https://code.launchpad.net/~nrtb-core/nrtb/alpha/+edit-subscription
=== added directory 'D_lang' === added file 'D_lang/Makefile' --- D_lang/Makefile 1970-01-01 00:00:00 +0000 +++ D_lang/Makefile 2012-08-20 22:19:10 +0000 @@ -0,0 +1,27 @@ +#*********************************************** +#This file is part of the NRTB project (https://launchpad.net/nrtb). +# +# NRTB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# NRTB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NRTB. If not, see <http://www.gnu.org/licenses/>. +# +#*********************************************** + +build_all: Makefile + @make action=lib doit + +clean: + @make action=clean doit + @rm -fv lib/* bin/* + +doit: + @cd common; make ${action} === added directory 'D_lang/bin' === added directory 'D_lang/common' === added file 'D_lang/common/Makefile' --- D_lang/common/Makefile 1970-01-01 00:00:00 +0000 +++ D_lang/common/Makefile 2012-08-21 01:34:33 +0000 @@ -0,0 +1,35 @@ +#*********************************************** +# This file is part of the NRTB project (https://launchpad.net/nrtb). +# +# NRTB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# NRTB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NRTB. If not, see <http://www.gnu.org/licenses/>. +# +#*********************************************** + +lib: ../lib/common.a + +../lib/common.a: test + @echo building ${modules} + @cd nrtb/common; dmd -lib -release -of../../../lib/common.a *.d -I../../ + @echo " ********* common build complete ***********" + +test: Makefile common.d ${modules} + @echo testing ${modules} + @cd nrtb/common; dmd -unittest -lib -of../../common.a *.d -I../../ + @dmd -unittest common.a -run common.d + +clean: + @rm -vf ../lib/common.a common *.o *.a + @echo all objects and executables have been erased. + +modules=`find nrtb/common -type f -name \*.d` \ No newline at end of file === added file 'D_lang/common/common.d' --- D_lang/common/common.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/common.d 2012-08-20 17:01:41 +0000 @@ -0,0 +1,25 @@ +/*********************************************** + This file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + +**********************************************/ + +import std.stdio; +import nrtb.common.vect3d; + +void main() +{ + writeln(" ******** NRTB Common Libs Unit Test Complete ********"); +} \ No newline at end of file === added directory 'D_lang/common/docs' === added file 'D_lang/common/docs/common.html' --- D_lang/common/docs/common.html 1970-01-01 00:00:00 +0000 +++ D_lang/common/docs/common.html 2012-08-20 16:23:38 +0000 @@ -0,0 +1,10 @@ +<html><head> + <META http-equiv="content-type" content="text/html; charset=utf-8"> + <title>common</title> + </head><body> + <h1>common</h1> + <!-- Generated by Ddoc from common.d --> +<br><br> + + <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small> + </body></html> === added file 'D_lang/common/docs/vect3d.html' --- D_lang/common/docs/vect3d.html 1970-01-01 00:00:00 +0000 +++ D_lang/common/docs/vect3d.html 2012-08-20 16:23:38 +0000 @@ -0,0 +1,80 @@ +<html><head> + <META http-equiv="content-type" content="text/html; charset=utf-8"> + <title>vect3d</title> + </head><body> + <h1>vect3d</h1> + <!-- Generated by Ddoc from vect3d/vect3d.d --> +<br><br> +<dl><dt><big>struct <u>vect3d</u>; +</big></dt> +<dd>Defines a point or vector in cartesian 3d space. Most binary math + operators shoould work + with both <u>vect3d</u> and real arguments, but only +, -, *, / and simple + assignment and equality are unit tested here. Note that operators + return the simple calculated results; dot product and vector product + are provided as discrete method calls. +<br><br> +Also provided are the common vector operations + vector_product, + dot_product, + magnitude, + range (distance between points), + and normalize (scales to magnitude 1.0).<br><br> + +<dl><dt><big>this(ref vect3d); +</big></dt> +<dd>blt copy override to avoid binding accidently.<br><br> + +</dd> +<dt><big>this(const(real[]) <i>a</i>); +</big></dt> +<dd>Construct from <i>a</i> real array. Only arrays of length 3 are acceptable.<br><br> + +</dd> +<dt><big>this(const(real) <i>a</i>); +</big></dt> +<dd>Construct from <i>a</i> single real. All three elements will be assigned the + same value.<br><br> + +</dd> +<dt><big>this(const(real) <i>x</i>, real <i>y</i>, real <i>z</i>); +</big></dt> +<dd>Construct from 3 reals. They are assigned in the order presented.<br><br> + +</dd> +<dt><big>vec <u>values</u>(); +</big></dt> +<dd>returns an array containing copies of the coordinates.<br><br> + +</dd> +<dt><big>real <u>magnitude</u>(); +</big></dt> +<dd>returns the length (the <u>magnitude</u>) of the vector<br><br> + +</dd> +<dt><big>real <u>dot_product</u>(in vect3d <i>a</i>); +</big></dt> +<dd>returns the dot product<br><br> + +</dd> +<dt><big>vect3d <u>vector_product</u>(in vect3d <i>a</i>); +</big></dt> +<dd>returns the vector product<br><br> + +</dd> +<dt><big>real <u>range</u>(in vect3d <i>a</i>); +</big></dt> +<dd><u>range</u> returns the distance between two vect3d<br><br> + +</dd> +<dt><big>vect3d <u>normalize</u>(); +</big></dt> +<dd>returns the normalized vector (scaled to length 1.0)<br><br> + +</dd> +</dl> +</dd> +</dl> + + <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small> + </body></html> === added directory 'D_lang/common/nrtb' === added directory 'D_lang/common/nrtb/common' === added file 'D_lang/common/nrtb/common/GPB_transceiver.d' --- D_lang/common/nrtb/common/GPB_transceiver.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/nrtb/common/GPB_transceiver.d 2012-08-20 17:01:41 +0000 @@ -0,0 +1,24 @@ +/*********************************************** + This file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + + **********************************************/ + +import std.socket; + +class gpb_transceiver +{ + +} \ No newline at end of file === added file 'D_lang/common/nrtb/common/conf_manager.d' --- D_lang/common/nrtb/common/conf_manager.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/nrtb/common/conf_manager.d 2012-08-20 17:01:41 +0000 @@ -0,0 +1,123 @@ +/*********************************************** + This file is part of the NRTB project (https://*launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + + **********************************************/ + +import std.stdio; +import std.conv; +import std.array; +import std.getopt; +import std.string; + +/** Reads command line and configuration file information. +* +* For this NRTB implementation, this class is implemented as +* a singleton. +* +* Values read are stored in a multimap of name/value pairs and +* may be accessed via provided iterators, or directly via the +* [] operator, all(), get<T>() and getall<T>() methods. Automatic +* handling of include files and comments is provided as well. The +* get<>() and getall<>() template methods provide easy and complete +* access to all types that have the ">>" stream operator +* defined, including all the C++ standard types. +**/ + +class conf_reader +{ + alias string[string] mylist; + + this(string[] args) + { + string c_file = "nrtb.config"; + string c_path = "."; + // get the traditional args. + getopt(args, + std.getopt.config.passThrough, + "config_file", &c_file, + "config_path", &c_path + ); + // store off the program name + values["__app_name"] = args[0]; + args = args[1 .. $]; + // process the includes first + string[] pending; + foreach(arg; args) + { + string[] tokens = split(arg,"="); + if (tokens[0] == "include") + load_file(tokens[1]); + else + pending ~= arg; + } + // process the remaining elements + foreach(arg; pending) + { + string[] tokens = split(arg,"="); + if (tokens.length == 1) + { + values[tokens[0]] = "1"; + } + else if (tokens.length == 2) + { + values[tokens[0]] = tokens[1]; + } + }; + } + + private void load_file(in string file_name) + { + // need to add the logic to read files here. + auto f = File(file_name, "r"); + scope(exit) {f.close();}; + foreach(string line; lines(f)) + { + // trim for comments + auto hash_index = indexOf(line,"#"); + if (hash_index != -1) + line = line[0 .. hash_index]; + // if we have anything left, parse it. + if (line != "") + { + // trim the string + line = line.strip(); + // split on first whitespace + for (auto i=0; i<line.length; i++) + { +// if ((line[i] == " ") || (line[i] == "\t")) + } + // trim both sides + // how do we store dups? + } + } + + } + + mylist get_list() { return values.dup; }; + + T get(T,E)(in string key,in E _default) + if (typeof(T = E) == typeof(T)) + { + if ((key in values) != null) + return to!T(values[key]); + else + return _default; + } + + private mylist values; + +} + === added file 'D_lang/common/nrtb/common/vect3d.d' --- D_lang/common/nrtb/common/vect3d.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/nrtb/common/vect3d.d 2012-08-20 17:01:41 +0000 @@ -0,0 +1,150 @@ +/*********************************************** +This file is part of the NRTB project (https://launchpad.net/nrtb). + + NRTB is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NRTB is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NRTB. If not, see <http://www.gnu.org/licenses/>. + +**********************************************/ + +import std.stdio, std.math; + +/** Defines a point or vector in cartesian 3d space. Most binary math + * operators shoould work + * with both vect3d and real arguments, but only +, -, *, / and simple + * assignment and equality are unit tested here. Note that operators + * return the simple calculated results; dot product and vector product + * are provided as discrete method calls. + * + * Also provided are the common vector operations + * vector_product, + * dot_product, + * magnitude, + * range (distance between points), + * and normalize (scales to magnitude 1.0). + **/ + +struct vect3d +{ + alias real[3] vec; + // vector + private vec coords; + /// blt copy override to avoid binding accidently. + this(ref this) { coords = coords.dup; } + /// Construct from a real array. Only arrays of length 3 are acceptable. + this(in real[] a) + { + assert(a.length==3,"!! Invalid input length in vect3d.(T[] a)."); + coords[] = a[0 .. 3]; + } + /// Construct from a single real. All three elements will be assigned the + /// same value. + this(in real a) { coords[] = a;} + /// Construct from 3 reals. They are assigned in the order presented. + this(in real x, real y, real z) { coords[0]=x; coords[1]=y; coords[2]=z;} + /// returns an array containing copies of the coordinates. + vec values() { vec v; v = coords.dup; return v; } + /// returns the length (the magnitude) of the vector + real magnitude() + { + real returnme = 0.0; + foreach(val; coords) { returnme += (val*val); } + return sqrt(returnme); + } + /// returns the dot product + real dot_product(in vect3d a) + { + real returnme = 0.0; + returnme += coords[0] * a.coords[0]; + returnme += coords[1] * a.coords[1]; + returnme += coords[2] * a.coords[2]; + return returnme; + } + /// returns the vector product + vect3d vector_product(in vect3d a) + { + vect3d returnme; + with (returnme) + { + coords[0] = + (this.coords[1] * a.coords[2]) - (this.coords[2] * a.coords[1]); + coords[1] = + (this.coords[2] * a.coords[0]) - (this.coords[0] * a.coords[2]); + coords[2] = + (this.coords[0] * a.coords[1]) - (this.coords[1] * a.coords[0]); + } + return returnme; + } + /// range returns the distance between two vect3d + real range(in vect3d a) + { + return (this - a).magnitude(); + } + /// returns the normalized vector (scaled to length 1.0) + vect3d normalize() + { + return this / magnitude(); + } + // vect3d by vect3d operators + vect3d opBinary(string op)(vect3d rhs) + { + vect3d v; + mixin("v.coords[] = coords[] "~op~" rhs.coords[];"); + return v; + } + // vect3d by real operators + vect3d opBinary(string op)(real rhs) + { + vect3d v; + mixin("v.coords[] = coords[] "~op~" rhs;"); + return v; + } +} + +unittest +{ + // test both literal constuctors + auto a = vect3d(2); + assert(a==vect3d(2,2,2)); + // test init from an array. + real[] array = [2,3,4]; + auto at = vect3d(array); + assert(at == vect3d(2,3,4)); + assert(at.values() == array); + // test copying + auto t=a; + assert(t==vect3d(2,2,2)); + // test major vect3d by vect3d math + auto b = vect3d(1,2,3); + assert((b+a)==vect3d(3,4,5)); + assert((b-a)==vect3d(-1,0,1)); + assert((b*a)==vect3d(2,4,6)); + assert((b/a)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0)); + // test major vect3d by real math shifts and scales + assert((b+1)==vect3d(2,3,4)); + assert((b-1)==vect3d(0,1,2)); + assert((b*2)==vect3d(2,4,6)); + assert((b/2.0)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0)); + // magnitude test + assert(a.magnitude()==sqrt(2.0*2.0*3.0)); + // dot_product test + assert(a.dot_product(a)==12.0); + // vector_product test. + assert(b.vector_product(a)==vect3d(-2,4,-2)); + assert(a.vector_product(a)==vect3d(0.0)); + // Range tests + assert(a.range(a)==0.0); + assert(approxEqual(a.range(b),1.41421)); + // normalize tests. + assert(approxEqual(a.normalize().magnitude(),1.0)); + assert(approxEqual(b.normalize().magnitude(),1.0)); +} === added file 'D_lang/common/nrtb/common/zmq.d' --- D_lang/common/nrtb/common/zmq.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/nrtb/common/zmq.d 2012-09-23 15:29:49 +0000 @@ -0,0 +1,236 @@ +/* + Copyright (c) 2007-2010 iMatix Corporation + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +module zmq; + + +extern (C) +{ + +/******************************************************************************/ +/* 0MQ versioning support. */ +/******************************************************************************/ + +/* Version macros for compile-time API version detection */ + +enum +{ + ZMQ_VERSION_MAJOR =2, + ZMQ_VERSION_MINOR =1, + ZMQ_VERSION_PATCH =10 +} + +/* Run-time API version detection */ +void zmq_version(int* major, int* minor, int* patch); + +/******************************************************************************/ +/* 0MQ errors. */ +/******************************************************************************/ + +/* A number random anough not to collide with different errno ranges on */ +/* different OSes. The assumption is that error_t is at least 32-bit type. */ +immutable enum +{ + ZMQ_HAUSNUMERO = 156384712, + +/* On Windows platform some of the standard POSIX errnos are not defined. */ + ENOTSUP = (ZMQ_HAUSNUMERO + 1), + EPROTONOSUPPORT = (ZMQ_HAUSNUMERO + 2), + ENOBUFS = (ZMQ_HAUSNUMERO + 3), + ENETDOWN = (ZMQ_HAUSNUMERO + 4), + EADDRINUSE = (ZMQ_HAUSNUMERO + 5), + EADDRNOTAVAIL = (ZMQ_HAUSNUMERO + 6), + ECONNREFUSED = (ZMQ_HAUSNUMERO + 7), + EINPROGRESS = (ZMQ_HAUSNUMERO + 8), + ENOTSOCK = (ZMQ_HAUSNUMERO + 9), + +/* Native 0MQ error codes. */ + EFSM = (ZMQ_HAUSNUMERO + 51), + ENOCOMPATPROTO = (ZMQ_HAUSNUMERO + 52), + ETERM = (ZMQ_HAUSNUMERO + 53), + EMTHREAD = (ZMQ_HAUSNUMERO + 54) +}//enum error_code + +/* This function retrieves the errno as it is known to 0MQ library. The goal */ +/* of this function is to make the code 100% portable, including where 0MQ */ +/* compiled with certain CRT library (on Windows) is linked to an */ +/* application that uses different CRT library. */ +int zmq_errno(); + +/* Resolves system errors and 0MQ errors to human-readable string. */ +char* zmq_strerror(int errnum); + +/******************************************************************************/ +/* 0MQ message definition. */ +/******************************************************************************/ +immutable enum +{ +/* Maximal size of "Very Small Message". VSMs are passed by value */ +/* to avoid excessive memory allocation/deallocation. */ +/* If VMSs larger than 255 bytes are required, type of 'vsm_size' */ +/* field in zmq_msg_t structure should be modified accordingly. */ + ZMQ_MAX_VSM_SIZE = 30, + +/* Message types. These integers may be stored in 'content' member of the */ +/* message instead of regular pointer to the data. */ + ZMQ_DELIMITER = 31, + ZMQ_VSM = 32, + +/* Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag */ +/* (it has no equivalent in the wire format), however, making it a flag */ +/* allows us to pack the stucture tigher and thus improve performance. */ + ZMQ_MSG_MORE = 1, + ZMQ_MSG_SHARED = 128, + ZMQ_MSG_MASK = 129 +} + +/* A message. Note that 'content' is not a pointer to the raw data. */ +/* Rather it is pointer to zmq::msg_content_t structure */ +/* (see src/msg_content.hpp for its definition). */ +struct zmq_msg_t +{ + void* content; + ubyte flags; + ubyte vsm_size; + ubyte vsm_data[ZMQ_MAX_VSM_SIZE]; +} + +int zmq_msg_init(zmq_msg_t* msg); +int zmq_msg_init_size(zmq_msg_t* msg, size_t size); +int zmq_msg_init_data(zmq_msg_t* msg, void* data, + size_t size, void function(void* data, void* hint), void* hint); +int zmq_msg_close(zmq_msg_t* msg); +int zmq_msg_move(zmq_msg_t* dest, zmq_msg_t* src); +int zmq_msg_copy(zmq_msg_t* dest, zmq_msg_t* src); +void* zmq_msg_data(zmq_msg_t* msg); +size_t zmq_msg_size(zmq_msg_t* msg); + +/******************************************************************************/ +/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */ +/******************************************************************************/ + +void* zmq_init(int io_threads); +int zmq_term(void* context); + +/******************************************************************************/ +/* 0MQ socket definition. */ +/******************************************************************************/ + +/* Socket types. */ +immutable enum +{ + ZMQ_PAIR = 0, + ZMQ_PUB = 1, + ZMQ_SUB = 2, + ZMQ_REQ = 3, + ZMQ_REP = 4, + ZMQ_DEALER = 5, + ZMQ_ROUTER = 6, + ZMQ_PULL = 7, + ZMQ_PUSH = 8, + ZMQ_XPUB = 9, + ZMQ_XSUB = 10, + ZMQ_XREQ = ZMQ_DEALER, /* Old alias, remove in 3.x */ + ZMQ_XREP = ZMQ_ROUTER, /* Old alias, remove in 3.x */ + ZMQ_UPSTREAM = ZMQ_PULL, /* Old alias, remove in 3.x */ + ZMQ_DOWNSTREAM = ZMQ_PUSH /* Old alias, remove in 3.x */ +} + +/* Socket options. */ +immutable enum +{ + ZMQ_HWM = 1, + ZMQ_SWAP = 3, + ZMQ_AFFINITY = 4, + ZMQ_IDENTITY = 5, + ZMQ_SUBSCRIBE = 6, + ZMQ_UNSUBSCRIBE = 7, + ZMQ_RATE = 8, + ZMQ_RECOVERY_IVL = 9, + ZMQ_MCAST_LOOP = 10, + ZMQ_SNDBUF = 11, + ZMQ_RCVBUF = 12, + ZMQ_RCVMORE = 13, + ZMQ_FD = 14, + ZMQ_EVENTS = 15, + ZMQ_TYPE = 16, + ZMQ_LINGER = 17, + ZMQ_RECONNECT_IVL = 18, + ZMQ_BACKLOG = 19, + ZMQ_RECOVERY_IVL_MSEC = 20, /*opt. recovery time, reconcile in 3.x */ + ZMQ_RECONNECT_IVL_MAX = 21 +} + +/* Send/recv options. */ +immutable enum +{ + ZMQ_NOBLOCK = 1, + ZMQ_SNDMORE = 2 +} + +void* zmq_socket(void* context, int type); +int zmq_close(void* s); +int zmq_setsockopt(void* s, int option, void* optval, size_t optvallen); +int zmq_getsockopt(void* s, int option, void* optval, size_t *optvallen); +int zmq_bind(void* s, const char* addr); +int zmq_connect(void* s, immutable char* addr); +int zmq_send(void* s, zmq_msg_t* msg, int flags); +int zmq_recv(void* s, zmq_msg_t* msg, int flags); + +/******************************************************************************/ +/* I/O multiplexing. */ +/******************************************************************************/ + +immutable enum +{ + ZMQ_POLLIN = 1, + ZMQ_POLLOUT = 2, + ZMQ_POLLERR = 4 +} + +__gshared struct zmq_pollitem_t +{ + void* socket; + version (win32) + { + SOCKET fd; + } + else + { + int fd; + } + short events; + short revents; +} + +int zmq_poll(zmq_pollitem_t* items, int nitems, long timeout); + +/******************************************************************************/ +/* Built-in devices */ +/******************************************************************************/ + +immutable enum +{ + ZMQ_STREAMER = 1, + ZMQ_FORWARDER = 2, + ZMQ_QUEUE = 3 +} + +int zmq_device(int device, void* insocket, void* outsocket); + +}// extern (C) === added file 'D_lang/common/nrtb/common/zmq_utils.d' --- D_lang/common/nrtb/common/zmq_utils.d 1970-01-01 00:00:00 +0000 +++ D_lang/common/nrtb/common/zmq_utils.d 2012-09-23 15:29:49 +0000 @@ -0,0 +1,58 @@ +/* + Copyright (c) 2007-2011 iMatix Corporation + Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +module zmq_utils; + +extern (C) +{ + +/*Handle DSO symbol visibility */ +/++ +#if defined _WIN32 +# if defined DLL_EXPORT +# define ZMQ_EXPORT __declspec(dllexport) +# else +# define ZMQ_EXPORT __declspec(dllimport) +# endif +#else +# if defined __SUNPRO_C || defined __SUNPRO_CC +# define ZMQ_EXPORT __global +# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER +# define ZMQ_EXPORT __attribute__ ((visibility("default"))) +# else +# define ZMQ_EXPORT +# endif +#endif +++/ + +/* Helper functions are used by perf tests so that they don't have to care */ +/* about minutiae of time-related functions on different OS platforms. */ + +/* Starts the stopwatch. Returns the handle to the watch. */ +void* zmq_stopwatch_start(); + +/* Stops the stopwatch. Returns the number of microseconds elapsed since */ +/* the stopwatch was started. */ +ulong zmq_stopwatch_stop(void* watch_); + +/* Sleeps for specified number of seconds. */ +void zmq_sleep(int seconds_); + +} === added directory 'D_lang/lib' === added directory 'D_lang/testing' === added directory 'D_lang/testing/threads' === added file 'D_lang/testing/threads/Makefile' --- D_lang/testing/threads/Makefile 1970-01-01 00:00:00 +0000 +++ D_lang/testing/threads/Makefile 2012-05-14 22:37:50 +0000 @@ -0,0 +1,30 @@ +#*********************************************** +# This file is part of the NRTB project (https://launchpad.net/nrtb). +# +# NRTB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# NRTB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NRTB. If not, see <http://www.gnu.org/licenses/>. +# +#*********************************************** + +lib: msg_passing + @./msg_passing + @echo build complete + +msg_passing: msg_passing.d Makefile + @rm -f msg_passing + @dmd msg_passing.d + +clean: + @rm -vf *.o msg_passing + @echo all objects and executables have been erased. + === added file 'D_lang/testing/threads/msg_passing.d' --- D_lang/testing/threads/msg_passing.d 1970-01-01 00:00:00 +0000 +++ D_lang/testing/threads/msg_passing.d 2012-05-14 22:48:57 +0000 @@ -0,0 +1,64 @@ +/********************* +Multithreaded message passing example in D +*********************/ + +// import the concurrency and standard IO modules +import std.concurrency, std.stdio; + +// main is just like main in C++ +void main() +{ + writeln("D Multithreaded Message Passing Example."); + + // intialize some variable; the compiler can figure out the type from usage. + auto low=0, high = 100; + + // launch a second thread using function receiver defined below. + auto rtid = spawn(&receiver); + + // foreach iterates a range; in this case all values between + // low and high are assigned are assigned to i sequencially. + foreach (i; low .. high) + { + // sends a message to receiver using it's thread id; queue management is automatic. + rtid.send(i); + // report our action + writeln("Sent ", i); + + } + writeln("** main() is complete **"); +} + +// receiver is a function which is run as a seperate thread by main. +void receiver() +{ + writeln("** receiver() started. **"); + + // a variable for error checking. + auto lastid = -1; + + // function to handle messages + void int_handler(int i) + { + // just print a line and record the last id received + writeln(" Received ",i); + lastid = i; + } + + // Loop until we the parent shuts down. + bool running = true; + while (running) + { + receive + ( + // handler for int messages + (int msg) { int_handler(msg); }, + // handler for "owner terminated" exception + (OwnerTerminated e) { running = false; } + ); + } + + // quick check to be sure we got them all. + assert(lastid == 99); + writeln("** receiver() is complete. **"); +} \ No newline at end of file === added directory 'obsolete' === added directory 'obsolete/Cpp' === renamed directory 'common' => 'obsolete/Cpp/common' === renamed directory 'plugins' => 'obsolete/Cpp/plugins' === renamed directory 'sim_engine' => 'obsolete/Cpp/sim_engine'
_______________________________________________ Mailing list: https://launchpad.net/~nrtb-core Post to : [email protected] Unsubscribe : https://launchpad.net/~nrtb-core More help : https://help.launchpad.net/ListHelp

