Ejemplo n.º 1
0
        public static bool SubscriptionMatchValid(DDS.IDataReader reader, int totalCount,
                                                  int totalCountChange)
        {
            bool result = false;

            DDS.SubscriptionMatchedStatus holder = new DDS.SubscriptionMatchedStatus();
            DDS.ReturnCode rc = reader.GetSubscriptionMatchedStatus(ref holder);
            if (rc == DDS.ReturnCode.Ok)
            {
                DDS.SubscriptionMatchedStatus status = holder;
                if (status.TotalCount == totalCount)
                {
                    if (status.TotalCountChange == totalCountChange)
                    {
                        result = true;
                    }
                    else
                    {
                        System.Console.Error.WriteLine("subscription_match.TotalCountChange != '" + totalCountChange
                                                       + "', but '" + status.TotalCountChange + "'.");
                    }
                }
                else
                {
                    System.Console.Error.WriteLine("subscription_match.TotalCount != '" + totalCount
                                                   + "', but '" + status.TotalCount + "'.");
                }
            }
            else
            {
                System.Console.Error.WriteLine("get_subscription_match_status returned " + rc);
            }
            return(result);
        }
        public virtual void OnSubscriptionMatched(DDS.IDataReader reader, DDS.SubscriptionMatchedStatus
                                                  status)
        {
            onSubscriptionMatchCalled = true;
            smStatus = status;
            Semaphore sem = null;

            if (semaphores.TryGetValue(DDS.StatusKind.SubscriptionMatched, out sem) == true)
            {
                sem.Release();
            }
        }
 public virtual void Reset()
 {
     onRequestedDeadlineMissedCalled = false;
     rdmStatus = new DDS.RequestedDeadlineMissedStatus();
     onRequestedIncompatibleQosCalled = false;
     riqStatus = new DDS.RequestedIncompatibleQosStatus();
     onSampleRejectedCalled = false;
     srStatus = new DDS.SampleRejectedStatus();
     onLivelinessChangedCalled = false;
     lcStatus = new DDS.LivelinessChangedStatus();
     onDataAvailableCalled     = false;
     onSubscriptionMatchCalled = false;
     smStatus           = new DDS.SubscriptionMatchedStatus();
     onSampleLostCalled = false;
     slStatus           = new DDS.SampleLostStatus();
 }
Ejemplo n.º 4
0
 public virtual void Reset()
 {
     onRequestedDeadlineMissedCalled = false;
     rdmStatus = new DDS.RequestedDeadlineMissedStatus();
     onRequestedIncompatibleQosCalled = false;
     riqStatus = new DDS.RequestedIncompatibleQosStatus();
     onSampleRejectedCalled = false;
     srStatus = new DDS.SampleRejectedStatus();
     onLivelinessChangedCalled = false;
     lcStatus = new DDS.LivelinessChangedStatus();
     onDataAvailableCalled = false;
     onSubscriptionMatchCalled = false;
     smStatus = new DDS.SubscriptionMatchedStatus();
     onSampleLostCalled = false;
     slStatus = new DDS.SampleLostStatus();
 }
        private void receiveData()
        {
            DDS.ConditionSeq activeConditions = new DDS.ConditionSeq();
            while (true)
            {
                try
                {
                    _waitset.wait(activeConditions, _timeout);
                    for (var c = 0; c < activeConditions.length; ++c)
                    {
                        if (activeConditions.get_at(c) == _statusCondition)
                        {
                            DDS.StatusMask triggeredmask =
                                _reader.get_status_changes();

                            if ((triggeredmask &
                                 (DDS.StatusMask)
                                 DDS.StatusKind.DATA_AVAILABLE_STATUS) != 0)
                            {
                                try
                                {
                                    DDS.TypedDataReader <T> dataReader
                                        = (DDS.TypedDataReader <T>)_reader;

                                    dataReader.take(
                                        _dataSeq,
                                        _infoSeq,
                                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                                        DDS.ViewStateKind.ANY_VIEW_STATE,
                                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);

                                    int dataLength = _dataSeq.length;
                                    //Console.WriteLine("Received {0}", dataLength);
                                    for (var i = 0; i < dataLength; ++i)
                                    {
                                        if (_infoSeq.get_at(i).valid_data)
                                        {
                                            var temp = new T();
                                            temp.copy_from(_dataSeq.get_at(i));
                                            _subject.OnNext(temp);
                                        }
                                        else if (_infoSeq.get_at(i).instance_state ==
                                                 DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE)
                                        {
                                            /* FIXME: If the instance comes back online,
                                             * it will break the Rx contract. */
                                            //Console.WriteLine("OnCompleted CALLED FROM LIB CODE on tid "+
                                            //System.Threading.Thread.CurrentThread.ManagedThreadId);
                                            _subject.OnCompleted();
                                        }
                                    }

                                    dataReader.return_loan(_dataSeq, _infoSeq);
                                }
                                catch (DDS.Retcode_NoData)
                                {
                                    _subject.OnCompleted();
                                    return;
                                }
                                catch (Exception ex)
                                {
                                    _subject.OnError(ex);
                                    Console.WriteLine($"ObservableTopicWaitSet: take error {ex}");
                                }
                            }
                            else
                            {
                                StatusKindPrinter.print((int)triggeredmask);
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS) != 0)
                                {
                                    DDS.SubscriptionMatchedStatus status = new DDS.SubscriptionMatchedStatus();
                                    _reader.get_subscription_matched_status(ref status);
                                    Console.WriteLine($"Subscription matched. current_count = {status.current_count}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.LIVELINESS_CHANGED_STATUS) != 0)
                                {
                                    DDS.LivelinessChangedStatus status = new DDS.LivelinessChangedStatus();
                                    _reader.get_liveliness_changed_status(ref status);
                                    Console.WriteLine($"Liveliness changed. alive_count = {status.alive_count}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_LOST_STATUS) != 0)
                                {
                                    DDS.SampleLostStatus status = new DDS.SampleLostStatus();
                                    _reader.get_sample_lost_status(ref status);
                                    Console.WriteLine($"Sample lost. Reason = {status.last_reason.ToString()}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_REJECTED_STATUS) != 0)
                                {
                                    DDS.SampleRejectedStatus status = new DDS.SampleRejectedStatus();
                                    _reader.get_sample_rejected_status(ref status);
                                    Console.WriteLine($"Sample Rejected. Reason = {status.last_reason.ToString()}");
                                }
                            }
                        }
                    }
                }
                catch (DDS.Retcode_Timeout)
                {
                    Console.WriteLine("wait timed out");
                }
            }
        }
Ejemplo n.º 6
0
        private void receiveData()
        {
            int count = 0;

            DDS.ConditionSeq active_conditions = new DDS.ConditionSeq();
            while (true)
            {
                try
                {
                    waitset.wait(active_conditions, timeout);
                    for (int c = 0; c < active_conditions.length; ++c)
                    {
                        if (active_conditions.get_at(c) == status_condition)
                        {
                            DDS.StatusMask triggeredmask =
                                reader.get_status_changes();

                            if ((triggeredmask &
                                 (DDS.StatusMask)
                                 DDS.StatusKind.DATA_AVAILABLE_STATUS) != 0)
                            {
                                try
                                {
                                    DDS.TypedDataReader <T> dataReader
                                        = (DDS.TypedDataReader <T>)reader;

                                    dataReader.take(
                                        dataSeq,
                                        infoSeq,
                                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                                        DDS.ViewStateKind.ANY_VIEW_STATE,
                                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);

                                    System.Int32 dataLength = dataSeq.length;
                                    for (int i = 0; i < dataLength; ++i)
                                    {
                                        if (infoSeq.get_at(i).valid_data)
                                        {
                                            T temp = new T();
                                            temp.copy_from(dataSeq.get_at(i));
                                            demultiplexer(temp);
                                        }
                                        else if (infoSeq.get_at(i).instance_state ==
                                                 DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE)
                                        {
                                            Console.WriteLine("DDS INSTANCE NOT_ALIVE_DISPOSED_INSTANCE_STATE");
                                            demultiplexer(null);
                                        }
                                    }

                                    dataReader.return_loan(dataSeq, infoSeq);
                                }
                                catch (DDS.Retcode_NoData)
                                {
                                    Console.WriteLine("RETCODE_NODATA");
                                    demultiplexer(null);
                                    return;
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("WaitsetSubscriber: take error {0}", ex);
                                }
                            }
                            else
                            {
                                StatusKindPrinter.print((int)triggeredmask);
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS) != 0)
                                {
                                    DDS.SubscriptionMatchedStatus status = new DDS.SubscriptionMatchedStatus();
                                    reader.get_subscription_matched_status(ref status);
                                    Console.WriteLine("Subscription matched. current_count = {0}", status.current_count);
                                }
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.LIVELINESS_CHANGED_STATUS) != 0)
                                {
                                    DDS.LivelinessChangedStatus status = new DDS.LivelinessChangedStatus();
                                    reader.get_liveliness_changed_status(ref status);
                                    Console.WriteLine("Liveliness changed. alive_count = {0}", status.alive_count);
                                    if (status.alive_count == 0)
                                    {
                                        Console.WriteLine("publisher disconnected");
                                        return;
                                    }
                                }
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_LOST_STATUS) != 0)
                                {
                                    DDS.SampleLostStatus status = new DDS.SampleLostStatus();
                                    reader.get_sample_lost_status(ref status);
                                    Console.WriteLine("Sample lost. Reason = {0}", status.last_reason.ToString());
                                }
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_REJECTED_STATUS) != 0)
                                {
                                    DDS.SampleRejectedStatus status = new DDS.SampleRejectedStatus();
                                    reader.get_sample_rejected_status(ref status);
                                    Console.WriteLine("Sample Rejected. Reason = {0}", status.last_reason.ToString());
                                }
                            }
                        }
                    }
                }
                catch (DDS.Retcode_Timeout)
                {
                    Console.WriteLine("wait timed out");
                    count += 2;
                    continue;
                }
            }
        }
Ejemplo n.º 7
0
 public override void on_subscription_matched(
     DDS.DataReader reader,
     ref DDS.SubscriptionMatchedStatus status)
 {
     Console.WriteLine("Subscription changed. {0} current count.", status.current_count);
 }
Ejemplo n.º 8
0
 public override Test.Framework.TestResult Run()
 {
     DDS.ReturnCode rc;
     mod.tstDataReader datareader;
     DDS.SampleRejectedStatus srStatus = new DDS.SampleRejectedStatus();
     DDS.LivelinessChangedStatus lcStatus = new DDS.LivelinessChangedStatus();
     DDS.RequestedDeadlineMissedStatus rdmStatus = new DDS.RequestedDeadlineMissedStatus();
     DDS.RequestedIncompatibleQosStatus riqStatus = new DDS.RequestedIncompatibleQosStatus();
     DDS.SubscriptionMatchedStatus smStatus = new DDS.SubscriptionMatchedStatus();
     DDS.SampleLostStatus slStatus = new DDS.SampleLostStatus();
     string expResult = "DataReader status test succeeded";
     Test.Framework.TestResult result;
     result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
         Test.Framework.TestVerdict.Fail);
     datareader = (mod.tstDataReader)this.ResolveObject("datareader");
     rc = datareader.GetSampleRejectedStatus(ref srStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = "SampleRejectedStatus could not be resolved.";
         return result;
     }
     if (srStatus.TotalCount != 0)
     {
         result.Result = "SampleRejectedStatus.TotalCount != 0.";
         return result;
     }
     if (srStatus.TotalCountChange != 0)
     {
         result.Result = "SampleRejectedStatus.TotalCountChange != 0.";
         return result;
     }
     rc = datareader.GetLivelinessChangedStatus(ref lcStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = string.Format("OfferedIncompatibleStatus could not be resolved. ReturnCode: {0}", rc);
         result.Result = "LivelinessChangedStatus could not be resolved.";
         return result;
     }
     rc = datareader.GetRequestedIncompatibleQosStatus(ref riqStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = string.Format("OfferedIncompatibleStatus could not be resolved. ReturnCode: {0}", rc);
         result.Result = "RequestedIncompatibleStatus could not be resolved.";
         return result;
     }
     if (riqStatus.TotalCount != 0)
     {
         result.Result = "RequestedIncompatibleQosStatus.TotalCount != 0.";
         return result;
     }
     if (riqStatus.TotalCountChange != 0)
     {
         result.Result = "RequestedIncompatibleQosStatus.TotalCountChange != 0.";
         return result;
     }
     rc = datareader.GetSubscriptionMatchedStatus(ref smStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = string.Format("SubscriptionMatchStatus could not be resolved. ReturnCode: {0}", rc);
         return result;
     }
     rc = datareader.GetSampleLostStatus(ref slStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = string.Format("SampleLostStatus could not be resolved. ReturnCode: {0}", rc);
         return result;
     }
     if (slStatus.TotalCount != 0)
     {
         result.Result = "SampleLostStatus.TotalCount != 0.";
         return result;
     }
     if (slStatus.TotalCountChange != 0)
     {
         result.Result = "SampleLostStatus.TotalCountChange != 0.";
         return result;
     }
     rc = datareader.GetRequestedDeadlineMissedStatus(ref rdmStatus);
     if (rc != DDS.ReturnCode.Ok)
     {
         result.Result = string.Format("RequestedDeadlineMissedStatus could not be resolved. ReturnCode: {0}", rc);
         return result;
     }
     result.Result = expResult;
     result.Verdict = Test.Framework.TestVerdict.Pass;
     return result;
 }
Ejemplo n.º 9
0
 public virtual void OnSubscriptionMatched(DDS.IDataReader reader, DDS.SubscriptionMatchedStatus
                                           status)
 {
     onSubscriptionMatchCalled = true;
     smStatus = status;
 }
Ejemplo n.º 10
0
 public virtual void OnSubscriptionMatched(DDS.IDataReader reader, DDS.SubscriptionMatchedStatus
      status)
 {
     onSubscriptionMatchCalled = true;
     smStatus = status;
 }
Ejemplo n.º 11
0
        public override Test.Framework.TestResult Run()
        {
            mod.tstDataReader reader;
            DDS.IStatusCondition condition;
            DDS.WaitSet waitset;
            Test.Framework.TestResult result;
            DDS.ReturnCode rc;
            bool value;
            DDS.StatusKind statusMask;
            DDS.ICondition[] holder;
            DDS.SubscriptionMatchedStatus smStatus = new DDS.SubscriptionMatchedStatus();
            DDS.LivelinessChangedStatus lcStatus = new DDS.LivelinessChangedStatus();
            string expResult = "ReadCondition test succeeded.";
            result = new Test.Framework.TestResult(expResult, string.Empty,
                Test.Framework.TestVerdict.Pass, Test.Framework.TestVerdict.Fail);

            reader = (mod.tstDataReader)this.ResolveObject("datareader");
            condition = reader.StatusCondition;
            if (condition == null)
            {
                result.Result = "Could not resolve status condition.";
                return result;
            }
            waitset = new DDS.WaitSet();
            rc = waitset.AttachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "attach_condition failed.";
                return result;
            }
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception)
            {
                System.Console.Error.WriteLine("Sleep failed...");
            }
            holder = new DDS.Condition[0];
            rc = waitset.Wait(ref holder, new DDS.Duration(3, 0));
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "wait failed (1). Retcode == " + rc;
                return result;
            }
            if (holder.Length != 1)
            {
                System.Console.Out.WriteLine("Holder length : " + holder.Length);
                System.Console.Out.WriteLine("Status changes: " + reader.StatusChanges);
                reader.GetSubscriptionMatchedStatus(ref smStatus);
                System.Console.Out.WriteLine("Total count   : " + smStatus.TotalCount);
                reader.GetLivelinessChangedStatus(ref lcStatus);
                System.Console.Out.WriteLine("Alive count   : " + lcStatus.AliveCount);
                result.Result = "wait should return 1 condition but didn't (1).";
                return result;
            }
            rc = reader.GetLivelinessChangedStatus(ref lcStatus);
            
            DDS.LivelinessChangedStatus status = lcStatus;
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "GetLivelinessChangedStatus call failed.";
                return result;
            }
            if (status.AliveCount != 1)
            {
                result.Result = "LivelinessChanged.AliveCount != 1. (" + status.AliveCount +
                    ").";
                return result;
            }
            if (status.AliveCountChange != 1)
            {
                result.Result = "LivelinessChanged.AliveCountChange != 1." + status.AliveCountChange
                     + ").";
                return result;
            }

            value = condition.GetTriggerValue();
            if (value)
            {
                result.Result = "GetTriggerValue returned true. " + reader.StatusChanges;
                return result;
            }
            statusMask = condition.GetEnabledStatuses();
            rc = condition.SetEnabledStatuses(statusMask);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "SetEnabledStatuses failed (1).";
                return result;
            }
            if (condition.GetEnabledStatuses() != statusMask)
            {
                result.Result = "GetEnabledStatuses does not match the applied one.";
                return result;
            }
            if (condition.GetEntity() != reader)
            {
                result.Result = "GetEntity does not return the correct entity.";
                return result;
            }
            result.Result = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return result;
        }
Ejemplo n.º 12
0
        public override Test.Framework.TestResult Run()
        {
            DDS.ReturnCode                     rc;
            mod.tstDataReader                  datareader;
            DDS.SampleRejectedStatus           srStatus  = new DDS.SampleRejectedStatus();
            DDS.LivelinessChangedStatus        lcStatus  = new DDS.LivelinessChangedStatus();
            DDS.RequestedDeadlineMissedStatus  rdmStatus = new DDS.RequestedDeadlineMissedStatus();
            DDS.RequestedIncompatibleQosStatus riqStatus = new DDS.RequestedIncompatibleQosStatus();
            DDS.SubscriptionMatchedStatus      smStatus  = new DDS.SubscriptionMatchedStatus();
            DDS.SampleLostStatus               slStatus  = new DDS.SampleLostStatus();
            string expResult = "DataReader status test succeeded";

            Test.Framework.TestResult result;
            result = new Test.Framework.TestResult(expResult, string.Empty, Test.Framework.TestVerdict.Pass,
                                                   Test.Framework.TestVerdict.Fail);
            datareader = (mod.tstDataReader) this.ResolveObject("datareader");
            rc         = datareader.GetSampleRejectedStatus(ref srStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "SampleRejectedStatus could not be resolved.";
                return(result);
            }
            if (srStatus.TotalCount != 0)
            {
                result.Result = "SampleRejectedStatus.TotalCount != 0.";
                return(result);
            }
            if (srStatus.TotalCountChange != 0)
            {
                result.Result = "SampleRejectedStatus.TotalCountChange != 0.";
                return(result);
            }
            rc = datareader.GetLivelinessChangedStatus(ref lcStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = string.Format("OfferedIncompatibleStatus could not be resolved. ReturnCode: {0}", rc);
                result.Result = "LivelinessChangedStatus could not be resolved.";
                return(result);
            }
            rc = datareader.GetRequestedIncompatibleQosStatus(ref riqStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = string.Format("OfferedIncompatibleStatus could not be resolved. ReturnCode: {0}", rc);
                result.Result = "RequestedIncompatibleStatus could not be resolved.";
                return(result);
            }
            if (riqStatus.TotalCount != 0)
            {
                result.Result = "RequestedIncompatibleQosStatus.TotalCount != 0.";
                return(result);
            }
            if (riqStatus.TotalCountChange != 0)
            {
                result.Result = "RequestedIncompatibleQosStatus.TotalCountChange != 0.";
                return(result);
            }
            rc = datareader.GetSubscriptionMatchedStatus(ref smStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = string.Format("SubscriptionMatchStatus could not be resolved. ReturnCode: {0}", rc);
                return(result);
            }
            rc = datareader.GetSampleLostStatus(ref slStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = string.Format("SampleLostStatus could not be resolved. ReturnCode: {0}", rc);
                return(result);
            }
            if (slStatus.TotalCount != 0)
            {
                result.Result = "SampleLostStatus.TotalCount != 0.";
                return(result);
            }
            if (slStatus.TotalCountChange != 0)
            {
                result.Result = "SampleLostStatus.TotalCountChange != 0.";
                return(result);
            }
            rc = datareader.GetRequestedDeadlineMissedStatus(ref rdmStatus);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = string.Format("RequestedDeadlineMissedStatus could not be resolved. ReturnCode: {0}", rc);
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Ejemplo n.º 13
0
 public static bool SubscriptionMatchValid(DDS.IDataReader reader, int totalCount,
     int totalCountChange)
 {
     bool result = false;
     DDS.SubscriptionMatchedStatus holder = new DDS.SubscriptionMatchedStatus();
     DDS.ReturnCode rc = reader.GetSubscriptionMatchedStatus(ref holder);
     if (rc == DDS.ReturnCode.Ok)
     {
         DDS.SubscriptionMatchedStatus status = holder;
         if (status.TotalCount == totalCount)
         {
             if (status.TotalCountChange == totalCountChange)
             {
                 result = true;
             }
             else
             {
                 System.Console.Error.WriteLine("subscription_match.TotalCountChange != '" + totalCountChange
                      + "', but '" + status.TotalCountChange + "'.");
             }
         }
         else
         {
             System.Console.Error.WriteLine("subscription_match.TotalCount != '" + totalCount
                  + "', but '" + status.TotalCount + "'.");
         }
     }
     else
     {
         System.Console.Error.WriteLine("get_subscription_match_status returned " + rc);
     }
     return result;
 }
Ejemplo n.º 14
0
 private void PrintStatusses(DDS.IDataReader reader)
 {
     DDS.ReturnCode rc;
     DDS.RequestedDeadlineMissedStatus rdmsHolder = new DDS.RequestedDeadlineMissedStatus();
     rc = reader.GetRequestedDeadlineMissedStatus(ref rdmsHolder);
     DDS.RequestedDeadlineMissedStatus rdms = rdmsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.RequestedIncompatibleQosStatus riqsHolder = new DDS.RequestedIncompatibleQosStatus();
     rc = reader.GetRequestedIncompatibleQosStatus(ref riqsHolder);
     DDS.RequestedIncompatibleQosStatus riqs = riqsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SampleRejectedStatus srsHolder = new DDS.SampleRejectedStatus();
     rc = reader.GetSampleRejectedStatus(ref srsHolder);
     DDS.SampleRejectedStatus srs = srsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.LivelinessChangedStatus lcsHolder = new DDS.LivelinessChangedStatus();
     rc = reader.GetLivelinessChangedStatus(ref lcsHolder);
     DDS.LivelinessChangedStatus lcs = lcsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SubscriptionMatchedStatus smsHolder = new DDS.SubscriptionMatchedStatus();
     rc = reader.GetSubscriptionMatchedStatus(ref smsHolder);
     DDS.SubscriptionMatchedStatus sms = smsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SampleLostStatus slsHolder = new DDS.SampleLostStatus();
     rc = reader.GetSampleLostStatus(ref slsHolder);
     DDS.SampleLostStatus sls = slsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     System.Console.Out.WriteLine("requested_deadline_missed.TotalCount         : " +
          rdms.TotalCount);
     System.Console.Out.WriteLine("requested_deadline_missed.TotalCountChange  : " +
          rdms.TotalCountChange);
     System.Console.Out.WriteLine("requested_deadline_missed.LastInstanceHandle: " +
          rdms.LastInstanceHandle);
     System.Console.Out.WriteLine("requested_incompatible_qos.TotalCount        : " +
          riqs.TotalCount);
     System.Console.Out.WriteLine("requested_incompatible_qos.TotalCountChange : " +
          riqs.TotalCountChange);
     System.Console.Out.WriteLine("requested_incompatible_qos.LastPolicyId     : " +
          riqs.LastPolicyId);
     System.Console.Out.WriteLine("sample_rejected.TotalCount                   : " +
          srs.TotalCount);
     System.Console.Out.WriteLine("sample_rejected.TotalCountChange            : " +
          srs.TotalCountChange);
     System.Console.Out.WriteLine("sample_rejected.LastInstanceHandle          : " +
          srs.LastInstanceHandle);
     System.Console.Out.WriteLine("liveliness_changed.AliveCount                : " +
          lcs.AliveCount);
     System.Console.Out.WriteLine("liveliness_changed.AliveCountChange         : " +
          lcs.AliveCountChange);
     System.Console.Out.WriteLine("liveliness_changed.not_alive_count            : " +
          lcs.NotAliveCount);
     System.Console.Out.WriteLine("liveliness_changed.not_alive_count_change     : " +
          lcs.NotAliveCountChange);
     System.Console.Out.WriteLine("subscription_match.TotalCount                : " +
          sms.TotalCount);
     System.Console.Out.WriteLine("subscription_match.TotalCountChange         : " +
          sms.TotalCountChange);
     System.Console.Out.WriteLine("subscription_match.last_publication_handle    : " +
          sms.LastPublicationHandle);
     System.Console.Out.WriteLine("sample_lost.TotalCount                       : " +
          sls.TotalCount);
     System.Console.Out.WriteLine("sample_lost.TotalCountChange                : " +
          sls.TotalCountChange + "\n");
 }
Ejemplo n.º 15
0
        public override Test.Framework.TestResult Run()
        {
            mod.tstDataReader         reader;
            DDS.IStatusCondition      condition;
            DDS.WaitSet               waitset;
            Test.Framework.TestResult result;
            DDS.ReturnCode            rc;
            bool value;

            DDS.StatusKind   statusMask;
            DDS.ICondition[] holder;
            DDS.SubscriptionMatchedStatus smStatus = new DDS.SubscriptionMatchedStatus();
            DDS.LivelinessChangedStatus   lcStatus = new DDS.LivelinessChangedStatus();
            string expResult = "ReadCondition test succeeded.";

            result = new Test.Framework.TestResult(expResult, string.Empty,
                                                   Test.Framework.TestVerdict.Pass, Test.Framework.TestVerdict.Fail);

            reader    = (mod.tstDataReader) this.ResolveObject("datareader");
            condition = reader.StatusCondition;
            if (condition == null)
            {
                result.Result = "Could not resolve status condition.";
                return(result);
            }
            waitset = new DDS.WaitSet();
            rc      = waitset.AttachCondition(condition);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "attach_condition failed.";
                return(result);
            }
            try
            {
                System.Threading.Thread.Sleep(3000);
            }
            catch (System.Exception)
            {
                System.Console.Error.WriteLine("Sleep failed...");
            }
            holder = new DDS.Condition[0];
            rc     = waitset.Wait(ref holder, new DDS.Duration(3, 0));
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "wait failed (1). Retcode == " + rc;
                return(result);
            }
            if (holder.Length != 1)
            {
                System.Console.Out.WriteLine("Holder length : " + holder.Length);
                System.Console.Out.WriteLine("Status changes: " + reader.StatusChanges);
                reader.GetSubscriptionMatchedStatus(ref smStatus);
                System.Console.Out.WriteLine("Total count   : " + smStatus.TotalCount);
                reader.GetLivelinessChangedStatus(ref lcStatus);
                System.Console.Out.WriteLine("Alive count   : " + lcStatus.AliveCount);
                result.Result = "wait should return 1 condition but didn't (1).";
                return(result);
            }
            rc = reader.GetLivelinessChangedStatus(ref lcStatus);

            DDS.LivelinessChangedStatus status = lcStatus;
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "GetLivelinessChangedStatus call failed.";
                return(result);
            }
            if (status.AliveCount != 1)
            {
                result.Result = "LivelinessChanged.AliveCount != 1. (" + status.AliveCount +
                                ").";
                return(result);
            }
            if (status.AliveCountChange != 1)
            {
                result.Result = "LivelinessChanged.AliveCountChange != 1." + status.AliveCountChange
                                + ").";
                return(result);
            }

            rc = reader.GetSubscriptionMatchedStatus(ref smStatus);

            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "GetSubscriptionMatchedStatus call failed.";
                return(result);
            }
            if (smStatus.TotalCount != 1)
            {
                result.Result = "SubscriptionMatched.TotalCount != 1. (" + smStatus.TotalCount +
                                ").";
                return(result);
            }
            if (smStatus.TotalCountChange != 1)
            {
                result.Result = "SubscriptionMatched.TotalCountChange != 1." + smStatus.TotalCountChange
                                + ").";
                return(result);
            }

            value = condition.GetTriggerValue();
            if (value)
            {
                result.Result = "GetTriggerValue returned true. " + reader.StatusChanges;
                return(result);
            }
            statusMask = condition.GetEnabledStatuses();
            rc         = condition.SetEnabledStatuses(statusMask);
            if (rc != DDS.ReturnCode.Ok)
            {
                result.Result = "SetEnabledStatuses failed (1).";
                return(result);
            }
            if (condition.GetEnabledStatuses() != statusMask)
            {
                result.Result = "GetEnabledStatuses does not match the applied one.";
                return(result);
            }
            if (condition.GetEntity() != reader)
            {
                result.Result = "GetEntity does not return the correct entity.";
                return(result);
            }
            result.Result  = expResult;
            result.Verdict = Test.Framework.TestVerdict.Pass;
            return(result);
        }
Ejemplo n.º 16
0
 public override void on_subscription_matched(
     DDS.DataReader reader,
     ref DDS.SubscriptionMatchedStatus status)
 {
 }
Ejemplo n.º 17
0
 private void PrintStatusses(DDS.IDataReader reader)
 {
     DDS.ReturnCode rc;
     DDS.RequestedDeadlineMissedStatus rdmsHolder = new DDS.RequestedDeadlineMissedStatus();
     rc = reader.GetRequestedDeadlineMissedStatus(ref rdmsHolder);
     DDS.RequestedDeadlineMissedStatus rdms = rdmsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.RequestedIncompatibleQosStatus riqsHolder = new DDS.RequestedIncompatibleQosStatus();
     rc = reader.GetRequestedIncompatibleQosStatus(ref riqsHolder);
     DDS.RequestedIncompatibleQosStatus riqs = riqsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SampleRejectedStatus srsHolder = new DDS.SampleRejectedStatus();
     rc = reader.GetSampleRejectedStatus(ref srsHolder);
     DDS.SampleRejectedStatus srs = srsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.LivelinessChangedStatus lcsHolder = new DDS.LivelinessChangedStatus();
     rc = reader.GetLivelinessChangedStatus(ref lcsHolder);
     DDS.LivelinessChangedStatus lcs = lcsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SubscriptionMatchedStatus smsHolder = new DDS.SubscriptionMatchedStatus();
     rc = reader.GetSubscriptionMatchedStatus(ref smsHolder);
     DDS.SubscriptionMatchedStatus sms = smsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     DDS.SampleLostStatus slsHolder = new DDS.SampleLostStatus();
     rc = reader.GetSampleLostStatus(ref slsHolder);
     DDS.SampleLostStatus sls = slsHolder;
     if (rc != DDS.ReturnCode.Ok)
     {
         System.Console.Error.WriteLine("Unable to resolve status!");
         return;
     }
     System.Console.Out.WriteLine("requested_deadline_missed.TotalCount         : " +
                                  rdms.TotalCount);
     System.Console.Out.WriteLine("requested_deadline_missed.TotalCountChange  : " +
                                  rdms.TotalCountChange);
     System.Console.Out.WriteLine("requested_deadline_missed.LastInstanceHandle: " +
                                  rdms.LastInstanceHandle);
     System.Console.Out.WriteLine("requested_incompatible_qos.TotalCount        : " +
                                  riqs.TotalCount);
     System.Console.Out.WriteLine("requested_incompatible_qos.TotalCountChange : " +
                                  riqs.TotalCountChange);
     System.Console.Out.WriteLine("requested_incompatible_qos.LastPolicyId     : " +
                                  riqs.LastPolicyId);
     System.Console.Out.WriteLine("sample_rejected.TotalCount                   : " +
                                  srs.TotalCount);
     System.Console.Out.WriteLine("sample_rejected.TotalCountChange            : " +
                                  srs.TotalCountChange);
     System.Console.Out.WriteLine("sample_rejected.LastInstanceHandle          : " +
                                  srs.LastInstanceHandle);
     System.Console.Out.WriteLine("liveliness_changed.AliveCount                : " +
                                  lcs.AliveCount);
     System.Console.Out.WriteLine("liveliness_changed.AliveCountChange         : " +
                                  lcs.AliveCountChange);
     System.Console.Out.WriteLine("liveliness_changed.not_alive_count            : " +
                                  lcs.NotAliveCount);
     System.Console.Out.WriteLine("liveliness_changed.not_alive_count_change     : " +
                                  lcs.NotAliveCountChange);
     System.Console.Out.WriteLine("subscription_match.TotalCount                : " +
                                  sms.TotalCount);
     System.Console.Out.WriteLine("subscription_match.TotalCountChange         : " +
                                  sms.TotalCountChange);
     System.Console.Out.WriteLine("subscription_match.last_publication_handle    : " +
                                  sms.LastPublicationHandle);
     System.Console.Out.WriteLine("sample_lost.TotalCount                       : " +
                                  sls.TotalCount);
     System.Console.Out.WriteLine("sample_lost.TotalCountChange                : " +
                                  sls.TotalCountChange + "\n");
 }
        private void ReceiveData()
        {
            DDS.ConditionSeq activeConditions = new DDS.ConditionSeq();
            while (true)
            {
                try
                {
                    _waitset.wait(activeConditions, _timeout);
                    for (var c = 0; c < activeConditions.length; ++c)
                    {
                        if (activeConditions.get_at(c) == _statusCondition)
                        {
                            DDS.StatusMask triggeredmask =
                                _reader.get_status_changes();

                            if ((triggeredmask &
                                 (DDS.StatusMask)
                                 DDS.StatusKind.DATA_AVAILABLE_STATUS) != 0)
                            {
                                try
                                {
                                    DDS.TypedDataReader <T> dataReader
                                        = (DDS.TypedDataReader <T>)_reader;

                                    dataReader.take(
                                        _dataSeq,
                                        _infoSeq,
                                        DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
                                        DDS.SampleStateKind.ANY_SAMPLE_STATE,
                                        DDS.ViewStateKind.ANY_VIEW_STATE,
                                        DDS.InstanceStateKind.ANY_INSTANCE_STATE);

                                    int dataLength = _dataSeq.length;
                                    //Console.WriteLine("Received {0}", dataLength);
                                    for (var i = 0; i < dataLength; ++i)
                                    {
                                        DDS.SampleInfo info = _infoSeq.get_at(i);
                                        if (info.valid_data)
                                        {
                                            var data = new T();
                                            data.copy_from(_dataSeq.get_at(i));
                                            var key = _keySelector(data);
                                            DDSKeyedSubject <TKey, T> keyedSubject;

                                            if (!_keyedSubjectDict.ContainsKey(key))
                                            {
                                                keyedSubject = new DDSKeyedSubject <TKey, T>(key, _scheduler);
                                                _keyedSubjectDict.Add(key, keyedSubject);
                                                _handleKeyDict.Add(info.instance_handle, key);
                                                _groupSubject.OnNext(keyedSubject);
                                            }
                                            else
                                            {
                                                keyedSubject = _keyedSubjectDict[key];
                                                if (_externalSubDict)
                                                {
                                                    if (!_handleKeyDict.ContainsKey(info.instance_handle))
                                                    {
                                                        _handleKeyDict.Add(info.instance_handle, key);
                                                        _groupSubject.OnNext(keyedSubject);
                                                    }
                                                }
                                            }

                                            keyedSubject.OnNext(data);
                                        }
                                        else if (info.instance_state ==
                                                 DDS.InstanceStateKind.NOT_ALIVE_DISPOSED_INSTANCE_STATE)
                                        {
                                            if (_handleKeyDict.ContainsKey(info.instance_handle))
                                            {
                                                var key = _handleKeyDict[info.instance_handle];
                                                if (_keyedSubjectDict.ContainsKey(key))
                                                {
                                                    var keyedSub = _keyedSubjectDict[key];
                                                    _keyedSubjectDict.Remove(key);
                                                    _handleKeyDict.Remove(info.instance_handle);
                                                    keyedSub.OnCompleted();
                                                    /* FIXME: If the instance comes alive again, it will break the Rx contract */
                                                }
                                                else
                                                {
                                                    Console.WriteLine(
                                                        "InstanceDataReaderListener invariant broken: keyedSubDict does not contain key");
                                                }
                                            }
                                            else
                                            {
                                                Console.WriteLine(
                                                    "InstanceDataReaderListener invariant broken: handleKeyDict does not contain info.instance_handle");
                                            }
                                        }
                                    }

                                    dataReader.return_loan(_dataSeq, _infoSeq);
                                }
                                catch (DDS.Retcode_NoData)
                                {
                                    _subject.OnCompleted();
                                    return;
                                }
                                catch (Exception ex)
                                {
                                    _subject.OnError(ex);
                                    Console.WriteLine($"ObservableTopicWaitSet: take error {ex}");
                                }
                            }
                            else
                            {
                                StatusKindPrinter.print((int)triggeredmask);
                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SUBSCRIPTION_MATCHED_STATUS) != 0)
                                {
                                    DDS.SubscriptionMatchedStatus status = new DDS.SubscriptionMatchedStatus();
                                    _reader.get_subscription_matched_status(ref status);
                                    Console.WriteLine($"Subscription matched. current_count = {status.current_count}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.LIVELINESS_CHANGED_STATUS) != 0)
                                {
                                    DDS.LivelinessChangedStatus status = new DDS.LivelinessChangedStatus();
                                    _reader.get_liveliness_changed_status(ref status);
                                    Console.WriteLine($"Liveliness changed. alive_count = {status.alive_count}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_LOST_STATUS) != 0)
                                {
                                    DDS.SampleLostStatus status = new DDS.SampleLostStatus();
                                    _reader.get_sample_lost_status(ref status);
                                    Console.WriteLine($"Sample lost. Reason = {status.last_reason.ToString()}");
                                }

                                if ((triggeredmask &
                                     (DDS.StatusMask)
                                     DDS.StatusKind.SAMPLE_REJECTED_STATUS) != 0)
                                {
                                    DDS.SampleRejectedStatus status = new DDS.SampleRejectedStatus();
                                    _reader.get_sample_rejected_status(ref status);
                                    Console.WriteLine($"Sample Rejected. Reason = {status.last_reason.ToString()}");
                                }
                            }
                        }
                    }
                }
                catch (DDS.Retcode_Timeout)
                {
                    Console.WriteLine("wait timed out");
                }
            }
        }