Merge lp:~fpstovall/nrtb/D_prototype into lp:nrtb

Proposed by Rick Stovall
Status: Merged
Approved by: Rick Stovall
Approved revision: 34
Merged at revision: 12
Proposed branch: lp:~fpstovall/nrtb/D_prototype
Merge into: lp:nrtb
Diff against target: 940 lines (+862/-0)
12 files modified
D_lang/Makefile (+27/-0)
D_lang/common/Makefile (+35/-0)
D_lang/common/common.d (+25/-0)
D_lang/common/docs/common.html (+10/-0)
D_lang/common/docs/vect3d.html (+80/-0)
D_lang/common/nrtb/common/GPB_transceiver.d (+24/-0)
D_lang/common/nrtb/common/conf_manager.d (+123/-0)
D_lang/common/nrtb/common/vect3d.d (+150/-0)
D_lang/common/nrtb/common/zmq.d (+236/-0)
D_lang/common/nrtb/common/zmq_utils.d (+58/-0)
D_lang/testing/threads/Makefile (+30/-0)
D_lang/testing/threads/msg_passing.d (+64/-0)
To merge this branch: bzr merge lp:~fpstovall/nrtb/D_prototype
Reviewer Review Type Date Requested Status
Rick Stovall merge Approve
NRTB Core refactoring Pending
Review via email: mp+130093@code.launchpad.net

Description of the change

This merge begins our formal project move to use D instead of C++.

1. Refactored directories to obsolete the C++ code and move the D stuff to the top.
2. Added the start of the D NRTB libs, and some test code.

This needs to be pushed to the alpha branch as soon as possible to facilitate the rest of team's work.

To post a comment you must log in.
Revision history for this message
Rick Stovall (fpstovall) wrote :

8:05 AM
me: I've proposed a (long overdue) merge to alpha. It's the directory restructure and D language code starts that was the D_Prototype branch.

Are you good with that?
8:06 AM
George: yes
12 minutes
8:18 AM
me: Okay.. if you are not where you can approve today, I'll copy this IM exchange and move it on.

review: Approve (merge)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'D_lang'
=== added file 'D_lang/Makefile'
--- D_lang/Makefile 1970-01-01 00:00:00 +0000
+++ D_lang/Makefile 2012-10-17 11:54:28 +0000
@@ -0,0 +1,27 @@
1#***********************************************
2#This file is part of the NRTB project (https://launchpad.net/nrtb).
3#
4# NRTB is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# NRTB is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16#
17#***********************************************
18
19build_all: Makefile
20 @make action=lib doit
21
22clean:
23 @make action=clean doit
24 @rm -fv lib/* bin/*
25
26doit:
27 @cd common; make ${action}
028
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,35 @@
1#***********************************************
2# This file is part of the NRTB project (https://launchpad.net/nrtb).
3#
4# NRTB is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# NRTB is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16#
17#***********************************************
18
19lib: ../lib/common.a
20
21../lib/common.a: test
22 @echo building ${modules}
23 @cd nrtb/common; dmd -lib -release -of../../../lib/common.a *.d -I../../
24 @echo " ********* common build complete ***********"
25
26test: Makefile common.d ${modules}
27 @echo testing ${modules}
28 @cd nrtb/common; dmd -unittest -lib -of../../common.a *.d -I../../
29 @dmd -unittest common.a -run common.d
30
31clean:
32 @rm -vf ../lib/common.a common *.o *.a
33 @echo all objects and executables have been erased.
34
35modules=`find nrtb/common -type f -name \*.d`
0\ No newline at end of file36\ No newline at end of file
137
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,25 @@
1/***********************************************
2 This file is part of the NRTB project (https://*launchpad.net/nrtb).
3
4 NRTB is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 NRTB is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16
17**********************************************/
18
19import std.stdio;
20import nrtb.common.vect3d;
21
22void main()
23{
24 writeln(" ******** NRTB Common Libs Unit Test Complete ********");
25}
0\ No newline at end of file26\ No newline at end of file
127
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,10 @@
1<html><head>
2 <META http-equiv="content-type" content="text/html; charset=utf-8">
3 <title>common</title>
4 </head><body>
5 <h1>common</h1>
6 <!-- Generated by Ddoc from common.d -->
7<br><br>
8
9 <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small>
10 </body></html>
011
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,80 @@
1<html><head>
2 <META http-equiv="content-type" content="text/html; charset=utf-8">
3 <title>vect3d</title>
4 </head><body>
5 <h1>vect3d</h1>
6 <!-- Generated by Ddoc from vect3d/vect3d.d -->
7<br><br>
8<dl><dt><big>struct <u>vect3d</u>;
9</big></dt>
10<dd>Defines a point or vector in cartesian 3d space. Most binary math
11 operators shoould work
12 with both <u>vect3d</u> and real arguments, but only +, -, *, / and simple
13 assignment and equality are unit tested here. Note that operators
14 return the simple calculated results; dot product and vector product
15 are provided as discrete method calls.
16<br><br>
17Also provided are the common vector operations
18 vector_product,
19 dot_product,
20 magnitude,
21 range (distance between points),
22 and normalize (scales to magnitude 1.0).<br><br>
23
24<dl><dt><big>this(ref vect3d);
25</big></dt>
26<dd>blt copy override to avoid binding accidently.<br><br>
27
28</dd>
29<dt><big>this(const(real[]) <i>a</i>);
30</big></dt>
31<dd>Construct from <i>a</i> real array. Only arrays of length 3 are acceptable.<br><br>
32
33</dd>
34<dt><big>this(const(real) <i>a</i>);
35</big></dt>
36<dd>Construct from <i>a</i> single real. All three elements will be assigned the
37 same value.<br><br>
38
39</dd>
40<dt><big>this(const(real) <i>x</i>, real <i>y</i>, real <i>z</i>);
41</big></dt>
42<dd>Construct from 3 reals. They are assigned in the order presented.<br><br>
43
44</dd>
45<dt><big>vec <u>values</u>();
46</big></dt>
47<dd>returns an array containing copies of the coordinates.<br><br>
48
49</dd>
50<dt><big>real <u>magnitude</u>();
51</big></dt>
52<dd>returns the length (the <u>magnitude</u>) of the vector<br><br>
53
54</dd>
55<dt><big>real <u>dot_product</u>(in vect3d <i>a</i>);
56</big></dt>
57<dd>returns the dot product<br><br>
58
59</dd>
60<dt><big>vect3d <u>vector_product</u>(in vect3d <i>a</i>);
61</big></dt>
62<dd>returns the vector product<br><br>
63
64</dd>
65<dt><big>real <u>range</u>(in vect3d <i>a</i>);
66</big></dt>
67<dd><u>range</u> returns the distance between two vect3d<br><br>
68
69</dd>
70<dt><big>vect3d <u>normalize</u>();
71</big></dt>
72<dd>returns the normalized vector (scaled to length 1.0)<br><br>
73
74</dd>
75</dl>
76</dd>
77</dl>
78
79 <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small>
80 </body></html>
081
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,24 @@
1/***********************************************
2 This file is part of the NRTB project (https://*launchpad.net/nrtb).
3
4 NRTB is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 NRTB is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16
17 **********************************************/
18
19import std.socket;
20
21class gpb_transceiver
22{
23
24}
0\ No newline at end of file25\ No newline at end of file
126
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,123 @@
1/***********************************************
2 This file is part of the NRTB project (https://*launchpad.net/nrtb).
3
4 NRTB is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 NRTB is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16
17 **********************************************/
18
19import std.stdio;
20import std.conv;
21import std.array;
22import std.getopt;
23import std.string;
24
25/** Reads command line and configuration file information.
26*
27* For this NRTB implementation, this class is implemented as
28* a singleton.
29*
30* Values read are stored in a multimap of name/value pairs and
31* may be accessed via provided iterators, or directly via the
32* [] operator, all(), get<T>() and getall<T>() methods. Automatic
33* handling of include files and comments is provided as well. The
34* get<>() and getall<>() template methods provide easy and complete
35* access to all types that have the ">>" stream operator
36* defined, including all the C++ standard types.
37**/
38
39class conf_reader
40{
41 alias string[string] mylist;
42
43 this(string[] args)
44 {
45 string c_file = "nrtb.config";
46 string c_path = ".";
47 // get the traditional args.
48 getopt(args,
49 std.getopt.config.passThrough,
50 "config_file", &c_file,
51 "config_path", &c_path
52 );
53 // store off the program name
54 values["__app_name"] = args[0];
55 args = args[1 .. $];
56 // process the includes first
57 string[] pending;
58 foreach(arg; args)
59 {
60 string[] tokens = split(arg,"=");
61 if (tokens[0] == "include")
62 load_file(tokens[1]);
63 else
64 pending ~= arg;
65 }
66 // process the remaining elements
67 foreach(arg; pending)
68 {
69 string[] tokens = split(arg,"=");
70 if (tokens.length == 1)
71 {
72 values[tokens[0]] = "1";
73 }
74 else if (tokens.length == 2)
75 {
76 values[tokens[0]] = tokens[1];
77 }
78 };
79 }
80
81 private void load_file(in string file_name)
82 {
83 // need to add the logic to read files here.
84 auto f = File(file_name, "r");
85 scope(exit) {f.close();};
86 foreach(string line; lines(f))
87 {
88 // trim for comments
89 auto hash_index = indexOf(line,"#");
90 if (hash_index != -1)
91 line = line[0 .. hash_index];
92 // if we have anything left, parse it.
93 if (line != "")
94 {
95 // trim the string
96 line = line.strip();
97 // split on first whitespace
98 for (auto i=0; i<line.length; i++)
99 {
100// if ((line[i] == " ") || (line[i] == "\t"))
101 }
102 // trim both sides
103 // how do we store dups?
104 }
105 }
106
107 }
108
109 mylist get_list() { return values.dup; };
110
111 T get(T,E)(in string key,in E _default)
112 if (typeof(T = E) == typeof(T))
113 {
114 if ((key in values) != null)
115 return to!T(values[key]);
116 else
117 return _default;
118 }
119
120 private mylist values;
121
122}
123
0124
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,150 @@
1/***********************************************
2This file is part of the NRTB project (https://launchpad.net/nrtb).
3
4 NRTB is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 NRTB is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16
17**********************************************/
18
19import std.stdio, std.math;
20
21/** Defines a point or vector in cartesian 3d space. Most binary math
22 * operators shoould work
23 * with both vect3d and real arguments, but only +, -, *, / and simple
24 * assignment and equality are unit tested here. Note that operators
25 * return the simple calculated results; dot product and vector product
26 * are provided as discrete method calls.
27 *
28 * Also provided are the common vector operations
29 * vector_product,
30 * dot_product,
31 * magnitude,
32 * range (distance between points),
33 * and normalize (scales to magnitude 1.0).
34 **/
35
36struct vect3d
37{
38 alias real[3] vec;
39 // vector
40 private vec coords;
41 /// blt copy override to avoid binding accidently.
42 this(ref this) { coords = coords.dup; }
43 /// Construct from a real array. Only arrays of length 3 are acceptable.
44 this(in real[] a)
45 {
46 assert(a.length==3,"!! Invalid input length in vect3d.(T[] a).");
47 coords[] = a[0 .. 3];
48 }
49 /// Construct from a single real. All three elements will be assigned the
50 /// same value.
51 this(in real a) { coords[] = a;}
52 /// Construct from 3 reals. They are assigned in the order presented.
53 this(in real x, real y, real z) { coords[0]=x; coords[1]=y; coords[2]=z;}
54 /// returns an array containing copies of the coordinates.
55 vec values() { vec v; v = coords.dup; return v; }
56 /// returns the length (the magnitude) of the vector
57 real magnitude()
58 {
59 real returnme = 0.0;
60 foreach(val; coords) { returnme += (val*val); }
61 return sqrt(returnme);
62 }
63 /// returns the dot product
64 real dot_product(in vect3d a)
65 {
66 real returnme = 0.0;
67 returnme += coords[0] * a.coords[0];
68 returnme += coords[1] * a.coords[1];
69 returnme += coords[2] * a.coords[2];
70 return returnme;
71 }
72 /// returns the vector product
73 vect3d vector_product(in vect3d a)
74 {
75 vect3d returnme;
76 with (returnme)
77 {
78 coords[0] =
79 (this.coords[1] * a.coords[2]) - (this.coords[2] * a.coords[1]);
80 coords[1] =
81 (this.coords[2] * a.coords[0]) - (this.coords[0] * a.coords[2]);
82 coords[2] =
83 (this.coords[0] * a.coords[1]) - (this.coords[1] * a.coords[0]);
84 }
85 return returnme;
86 }
87 /// range returns the distance between two vect3d
88 real range(in vect3d a)
89 {
90 return (this - a).magnitude();
91 }
92 /// returns the normalized vector (scaled to length 1.0)
93 vect3d normalize()
94 {
95 return this / magnitude();
96 }
97 // vect3d by vect3d operators
98 vect3d opBinary(string op)(vect3d rhs)
99 {
100 vect3d v;
101 mixin("v.coords[] = coords[] "~op~" rhs.coords[];");
102 return v;
103 }
104 // vect3d by real operators
105 vect3d opBinary(string op)(real rhs)
106 {
107 vect3d v;
108 mixin("v.coords[] = coords[] "~op~" rhs;");
109 return v;
110 }
111}
112
113unittest
114{
115 // test both literal constuctors
116 auto a = vect3d(2);
117 assert(a==vect3d(2,2,2));
118 // test init from an array.
119 real[] array = [2,3,4];
120 auto at = vect3d(array);
121 assert(at == vect3d(2,3,4));
122 assert(at.values() == array);
123 // test copying
124 auto t=a;
125 assert(t==vect3d(2,2,2));
126 // test major vect3d by vect3d math
127 auto b = vect3d(1,2,3);
128 assert((b+a)==vect3d(3,4,5));
129 assert((b-a)==vect3d(-1,0,1));
130 assert((b*a)==vect3d(2,4,6));
131 assert((b/a)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0));
132 // test major vect3d by real math shifts and scales
133 assert((b+1)==vect3d(2,3,4));
134 assert((b-1)==vect3d(0,1,2));
135 assert((b*2)==vect3d(2,4,6));
136 assert((b/2.0)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0));
137 // magnitude test
138 assert(a.magnitude()==sqrt(2.0*2.0*3.0));
139 // dot_product test
140 assert(a.dot_product(a)==12.0);
141 // vector_product test.
142 assert(b.vector_product(a)==vect3d(-2,4,-2));
143 assert(a.vector_product(a)==vect3d(0.0));
144 // Range tests
145 assert(a.range(a)==0.0);
146 assert(approxEqual(a.range(b),1.41421));
147 // normalize tests.
148 assert(approxEqual(a.normalize().magnitude(),1.0));
149 assert(approxEqual(b.normalize().magnitude(),1.0));
150}
0151
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,236 @@
1/*
2 Copyright (c) 2007-2010 iMatix Corporation
3
4 This file is part of 0MQ.
5
6 0MQ is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 0MQ is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19module zmq;
20
21
22extern (C)
23{
24
25/******************************************************************************/
26/* 0MQ versioning support. */
27/******************************************************************************/
28
29/* Version macros for compile-time API version detection */
30
31enum
32{
33 ZMQ_VERSION_MAJOR =2,
34 ZMQ_VERSION_MINOR =1,
35 ZMQ_VERSION_PATCH =10
36}
37
38/* Run-time API version detection */
39void zmq_version(int* major, int* minor, int* patch);
40
41/******************************************************************************/
42/* 0MQ errors. */
43/******************************************************************************/
44
45/* A number random anough not to collide with different errno ranges on */
46/* different OSes. The assumption is that error_t is at least 32-bit type. */
47immutable enum
48{
49 ZMQ_HAUSNUMERO = 156384712,
50
51/* On Windows platform some of the standard POSIX errnos are not defined. */
52 ENOTSUP = (ZMQ_HAUSNUMERO + 1),
53 EPROTONOSUPPORT = (ZMQ_HAUSNUMERO + 2),
54 ENOBUFS = (ZMQ_HAUSNUMERO + 3),
55 ENETDOWN = (ZMQ_HAUSNUMERO + 4),
56 EADDRINUSE = (ZMQ_HAUSNUMERO + 5),
57 EADDRNOTAVAIL = (ZMQ_HAUSNUMERO + 6),
58 ECONNREFUSED = (ZMQ_HAUSNUMERO + 7),
59 EINPROGRESS = (ZMQ_HAUSNUMERO + 8),
60 ENOTSOCK = (ZMQ_HAUSNUMERO + 9),
61
62/* Native 0MQ error codes. */
63 EFSM = (ZMQ_HAUSNUMERO + 51),
64 ENOCOMPATPROTO = (ZMQ_HAUSNUMERO + 52),
65 ETERM = (ZMQ_HAUSNUMERO + 53),
66 EMTHREAD = (ZMQ_HAUSNUMERO + 54)
67}//enum error_code
68
69/* This function retrieves the errno as it is known to 0MQ library. The goal */
70/* of this function is to make the code 100% portable, including where 0MQ */
71/* compiled with certain CRT library (on Windows) is linked to an */
72/* application that uses different CRT library. */
73int zmq_errno();
74
75/* Resolves system errors and 0MQ errors to human-readable string. */
76char* zmq_strerror(int errnum);
77
78/******************************************************************************/
79/* 0MQ message definition. */
80/******************************************************************************/
81immutable enum
82{
83/* Maximal size of "Very Small Message". VSMs are passed by value */
84/* to avoid excessive memory allocation/deallocation. */
85/* If VMSs larger than 255 bytes are required, type of 'vsm_size' */
86/* field in zmq_msg_t structure should be modified accordingly. */
87 ZMQ_MAX_VSM_SIZE = 30,
88
89/* Message types. These integers may be stored in 'content' member of the */
90/* message instead of regular pointer to the data. */
91 ZMQ_DELIMITER = 31,
92 ZMQ_VSM = 32,
93
94/* Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag */
95/* (it has no equivalent in the wire format), however, making it a flag */
96/* allows us to pack the stucture tigher and thus improve performance. */
97 ZMQ_MSG_MORE = 1,
98 ZMQ_MSG_SHARED = 128,
99 ZMQ_MSG_MASK = 129
100}
101
102/* A message. Note that 'content' is not a pointer to the raw data. */
103/* Rather it is pointer to zmq::msg_content_t structure */
104/* (see src/msg_content.hpp for its definition). */
105struct zmq_msg_t
106{
107 void* content;
108 ubyte flags;
109 ubyte vsm_size;
110 ubyte vsm_data[ZMQ_MAX_VSM_SIZE];
111}
112
113int zmq_msg_init(zmq_msg_t* msg);
114int zmq_msg_init_size(zmq_msg_t* msg, size_t size);
115int zmq_msg_init_data(zmq_msg_t* msg, void* data,
116 size_t size, void function(void* data, void* hint), void* hint);
117int zmq_msg_close(zmq_msg_t* msg);
118int zmq_msg_move(zmq_msg_t* dest, zmq_msg_t* src);
119int zmq_msg_copy(zmq_msg_t* dest, zmq_msg_t* src);
120void* zmq_msg_data(zmq_msg_t* msg);
121size_t zmq_msg_size(zmq_msg_t* msg);
122
123/******************************************************************************/
124/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */
125/******************************************************************************/
126
127void* zmq_init(int io_threads);
128int zmq_term(void* context);
129
130/******************************************************************************/
131/* 0MQ socket definition. */
132/******************************************************************************/
133
134/* Socket types. */
135immutable enum
136{
137 ZMQ_PAIR = 0,
138 ZMQ_PUB = 1,
139 ZMQ_SUB = 2,
140 ZMQ_REQ = 3,
141 ZMQ_REP = 4,
142 ZMQ_DEALER = 5,
143 ZMQ_ROUTER = 6,
144 ZMQ_PULL = 7,
145 ZMQ_PUSH = 8,
146 ZMQ_XPUB = 9,
147 ZMQ_XSUB = 10,
148 ZMQ_XREQ = ZMQ_DEALER, /* Old alias, remove in 3.x */
149 ZMQ_XREP = ZMQ_ROUTER, /* Old alias, remove in 3.x */
150 ZMQ_UPSTREAM = ZMQ_PULL, /* Old alias, remove in 3.x */
151 ZMQ_DOWNSTREAM = ZMQ_PUSH /* Old alias, remove in 3.x */
152}
153
154/* Socket options. */
155immutable enum
156{
157 ZMQ_HWM = 1,
158 ZMQ_SWAP = 3,
159 ZMQ_AFFINITY = 4,
160 ZMQ_IDENTITY = 5,
161 ZMQ_SUBSCRIBE = 6,
162 ZMQ_UNSUBSCRIBE = 7,
163 ZMQ_RATE = 8,
164 ZMQ_RECOVERY_IVL = 9,
165 ZMQ_MCAST_LOOP = 10,
166 ZMQ_SNDBUF = 11,
167 ZMQ_RCVBUF = 12,
168 ZMQ_RCVMORE = 13,
169 ZMQ_FD = 14,
170 ZMQ_EVENTS = 15,
171 ZMQ_TYPE = 16,
172 ZMQ_LINGER = 17,
173 ZMQ_RECONNECT_IVL = 18,
174 ZMQ_BACKLOG = 19,
175 ZMQ_RECOVERY_IVL_MSEC = 20, /*opt. recovery time, reconcile in 3.x */
176 ZMQ_RECONNECT_IVL_MAX = 21
177}
178
179/* Send/recv options. */
180immutable enum
181{
182 ZMQ_NOBLOCK = 1,
183 ZMQ_SNDMORE = 2
184}
185
186void* zmq_socket(void* context, int type);
187int zmq_close(void* s);
188int zmq_setsockopt(void* s, int option, void* optval, size_t optvallen);
189int zmq_getsockopt(void* s, int option, void* optval, size_t *optvallen);
190int zmq_bind(void* s, const char* addr);
191int zmq_connect(void* s, immutable char* addr);
192int zmq_send(void* s, zmq_msg_t* msg, int flags);
193int zmq_recv(void* s, zmq_msg_t* msg, int flags);
194
195/******************************************************************************/
196/* I/O multiplexing. */
197/******************************************************************************/
198
199immutable enum
200{
201 ZMQ_POLLIN = 1,
202 ZMQ_POLLOUT = 2,
203 ZMQ_POLLERR = 4
204}
205
206__gshared struct zmq_pollitem_t
207{
208 void* socket;
209 version (win32)
210 {
211 SOCKET fd;
212 }
213 else
214 {
215 int fd;
216 }
217 short events;
218 short revents;
219}
220
221int zmq_poll(zmq_pollitem_t* items, int nitems, long timeout);
222
223/******************************************************************************/
224/* Built-in devices */
225/******************************************************************************/
226
227immutable enum
228{
229 ZMQ_STREAMER = 1,
230 ZMQ_FORWARDER = 2,
231 ZMQ_QUEUE = 3
232}
233
234int zmq_device(int device, void* insocket, void* outsocket);
235
236}// extern (C)
0237
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,58 @@
1/*
2 Copyright (c) 2007-2011 iMatix Corporation
3 Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
4
5 This file is part of 0MQ.
6
7 0MQ is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 0MQ is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21module zmq_utils;
22
23extern (C)
24{
25
26/*Handle DSO symbol visibility */
27/++
28#if defined _WIN32
29# if defined DLL_EXPORT
30# define ZMQ_EXPORT __declspec(dllexport)
31# else
32# define ZMQ_EXPORT __declspec(dllimport)
33# endif
34#else
35# if defined __SUNPRO_C || defined __SUNPRO_CC
36# define ZMQ_EXPORT __global
37# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
38# define ZMQ_EXPORT __attribute__ ((visibility("default")))
39# else
40# define ZMQ_EXPORT
41# endif
42#endif
43++/
44
45/* Helper functions are used by perf tests so that they don't have to care */
46/* about minutiae of time-related functions on different OS platforms. */
47
48/* Starts the stopwatch. Returns the handle to the watch. */
49void* zmq_stopwatch_start();
50
51/* Stops the stopwatch. Returns the number of microseconds elapsed since */
52/* the stopwatch was started. */
53ulong zmq_stopwatch_stop(void* watch_);
54
55/* Sleeps for specified number of seconds. */
56void zmq_sleep(int seconds_);
57
58}
059
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,30 @@
1#***********************************************
2# This file is part of the NRTB project (https://launchpad.net/nrtb).
3#
4# NRTB is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# NRTB is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
16#
17#***********************************************
18
19lib: msg_passing
20 @./msg_passing
21 @echo build complete
22
23msg_passing: msg_passing.d Makefile
24 @rm -f msg_passing
25 @dmd msg_passing.d
26
27clean:
28 @rm -vf *.o msg_passing
29 @echo all objects and executables have been erased.
30
031
=== 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-10-17 11:54:28 +0000
@@ -0,0 +1,64 @@
1/*********************
2Multithreaded message passing example in D
3*********************/
4
5// import the concurrency and standard IO modules
6import std.concurrency, std.stdio;
7
8// main is just like main in C++
9void main()
10{
11 writeln("D Multithreaded Message Passing Example.");
12
13 // intialize some variable; the compiler can figure out the type from usage.
14 auto low=0, high = 100;
15
16 // launch a second thread using function receiver defined below.
17 auto rtid = spawn(&receiver);
18
19 // foreach iterates a range; in this case all values between
20 // low and high are assigned are assigned to i sequencially.
21 foreach (i; low .. high)
22 {
23 // sends a message to receiver using it's thread id; queue management is automatic.
24 rtid.send(i);
25 // report our action
26 writeln("Sent ", i);
27
28 }
29 writeln("** main() is complete **");
30}
31
32// receiver is a function which is run as a seperate thread by main.
33void receiver()
34{
35 writeln("** receiver() started. **");
36
37 // a variable for error checking.
38 auto lastid = -1;
39
40 // function to handle messages
41 void int_handler(int i)
42 {
43 // just print a line and record the last id received
44 writeln(" Received ",i);
45 lastid = i;
46 }
47
48 // Loop until we the parent shuts down.
49 bool running = true;
50 while (running)
51 {
52 receive
53 (
54 // handler for int messages
55 (int msg) { int_handler(msg); },
56 // handler for "owner terminated" exception
57 (OwnerTerminated e) { running = false; }
58 );
59 }
60
61 // quick check to be sure we got them all.
62 assert(lastid == 99);
63 writeln("** receiver() is complete. **");
64}
0\ No newline at end of file65\ No newline at end of file
166
=== 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'

Subscribers

People subscribed via source and target branches

to all changes: