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
1=== added directory 'D_lang'
2=== added file 'D_lang/Makefile'
3--- D_lang/Makefile 1970-01-01 00:00:00 +0000
4+++ D_lang/Makefile 2012-10-17 11:54:28 +0000
5@@ -0,0 +1,27 @@
6+#***********************************************
7+#This file is part of the NRTB project (https://launchpad.net/nrtb).
8+#
9+# NRTB is free software: you can redistribute it and/or modify
10+# it under the terms of the GNU General Public License as published by
11+# the Free Software Foundation, either version 3 of the License, or
12+# (at your option) any later version.
13+#
14+# NRTB is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License
20+# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
21+#
22+#***********************************************
23+
24+build_all: Makefile
25+ @make action=lib doit
26+
27+clean:
28+ @make action=clean doit
29+ @rm -fv lib/* bin/*
30+
31+doit:
32+ @cd common; make ${action}
33
34=== added directory 'D_lang/bin'
35=== added directory 'D_lang/common'
36=== added file 'D_lang/common/Makefile'
37--- D_lang/common/Makefile 1970-01-01 00:00:00 +0000
38+++ D_lang/common/Makefile 2012-10-17 11:54:28 +0000
39@@ -0,0 +1,35 @@
40+#***********************************************
41+# This file is part of the NRTB project (https://launchpad.net/nrtb).
42+#
43+# NRTB is free software: you can redistribute it and/or modify
44+# it under the terms of the GNU General Public License as published by
45+# the Free Software Foundation, either version 3 of the License, or
46+# (at your option) any later version.
47+#
48+# NRTB is distributed in the hope that it will be useful,
49+# but WITHOUT ANY WARRANTY; without even the implied warranty of
50+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+# GNU General Public License for more details.
52+#
53+# You should have received a copy of the GNU General Public License
54+# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
55+#
56+#***********************************************
57+
58+lib: ../lib/common.a
59+
60+../lib/common.a: test
61+ @echo building ${modules}
62+ @cd nrtb/common; dmd -lib -release -of../../../lib/common.a *.d -I../../
63+ @echo " ********* common build complete ***********"
64+
65+test: Makefile common.d ${modules}
66+ @echo testing ${modules}
67+ @cd nrtb/common; dmd -unittest -lib -of../../common.a *.d -I../../
68+ @dmd -unittest common.a -run common.d
69+
70+clean:
71+ @rm -vf ../lib/common.a common *.o *.a
72+ @echo all objects and executables have been erased.
73+
74+modules=`find nrtb/common -type f -name \*.d`
75\ No newline at end of file
76
77=== added file 'D_lang/common/common.d'
78--- D_lang/common/common.d 1970-01-01 00:00:00 +0000
79+++ D_lang/common/common.d 2012-10-17 11:54:28 +0000
80@@ -0,0 +1,25 @@
81+/***********************************************
82+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
83+
84+ NRTB is free software: you can redistribute it and/or modify
85+ it under the terms of the GNU General Public License as published by
86+ the Free Software Foundation, either version 3 of the License, or
87+ (at your option) any later version.
88+
89+ NRTB is distributed in the hope that it will be useful,
90+ but WITHOUT ANY WARRANTY; without even the implied warranty of
91+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92+ GNU General Public License for more details.
93+
94+ You should have received a copy of the GNU General Public License
95+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
96+
97+**********************************************/
98+
99+import std.stdio;
100+import nrtb.common.vect3d;
101+
102+void main()
103+{
104+ writeln(" ******** NRTB Common Libs Unit Test Complete ********");
105+}
106\ No newline at end of file
107
108=== added directory 'D_lang/common/docs'
109=== added file 'D_lang/common/docs/common.html'
110--- D_lang/common/docs/common.html 1970-01-01 00:00:00 +0000
111+++ D_lang/common/docs/common.html 2012-10-17 11:54:28 +0000
112@@ -0,0 +1,10 @@
113+<html><head>
114+ <META http-equiv="content-type" content="text/html; charset=utf-8">
115+ <title>common</title>
116+ </head><body>
117+ <h1>common</h1>
118+ <!-- Generated by Ddoc from common.d -->
119+<br><br>
120+
121+ <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small>
122+ </body></html>
123
124=== added file 'D_lang/common/docs/vect3d.html'
125--- D_lang/common/docs/vect3d.html 1970-01-01 00:00:00 +0000
126+++ D_lang/common/docs/vect3d.html 2012-10-17 11:54:28 +0000
127@@ -0,0 +1,80 @@
128+<html><head>
129+ <META http-equiv="content-type" content="text/html; charset=utf-8">
130+ <title>vect3d</title>
131+ </head><body>
132+ <h1>vect3d</h1>
133+ <!-- Generated by Ddoc from vect3d/vect3d.d -->
134+<br><br>
135+<dl><dt><big>struct <u>vect3d</u>;
136+</big></dt>
137+<dd>Defines a point or vector in cartesian 3d space. Most binary math
138+ operators shoould work
139+ with both <u>vect3d</u> and real arguments, but only +, -, *, / and simple
140+ assignment and equality are unit tested here. Note that operators
141+ return the simple calculated results; dot product and vector product
142+ are provided as discrete method calls.
143+<br><br>
144+Also provided are the common vector operations
145+ vector_product,
146+ dot_product,
147+ magnitude,
148+ range (distance between points),
149+ and normalize (scales to magnitude 1.0).<br><br>
150+
151+<dl><dt><big>this(ref vect3d);
152+</big></dt>
153+<dd>blt copy override to avoid binding accidently.<br><br>
154+
155+</dd>
156+<dt><big>this(const(real[]) <i>a</i>);
157+</big></dt>
158+<dd>Construct from <i>a</i> real array. Only arrays of length 3 are acceptable.<br><br>
159+
160+</dd>
161+<dt><big>this(const(real) <i>a</i>);
162+</big></dt>
163+<dd>Construct from <i>a</i> single real. All three elements will be assigned the
164+ same value.<br><br>
165+
166+</dd>
167+<dt><big>this(const(real) <i>x</i>, real <i>y</i>, real <i>z</i>);
168+</big></dt>
169+<dd>Construct from 3 reals. They are assigned in the order presented.<br><br>
170+
171+</dd>
172+<dt><big>vec <u>values</u>();
173+</big></dt>
174+<dd>returns an array containing copies of the coordinates.<br><br>
175+
176+</dd>
177+<dt><big>real <u>magnitude</u>();
178+</big></dt>
179+<dd>returns the length (the <u>magnitude</u>) of the vector<br><br>
180+
181+</dd>
182+<dt><big>real <u>dot_product</u>(in vect3d <i>a</i>);
183+</big></dt>
184+<dd>returns the dot product<br><br>
185+
186+</dd>
187+<dt><big>vect3d <u>vector_product</u>(in vect3d <i>a</i>);
188+</big></dt>
189+<dd>returns the vector product<br><br>
190+
191+</dd>
192+<dt><big>real <u>range</u>(in vect3d <i>a</i>);
193+</big></dt>
194+<dd><u>range</u> returns the distance between two vect3d<br><br>
195+
196+</dd>
197+<dt><big>vect3d <u>normalize</u>();
198+</big></dt>
199+<dd>returns the normalized vector (scaled to length 1.0)<br><br>
200+
201+</dd>
202+</dl>
203+</dd>
204+</dl>
205+
206+ <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small>
207+ </body></html>
208
209=== added directory 'D_lang/common/nrtb'
210=== added directory 'D_lang/common/nrtb/common'
211=== added file 'D_lang/common/nrtb/common/GPB_transceiver.d'
212--- D_lang/common/nrtb/common/GPB_transceiver.d 1970-01-01 00:00:00 +0000
213+++ D_lang/common/nrtb/common/GPB_transceiver.d 2012-10-17 11:54:28 +0000
214@@ -0,0 +1,24 @@
215+/***********************************************
216+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
217+
218+ NRTB is free software: you can redistribute it and/or modify
219+ it under the terms of the GNU General Public License as published by
220+ the Free Software Foundation, either version 3 of the License, or
221+ (at your option) any later version.
222+
223+ NRTB is distributed in the hope that it will be useful,
224+ but WITHOUT ANY WARRANTY; without even the implied warranty of
225+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226+ GNU General Public License for more details.
227+
228+ You should have received a copy of the GNU General Public License
229+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
230+
231+ **********************************************/
232+
233+import std.socket;
234+
235+class gpb_transceiver
236+{
237+
238+}
239\ No newline at end of file
240
241=== added file 'D_lang/common/nrtb/common/conf_manager.d'
242--- D_lang/common/nrtb/common/conf_manager.d 1970-01-01 00:00:00 +0000
243+++ D_lang/common/nrtb/common/conf_manager.d 2012-10-17 11:54:28 +0000
244@@ -0,0 +1,123 @@
245+/***********************************************
246+ This file is part of the NRTB project (https://*launchpad.net/nrtb).
247+
248+ NRTB is free software: you can redistribute it and/or modify
249+ it under the terms of the GNU General Public License as published by
250+ the Free Software Foundation, either version 3 of the License, or
251+ (at your option) any later version.
252+
253+ NRTB is distributed in the hope that it will be useful,
254+ but WITHOUT ANY WARRANTY; without even the implied warranty of
255+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
256+ GNU General Public License for more details.
257+
258+ You should have received a copy of the GNU General Public License
259+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
260+
261+ **********************************************/
262+
263+import std.stdio;
264+import std.conv;
265+import std.array;
266+import std.getopt;
267+import std.string;
268+
269+/** Reads command line and configuration file information.
270+*
271+* For this NRTB implementation, this class is implemented as
272+* a singleton.
273+*
274+* Values read are stored in a multimap of name/value pairs and
275+* may be accessed via provided iterators, or directly via the
276+* [] operator, all(), get<T>() and getall<T>() methods. Automatic
277+* handling of include files and comments is provided as well. The
278+* get<>() and getall<>() template methods provide easy and complete
279+* access to all types that have the ">>" stream operator
280+* defined, including all the C++ standard types.
281+**/
282+
283+class conf_reader
284+{
285+ alias string[string] mylist;
286+
287+ this(string[] args)
288+ {
289+ string c_file = "nrtb.config";
290+ string c_path = ".";
291+ // get the traditional args.
292+ getopt(args,
293+ std.getopt.config.passThrough,
294+ "config_file", &c_file,
295+ "config_path", &c_path
296+ );
297+ // store off the program name
298+ values["__app_name"] = args[0];
299+ args = args[1 .. $];
300+ // process the includes first
301+ string[] pending;
302+ foreach(arg; args)
303+ {
304+ string[] tokens = split(arg,"=");
305+ if (tokens[0] == "include")
306+ load_file(tokens[1]);
307+ else
308+ pending ~= arg;
309+ }
310+ // process the remaining elements
311+ foreach(arg; pending)
312+ {
313+ string[] tokens = split(arg,"=");
314+ if (tokens.length == 1)
315+ {
316+ values[tokens[0]] = "1";
317+ }
318+ else if (tokens.length == 2)
319+ {
320+ values[tokens[0]] = tokens[1];
321+ }
322+ };
323+ }
324+
325+ private void load_file(in string file_name)
326+ {
327+ // need to add the logic to read files here.
328+ auto f = File(file_name, "r");
329+ scope(exit) {f.close();};
330+ foreach(string line; lines(f))
331+ {
332+ // trim for comments
333+ auto hash_index = indexOf(line,"#");
334+ if (hash_index != -1)
335+ line = line[0 .. hash_index];
336+ // if we have anything left, parse it.
337+ if (line != "")
338+ {
339+ // trim the string
340+ line = line.strip();
341+ // split on first whitespace
342+ for (auto i=0; i<line.length; i++)
343+ {
344+// if ((line[i] == " ") || (line[i] == "\t"))
345+ }
346+ // trim both sides
347+ // how do we store dups?
348+ }
349+ }
350+
351+ }
352+
353+ mylist get_list() { return values.dup; };
354+
355+ T get(T,E)(in string key,in E _default)
356+ if (typeof(T = E) == typeof(T))
357+ {
358+ if ((key in values) != null)
359+ return to!T(values[key]);
360+ else
361+ return _default;
362+ }
363+
364+ private mylist values;
365+
366+}
367+
368
369=== added file 'D_lang/common/nrtb/common/vect3d.d'
370--- D_lang/common/nrtb/common/vect3d.d 1970-01-01 00:00:00 +0000
371+++ D_lang/common/nrtb/common/vect3d.d 2012-10-17 11:54:28 +0000
372@@ -0,0 +1,150 @@
373+/***********************************************
374+This file is part of the NRTB project (https://launchpad.net/nrtb).
375+
376+ NRTB is free software: you can redistribute it and/or modify
377+ it under the terms of the GNU General Public License as published by
378+ the Free Software Foundation, either version 3 of the License, or
379+ (at your option) any later version.
380+
381+ NRTB is distributed in the hope that it will be useful,
382+ but WITHOUT ANY WARRANTY; without even the implied warranty of
383+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
384+ GNU General Public License for more details.
385+
386+ You should have received a copy of the GNU General Public License
387+ along with NRTB. If not, see <http://www.gnu.org/licenses/>.
388+
389+**********************************************/
390+
391+import std.stdio, std.math;
392+
393+/** Defines a point or vector in cartesian 3d space. Most binary math
394+ * operators shoould work
395+ * with both vect3d and real arguments, but only +, -, *, / and simple
396+ * assignment and equality are unit tested here. Note that operators
397+ * return the simple calculated results; dot product and vector product
398+ * are provided as discrete method calls.
399+ *
400+ * Also provided are the common vector operations
401+ * vector_product,
402+ * dot_product,
403+ * magnitude,
404+ * range (distance between points),
405+ * and normalize (scales to magnitude 1.0).
406+ **/
407+
408+struct vect3d
409+{
410+ alias real[3] vec;
411+ // vector
412+ private vec coords;
413+ /// blt copy override to avoid binding accidently.
414+ this(ref this) { coords = coords.dup; }
415+ /// Construct from a real array. Only arrays of length 3 are acceptable.
416+ this(in real[] a)
417+ {
418+ assert(a.length==3,"!! Invalid input length in vect3d.(T[] a).");
419+ coords[] = a[0 .. 3];
420+ }
421+ /// Construct from a single real. All three elements will be assigned the
422+ /// same value.
423+ this(in real a) { coords[] = a;}
424+ /// Construct from 3 reals. They are assigned in the order presented.
425+ this(in real x, real y, real z) { coords[0]=x; coords[1]=y; coords[2]=z;}
426+ /// returns an array containing copies of the coordinates.
427+ vec values() { vec v; v = coords.dup; return v; }
428+ /// returns the length (the magnitude) of the vector
429+ real magnitude()
430+ {
431+ real returnme = 0.0;
432+ foreach(val; coords) { returnme += (val*val); }
433+ return sqrt(returnme);
434+ }
435+ /// returns the dot product
436+ real dot_product(in vect3d a)
437+ {
438+ real returnme = 0.0;
439+ returnme += coords[0] * a.coords[0];
440+ returnme += coords[1] * a.coords[1];
441+ returnme += coords[2] * a.coords[2];
442+ return returnme;
443+ }
444+ /// returns the vector product
445+ vect3d vector_product(in vect3d a)
446+ {
447+ vect3d returnme;
448+ with (returnme)
449+ {
450+ coords[0] =
451+ (this.coords[1] * a.coords[2]) - (this.coords[2] * a.coords[1]);
452+ coords[1] =
453+ (this.coords[2] * a.coords[0]) - (this.coords[0] * a.coords[2]);
454+ coords[2] =
455+ (this.coords[0] * a.coords[1]) - (this.coords[1] * a.coords[0]);
456+ }
457+ return returnme;
458+ }
459+ /// range returns the distance between two vect3d
460+ real range(in vect3d a)
461+ {
462+ return (this - a).magnitude();
463+ }
464+ /// returns the normalized vector (scaled to length 1.0)
465+ vect3d normalize()
466+ {
467+ return this / magnitude();
468+ }
469+ // vect3d by vect3d operators
470+ vect3d opBinary(string op)(vect3d rhs)
471+ {
472+ vect3d v;
473+ mixin("v.coords[] = coords[] "~op~" rhs.coords[];");
474+ return v;
475+ }
476+ // vect3d by real operators
477+ vect3d opBinary(string op)(real rhs)
478+ {
479+ vect3d v;
480+ mixin("v.coords[] = coords[] "~op~" rhs;");
481+ return v;
482+ }
483+}
484+
485+unittest
486+{
487+ // test both literal constuctors
488+ auto a = vect3d(2);
489+ assert(a==vect3d(2,2,2));
490+ // test init from an array.
491+ real[] array = [2,3,4];
492+ auto at = vect3d(array);
493+ assert(at == vect3d(2,3,4));
494+ assert(at.values() == array);
495+ // test copying
496+ auto t=a;
497+ assert(t==vect3d(2,2,2));
498+ // test major vect3d by vect3d math
499+ auto b = vect3d(1,2,3);
500+ assert((b+a)==vect3d(3,4,5));
501+ assert((b-a)==vect3d(-1,0,1));
502+ assert((b*a)==vect3d(2,4,6));
503+ assert((b/a)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0));
504+ // test major vect3d by real math shifts and scales
505+ assert((b+1)==vect3d(2,3,4));
506+ assert((b-1)==vect3d(0,1,2));
507+ assert((b*2)==vect3d(2,4,6));
508+ assert((b/2.0)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0));
509+ // magnitude test
510+ assert(a.magnitude()==sqrt(2.0*2.0*3.0));
511+ // dot_product test
512+ assert(a.dot_product(a)==12.0);
513+ // vector_product test.
514+ assert(b.vector_product(a)==vect3d(-2,4,-2));
515+ assert(a.vector_product(a)==vect3d(0.0));
516+ // Range tests
517+ assert(a.range(a)==0.0);
518+ assert(approxEqual(a.range(b),1.41421));
519+ // normalize tests.
520+ assert(approxEqual(a.normalize().magnitude(),1.0));
521+ assert(approxEqual(b.normalize().magnitude(),1.0));
522+}
523
524=== added file 'D_lang/common/nrtb/common/zmq.d'
525--- D_lang/common/nrtb/common/zmq.d 1970-01-01 00:00:00 +0000
526+++ D_lang/common/nrtb/common/zmq.d 2012-10-17 11:54:28 +0000
527@@ -0,0 +1,236 @@
528+/*
529+ Copyright (c) 2007-2010 iMatix Corporation
530+
531+ This file is part of 0MQ.
532+
533+ 0MQ is free software; you can redistribute it and/or modify it under
534+ the terms of the GNU Lesser General Public License as published by
535+ the Free Software Foundation; either version 3 of the License, or
536+ (at your option) any later version.
537+
538+ 0MQ is distributed in the hope that it will be useful,
539+ but WITHOUT ANY WARRANTY; without even the implied warranty of
540+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
541+ GNU Lesser General Public License for more details.
542+
543+ You should have received a copy of the GNU Lesser General Public License
544+ along with this program. If not, see <http://www.gnu.org/licenses/>.
545+*/
546+module zmq;
547+
548+
549+extern (C)
550+{
551+
552+/******************************************************************************/
553+/* 0MQ versioning support. */
554+/******************************************************************************/
555+
556+/* Version macros for compile-time API version detection */
557+
558+enum
559+{
560+ ZMQ_VERSION_MAJOR =2,
561+ ZMQ_VERSION_MINOR =1,
562+ ZMQ_VERSION_PATCH =10
563+}
564+
565+/* Run-time API version detection */
566+void zmq_version(int* major, int* minor, int* patch);
567+
568+/******************************************************************************/
569+/* 0MQ errors. */
570+/******************************************************************************/
571+
572+/* A number random anough not to collide with different errno ranges on */
573+/* different OSes. The assumption is that error_t is at least 32-bit type. */
574+immutable enum
575+{
576+ ZMQ_HAUSNUMERO = 156384712,
577+
578+/* On Windows platform some of the standard POSIX errnos are not defined. */
579+ ENOTSUP = (ZMQ_HAUSNUMERO + 1),
580+ EPROTONOSUPPORT = (ZMQ_HAUSNUMERO + 2),
581+ ENOBUFS = (ZMQ_HAUSNUMERO + 3),
582+ ENETDOWN = (ZMQ_HAUSNUMERO + 4),
583+ EADDRINUSE = (ZMQ_HAUSNUMERO + 5),
584+ EADDRNOTAVAIL = (ZMQ_HAUSNUMERO + 6),
585+ ECONNREFUSED = (ZMQ_HAUSNUMERO + 7),
586+ EINPROGRESS = (ZMQ_HAUSNUMERO + 8),
587+ ENOTSOCK = (ZMQ_HAUSNUMERO + 9),
588+
589+/* Native 0MQ error codes. */
590+ EFSM = (ZMQ_HAUSNUMERO + 51),
591+ ENOCOMPATPROTO = (ZMQ_HAUSNUMERO + 52),
592+ ETERM = (ZMQ_HAUSNUMERO + 53),
593+ EMTHREAD = (ZMQ_HAUSNUMERO + 54)
594+}//enum error_code
595+
596+/* This function retrieves the errno as it is known to 0MQ library. The goal */
597+/* of this function is to make the code 100% portable, including where 0MQ */
598+/* compiled with certain CRT library (on Windows) is linked to an */
599+/* application that uses different CRT library. */
600+int zmq_errno();
601+
602+/* Resolves system errors and 0MQ errors to human-readable string. */
603+char* zmq_strerror(int errnum);
604+
605+/******************************************************************************/
606+/* 0MQ message definition. */
607+/******************************************************************************/
608+immutable enum
609+{
610+/* Maximal size of "Very Small Message". VSMs are passed by value */
611+/* to avoid excessive memory allocation/deallocation. */
612+/* If VMSs larger than 255 bytes are required, type of 'vsm_size' */
613+/* field in zmq_msg_t structure should be modified accordingly. */
614+ ZMQ_MAX_VSM_SIZE = 30,
615+
616+/* Message types. These integers may be stored in 'content' member of the */
617+/* message instead of regular pointer to the data. */
618+ ZMQ_DELIMITER = 31,
619+ ZMQ_VSM = 32,
620+
621+/* Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag */
622+/* (it has no equivalent in the wire format), however, making it a flag */
623+/* allows us to pack the stucture tigher and thus improve performance. */
624+ ZMQ_MSG_MORE = 1,
625+ ZMQ_MSG_SHARED = 128,
626+ ZMQ_MSG_MASK = 129
627+}
628+
629+/* A message. Note that 'content' is not a pointer to the raw data. */
630+/* Rather it is pointer to zmq::msg_content_t structure */
631+/* (see src/msg_content.hpp for its definition). */
632+struct zmq_msg_t
633+{
634+ void* content;
635+ ubyte flags;
636+ ubyte vsm_size;
637+ ubyte vsm_data[ZMQ_MAX_VSM_SIZE];
638+}
639+
640+int zmq_msg_init(zmq_msg_t* msg);
641+int zmq_msg_init_size(zmq_msg_t* msg, size_t size);
642+int zmq_msg_init_data(zmq_msg_t* msg, void* data,
643+ size_t size, void function(void* data, void* hint), void* hint);
644+int zmq_msg_close(zmq_msg_t* msg);
645+int zmq_msg_move(zmq_msg_t* dest, zmq_msg_t* src);
646+int zmq_msg_copy(zmq_msg_t* dest, zmq_msg_t* src);
647+void* zmq_msg_data(zmq_msg_t* msg);
648+size_t zmq_msg_size(zmq_msg_t* msg);
649+
650+/******************************************************************************/
651+/* 0MQ infrastructure (a.k.a. context) initialisation & termination. */
652+/******************************************************************************/
653+
654+void* zmq_init(int io_threads);
655+int zmq_term(void* context);
656+
657+/******************************************************************************/
658+/* 0MQ socket definition. */
659+/******************************************************************************/
660+
661+/* Socket types. */
662+immutable enum
663+{
664+ ZMQ_PAIR = 0,
665+ ZMQ_PUB = 1,
666+ ZMQ_SUB = 2,
667+ ZMQ_REQ = 3,
668+ ZMQ_REP = 4,
669+ ZMQ_DEALER = 5,
670+ ZMQ_ROUTER = 6,
671+ ZMQ_PULL = 7,
672+ ZMQ_PUSH = 8,
673+ ZMQ_XPUB = 9,
674+ ZMQ_XSUB = 10,
675+ ZMQ_XREQ = ZMQ_DEALER, /* Old alias, remove in 3.x */
676+ ZMQ_XREP = ZMQ_ROUTER, /* Old alias, remove in 3.x */
677+ ZMQ_UPSTREAM = ZMQ_PULL, /* Old alias, remove in 3.x */
678+ ZMQ_DOWNSTREAM = ZMQ_PUSH /* Old alias, remove in 3.x */
679+}
680+
681+/* Socket options. */
682+immutable enum
683+{
684+ ZMQ_HWM = 1,
685+ ZMQ_SWAP = 3,
686+ ZMQ_AFFINITY = 4,
687+ ZMQ_IDENTITY = 5,
688+ ZMQ_SUBSCRIBE = 6,
689+ ZMQ_UNSUBSCRIBE = 7,
690+ ZMQ_RATE = 8,
691+ ZMQ_RECOVERY_IVL = 9,
692+ ZMQ_MCAST_LOOP = 10,
693+ ZMQ_SNDBUF = 11,
694+ ZMQ_RCVBUF = 12,
695+ ZMQ_RCVMORE = 13,
696+ ZMQ_FD = 14,
697+ ZMQ_EVENTS = 15,
698+ ZMQ_TYPE = 16,
699+ ZMQ_LINGER = 17,
700+ ZMQ_RECONNECT_IVL = 18,
701+ ZMQ_BACKLOG = 19,
702+ ZMQ_RECOVERY_IVL_MSEC = 20, /*opt. recovery time, reconcile in 3.x */
703+ ZMQ_RECONNECT_IVL_MAX = 21
704+}
705+
706+/* Send/recv options. */
707+immutable enum
708+{
709+ ZMQ_NOBLOCK = 1,
710+ ZMQ_SNDMORE = 2
711+}
712+
713+void* zmq_socket(void* context, int type);
714+int zmq_close(void* s);
715+int zmq_setsockopt(void* s, int option, void* optval, size_t optvallen);
716+int zmq_getsockopt(void* s, int option, void* optval, size_t *optvallen);
717+int zmq_bind(void* s, const char* addr);
718+int zmq_connect(void* s, immutable char* addr);
719+int zmq_send(void* s, zmq_msg_t* msg, int flags);
720+int zmq_recv(void* s, zmq_msg_t* msg, int flags);
721+
722+/******************************************************************************/
723+/* I/O multiplexing. */
724+/******************************************************************************/
725+
726+immutable enum
727+{
728+ ZMQ_POLLIN = 1,
729+ ZMQ_POLLOUT = 2,
730+ ZMQ_POLLERR = 4
731+}
732+
733+__gshared struct zmq_pollitem_t
734+{
735+ void* socket;
736+ version (win32)
737+ {
738+ SOCKET fd;
739+ }
740+ else
741+ {
742+ int fd;
743+ }
744+ short events;
745+ short revents;
746+}
747+
748+int zmq_poll(zmq_pollitem_t* items, int nitems, long timeout);
749+
750+/******************************************************************************/
751+/* Built-in devices */
752+/******************************************************************************/
753+
754+immutable enum
755+{
756+ ZMQ_STREAMER = 1,
757+ ZMQ_FORWARDER = 2,
758+ ZMQ_QUEUE = 3
759+}
760+
761+int zmq_device(int device, void* insocket, void* outsocket);
762+
763+}// extern (C)
764
765=== added file 'D_lang/common/nrtb/common/zmq_utils.d'
766--- D_lang/common/nrtb/common/zmq_utils.d 1970-01-01 00:00:00 +0000
767+++ D_lang/common/nrtb/common/zmq_utils.d 2012-10-17 11:54:28 +0000
768@@ -0,0 +1,58 @@
769+/*
770+ Copyright (c) 2007-2011 iMatix Corporation
771+ Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
772+
773+ This file is part of 0MQ.
774+
775+ 0MQ is free software; you can redistribute it and/or modify it under
776+ the terms of the GNU Lesser General Public License as published by
777+ the Free Software Foundation; either version 3 of the License, or
778+ (at your option) any later version.
779+
780+ 0MQ is distributed in the hope that it will be useful,
781+ but WITHOUT ANY WARRANTY; without even the implied warranty of
782+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
783+ GNU Lesser General Public License for more details.
784+
785+ You should have received a copy of the GNU Lesser General Public License
786+ along with this program. If not, see <http://www.gnu.org/licenses/>.
787+*/
788+
789+module zmq_utils;
790+
791+extern (C)
792+{
793+
794+/*Handle DSO symbol visibility */
795+/++
796+#if defined _WIN32
797+# if defined DLL_EXPORT
798+# define ZMQ_EXPORT __declspec(dllexport)
799+# else
800+# define ZMQ_EXPORT __declspec(dllimport)
801+# endif
802+#else
803+# if defined __SUNPRO_C || defined __SUNPRO_CC
804+# define ZMQ_EXPORT __global
805+# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
806+# define ZMQ_EXPORT __attribute__ ((visibility("default")))
807+# else
808+# define ZMQ_EXPORT
809+# endif
810+#endif
811+++/
812+
813+/* Helper functions are used by perf tests so that they don't have to care */
814+/* about minutiae of time-related functions on different OS platforms. */
815+
816+/* Starts the stopwatch. Returns the handle to the watch. */
817+void* zmq_stopwatch_start();
818+
819+/* Stops the stopwatch. Returns the number of microseconds elapsed since */
820+/* the stopwatch was started. */
821+ulong zmq_stopwatch_stop(void* watch_);
822+
823+/* Sleeps for specified number of seconds. */
824+void zmq_sleep(int seconds_);
825+
826+}
827
828=== added directory 'D_lang/lib'
829=== added directory 'D_lang/testing'
830=== added directory 'D_lang/testing/threads'
831=== added file 'D_lang/testing/threads/Makefile'
832--- D_lang/testing/threads/Makefile 1970-01-01 00:00:00 +0000
833+++ D_lang/testing/threads/Makefile 2012-10-17 11:54:28 +0000
834@@ -0,0 +1,30 @@
835+#***********************************************
836+# This file is part of the NRTB project (https://launchpad.net/nrtb).
837+#
838+# NRTB is free software: you can redistribute it and/or modify
839+# it under the terms of the GNU General Public License as published by
840+# the Free Software Foundation, either version 3 of the License, or
841+# (at your option) any later version.
842+#
843+# NRTB is distributed in the hope that it will be useful,
844+# but WITHOUT ANY WARRANTY; without even the implied warranty of
845+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
846+# GNU General Public License for more details.
847+#
848+# You should have received a copy of the GNU General Public License
849+# along with NRTB. If not, see <http://www.gnu.org/licenses/>.
850+#
851+#***********************************************
852+
853+lib: msg_passing
854+ @./msg_passing
855+ @echo build complete
856+
857+msg_passing: msg_passing.d Makefile
858+ @rm -f msg_passing
859+ @dmd msg_passing.d
860+
861+clean:
862+ @rm -vf *.o msg_passing
863+ @echo all objects and executables have been erased.
864+
865
866=== added file 'D_lang/testing/threads/msg_passing.d'
867--- D_lang/testing/threads/msg_passing.d 1970-01-01 00:00:00 +0000
868+++ D_lang/testing/threads/msg_passing.d 2012-10-17 11:54:28 +0000
869@@ -0,0 +1,64 @@
870+/*********************
871+Multithreaded message passing example in D
872+*********************/
873+
874+// import the concurrency and standard IO modules
875+import std.concurrency, std.stdio;
876+
877+// main is just like main in C++
878+void main()
879+{
880+ writeln("D Multithreaded Message Passing Example.");
881+
882+ // intialize some variable; the compiler can figure out the type from usage.
883+ auto low=0, high = 100;
884+
885+ // launch a second thread using function receiver defined below.
886+ auto rtid = spawn(&receiver);
887+
888+ // foreach iterates a range; in this case all values between
889+ // low and high are assigned are assigned to i sequencially.
890+ foreach (i; low .. high)
891+ {
892+ // sends a message to receiver using it's thread id; queue management is automatic.
893+ rtid.send(i);
894+ // report our action
895+ writeln("Sent ", i);
896+
897+ }
898+ writeln("** main() is complete **");
899+}
900+
901+// receiver is a function which is run as a seperate thread by main.
902+void receiver()
903+{
904+ writeln("** receiver() started. **");
905+
906+ // a variable for error checking.
907+ auto lastid = -1;
908+
909+ // function to handle messages
910+ void int_handler(int i)
911+ {
912+ // just print a line and record the last id received
913+ writeln(" Received ",i);
914+ lastid = i;
915+ }
916+
917+ // Loop until we the parent shuts down.
918+ bool running = true;
919+ while (running)
920+ {
921+ receive
922+ (
923+ // handler for int messages
924+ (int msg) { int_handler(msg); },
925+ // handler for "owner terminated" exception
926+ (OwnerTerminated e) { running = false; }
927+ );
928+ }
929+
930+ // quick check to be sure we got them all.
931+ assert(lastid == 99);
932+ writeln("** receiver() is complete. **");
933+}
934\ No newline at end of file
935
936=== added directory 'obsolete'
937=== added directory 'obsolete/Cpp'
938=== renamed directory 'common' => 'obsolete/Cpp/common'
939=== renamed directory 'plugins' => 'obsolete/Cpp/plugins'
940=== renamed directory 'sim_engine' => 'obsolete/Cpp/sim_engine'

Subscribers

People subscribed via source and target branches

to all changes: