Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
LabComm
Commits
b7760998
Commit
b7760998
authored
11 years ago
by
Sven Robertz
Browse files
Options
Downloads
Patches
Plain Diff
more cleanup and doc
parent
1562625c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/dynamic/README
+1
-0
1 addition, 0 deletions
examples/dynamic/README
examples/dynamic/TestLabcommGen.java
+50
-27
50 additions, 27 deletions
examples/dynamic/TestLabcommGen.java
with
51 additions
and
27 deletions
examples/dynamic/README
+
1
−
0
View file @
b7760998
...
...
@@ -31,3 +31,4 @@ bar:handler(int value) {
System.out.println(value);
}###
Note that parameters differ: the value for foo is an object but for bar it is a primitive type (int) value.
This diff is collapsed.
Click to expand it.
examples/dynamic/TestLabcommGen.java
+
50
−
27
View file @
b7760998
import
java.io.ByteArrayInputStream
;
import
java.io.EOFException
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
...
...
@@ -28,6 +29,7 @@ import beaver.Parser.Exception;
public
class
TestLabcommGen
{
private
static
final
String
SAMPLE_NAME_FOO
=
"foo"
;
private
static
final
String
SAMPLE_NAME_BAR
=
"bar"
;
static
class
HandlerSrc
{
private
String
sampleName
;
...
...
@@ -78,8 +80,8 @@ public class TestLabcommGen {
String
tmpFile
=
args
[
2
];
System
.
out
.
println
(
"*** Testing writing and reading file "
+
tmpFile
);
encodeTest
(
irc
,
SAMPLE_NAME_FOO
,
tmpFile
);
decodeTest
(
irc
,
SAMPLE_NAME_FOO
,
tmpFile
);
encodeTest
(
irc
,
tmpFile
);
decodeTest
(
irc
,
tmpFile
,
SAMPLE_NAME_FOO
,
SAMPLE_NAME_BAR
);
}
}
public
static
void
generateHandlers
(
String
srcStr
,
HashMap
<
String
,
String
>
handlers
)
{
...
...
@@ -239,21 +241,28 @@ public class TestLabcommGen {
}
/** test method
*/
private
static
void
decodeTest
(
InRAMCompiler
irc
,
String
sampleName
,
String
tmpFile
)
{
private
static
void
decodeTest
(
InRAMCompiler
irc
,
String
tmpFile
,
String
...
sampleNames
)
{
try
{
FileInputStream
in
=
new
FileInputStream
(
tmpFile
);
LabCommDecoderChannel
dec
=
new
LabCommDecoderChannel
(
in
);
for
(
String
sampleName
:
sampleNames
)
{
System
.
out
.
println
(
"registering handler for "
+
sampleName
);
Class
sampleClass
=
irc
.
load
(
sampleName
);
Class
handlerClass
=
irc
.
load
(
"gen_"
+
sampleName
+
"Handler"
);
Class
handlerInterface
=
irc
.
load
(
sampleName
+
"$Handler"
);
Class
fc
=
irc
.
load
(
sampleName
);
Class
hc
=
irc
.
load
(
"gen_"
+
sampleName
+
"Handler"
);
Class
hi
=
irc
.
load
(
sampleName
+
"$Handler"
);
Object
handler
=
handlerClass
.
newInstance
();
Object
h
=
hc
.
newInstance
();
Method
reg
=
fc
.
getDeclaredMethod
(
"register"
,
LabCommDecoder
.
class
,
hi
);
reg
.
invoke
(
fc
,
dec
,
h
);
Method
reg
=
sampleClass
.
getDeclaredMethod
(
"register"
,
LabCommDecoder
.
class
,
handlerInterface
);
reg
.
invoke
(
sampleClass
,
dec
,
handler
);
}
dec
.
runOne
();
try
{
System
.
out
.
println
(
"*** decoding:"
);
dec
.
run
();
}
catch
(
EOFException
e
)
{
System
.
out
.
println
(
"*** reached EOF ***"
);
}
in
.
close
();
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
...
...
@@ -262,10 +271,14 @@ public class TestLabcommGen {
}
/** test encoding
*/
private
static
void
encodeTest
(
InRAMCompiler
irc
,
String
sampleName
,
String
tmpFile
)
{
private
static
void
encodeTest
(
InRAMCompiler
irc
,
String
tmpFile
)
{
try
{
Class
fc
=
irc
.
load
(
sampleName
);
Class
fc
=
irc
.
load
(
SAMPLE_NAME_FOO
);
Class
bc
=
irc
.
load
(
SAMPLE_NAME_BAR
);
/* create sample class and instance objects */
Object
f
=
fc
.
newInstance
();
Field
x
=
fc
.
getDeclaredField
(
"x"
);
Field
y
=
fc
.
getDeclaredField
(
"y"
);
Field
z
=
fc
.
getDeclaredField
(
"z"
);
...
...
@@ -273,13 +286,23 @@ public class TestLabcommGen {
y
.
setInt
(
f
,
11
);
z
.
setInt
(
f
,
12
);
FileOutputStream
out
=
new
FileOutputStream
(
tmpFile
);
LabCommEncoderChannel
enc
=
new
LabCommEncoderChannel
(
out
);
Method
reg
=
fc
.
getDeclaredMethod
(
"register"
,
LabCommEncoder
.
class
);
reg
.
invoke
(
fc
,
enc
);
Method
doEncode
=
fc
.
getDeclaredMethod
(
"encode"
,
LabCommEncoder
.
class
,
fc
);
doEncode
.
invoke
(
fc
,
enc
,
f
);
/* register and send foo */
Method
regFoo
=
fc
.
getDeclaredMethod
(
"register"
,
LabCommEncoder
.
class
);
regFoo
.
invoke
(
fc
,
enc
);
Method
doEncodeFoo
=
fc
.
getDeclaredMethod
(
"encode"
,
LabCommEncoder
.
class
,
fc
);
doEncodeFoo
.
invoke
(
fc
,
enc
,
f
);
/* register and send bar (NB! uses primitive type int) */
Method
regBar
=
bc
.
getDeclaredMethod
(
"register"
,
LabCommEncoder
.
class
);
regBar
.
invoke
(
bc
,
enc
);
Method
doEncodeBar
=
bc
.
getDeclaredMethod
(
"encode"
,
LabCommEncoder
.
class
,
Integer
.
TYPE
);
doEncodeBar
.
invoke
(
bc
,
enc
,
42
);
out
.
close
();
}
catch
(
Throwable
e
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment