package Logger; import com.rti.dds.dynamicdata.DynamicData; import com.rti.dds.dynamicdata.DynamicDataMemberInfo; import com.rti.dds.dynamicdata.DynamicDataReader; import com.rti.dds.dynamicdata.DynamicDataSeq; import com.rti.dds.infrastructure.ByteSeq; import com.rti.dds.infrastructure.RETCODE_NO_DATA; import com.rti.dds.infrastructure.ResourceLimitsQosPolicy; import com.rti.dds.subscription.DataReader; import com.rti.dds.subscription.DataReaderListener; import com.rti.dds.subscription.InstanceStateKind; import com.rti.dds.subscription.LivelinessChangedStatus; import com.rti.dds.subscription.RequestedDeadlineMissedStatus; import com.rti.dds.subscription.RequestedIncompatibleQosStatus; import com.rti.dds.subscription.SampleInfo; import com.rti.dds.subscription.SampleInfoSeq; import com.rti.dds.subscription.SampleLostStatus; import com.rti.dds.subscription.SampleRejectedStatus; import com.rti.dds.subscription.SampleStateKind; import com.rti.dds.subscription.SubscriptionMatchedStatus; import com.rti.dds.subscription.ViewStateKind; import com.rti.dds.typecode.TCKind; public class DynamicListener implements DataReaderListener { Logger logger; DynamicListener(Logger l) { super(); logger = l; } public void processDynamicData(DynamicData data, SampleInfo info) { if (info.valid_data) { System.out.println("Data kind: " + data.get_type_kind()); System.out.println("Data type: " + data.get_type()); System.out.println("Data member count: " + data.get_member_count()); for (int j = 0; j < data.get_member_count(); j++) { DynamicDataMemberInfo memberInfo = new DynamicDataMemberInfo(); data.get_member_info_by_index(memberInfo, j); System.out.println("Member Name: " + memberInfo.member_name); System.out.println("Member ID: " + memberInfo.member_id); System.out.println("Member Kind: " + memberInfo.member_kind); if (memberInfo.member_kind == TCKind.TK_STRING) { //Data is in string form String stringData = data.get_string(memberInfo.member_name, memberInfo.member_id); System.out.println("String: " + stringData); } else if (memberInfo.member_kind == TCKind.TK_LONG) { long longData = data.get_long(memberInfo.member_name, memberInfo.member_id); System.out.println("Long: " + longData); } else if (memberInfo.member_kind == TCKind.TK_SEQUENCE) { ByteSeq seq = new ByteSeq(); data.get_byte_seq(seq, memberInfo.member_name, memberInfo.member_id); System.out.println("Byte Sequence: " + seq); } else { System.out.println("Type: " + memberInfo.member_kind); } } } } public void on_data_available(DataReader arg0) { System.out.println("Data available!"); DynamicDataReader reader = (DynamicDataReader)arg0; DynamicDataSeq dataSeq = new DynamicDataSeq(); SampleInfoSeq infoSeq = new SampleInfoSeq(); boolean noData = false; while(noData == false) { try { reader.take(dataSeq, infoSeq, ResourceLimitsQosPolicy.LENGTH_UNLIMITED, SampleStateKind.ANY_SAMPLE_STATE, ViewStateKind.ANY_VIEW_STATE, InstanceStateKind.ANY_INSTANCE_STATE); for(int i = 0; i < infoSeq.size(); i++) { SampleInfo sa = (SampleInfo)infoSeq.get(i); DynamicData da = (DynamicData)dataSeq.get(i); processDynamicData(da, sa); } } catch (RETCODE_NO_DATA ret) { noData = true; } finally { reader.return_loan(dataSeq, infoSeq); } } } @Override public void on_liveliness_changed(DataReader arg0, LivelinessChangedStatus arg1) { // TODO Auto-generated method stub System.out.println("Liveliness changed"); } @Override public void on_requested_deadline_missed(DataReader arg0, RequestedDeadlineMissedStatus arg1) { // TODO Auto-generated method stub System.out.println("on_requested_deadline_missed"); } @Override public void on_requested_incompatible_qos(DataReader arg0, RequestedIncompatibleQosStatus arg1) { // TODO Auto-generated method stub System.out.println("on_requested_incompatible_qos: " + arg1); //System.out.println("Total Count: "+arg1.total_count); //System.out.println("Total Count Change: "+arg1.total_count_change); //System.out.println("Last policy ID: "+arg1.last_policy_id); //System.out.println("Policies: "+arg1.policies); //for (int i = 0; i < arg1.policies.size(); i++) { // QosPolicyCount qpc = (QosPolicyCount) arg1.policies.get(i); // System.out.println("P #: " + i + ", Count: " + qpc.hashCode() + ", Policy ID: " + qpc.policy_id); //} } @Override public void on_sample_lost(DataReader arg0, SampleLostStatus arg1) { // TODO Auto-generated method stub System.out.println("on_sample_lost"); } @Override public void on_sample_rejected(DataReader arg0, SampleRejectedStatus arg1) { // TODO Auto-generated method stub System.out.println("on_sample_rejected"); } @Override public void on_subscription_matched(DataReader arg0, SubscriptionMatchedStatus arg1) { // TODO Auto-generated method stub System.out.println("on_subscription_matched"); } }