Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tommy Olofsson
LabComm
Commits
c75c4deb
Commit
c75c4deb
authored
Jan 29, 2015
by
Tommy Olofsson
Browse files
Restructured DecoderChannel to be easier to subclass.
parent
c6627bc8
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/java/Makefile
View file @
c75c4deb
MODULES
=
Constant
\
Decoder
\
DecoderChannel
\
DynamicDecoderChannel
\
DecoderRegistry
\
Encoder
\
EncoderChannel
\
...
...
lib/java/se/lth/control/labcomm/DecoderChannel.java
View file @
c75c4deb
...
...
@@ -8,9 +8,9 @@ import java.io.EOFException;
public
class
DecoderChannel
implements
Decoder
{
pr
ivate
DataInputStream
in
;
pr
ivate
DecoderRegistry
def_registry
=
new
DecoderRegistry
();
pr
ivate
DecoderRegistry
ref_registry
=
new
DecoderRegistry
();
pr
otected
DataInputStream
in
;
pr
otected
DecoderRegistry
def_registry
=
new
DecoderRegistry
();
pr
otected
DecoderRegistry
ref_registry
=
new
DecoderRegistry
();
public
DecoderChannel
(
InputStream
in
)
throws
IOException
{
this
.
in
=
new
DataInputStream
(
in
);
...
...
@@ -55,9 +55,38 @@ public class DecoderChannel implements Decoder {
}
}
protected
void
processSample
(
int
tag
)
throws
Exception
{
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
tag
);
if
(
e
==
null
)
{
throw
new
IOException
(
"Unhandled tag "
+
tag
);
}
SampleDispatcher
d
=
e
.
getDispatcher
();
if
(
d
==
null
)
{
throw
new
IOException
(
"No dispatcher for '"
+
e
.
getName
()
+
"'"
);
}
SampleHandler
h
=
e
.
getHandler
();
if
(
h
==
null
)
{
throw
new
IOException
(
"No handler for '"
+
e
.
getName
()
+
"'"
);
}
d
.
decodeAndHandle
(
this
,
h
);
}
public
void
runOne
()
throws
Exception
{
boolean
done
=
false
;
while
(!
done
)
{
runOne
(
true
);
}
/**
* Run the decoder.
*
* @param waitForSample Wether to wait until an actual sample has
* been decoded or to return after any complete entity has
* been decoded. Set to <code>true</code> to get the old
* behaviour.
*/
public
void
runOne
(
boolean
waitForSample
)
throws
Exception
{
boolean
done
=
!
waitForSample
;
do
{
int
tag
=
decodePacked32
();
int
length
=
decodePacked32
();
switch
(
tag
)
{
...
...
@@ -84,23 +113,11 @@ public class DecoderChannel implements Decoder {
processPragma
(
length
);
}
break
;
default
:
{
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
tag
);
if
(
e
==
null
)
{
throw
new
IOException
(
"Unhandled tag "
+
tag
);
}
SampleDispatcher
d
=
e
.
getDispatcher
();
if
(
d
==
null
)
{
throw
new
IOException
(
"No dispatcher for '"
+
e
.
getName
()
+
"'"
);
}
SampleHandler
h
=
e
.
getHandler
();
if
(
h
==
null
)
{
throw
new
IOException
(
"No handler for '"
+
e
.
getName
()
+
"'"
);
}
d
.
decodeAndHandle
(
this
,
h
);
processSample
(
tag
);
done
=
true
;
}
}
}
}
while
(!
done
);
}
public
void
run
()
throws
Exception
{
...
...
lib/java/se/lth/control/labcomm/DynamicDecoderChannel.java
0 → 100644
View file @
c75c4deb
package
se.lth.control.labcomm
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
DynamicDecoderChannel
extends
DecoderChannel
{
public
DynamicDecoderChannel
(
InputStream
in
)
throws
IOException
{
super
(
in
);
}
public
void
runOne
()
throws
Exception
{
runOne
(
false
);
}
protected
void
processSample
(
int
tag
)
throws
Exception
{
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
tag
);
if
(
e
==
null
)
throw
new
IOException
(
"Have not read any registration for "
+
tag
);
SampleDispatcher
d
=
e
.
getDispatcher
();
if
(
d
!=
null
)
{
SampleHandler
h
=
e
.
getHandler
();
if
(
h
==
null
)
throw
new
IOException
(
"No handler for '"
+
e
.
getName
()
+
"'"
);
d
.
decodeAndHandle
(
this
,
h
);
}
else
{
dynamicDecode
();
}
}
private
void
dynamicDecode
()
{
throw
new
UnsupportedOperationException
(
"Dynamic decoding not implemented yet."
);
}
}
lib/java/se/lth/control/labcomm2006/DynamicDecoderChannel.java
0 → 100644
View file @
c75c4deb
package
se.lth.control.labcomm2006
;
import
java.io.IOException
;
import
java.io.InputStream
;
public
class
DynamicDecoderChannel
extends
DecoderChannel
{
public
DynamicDecoderChannel
(
InputStream
in
)
throws
IOException
{
super
(
in
);
throw
new
UnsupportedOperationException
(
"Use 2014."
);
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment