Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
17d3b32c
Commit
17d3b32c
authored
Jan 31, 2015
by
Sven Gestegård Robertz
Browse files
added handling for type bindings in Java
parent
1d01446e
Changes
6
Hide whitespace changes
Inline
Side-by-side
examples/user_types/Decoder.java
View file @
17d3b32c
...
...
@@ -4,13 +4,15 @@ import java.io.InputStream;
import
se.lth.control.labcomm.DecoderChannel
;
import
se.lth.control.labcomm.Typedef
;
import
se.lth.control.labcomm.TypeBinding
;
public
class
Decoder
implements
twoLines
.
Handler
,
twoInts
.
Handler
,
theFirstInt
.
Handler
,
theSecondInt
.
Handler
,
Typedef
.
Handler
Typedef
.
Handler
,
TypeBinding
.
Handler
{
...
...
@@ -25,6 +27,7 @@ public class Decoder
theFirstInt
.
register
(
decoder
,
this
);
theSecondInt
.
register
(
decoder
,
this
);
Typedef
.
register
(
decoder
,
this
);
TypeBinding
.
register
(
decoder
,
this
);
try
{
System
.
out
.
println
(
"Running decoder."
);
...
...
@@ -46,6 +49,10 @@ public class Decoder
System
.
out
.
println
(
"Got Typedef: "
+
d
.
getName
()+
"("
+
d
.
getIndex
()+
")"
);
}
public
void
handle_TypeBinding
(
TypeBinding
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
println
(
"Got TypeBinding: "
+
d
.
getSampleIndex
()+
" --> "
+
d
.
getTypeIndex
()+
""
);
}
public
void
handle_twoInts
(
twoInts
d
)
throws
java
.
io
.
IOException
{
System
.
out
.
print
(
"Got twoInts: "
);
System
.
out
.
println
(
d
.
a
+
", "
+
d
.
b
);
...
...
lib/java/Makefile
View file @
17d3b32c
...
...
@@ -11,6 +11,7 @@ MODULES=Constant \
SampleHandler
\
SampleType
\
Typedef
\
TypeBinding
\
Writer
\
WriterWrapper
...
...
lib/java/se/lth/control/labcomm/DecoderChannel.java
View file @
17d3b32c
...
...
@@ -55,10 +55,15 @@ public class DecoderChannel implements Decoder {
}
private
void
processTypeBinding
(
int
len
)
throws
IOException
{
try
{
processSample
(
Constant
.
TYPE_BINDING
);
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
ex
.
getMessage
());
//System.err.println("Got TypeBinding: skipping "+len+" bytes");
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
decodeByte
();
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
decodeByte
();
}
}
}
private
void
processPragma
(
int
len
)
throws
IOException
{
...
...
lib/java/se/lth/control/labcomm/DecoderRegistry.java
View file @
17d3b32c
...
...
@@ -103,6 +103,12 @@ public class DecoderRegistry {
byClass
.
put
(
dispatcher
.
getSampleClass
(),
e
);
byIndex
.
put
(
Integer
.
valueOf
(
Constant
.
TYPE_DEF
),
e
);
//System.out.println("LCDecoderRegistry.add("+e.getName()+", "+e.getIndex()+")");
}
else
if
(
dispatcher
.
getSampleClass
()
==
TypeBinding
.
class
){
Entry
e
=
new
Entry
(
dispatcher
,
handler
);
e
.
setIndex
(
Constant
.
TYPE_BINDING
);
byClass
.
put
(
dispatcher
.
getSampleClass
(),
e
);
byIndex
.
put
(
Integer
.
valueOf
(
Constant
.
TYPE_BINDING
),
e
);
//System.out.println("LCDecoderRegistry.add("+e.getName()+", "+e.getIndex()+")");
}
else
{
Entry
e
=
byClass
.
get
(
dispatcher
.
getSampleClass
());
if
(
e
!=
null
)
{
...
...
lib/java/se/lth/control/labcomm/TypeBinding.java
0 → 100644
View file @
17d3b32c
package
se.lth.control.labcomm
;
import
java.io.IOException
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayInputStream
;
import
se.lth.control.labcomm.Decoder
;
import
se.lth.control.labcomm.DecoderChannel
;
import
se.lth.control.labcomm.SampleDispatcher
;
import
se.lth.control.labcomm.SampleHandler
;
public
class
TypeBinding
implements
SampleType
{
private
int
sampleIndex
;
private
int
typeIndex
;
public
int
getSampleIndex
()
{
return
sampleIndex
;
}
public
int
getTypeIndex
()
{
return
typeIndex
;
}
public
TypeBinding
(
int
sampleIndex
,
int
typeIndex
)
{
this
.
sampleIndex
=
sampleIndex
;
this
.
typeIndex
=
typeIndex
;
}
public
interface
Handler
extends
SampleHandler
{
public
void
handle_TypeBinding
(
TypeBinding
value
)
throws
Exception
;
}
public
static
void
register
(
Decoder
d
,
Handler
h
)
throws
IOException
{
d
.
register
(
Dispatcher
.
singleton
(),
h
);
}
public
static
void
register
(
Encoder
e
)
throws
IOException
{
register
(
e
,
false
);
}
public
static
void
register
(
Encoder
e
,
boolean
sendMetaData
)
throws
IOException
{
throw
new
IOException
(
"cannot send TypeDefs"
);
}
static
class
Dispatcher
implements
SampleDispatcher
<
TypeBinding
>
{
private
static
Dispatcher
singleton
;
public
synchronized
static
Dispatcher
singleton
()
{
if
(
singleton
==
null
)
singleton
=
new
Dispatcher
();
return
singleton
;
}
public
Class
<
TypeBinding
>
getSampleClass
()
{
return
TypeBinding
.
class
;
}
public
String
getName
()
{
return
"TypeBinding"
;
}
public
byte
getTypeDeclTag
()
{
throw
new
Error
(
"Should not be called"
);
}
public
boolean
isSample
()
{
throw
new
Error
(
"Should not be called"
);
}
public
boolean
hasStaticSignature
()
{
throw
new
Error
(
"Should not be called"
);
}
/** return the flat signature. Intended use is on decoder side */
public
byte
[]
getSignature
()
{
return
null
;
// not used for matching
}
public
void
encodeTypeDef
(
Encoder
e
,
int
index
)
throws
IOException
{
throw
new
Error
(
"Should not be called"
);
}
// public boolean canDecodeAndHandle() {
// return true;
// }
public
void
decodeAndHandle
(
Decoder
d
,
SampleHandler
h
)
throws
Exception
{
((
Handler
)
h
).
handle_TypeBinding
(
TypeBinding
.
decode
(
d
));
}
public
boolean
hasDependencies
()
{
return
false
;
}
}
public
static
void
encode
(
Encoder
e
,
TypeBinding
value
)
throws
IOException
{
throw
new
Error
(
"Should not be called"
);
}
public
static
TypeBinding
decode
(
Decoder
d
)
throws
IOException
{
TypeBinding
result
;
int
sampleIndex
=
d
.
decodePacked32
();
int
typeIndex
=
d
.
decodePacked32
();
result
=
new
TypeBinding
(
sampleIndex
,
typeIndex
);
return
result
;
}
}
lib/java/se/lth/control/labcomm2006/TypeBinding.java
0 → 100644
View file @
17d3b32c
public
class
TypeBinding
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment