1
0
Fork 0

Switch to always add the GUID. Setting a string to null doesn't work for DDS samples and leads to a segmentation fault.

This commit is contained in:
Erik Hofman 2021-04-09 14:42:38 +02:00
parent 3274925cf3
commit 162f5f317d
5 changed files with 52 additions and 45 deletions

View file

@ -22,4 +22,13 @@ add_executable(fg_dds_log
)
setup_fgfs_libraries(fg_dds_log)
add_executable(fg_dds_prop
WIN32
MACOSX_BUNDLE
fg_dds_prop.cpp
${SOURCES}
)
setup_fgfs_libraries(fg_dds_prop)
flightgear_component(Network "${SOURCES}" "${HEADERS}")

View file

@ -17,6 +17,7 @@ static const dds_key_descriptor_t FG_DDS_PROP_keys[1] =
static const uint32_t FG_DDS_PROP_ops [] =
{
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_SGN | DDS_OP_FLAG_KEY, offsetof (FG_DDS_PROP, id),
DDS_OP_ADR | DDS_OP_TYPE_ARR | DDS_OP_SUBTYPE_1BY, offsetof (FG_DDS_PROP, guid), 16,
DDS_OP_ADR | DDS_OP_TYPE_4BY | DDS_OP_FLAG_SGN, offsetof (FG_DDS_PROP, type),
DDS_OP_ADR | DDS_OP_TYPE_UNI | DDS_OP_SUBTYPE_4BY | DDS_OP_FLAG_SGN, offsetof (FG_DDS_PROP, val._d), 9u, (31u << 16) + 4u,
DDS_OP_JEQ | DDS_OP_TYPE_BOO | 0, FG_DDS_BOOL, offsetof (FG_DDS_PROP, val._u.Bool),
@ -28,7 +29,6 @@ static const uint32_t FG_DDS_PROP_ops [] =
DDS_OP_JEQ | DDS_OP_TYPE_STR | 0, FG_DDS_ALIAS, offsetof (FG_DDS_PROP, val._u.String),
DDS_OP_JEQ | DDS_OP_TYPE_STR | 0, FG_DDS_STRING, offsetof (FG_DDS_PROP, val._u.String),
DDS_OP_JEQ | DDS_OP_TYPE_STR | 0, FG_DDS_UNSPECIFIED, offsetof (FG_DDS_PROP, val._u.String),
DDS_OP_ADR | DDS_OP_TYPE_STR, offsetof (FG_DDS_PROP, guid),
DDS_OP_RTS
};
@ -42,5 +42,5 @@ const dds_topic_descriptor_t FG_DDS_PROP_desc =
FG_DDS_PROP_keys,
14,
FG_DDS_PROP_ops,
"<MetaData version=\"1.0.0\"><Module name=\"FG\"><Enum name=\"propType\"><Element name=\"DDS_NONE\" value=\"0\"/><Element name=\"DDS_ALIAS\" value=\"1\"/><Element name=\"DDS_BOOL\" value=\"2\"/><Element name=\"DDS_INT\" value=\"3\"/><Element name=\"DDS_LONG\" value=\"4\"/><Element name=\"DDS_FLOAT\" value=\"5\"/><Element name=\"DDS_DOUBLE\" value=\"6\"/><Element name=\"DDS_STRING\" value=\"7\"/><Element name=\"DDS_UNSPECIFIED\" value=\"8\"/></Enum><Union name=\"propValue\"><SwitchType><Type name=\"propType\"/></SwitchType><Case name=\"Bool\"><Boolean/><Label value=\"DDS_BOOL\"/></Case><Case name=\"Int32\"><Long/><Label value=\"DDS_NONE\"/><Label value=\"DDS_INT\"/></Case><Case name=\"Int64\"><LongLong/><Label value=\"DDS_LONG\"/></Case><Case name=\"Float32\"><Float/><Label value=\"DDS_FLOAT\"/></Case><Case name=\"Float64\"><Double/><Label value=\"DDS_DOUBLE\"/></Case><Case name=\"String\"><String/><Label value=\"DDS_ALIAS\"/><Label value=\"DDS_STRING\"/><Label value=\"DDS_UNSPECIFIED\"/></Case></Union><Struct name=\"DDS_PROP\"><Member name=\"id\"><Long/></Member><Member name=\"type\"><Type name=\"propType\"/></Member><Member name=\"val\"><Type name=\"propValue\"/></Member><Member name=\"guid\"><String/></Member></Struct></Module></MetaData>"
"<MetaData version=\"1.0.0\"><Module name=\"FG\"><Enum name=\"propType\"><Element name=\"DDS_NONE\" value=\"0\"/><Element name=\"DDS_ALIAS\" value=\"1\"/><Element name=\"DDS_BOOL\" value=\"2\"/><Element name=\"DDS_INT\" value=\"3\"/><Element name=\"DDS_LONG\" value=\"4\"/><Element name=\"DDS_FLOAT\" value=\"5\"/><Element name=\"DDS_DOUBLE\" value=\"6\"/><Element name=\"DDS_STRING\" value=\"7\"/><Element name=\"DDS_UNSPECIFIED\" value=\"8\"/></Enum><Union name=\"propValue\"><SwitchType><Type name=\"propType\"/></SwitchType><Case name=\"Bool\"><Boolean/><Label value=\"DDS_BOOL\"/></Case><Case name=\"Int32\"><Long/><Label value=\"DDS_NONE\"/><Label value=\"DDS_INT\"/></Case><Case name=\"Int64\"><LongLong/><Label value=\"DDS_LONG\"/></Case><Case name=\"Float32\"><Float/><Label value=\"DDS_FLOAT\"/></Case><Case name=\"Float64\"><Double/><Label value=\"DDS_DOUBLE\"/></Case><Case name=\"String\"><String/><Label value=\"DDS_ALIAS\"/><Label value=\"DDS_STRING\"/><Label value=\"DDS_UNSPECIFIED\"/></Case></Union><Struct name=\"DDS_PROP\"><Member name=\"id\"><Long/></Member><Member name=\"guid\"><Array size=\"16\"><Octet/></Array></Member><Member name=\"type\"><Type name=\"propType\"/></Member><Member name=\"val\"><Type name=\"propValue\"/></Member></Struct></Module></MetaData>"
};

View file

@ -56,9 +56,9 @@ typedef struct FG_propValue
typedef struct FG_DDS_PROP
{
int32_t id;
uint8_t guid[16];
FG_propType type;
FG_propValue val;
char * guid;
} FG_DDS_PROP;
extern const dds_topic_descriptor_t FG_DDS_PROP_desc;

View file

@ -75,10 +75,10 @@ struct DDS_PROP
{
long id; // property index and DDS id
octet guid[16];
propType type;
propValue val;
string guid; // requesters globally unique identifier
};
#pragma keylist DDS_PROP id

View file

@ -113,47 +113,45 @@ int main()
if (topics["prop"]->read()) {
printf("=== [fg_dds_log] Received : ");
printf("PROP Message:\n");
printf(" type: ");
switch(prop.type)
printf("Prop Message:\n");
if (prop.id == FG_DDS_PROP_REQUEST) {
printf(" request: %s\n", prop.val._u.String);
printf("GUID: ");
for(int i=0; i<16; ++i)
printf("%X ", prop.guid[i]);
printf("\n");
}
else
{
case FG_DDS_NONE:
printf(" type: none");
break;
case FG_DDS_ALIAS:
printf(" type: alias");
printf(" value: %s\n", prop.val._u.String);
break;
case FG_DDS_BOOL:
printf(" type: bool");
printf(" value: %i\n", prop.val._u.Bool);
break;
case FG_DDS_INT:
printf(" type: int");
printf(" value: %i\n", prop.val._u.Int32);
break;
case FG_DDS_LONG:
printf(" type: long");
printf(" value: %li\n", prop.val._u.Int64);
break;
case FG_DDS_FLOAT:
printf(" type: float");
printf(" value: %f\n", prop.val._u.Float32);
break;
case FG_DDS_DOUBLE:
printf(" type: double");
printf(" value: %lf\n", prop.val._u.Float64);
break;
case FG_DDS_STRING:
printf(" type: string");
printf(" value: %s\n", prop.val._u.String);
break;
case FG_DDS_UNSPECIFIED:
printf(" type: unspecified");
printf(" value: %s\n", prop.val._u.String);
break;
default:
break;
switch(prop.val._d)
{
case FG_DDS_BOOL:
printf(" type: bool");
printf(" value: %i\n", prop.val._u.Bool);
break;
case FG_DDS_INT:
printf(" type: int");
printf(" value: %i\n", prop.val._u.Int32);
break;
case FG_DDS_LONG:
printf(" type: long");
printf(" value: %li\n", prop.val._u.Int64);
break;
case FG_DDS_FLOAT:
printf(" type: float");
printf(" value: %f\n", prop.val._u.Float32);
break;
case FG_DDS_DOUBLE:
printf(" type: double");
printf(" value: %lf\n", prop.val._u.Float64);
break;
case FG_DDS_STRING:
printf(" type: string");
printf(" value: %s\n", prop.val._u.String);
break;
default:
break;
}
}
}