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
Anders Blomdell
LabComm
Commits
8973c6d7
Commit
8973c6d7
authored
Nov 14, 2014
by
Anders Blomdell
Browse files
First implementation of sample references, only for C this far.
parent
1f9f6437
Changes
21
Hide whitespace changes
Inline
Side-by-side
compiler/C_CodeGen.jrag
View file @
8973c6d7
...
...
@@ -275,6 +275,9 @@ aspect C_Type {
getType().C_emitType(env, env.prefix + getName());
env.println(";");
env.println("#endif");
env.println("extern const struct labcomm"+env.verStr+"_signature " +
"*labcomm"+env.verStr+"_signature_" + env.prefix + getName() +
";");
}
public void Type.C_emitType(C_env env, String name) {
...
...
@@ -287,6 +290,10 @@ aspect C_Type {
env.print("char " + name);
}
public void SampleRefType.C_emitType(C_env env, String name) {
env.print("const struct labcomm_signature *" + name);
}
public void PrimType.C_emitType(C_env env, String name) {
switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("uint8_t"); } break;
...
...
@@ -508,6 +515,10 @@ aspect C_Decoder {
public void VoidType.C_emitDecoder(C_env env) {
}
public void SampleRefType.C_emitDecoder(C_env env) {
env.println(env.qualid + " = labcomm_internal_decoder_index_to_signature(" +
"r->decoder, labcomm"+env.verStr+"_read_int(r));");
}
public void PrimType.C_emitDecoder(C_env env) {
env.println(env.qualid + " = labcomm"+env.verStr+"_read_" + getName() + "(r);");
}
...
...
@@ -585,6 +596,9 @@ aspect C_Decoder {
" not declared");
}
public void SampleRefType.C_emitDecoderDeallocation(C_env env) {
}
public void PrimType.C_emitDecoderDeallocation(C_env env) {
if (C_isDynamic()) {
env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " +
...
...
@@ -669,7 +683,7 @@ aspect C_Decoder {
env.println("return labcomm"+env.verStr+"_internal_decoder_register(");
env.indent();
env.println("d,");
env.println("&
labcomm"+env.verStr+"_
signature_" + env.prefix + getName() + ",");
env.println("&signature_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_decoder_function)decode_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_handler_function)handler,");
env.println("context");
...
...
@@ -737,6 +751,12 @@ aspect C_copy {
public void VoidType.C_emitCopy(C_env env_src, C_env env_dst) {
}
public void SampleRefType.C_emitCopy(C_env env_src, C_env env_dst) {
env_src.println(env_dst.accessor() + env_dst.qualid + " = " +
env_src.accessor() + env_src.qualid + ";");
}
public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) {
if (C_isDynamic()) {
env_src.println(String.format(
...
...
@@ -880,6 +900,9 @@ aspect C_copy {
public void VoidType.C_emitCopyDeallocation(C_env env) {
}
public void SampleRefType.C_emitCopyDeallocation(C_env env) {
}
public void PrimType.C_emitCopyDeallocation(C_env env) {
if (C_isDynamic()) {
env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " +
...
...
@@ -964,7 +987,7 @@ aspect C_DecoderIoctl {
env.println("va_start(va, ioctl_action);");
env.println("result = labcomm"+env.verStr+"_internal_decoder_ioctl(");
env.indent();
env.println("d, &
labcomm"+env.verStr+"_
signature_" + env.prefix + getName() + ", ");
env.println("d, &signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);");
env.unindent();
env.println("va_end(va);");
...
...
@@ -1014,7 +1037,7 @@ aspect C_Encoder {
env.println(")");
env.println("{");
env.indent();
env.println("return labcomm"+env.verStr+"_internal_encode(e, &
labcomm"+env.verStr+"_
signature_" +
env.println("return labcomm"+env.verStr+"_internal_encode(e, &signature_" +
env.prefix + getName() +
", (labcomm"+env.verStr+"_encoder_function)encode_" +
env.prefix + getName() +
...
...
@@ -1033,6 +1056,13 @@ aspect C_Encoder {
env.println("result = 0;");
}
public void SampleRefType.C_emitEncoder(C_env env) {
env.println("result = labcomm"+env.verStr+"_write_int(w, " +
"labcomm_internal_encoder_signature_to_index(w->encoder, " +
env.qualid + "));");
env.println("if (result != 0) { return result; }");
}
public void PrimType.C_emitEncoder(C_env env) {
env.println("result = labcomm"+env.verStr+"_write_" + getName() +
"(w, " + env.qualid + ");");
...
...
@@ -1111,7 +1141,7 @@ aspect C_Encoder {
env.println("return labcomm"+env.verStr+"_internal_encoder_register(");
env.indent();
env.println("e,");
env.println("&
labcomm"+env.verStr+"_
signature_" + env.prefix + getName() + ",");
env.println("&signature_" + env.prefix + getName() + ",");
env.println("(labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName());
env.unindent();
env.println(");");
...
...
@@ -1147,7 +1177,7 @@ aspect C_EncoderIoctl {
env.println("va_start(va, ioctl_action);");
env.println("result = labcomm"+env.verStr+"_internal_encoder_ioctl(");
env.indent();
env.println("e, &
labcomm"+env.verStr+"_
signature_" + env.prefix + getName() + ", ");
env.println("e, &signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);");
env.unindent();
env.println("va_end(va);");
...
...
@@ -1189,8 +1219,8 @@ aspect C_Signature {
}
env.println("};");
C_emitSizeofValue(env);
env.println("struct labcomm"+env.verStr+"_signature
labcomm"+env.verStr+"_signature_
" +
env.prefix + getName() + " = {");
env.println("
static
struct labcomm"+env.verStr+"_signature " +
"signature_" +
env.prefix + getName() + " = {");
env.indent();
env.println("\"" + getName() + "\",");
env.println("sizeof_" + env.prefix + getName() + ",");
...
...
@@ -1199,6 +1229,9 @@ aspect C_Signature {
env.println("0");
env.unindent();
env.println(" };");
env.println("const struct labcomm"+env.verStr+"_signature " +
"*labcomm"+env.verStr+"_signature_" + env.prefix + getName() +
" = &signature_" + env.prefix + getName() + ";");
}
public void ASTNode.C_emitConstructor(C_env env) {
...
...
@@ -1229,7 +1262,7 @@ aspect C_Signature {
}
public void SampleDecl.C_emitConstructor(C_env env) {
env.println("labcomm"+env.verStr+"_set_local_index(&
labcomm"+env.verStr+"_
signature_" +
env.println("labcomm"+env.verStr+"_set_local_index(&signature_" +
env.prefix + getName() + ");");
}
...
...
@@ -1270,7 +1303,7 @@ aspect C_Sizeof {
env.println("{");
env.indent();
env.println("return labcomm"+env.verStr+"_internal_sizeof(" +
"&
labcomm" + env.verStr+"_
signature_" + env.prefix + getName() +
"&signature_" + env.prefix + getName() +
", v);");
env.unindent();
env.println("}");
...
...
@@ -1286,6 +1319,10 @@ aspect C_Sizeof {
return 0;
}
public int SampleRefType.C_fixedSizeof() {
return 4;
}
public int PrimType.C_fixedSizeof() {
switch (getToken()) {
case LABCOMM_BOOLEAN: { return 1; }
...
...
compiler/LabComm.ast
View file @
8973c6d7
...
...
@@ -8,6 +8,7 @@ Field ::= Type <Name:String>;
abstract Type;
VoidType : Type;
SampleRefType : Type;
PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>;
StructType : Type ::= Field*;
...
...
compiler/LabComm.java
View file @
8973c6d7
...
...
@@ -33,7 +33,7 @@ public class LabComm {
println
(
"[ RAPID options ]"
);
println
(
" --rapid Generates RAPID code in FILE.sys"
);
println
(
"[ Misc options ]"
);
println
(
" --pretty
Pretty prints
on standard output
"
);
println
(
" --pretty
=PFILE
Pretty prints
to PFILE
"
);
println
(
" --typeinfo=TIFILE Generates typeinfo in TIFILE"
);
}
...
...
compiler/LabCommParser.parser
View file @
8973c6d7
...
...
@@ -77,6 +77,7 @@ Type type =
|
user_type
.
u
{:
return
u
;
:}
|
struct_type
.
s
{:
return
s
;
:}
|
void_type
.
v
{:
return
v
;
:}
|
sample_ref_type
.
s
{:
return
s
;
:}
;
PrimType
prim_type
=
...
...
@@ -110,6 +111,10 @@ VoidType void_type =
VOID
{:
return
new
VoidType
();
:}
;
SampleRefType
sample_ref_type
=
SAMPLE
{:
return
new
SampleRefType
();
:}
;
List
dim_list
=
dim
.
d
{:
return
new
List
().
add
(
d
);
:}
|
dim_list
.
l
dim
.
d
{:
return
l
.
add
(
d
);
:}
...
...
compiler/LabCommmTokens.jrag
View file @
8973c6d7
aspect LabCommTokens {
public static final int ASTNode.LABCOMM_
TYPE
DEF = 0x0
1
;
public static final int ASTNode.LABCOMM_SAMPLE =
0x0
2
;
public static final int ASTNode.LABCOMM_
SAMPLE_
DEF = 0x0
2
;
public static final int ASTNode.LABCOMM_SAMPLE
_REF
= 0x0
3
;
public static final int ASTNode.LABCOMM_ARRAY = 0x10;
public static final int ASTNode.LABCOMM_STRUCT = 0x11;
public static final int ASTNode.LABCOMM_ARRAY =
0x10;
public static final int ASTNode.LABCOMM_STRUCT =
0x11;
public static final int ASTNode.LABCOMM_BOOLEAN = 0x20;
public static final int ASTNode.LABCOMM_BYTE = 0x21;
public static final int ASTNode.LABCOMM_SHORT = 0x22;
public static final int ASTNode.LABCOMM_INT = 0x23;
public static final int ASTNode.LABCOMM_LONG = 0x24;
public static final int ASTNode.LABCOMM_FLOAT = 0x25;
public static final int ASTNode.LABCOMM_DOUBLE = 0x26;
public static final int ASTNode.LABCOMM_STRING = 0x27;
public static final int ASTNode.LABCOMM_BOOLEAN =
0x20;
public static final int ASTNode.LABCOMM_BYTE =
0x21;
public static final int ASTNode.LABCOMM_SHORT =
0x22;
public static final int ASTNode.LABCOMM_INT =
0x23;
public static final int ASTNode.LABCOMM_LONG =
0x24;
public static final int ASTNode.LABCOMM_FLOAT =
0x25;
public static final int ASTNode.LABCOMM_DOUBLE =
0x26;
public static final int ASTNode.LABCOMM_STRING =
0x27;
}
\ No newline at end of file
compiler/PrettyPrint.jrag
View file @
8973c6d7
...
...
@@ -68,6 +68,10 @@ aspect PrettyPrint {
out.print("void");
}
public void SampleRefType.ppPrefix(PrintStream out) {
out.print("sample");
}
public void PrimType.ppPrefix(PrintStream out) {
out.print(getName());
}
...
...
compiler/Signature.jrag
View file @
8973c6d7
...
...
@@ -134,6 +134,10 @@ aspect Signature {
list.addInt(0, null);
}
public void SampleRefType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_SAMPLE_REF, "sample");
}
public void PrimType.flatSignature(SignatureList list) {
list.addInt(getToken(), null);
}
...
...
@@ -200,6 +204,10 @@ aspect Signature {
return getType().signatureComment() + " '" + getName() +"'";
}
public String SampleRefType.signatureComment() {
return "sample";
}
public String PrimType.signatureComment() {
return getName();
}
...
...
examples/twoway/decimating.c
View file @
8973c6d7
...
...
@@ -106,7 +106,7 @@ static void enqueue_decimation(struct decimating_private *decimating,
static
int
wrap_reader_start
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
int
local_index
,
int
remote_index
,
struct
labcomm_signature
*
signature
,
int
local_index
,
int
remote_index
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
struct
decimating_private
*
decimating
=
action_context
->
context
;
...
...
@@ -133,7 +133,7 @@ static int wrap_reader_ioctl(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
int
local_index
,
int
remote_index
,
struct
labcomm_signature
*
signature
,
const
struct
labcomm_signature
*
signature
,
uint32_t
action
,
va_list
args
)
{
struct
decimating_private
*
decimating
=
action_context
->
context
;
...
...
@@ -197,7 +197,7 @@ static int wrap_writer_alloc(
static
int
wrap_writer_start
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
int
index
,
struct
labcomm_signature
*
signature
,
int
index
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
struct
decimating_private
*
decimating
=
action_context
->
context
;
...
...
examples/twoway/introspecting.c
View file @
8973c6d7
...
...
@@ -44,13 +44,13 @@ struct introspecting_private {
LABCOMM_SIGNATURE_ARRAY_DEF
(
local
,
struct
local
{
enum
introspecting_status
status
;
struct
labcomm_signature
*
signature
;
const
struct
labcomm_signature
*
signature
;
});
};
static
struct
local
*
get_local
(
struct
introspecting_private
*
introspecting
,
int
index
,
struct
labcomm_signature
*
signature
)
const
struct
labcomm_signature
*
signature
)
{
/* Called with data_lock held */
struct
local
*
local
;
...
...
@@ -137,7 +137,7 @@ static int wrap_reader_alloc(
struct
handles_signature
{
struct
introspecting_private
*
introspecting
;
int
index
;
struct
labcomm_signature
*
signature
;
const
struct
labcomm_signature
*
signature
;
};
static
void
send_handles_signature
(
void
*
arg
)
...
...
@@ -156,7 +156,7 @@ static void send_handles_signature(void *arg)
static
int
wrap_reader_start
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
int
local_index
,
int
remote_index
,
struct
labcomm_signature
*
signature
,
int
local_index
,
int
remote_index
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
...
...
@@ -180,7 +180,7 @@ static int wrap_reader_start(
struct
labcomm_encoder
*
encoder
,
void
*
context
)
{
struct
labcomm_signature
*
signature
=
context
;
const
struct
labcomm_signature
*
signature
=
context
;
introspecting_messages_handles_signature
handles_signature
;
int
index
=
0
;
...
...
@@ -224,7 +224,7 @@ static int wrap_writer_alloc(
static
int
wrap_writer_start
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
int
index
,
struct
labcomm_signature
*
signature
,
int
index
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
...
...
@@ -243,7 +243,7 @@ static int wrap_writer_start(
static
int
wrap_writer_ioctl
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
int
index
,
struct
labcomm_signature
*
signature
,
int
index
,
const
struct
labcomm_signature
*
signature
,
uint32_t
ioctl_action
,
va_list
args
)
{
struct
introspecting_private
*
introspecting
=
action_context
->
context
;
...
...
lib/c/labcomm.c
View file @
8973c6d7
...
...
@@ -64,7 +64,7 @@ int labcomm_reader_free(struct labcomm_reader *r,
int
labcomm_reader_start
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
int
local_index
,
int
remote_index
,
struct
labcomm_signature
*
signature
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
UNWRAP
(
start
,
r
,
action_context
,
local_index
,
remote_index
,
signature
,
value
);
...
...
@@ -85,7 +85,7 @@ int labcomm_reader_fill(struct labcomm_reader *r,
int
labcomm_reader_ioctl
(
struct
labcomm_reader
*
r
,
struct
labcomm_reader_action_context
*
action_context
,
int
local_index
,
int
remote_index
,
struct
labcomm_signature
*
signature
,
const
struct
labcomm_signature
*
signature
,
uint32_t
ioctl_action
,
va_list
args
)
{
UNWRAP
(
ioctl
,
r
,
action_context
,
...
...
@@ -106,7 +106,7 @@ int labcomm_writer_free(struct labcomm_writer *w,
int
labcomm_writer_start
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
int
index
,
struct
labcomm_signature
*
signature
,
int
index
,
const
struct
labcomm_signature
*
signature
,
void
*
value
)
{
UNWRAP
(
start
,
w
,
action_context
,
index
,
signature
,
value
);
...
...
@@ -127,7 +127,7 @@ int labcomm_writer_flush(struct labcomm_writer *w,
int
labcomm_writer_ioctl
(
struct
labcomm_writer
*
w
,
struct
labcomm_writer_action_context
*
action_context
,
int
index
,
struct
labcomm_signature
*
signature
,
const
struct
labcomm_signature
*
signature
,
uint32_t
ioctl_action
,
va_list
args
)
{
UNWRAP
(
ioctl
,
w
,
action_context
,
index
,
signature
,
ioctl_action
,
args
);
...
...
@@ -250,7 +250,7 @@ void labcomm_set_local_index(struct labcomm_signature *signature)
local_index
++
;
}
int
labcomm_get_local_index
(
struct
labcomm_signature
*
signature
)
int
labcomm_get_local_index
(
const
struct
labcomm_signature
*
signature
)
{
if
(
signature
->
index
==
0
)
{
labcomm_error_fatal_global
(
LABCOMM_ERROR_SIGNATURE_NOT_SET
,
...
...
@@ -259,7 +259,7 @@ int labcomm_get_local_index(struct labcomm_signature *signature)
return
signature
->
index
;
}
int
labcomm_internal_sizeof
(
struct
labcomm_signature
*
signature
,
int
labcomm_internal_sizeof
(
const
struct
labcomm_signature
*
signature
,
void
*
v
)
{
int
length
=
signature
->
encoded_size
(
v
);
...
...
lib/c/labcomm.h
View file @
8973c6d7
...
...
@@ -119,6 +119,9 @@ int labcomm_decoder_decode_one(
struct
labcomm_decoder
*
decoder
);
void
labcomm_decoder_run
(
struct
labcomm_decoder
*
decoder
);
int
labcomm_decoder_sample_ref_register
(
struct
labcomm_decoder
*
decoder
,
const
struct
labcomm_signature
*
signature
);
/* See labcomm_ioctl.h for predefined ioctl_action values */
int
labcomm_decoder_ioctl
(
struct
labcomm_decoder
*
decoder
,
...
...
@@ -137,6 +140,9 @@ struct labcomm_encoder *labcomm_encoder_new(
struct
labcomm_scheduler
*
scheduler
);
void
labcomm_encoder_free
(
struct
labcomm_encoder
*
encoder
);
int
labcomm_encoder_sample_ref_register
(
struct
labcomm_encoder
*
encoder
,
const
struct
labcomm_signature
*
signature
);
/* See labcomm_ioctl.h for predefined ioctl_action values */
int
labcomm_encoder_ioctl
(
struct
labcomm_encoder
*
encoder
,
...
...
lib/c/labcomm_decoder.c
View file @
8973c6d7
...
...
@@ -28,7 +28,7 @@
struct
sample_entry
{
int
remote_index
;
struct
labcomm_signature
*
signature
;
const
struct
labcomm_signature
*
signature
;
labcomm_decoder_function
decode
;
labcomm_handler_function
handler
;
void
*
context
;
...
...
@@ -45,6 +45,8 @@ struct labcomm_decoder {
labcomm_handle_new_datatype_callback
on_new_datatype
;
LABCOMM_SIGNATURE_ARRAY_DEF
(
local
,
struct
sample_entry
);
LABCOMM_SIGNATURE_ARRAY_DEF
(
remote_to_local
,
int
);
LABCOMM_SIGNATURE_ARRAY_DEF
(
local_ref
,
const
struct
labcomm_signature
*
);
LABCOMM_SIGNATURE_ARRAY_DEF
(
remote_to_local_ref
,
int
);
};
struct
labcomm_decoder
*
labcomm_decoder_new
(
...
...
@@ -72,6 +74,9 @@ struct labcomm_decoder *labcomm_decoder_new(
result
->
on_error
=
on_error_fprintf
;
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
local
,
struct
sample_entry
);
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
remote_to_local
,
int
);
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
local_ref
,
const
struct
labcomm_signature
*
);
LABCOMM_SIGNATURE_ARRAY_INIT
(
result
->
remote_to_local_ref
,
int
);
}
return
result
;
}
...
...
@@ -83,17 +88,91 @@ void labcomm_decoder_free(struct labcomm_decoder* d)
labcomm_reader_free
(
d
->
reader
,
d
->
reader
->
action_context
);
LABCOMM_SIGNATURE_ARRAY_FREE
(
memory
,
d
->
local
,
struct
sample_entry
);
LABCOMM_SIGNATURE_ARRAY_FREE
(
memory
,
d
->
remote_to_local
,
int
);
LABCOMM_SIGNATURE_ARRAY_FREE
(
memory
,
d
->
local_ref
,
const
struct
labcomm_signature
*
);
LABCOMM_SIGNATURE_ARRAY_FREE
(
memory
,
d
->
remote_to_local_ref
,
int
);
labcomm_memory_free
(
memory
,
0
,
d
);
}
static
int
decode_sample
(
struct
labcomm_decoder
*
d
,
int
kind
)
static
int
handle_sample_def
(
struct
labcomm_decoder
*
d
,
int
remote_index
,
const
struct
labcomm_signature
*
signature
)
{
int
result
;
struct
labcomm_signature
signature
,
*
local_signature
;
int
remote_index
,
local_index
,
i
;
local_signature
=
NULL
;
local_index
=
0
;
int
i
;
const
struct
labcomm_signature
*
local_signature
=
NULL
;
int
local_index
=
0
;
labcomm_scheduler_data_lock
(
d
->
scheduler
);
LABCOMM_SIGNATURE_ARRAY_FOREACH
(
d
->
local
,
struct
sample_entry
,
i
)
{
struct
sample_entry
*
s
;
int
*
remote_to_local
;
result
=
-
ENOENT
;
s
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
local
,
struct
sample_entry
,
i
);
if
(
s
->
signature
&&
s
->
signature
->
size
==
signature
->
size
&&
strcmp
(
s
->
signature
->
name
,
signature
->
name
)
==
0
&&
memcmp
((
void
*
)
s
->
signature
->
signature
,
(
void
*
)
signature
->
signature
,
signature
->
size
)
==
0
)
{
s
->
remote_index
=
remote_index
;
local_signature
=
s
->
signature
;
local_index
=
i
;
remote_to_local
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
remote_to_local
,
int
,
remote_index
);
*
remote_to_local
=
i
;
result
=
remote_index
;
break
;
}
}
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
if
(
local_signature
)
{
labcomm_reader_start
(
d
->
reader
,
d
->
reader
->
action_context
,
local_index
,
remote_index
,
local_signature
,
NULL
);
labcomm_reader_end
(
d
->
reader
,
d
->
reader
->
action_context
);
}
return
result
;
}
static
int
handle_sample_ref
(
struct
labcomm_decoder
*
d
,
int
remote_index
,
const
struct
labcomm_signature
*
signature
)
{
int
result
;
int
i
;
labcomm_scheduler_data_lock
(
d
->
scheduler
);
LABCOMM_SIGNATURE_ARRAY_FOREACH
(
d
->
local_ref
,
const
struct
labcomm_signature
*
,
i
)
{
const
struct
labcomm_signature
*
s
;
int
*
remote_to_local_ref
;
result
=
-
ENOENT
;
s
=
LABCOMM_SIGNATURE_ARRAY_GET
(
d
->
local_ref
,
const
struct
labcomm_signature
*
,
i
,
0
);
if
(
s
&&
s
->
signature
&&
s
->
size
==
signature
->
size
&&
strcmp
(
s
->
name
,
signature
->
name
)
==
0
&&
memcmp
((
void
*
)
s
->
signature
,
(
void
*
)
signature
->
signature
,
signature
->
size
)
==
0
)
{
remote_to_local_ref
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
remote_to_local_ref
,
int
,
remote_index
);
*
remote_to_local_ref
=
i
;
result
=
remote_index
;
break
;
}
}
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
return
result
;
}
static
int
decode_sample_def_or_ref
(
struct
labcomm_decoder
*
d
,
int
kind
)
{
int
result
;
struct
labcomm_signature
signature
;
int
i
,
remote_index
;
remote_index
=
labcomm_read_packed32
(
d
->
reader
);
if
(
d
->
reader
->
error
<
0
)
{
result
=
d
->
reader
->
error
;
...
...
@@ -121,36 +200,16 @@ static int decode_sample(struct labcomm_decoder *d, int kind)
goto
free_signature_signature
;
}
}
labcomm_scheduler_data_lock
(
d
->
scheduler
);
LABCOMM_SIGNATURE_ARRAY_FOREACH
(
d
->
local
,
struct
sample_entry
,
i
)
{
struct
sample_entry
*
s
;
int
*
remote_to_local
;
result
=
-
ENOENT
;
s
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
local
,
struct
sample_entry
,
i
);
if
(
s
->
signature
&&
s
->
signature
->
size
==
signature
.
size
&&
strcmp
(
s
->
signature
->
name
,
signature
.
name
)
==
0
&&
memcmp
((
void
*
)
s
->
signature
->
signature
,
(
void
*
)
signature
.
signature
,
signature
.
size
)
==
0
)
{
s
->
remote_index
=
remote_index
;
local_signature
=
s
->
signature
;
local_index
=
i
;
remote_to_local
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
remote_to_local
,
int
,
remote_index
);
*
remote_to_local
=
i
;
result
=
remote_index
;
break
;
if
(
kind
==
LABCOMM_SAMPLE_DEF
)
{
result
=
handle_sample_def
(
d
,
remote_index
,
&
signature
);
}
else
if
(
kind
==
LABCOMM_SAMPLE_REF
)
{
result
=
handle_sample_ref
(
d
,
remote_index
,
&
signature
);
if
(
result
==
-
ENOENT
)
{
/* Dummy value to silently continue */
result
=
LABCOMM_SAMPLE_REF
;
}
}
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
if
(
local_signature
)
{
labcomm_reader_start
(
d
->
reader
,
d
->
reader
->
action_context
,
local_index
,
remote_index
,
local_signature
,
NULL
);
labcomm_reader_end
(
d
->
reader
,
d
->
reader
->
action_context
);
}
else
{
result
=
-
EINVAL
;
}
free_signature_signature:
labcomm_memory_free
(
d
->
memory
,
1
,
signature
.
signature
);
...
...
@@ -164,7 +223,7 @@ struct call_handler_context {
struct
labcomm_reader
*
reader
;
int
local_index
;
int
remote_index
;
struct
labcomm_signature
*
signature
;
const
struct
labcomm_signature
*
signature
;
labcomm_handler_function
handler
;
void
*
context
;
};
...
...
@@ -221,8 +280,10 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
}
else
if
(
!
d
->
version_ok
)
{
fprintf
(
stderr
,
"No VERSION %d %d
\n
"
,
remote_index
,
length
);
result
=
-
ECONNRESET
;
}
else
if
(
remote_index
==
LABCOMM_SAMPLE
)
{
result
=
decode_sample
(
d
,
remote_index
);
}
else
if
(
remote_index
==
LABCOMM_SAMPLE_DEF
)
{
result
=
decode_sample_def_or_ref
(
d
,
LABCOMM_SAMPLE_DEF
);
}
else
if
(
remote_index
==
LABCOMM_SAMPLE_REF
)
{
result
=
decode_sample_def_or_ref
(
d
,
LABCOMM_SAMPLE_REF
);
}
else
if
(
remote_index
==
LABCOMM_PRAGMA
&&
0
/* d->pragma_handler*/
)
{
/* d->prama_handler(...); */
}
else
if
(
remote_index
<
LABCOMM_USER
)
{
...
...
@@ -291,8 +352,34 @@ int labcomm_decoder_ioctl(struct labcomm_decoder *d,
return
result
;
}
int
labcomm_decoder_sample_ref_register
(
struct
labcomm_decoder
*
d
,
const
struct
labcomm_signature
*
signature
)
{
int
local_index
,
*
remote_to_local_ref
;
const
struct
labcomm_signature
**
s
;
local_index
=
labcomm_get_local_index
(
signature
);