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
e32f8e9e
Commit
e32f8e9e
authored
Nov 27, 2013
by
Sven Gestegård Robertz
Browse files
added Java server and client to jgrafchart test
parent
fdfd3146
Changes
9
Show whitespace changes
Inline
Side-by-side
examples/jgrafchart/Makefile
View file @
e32f8e9e
#SAMPLENAME=foo
LCFILE
=
jg
LCDIR
=
../..
LCC
=
java
-jar
${LCDIR}
/compiler/labComm.jar
CLASSPATH
=
.:
${LCDIR}
/lib/java/labcomm.jar
JAVA_PKG
=
labcommTCPtest
SAMPLENAME
=
foo
LCC
=
java
-jar
${LCDIR}
/compiler/labComm.jar
LCLIBDIR
=
${LCDIR}
/lib/c
LCFILE
=
jg
AUX
=
enc.c dec.c
${JAVA_PKG}/gen/foo.java
:
${LCFILE}.lc
${LCC}
--javapackage
=
${JAVA_PKG}
.gen
--java
=
${JAVA_PKG}
/gen
$<
${JAVA_PKG}/gen/${SAMPLENAME}.class
:
${JAVA_PKG}/gen/${SAMPLENAME}.java
javac
-cp
${CLASSPATH}
$<
${JAVA_PKG}/server/TestServer.class
:
${JAVA_PKG}/server/TestServer.java ${JAVA_PKG}/gen/${SAMPLENAME}.class
javac
-cp
${CLASSPATH}
$<
${JAVA_PKG}/client/TestClient.class
:
${JAVA_PKG}/client/TestClient.java ${JAVA_PKG}/gen/${SAMPLENAME}.class
javac
-cp
${CLASSPATH}
$<
runjavaserver
:
${JAVA_PKG}/server/TestServer.class
java
-cp
${CLASSPATH}
$
(
<:.class
=)
runjavaclient
:
${JAVA_PKG}/client/TestClient.class
java
-cp
${CLASSPATH}
$
(
<:.class
=)
client
:
client.c ${LCFILE}.c ${AUX} ${AUX:.c=.h}
${CC}
-o
$@
client.c
${AUX}
${LCFILE}
.c
-I
${LCLIBDIR}
-L
${LCLIBDIR}
-llabcomm
...
...
@@ -14,10 +38,12 @@ testserver: testserver.c ${LCFILE}.c ${AUX} ${AUX:.c=.h}
${LCFILE}.c
:
${LCFILE}.lc
${LCC}
-C
${LCFILE}
.lc
all
:
client testserver ${JAVA_PKG}/server/TestServer.class ${JAVA_PKG}/client/TestClient.class
.PHONY
:
clean runclient
.PHONY
:
clean runclient
runserver runjavaserver runjavaclient
clean
:
rm
${LCFILE}
.c
${LCFILE}
.h client testserver
rm
${JAVA_PKG}
/server/
*
.class
${JAVA_PKG}
/client/
*
.class
${JAVA_PKG}
/gen/
*
runclient
:
client
LD_LIBRARY_PATH
=
${LCLIBDIR}
./
$<
localhost 9999
...
...
examples/jgrafchart/jg.c
deleted
100644 → 0
View file @
fdfd3146
#include "labcomm.h"
#include "labcomm_private.h"
#include "jg.h"
static
unsigned
char
signature_bytes_jg_foo
[]
=
{
// struct { 8 fields
17
,
8
,
// double 'b'
1
,
98
,
38
,
// int 'c'
1
,
99
,
35
,
// int 'd'
1
,
100
,
35
,
// string 'e'
1
,
101
,
39
,
// boolean 'f'
1
,
102
,
32
,
// short 'g'
1
,
103
,
34
,
// long 'h'
1
,
104
,
36
,
// float 'i'
1
,
105
,
37
,
// }
};
struct
labcomm_signature
labcomm_signature_jg_foo
=
{
LABCOMM_SAMPLE
,
"foo"
,
(
int
(
*
)(
struct
labcomm_signature
*
,
void
*
))
labcomm_sizeof_jg_foo
,
sizeof
(
signature_bytes_jg_foo
),
signature_bytes_jg_foo
,
0
};
static
void
decode_jg_foo
(
struct
labcomm_reader
*
r
,
void
(
*
handle
)(
jg_foo
*
v
,
void
*
context
),
void
*
context
)
{
jg_foo
v
;
v
.
b
=
labcomm_read_double
(
r
);
v
.
c
=
labcomm_read_int
(
r
);
v
.
d
=
labcomm_read_int
(
r
);
v
.
e
=
labcomm_read_string
(
r
);
v
.
f
=
labcomm_read_boolean
(
r
);
v
.
g
=
labcomm_read_short
(
r
);
v
.
h
=
labcomm_read_long
(
r
);
v
.
i
=
labcomm_read_float
(
r
);
handle
(
&
v
,
context
);
{
labcomm_memory_free
(
r
->
memory
,
1
,
v
.
e
);
}
}
int
labcomm_decoder_register_jg_foo
(
struct
labcomm_decoder
*
d
,
void
(
*
handler
)(
jg_foo
*
v
,
void
*
context
),
void
*
context
)
{
return
labcomm_internal_decoder_register
(
d
,
&
labcomm_signature_jg_foo
,
(
labcomm_decoder_function
)
decode_jg_foo
,
(
labcomm_handler_function
)
handler
,
context
);
}
int
labcomm_decoder_ioctl_jg_foo
(
struct
labcomm_decoder
*
d
,
int
ioctl_action
,
...
)
{
int
result
;
va_list
va
;
va_start
(
va
,
ioctl_action
);
result
=
labcomm_internal_decoder_ioctl
(
d
,
&
labcomm_signature_jg_foo
,
ioctl_action
,
va
);
va_end
(
va
);
return
result
;
}
static
int
encode_jg_foo
(
struct
labcomm_writer
*
w
,
jg_foo
*
v
)
{
int
result
=
0
;
result
=
labcomm_write_double
(
w
,
(
*
v
).
b
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_int
(
w
,
(
*
v
).
c
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_int
(
w
,
(
*
v
).
d
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_string
(
w
,
(
*
v
).
e
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_boolean
(
w
,
(
*
v
).
f
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_short
(
w
,
(
*
v
).
g
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_long
(
w
,
(
*
v
).
h
);
if
(
result
!=
0
)
{
return
result
;
}
result
=
labcomm_write_float
(
w
,
(
*
v
).
i
);
if
(
result
!=
0
)
{
return
result
;
}
return
result
;
}
int
labcomm_encode_jg_foo
(
struct
labcomm_encoder
*
e
,
jg_foo
*
v
)
{
return
labcomm_internal_encode
(
e
,
&
labcomm_signature_jg_foo
,
(
labcomm_encoder_function
)
encode_jg_foo
,
v
);
}
int
labcomm_encoder_register_jg_foo
(
struct
labcomm_encoder
*
e
)
{
return
labcomm_internal_encoder_register
(
e
,
&
labcomm_signature_jg_foo
,
(
labcomm_encoder_function
)
encode_jg_foo
);
}
int
labcomm_encoder_ioctl_jg_foo
(
struct
labcomm_encoder
*
e
,
int
ioctl_action
,
...
)
{
int
result
;
va_list
va
;
va_start
(
va
,
ioctl_action
);
result
=
labcomm_internal_encoder_ioctl
(
e
,
&
labcomm_signature_jg_foo
,
ioctl_action
,
va
);
va_end
(
va
);
return
result
;
}
int
labcomm_sizeof_jg_foo
(
jg_foo
*
v
)
{
int
result
=
labcomm_size_packed32
(
labcomm_signature_jg_foo
.
index
);
result
+=
0
+
strlen
((
*
v
).
e
);
result
+=
31
;
return
result
;
}
LABCOMM_CONSTRUCTOR
void
init_jg__signatures
(
void
)
{
static
int
initialized
=
0
;
if
(
initialized
==
0
)
{
initialized
=
1
;
labcomm_set_local_index
(
&
labcomm_signature_jg_foo
);
}
}
examples/jgrafchart/jg.h
deleted
100644 → 0
View file @
fdfd3146
/* LabComm declarations:
sample struct {
double b;
int c;
int d;
string e;
boolean f;
short g;
long h;
float i;
} foo;
*/
#ifndef __LABCOMM_jg_H__
#define __LABCOMM_jg_H__
#include <stdint.h>
#include "labcomm.h"
#ifndef PREDEFINED_jg_foo
typedef
struct
{
double
b
;
int32_t
c
;
int32_t
d
;
char
*
e
;
uint8_t
f
;
int16_t
g
;
int64_t
h
;
float
i
;
}
jg_foo
;
#endif
int
labcomm_decoder_register_jg_foo
(
struct
labcomm_decoder
*
d
,
void
(
*
handler
)(
jg_foo
*
v
,
void
*
context
),
void
*
context
);
int
labcomm_decoder_ioctl_jg_foo
(
struct
labcomm_decoder
*
d
,
int
ioctl_action
,
...
);
int
labcomm_encoder_register_jg_foo
(
struct
labcomm_encoder
*
e
);
int
labcomm_encode_jg_foo
(
struct
labcomm_encoder
*
e
,
jg_foo
*
v
);
int
labcomm_encoder_ioctl_jg_foo
(
struct
labcomm_encoder
*
e
,
int
ioctl_action
,
...
);
extern
int
labcomm_sizeof_jg_foo
(
jg_foo
*
v
);
void
init_jg__signatures
(
void
);
#define LABCOMM_FORALL_SAMPLES_jg(func, sep) \
func(foo, jg_foo)
#endif
examples/jgrafchart/labcommTCPtest/client/TestClient.java
0 → 100644
View file @
e32f8e9e
package
labcommTCPtest.client
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
import
labcommTCPtest.gen.foo
;
import
labcommTCPtest.gen.foo.Handler
;
public
class
TestClient
implements
Handler
{
private
OutputStream
out
;
private
InputStream
in
;
public
TestClient
(
Socket
server
)
throws
IOException
{
out
=
server
.
getOutputStream
();
in
=
server
.
getInputStream
();
}
public
void
test
()
{
try
{
LabCommEncoderChannel
e
=
new
LabCommEncoderChannel
(
out
);
foo
.
register
(
e
);
foo
sample
=
new
foo
();
sample
.
c
=
17
;
sample
.
d
=
42
;
sample
.
h
=
1717
;
sample
.
b
=
0.42
;
sample
.
e
=
"Testing"
;
printSample
(
"Client sending"
,
sample
);
foo
.
encode
(
e
,
sample
);
LabCommDecoderChannel
c
=
new
LabCommDecoderChannel
(
in
);
foo
.
register
(
c
,
this
);
c
.
run
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
...
args
)
{
String
server
=
"localhost"
;
int
port
=
9999
;
try
{
Socket
s
=
new
Socket
(
server
,
port
);
TestClient
c
=
new
TestClient
(
s
);
c
.
test
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
void
printSample
(
String
header
,
foo
sample2
)
throws
Exception
{
System
.
out
.
println
(
header
);
System
.
out
.
format
(
"TestClient.invoke(%f, %d, %d, %d)\n"
,
sample2
.
b
,
sample2
.
c
,
sample2
.
d
,
sample2
.
h
);
}
public
void
handle_foo
(
foo
sample2
)
throws
Exception
{
printSample
(
"TestClient.handle_foo"
,
sample2
);
}
}
examples/jgrafchart/labcommTCPtest/client/TestClientSingleshot.java
0 → 100644
View file @
e32f8e9e
package
labcommTCPtest.client
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
import
labcommTCPtest.gen.FooSample
;
import
labcommTCPtest.gen.FooSample.Handler
;
public
class
TestClientSingleshot
implements
Handler
{
private
OutputStream
out
;
private
InputStream
in
;
public
TestClientSingleshot
(
Socket
server
)
throws
IOException
{
out
=
server
.
getOutputStream
();
in
=
server
.
getInputStream
();
}
public
void
test
()
{
try
{
LabCommEncoderChannel
e
=
new
LabCommEncoderChannel
(
out
);
FooSample
.
register
(
e
);
FooSample
sample
=
new
FooSample
();
sample
.
x
=
17
;
sample
.
y
=
42
;
sample
.
t
=
1717
;
sample
.
d
=
0.42
;
printSample
(
"Client sending"
,
sample
);
FooSample
.
encode
(
e
,
sample
);
LabCommDecoderChannel
c
=
new
LabCommDecoderChannel
(
in
);
FooSample
.
register
(
c
,
this
);
c
.
runOne
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
...
args
)
{
String
server
=
"localhost"
;
int
port
=
9999
;
try
{
Socket
s
=
new
Socket
(
server
,
port
);
TestClientSingleshot
c
=
new
TestClientSingleshot
(
s
);
c
.
test
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
void
printSample
(
String
header
,
FooSample
sample2
)
throws
Exception
{
System
.
out
.
println
(
header
);
System
.
out
.
format
(
"TestClientSingleshot.invoke(%d, %d, %d, %f)\n"
,
sample2
.
x
,
sample2
.
y
,
sample2
.
t
,
sample2
.
d
);
}
public
void
handle_FooSample
(
FooSample
sample2
)
throws
Exception
{
printSample
(
"TestClientSingleshot.handle_FooSample"
,
sample2
);
}
}
examples/jgrafchart/labcommTCPtest/server/TestObject.java
0 → 100644
View file @
e32f8e9e
package
labcommTCPtest.server
;
/**
* The service object to be accessed remotely via a LabComm channel
*
*/
public
class
TestObject
{
/**
* A test method. The matching LabComm description is in test.lc
*
* @param x
* @param y
* @param t
* @param d
*/
public
void
foo
(
int
x
,
int
y
,
long
t
,
double
d
)
{
System
.
out
.
format
(
"TestObject.foo(%d, %d, %d, %f)\n"
,
x
,
y
,
t
,
d
);
}
}
examples/jgrafchart/labcommTCPtest/server/TestServer.java
0 → 100644
View file @
e32f8e9e
package
labcommTCPtest.server
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
import
labcommTCPtest.gen.foo
;
import
labcommTCPtest.gen.foo.Handler
;
public
class
TestServer
implements
Handler
{
private
OutputStream
out
;
private
InputStream
in
;
public
static
void
main
(
String
a
[])
{
try
{
ServerSocket
ss
=
new
ServerSocket
(
9999
);
Socket
s
=
ss
.
accept
();
TestServer
ts
=
new
TestServer
(
s
);
ts
.
runOne
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
TestServer
(
Socket
s
)
throws
IOException
{
out
=
s
.
getOutputStream
();
in
=
s
.
getInputStream
();
}
public
void
runOne
()
{
try
{
LabCommDecoderChannel
c
=
new
LabCommDecoderChannel
(
in
);
foo
.
register
(
c
,
this
);
c
.
runOne
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
void
handle_foo
(
foo
sample
)
throws
Exception
{
LabCommEncoderChannel
e
=
new
LabCommEncoderChannel
(
out
);
foo
.
register
(
e
);
System
.
out
.
println
(
"TestServer.handle_foo..."
);
sample
.
b
*=
2
;
sample
.
c
*=
2
;
sample
.
d
*=
2
;
sample
.
h
*=
2
;
foo
.
encode
(
e
,
sample
);
}
}
examples/tcp/labcommTCPtest/client/TestClient.java
View file @
e32f8e9e
...
...
@@ -37,7 +37,7 @@ public class TestClient implements Handler {
LabCommDecoderChannel
c
=
new
LabCommDecoderChannel
(
in
);
FooSample
.
register
(
c
,
this
);
c
.
run
One
();
c
.
run
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
examples/tcp/labcommTCPtest/client/TestClientSingleshot.java
0 → 100644
View file @
e32f8e9e
package
labcommTCPtest.client
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.Socket
;
import
java.net.UnknownHostException
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
import
labcommTCPtest.gen.FooSample
;
import
labcommTCPtest.gen.FooSample.Handler
;
public
class
TestClientSingleshot
implements
Handler
{
private
OutputStream
out
;
private
InputStream
in
;
public
TestClientSingleshot
(
Socket
server
)
throws
IOException
{
out
=
server
.
getOutputStream
();
in
=
server
.
getInputStream
();
}
public
void
test
()
{
try
{
LabCommEncoderChannel
e
=
new
LabCommEncoderChannel
(
out
);
FooSample
.
register
(
e
);
FooSample
sample
=
new
FooSample
();
sample
.
x
=
17
;
sample
.
y
=
42
;
sample
.
t
=
1717
;
sample
.
d
=
0.42
;
printSample
(
"Client sending"
,
sample
);
FooSample
.
encode
(
e
,
sample
);
LabCommDecoderChannel
c
=
new
LabCommDecoderChannel
(
in
);
FooSample
.
register
(
c
,
this
);
c
.
runOne
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
...
args
)
{
String
server
=
"localhost"
;
int
port
=
9999
;
try
{
Socket
s
=
new
Socket
(
server
,
port
);
TestClientSingleshot
c
=
new
TestClientSingleshot
(
s
);
c
.
test
();
}
catch
(
UnknownHostException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
void
printSample
(
String
header
,
FooSample
sample2
)
throws
Exception
{
System
.
out
.
println
(
header
);
System
.
out
.
format
(
"TestClientSingleshot.invoke(%d, %d, %d, %f)\n"
,
sample2
.
x
,
sample2
.
y
,
sample2
.
t
,
sample2
.
d
);
}
public
void
handle_FooSample
(
FooSample
sample2
)
throws
Exception
{
printSample
(
"TestClientSingleshot.handle_FooSample"
,
sample2
);
}
}
Write
Preview
Supports
Markdown
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