问题描述
我有以下idl结构.我想使用 opendds 发布它
I have following idl structure. I want to publish it using opendds
#pragma DCPS_DATA_TYPE "B::CData"
#pragma DCPS_DATA_KEY "B::CData id"
module B {
struct Quote {
string skit_name;
string episode_name;
string line;
};
struct CData{
long id;
Quote payload;
};
};
我用java编写了发布者和订阅者.但是在发布和订阅上述主题时,JVM 崩溃了.
I have written publisher and subscriber in java. but while publishing and subscribing to above topic JVM crashes.
有人对此有什么想法吗?
Any one has idea about this?
以下是公开话题的java代码
Below is the java code for public Topic
public static void main(String[] args) {
DomainParticipantFactory dpf =
TheParticipantFactory.WithArgs(new StringSeqHolder(args));
if (dpf == null) {
System.err.println ("Domain Participant Factory not found");
return;
}
final int DOMAIN_ID = 42;
DomainParticipant dp = dpf.create_participant(DOMAIN_ID,
PARTICIPANT_QOS_DEFAULT.get(), null, DEFAULT_STATUS_MASK.value);
if (dp == null) {
System.err.println ("Domain Participant creation failed");
return;
}
CDataTypeSupportImpl servant = new CDataTypeSupportImpl();
if (servant.register_type(dp, "") != RETCODE_OK.value) {
System.err.println ("register_type failed");
return;
}
Topic top = dp.create_topic("data",
servant.get_type_name(),
TOPIC_QOS_DEFAULT.get(), null,
DEFAULT_STATUS_MASK.value);
Publisher pub = dp.create_publisher(
PUBLISHER_QOS_DEFAULT.get(),
null,
DEFAULT_STATUS_MASK.value);
DataWriter dw = pub.create_datawriter(
top, DATAWRITER_QOS_DEFAULT.get(), null, DEFAULT_STATUS_MASK.value);
CDataDataWriter mdw = CDataDataWriterHelper.narrow(dw);
CData cData=new CData();
int handle = mdw.register(cData);
// above statement crashes the jvm
int ret = mdw.write(msg, handle);
}
推荐答案
可以使用openDDS传递复杂的结构
You can pass complex structure using openDDS
你需要定义像idl这样的复杂结构
you need to define complex structure idl like
module B {
typedef struct Quote {
string skit_name;
string episode_name;
string line;
} QuoteData;
@topic
struct CData {
@key long id;
QuoteData payload;
};
};
在接收数据时,您需要为复杂数据类型预先分配内存.如果是 CData
和 QuoteData
,我们将首先为 QuoteData分配内存code>,然后为
CData
分配内存.
while receiving data you need to pre allocate memory for your complex data type.In case of CData
and QuoteData
first we will allocate memory for QuoteData
and then allocate memory for CData
.
就我而言,我在 Java 中使用 openDDS.JAVA 中的 openDDS 使用本地库,即编译 openDDS 和 ACEWrappers 后生成的 dll 或 lib.
In my case, I'm using openDDS in Java. openDDS in JAVA uses native libraries i.e.dll or lib which are generated after compiling openDDS and ACEWrappers.
JVM 崩溃了,因为我没有为复杂对象预先分配内存.我只传递 CData 对象.当我第一次创建 QuoteData 对象,之后我创建了 CData 对象时,它工作正常.
JVM was crashing because I haven't pre-allocated memory for complex object.I'm passing only CData object. When I first created QuoteData object and after that I have created CData object it works fine.
这篇关于从 OpenDDS 发布者传递复杂结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!