private static DomainParticipantQos ConfigureFlowController(
            uint tokenBucketPeriodMs)
        {
            // We'll get the QoS defined in the XML profile "cfc_Profile"
            // (the default profile in USER_QOS_PROFILES.xml) and tweak the
            // token bucket period
            DomainParticipantQos baseQos =
                QosProvider.Default.GetDomainParticipantQos();

            if (tokenBucketPeriodMs == 0)
            {
                return(baseQos);
            }

            // This is the name we use in the XML file
            const string flowControllerName =
                "dds.flow_controller.token_bucket.custom_flowcontroller";

            // baseQos.WithProperty(...) creates a new DomainParticipantQos
            // object with the changes we specify in the lambda function.
            return(baseQos.WithProperty(property =>
            {
                // In WithProperty the input argument 'property' contains the
                // current values of baseQos.Property. We will just modify these
                // two properties.
                var period = Duration.FromMilliseconds(tokenBucketPeriodMs);
                property[$"{flowControllerName}.token_bucket.period.sec"] =
                    period.Seconds.ToString();
                property[$"{flowControllerName}.token_bucket.period.nanosec"] =
                    period.Nanoseconds.ToString();
            }));
        }
Esempio n. 2
0
        public void TestSetDefaultDomainParticipantQos()
        {
            // Creates a non-default QoS, set it an check it
            DomainParticipantQos qos    = TestHelper.CreateNonDefaultDomainParticipantQos();
            ReturnCode           result = AssemblyInitializer.Factory.SetDefaultDomainParticipantQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new DomainParticipantQos();
            result = AssemblyInitializer.Factory.GetDefaultDomainParticipantQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestNonDefaultDomainParticipantQos(qos);

            // Put back the default QoS and check it
            qos    = new DomainParticipantQos();
            result = AssemblyInitializer.Factory.SetDefaultDomainParticipantQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            result = AssemblyInitializer.Factory.GetDefaultDomainParticipantQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestDefaultDomainParticipantQos(qos);

            // Test with null parameter
            result = AssemblyInitializer.Factory.SetDefaultDomainParticipantQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
 internal static DDS.ReturnCode CopyIn(DomainParticipantQos from, IntPtr to)
 {
     DDS.ReturnCode result;
     if (from != null) {
         result = UserDataQosPolicyMarshaler.CopyIn(from.UserData, to, offset_user_data);
         if (result == DDS.ReturnCode.Ok) {
             result = EntityFactoryQosPolicyMarshaler.CopyIn(
                     from.EntityFactory, to, offset_entity_factory);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = SchedulingQosPolicyMarshaler.CopyIn(
                     from.WatchdogScheduling, to, offset_watchdog_scheduling);
         }
         if (result == DDS.ReturnCode.Ok) {
             result = SchedulingQosPolicyMarshaler.CopyIn(
                     from.ListenerScheduling, to, offset_listener_scheduling);
         }
     } else {
         result = DDS.ReturnCode.BadParameter;
         DDS.OpenSplice.OS.Report(
                 DDS.OpenSplice.ReportType.OS_ERROR,
                 "DDS.OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler.CopyIn",
                 "DDS/OpenSplice/CustomMarshalers/QosToplevelMarshalers.cs",
                 DDS.ErrorCode.InvalidValue,
                 "DomainParticipantQos attribute may not be a null pointer.");
     }
     return result;
 }
Esempio n. 4
0
        public void TestTakeNextInstance()
        {
            List <ParticipantBuiltinTopicData> data = new List <ParticipantBuiltinTopicData>();
            List <SampleInfo> infos = new List <SampleInfo>();
            ReturnCode        ret   = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Assert.IsTrue(_participant.WaitForParticipants(1, 20_000));

            ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            Assert.AreEqual(1, data.First().UserData.Value.Count);
            Assert.AreEqual(0x42, data.First().UserData.Value.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
Esempio n. 5
0
        public ISubscriber CreateSubscriber(SubscriberQos qos, ISubscriberListener listener, StatusKind mask)
        {
            ISubscriber subscriber = null;

            using (OpenSplice.CustomMarshalers.SubscriberQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.SubscriberQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        OpenSplice.Gapi.gapi_subscriberListener gapiListener;
                        SubscriberListenerHelper listenerHelper = new SubscriberListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (SubscriberListenerMarshaler listenerMarshaler =
                                   new SubscriberListenerMarshaler(ref gapiListener))
                        {
                            IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                                GapiPeer,
                                marshaler.GapiPtr,
                                listenerMarshaler.GapiPtr,
                                mask);
                            if (gapiPtr != IntPtr.Zero)
                            {
                                subscriber = new Subscriber(gapiPtr, listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                            GapiPeer,
                            marshaler.GapiPtr,
                            IntPtr.Zero,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            subscriber = new Subscriber(gapiPtr);
                        }
                    }
                }
            }

            if (subscriber != null)
            {
                DomainParticipantQos dpQos  = null;
                ReturnCode           result = GetQos(ref dpQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        subscriber.Enable();
                    }
                }
            }

            return(subscriber);
        }
Esempio n. 6
0
        public void TestLookupInstance()
        {
            ParticipantBuiltinTopicData data = default;
            SampleInfo info = new SampleInfo();

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Thread.Sleep(500);

            ReturnCode ret = _dr.ReadNextSample(ref data, info);

            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.UserData.Value.Count());
            Assert.AreEqual(0x42, data.UserData.Value.First());

            // Lookup for an existing instance
            var handle = _dr.LookupInstance(data);

            Assert.AreNotEqual(InstanceHandle.HandleNil, handle);

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
Esempio n. 7
0
        /// <summary>
        /// This operation gets the default DomainParticipantQos of the DomainParticipantFactory
        /// </summary>
        /// <remarks>
        /// This operation gets the default DomainParticipantQos of the
        /// DomainParticipantFactory (that is the struct with the QosPolicy settings)
        /// which is used for newly created IDomainParticipant objects, in case no QoS is used
        /// in the CreateParticipant operation.
        ///
        /// The application must provide the DomainParticipantQos struct in which the
        /// QosPolicy settings can be stored and provide a reference to the struct. The
        /// operation writes the default QosPolicy settings to the struct referenced to by qos.<br>
        /// Any settings in the struct are overwritten.<br>
        /// The values retrieved by this operation match the set of values specified on the last
        /// successful call to SetDefaultParticipantQos(), or, if the call was never
        /// made, the default values as specified for each QosPolicy setting.
        /// </remarks>
        /// @param qos A reference to the DomainParticipantQos in which the default
        ///            DomainParticipantQos for the IDomainParticipant is written
        /// @return DDS.ReturnCode Ok - The new default DomainParticipantQos is set
        /// @return DDS.ReturnCode Error - An internal error has occured
        /// @return DDS.ReturnCode OutOfResources - The DDS ran out of resources to complete this operation
        public ReturnCode GetDefaultParticipantQos(ref DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                lock (singleton_lock)
                {
                    ReportStack.Start();
                    result = marshaler.CopyIn(defaultParticipantQos);
                    if (result == ReturnCode.Ok)
                    {
                        marshaler.CopyOut(ref qos);
                        // Listener scheduling qospolicy is not part of User Layer, so obtain it separately from participant.
                        if (qos.ListenerScheduling.SchedulingClass == null)
                        {
                            qos.ListenerScheduling.SchedulingClass = new SchedulingClassQosPolicy();
                        }
                        qos.ListenerScheduling.SchedulingClass.Kind = this.defaultParticipantQos.ListenerScheduling.SchedulingClass.Kind;
                        if (qos.ListenerScheduling.SchedulingPriorityKind == null)
                        {
                            qos.ListenerScheduling.SchedulingPriorityKind = new SchedulingPriorityQosPolicy();
                        }
                        qos.ListenerScheduling.SchedulingPriorityKind.Kind = this.defaultParticipantQos.ListenerScheduling.SchedulingPriorityKind.Kind;
                        qos.ListenerScheduling.SchedulingPriority          = this.defaultParticipantQos.ListenerScheduling.SchedulingPriority;
                    }
                    ReportStack.Flush(null, result != ReturnCode.Ok);
                }
            }

            return(result);
        }
Esempio n. 8
0
        public void TestRead()
        {
            List <ParticipantBuiltinTopicData> data = new List <ParticipantBuiltinTopicData>();
            List <SampleInfo> infos = new List <SampleInfo>();
            ReturnCode        ret   = _dr.Read(data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);
            Assert.AreEqual(0, data.Count);
            Assert.AreEqual(0, infos.Count);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Thread.Sleep(500);

            ret = _dr.Read(data, infos);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, infos.Count);
            Assert.AreEqual(1, data.First().UserData.Value.Count());
            Assert.AreEqual(0x42, data.First().UserData.Value.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
Esempio n. 9
0
 internal virtual AddDomainStatus AddDomainParticipant(int domain, DomainParticipantQos qos)
 {
     lock (this)
     {
         AddDomainStatus ads = new AddDomainStatus() { id = new GUID(), federated = false };
         generator.Populate(ref ads.id);
         ads.id.EntityId = EntityId.ENTITYID_PARTICIPANT;
         try
         {
             if (participants_.ContainsKey(domain) && participants_[domain] != null)
             {
                 participants_[domain][ads.id] = new Spdp(domain, ads.id, qos, this);
             }
             else
             {
                 participants_[domain] = new Dictionary<GUID, Spdp>();
                 participants_[domain][ads.id] = new Spdp(domain, ads.id, qos, this);
             }
         }
         catch (Exception e)
         {
             ads.id = GUID.GUID_UNKNOWN;
             //  ACE_ERROR((LM_ERROR, "(%P|%t) RtpsDiscovery::add_domain_participant() - "
             //    "failed to initialize RTPS Simple Participant Discovery Protocol: %C\n",
             //    e.what()));
         }
         return ads;
     }
 }
Esempio n. 10
0
        public void TestTakeNextSample()
        {
            ParticipantBuiltinTopicData data = default;
            SampleInfo infos = new SampleInfo();
            ReturnCode ret   = _dr.TakeNextSample(ref data, infos);

            Assert.AreEqual(ReturnCode.NoData, ret);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Assert.IsTrue(_participant.WaitForParticipants(1, 20_000));

            ret = _dr.TakeNextSample(ref data, infos);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.UserData.Value.Count);
            Assert.AreEqual(0x42, data.UserData.Value.First());

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
        private bool ConfigureWanTransport(ref DomainParticipantQos qos)
        {
            qos = qos.WithTransportBuiltin(policy =>
                                           policy.Mask = Rti.Dds.Core.Policy.TransportBuiltinMask.None);

            qos = qos.WithProperty(policy =>
                                   policy.Add("dds.transport.load_plugins",
                                              TransportConfig.PrefixString));

            qos = qos.WithProperty(policy =>
                                   policy.Add(TransportConfig.PrefixString + ".library",
                                              "nddstransportwan"));

            qos = qos.WithProperty(policy =>
                                   policy.Add(TransportConfig.PrefixString + ".create_function",
                                              "NDDS_Transport_WAN_create"));

            if (!string.IsNullOrEmpty(WanOptions.WanServerAddress))
            {
                qos = qos.WithProperty(policy =>
                                       policy.Add(TransportConfig.PrefixString + ".server",
                                                  WanOptions.WanServerAddress));
            }
            else
            {
                Console.Error.Write(ClassLoggingString + " Wan Server Address is required");
                return(false);
            }

            if (!string.IsNullOrEmpty(WanOptions.WanServerPort))
            {
                qos = qos.WithProperty(policy =>
                                       policy.Add(TransportConfig.PrefixString + ".server_port",
                                                  WanOptions.WanServerPort));
            }

            if (!string.IsNullOrEmpty(WanOptions.WanId))
            {
                qos = qos.WithProperty(policy =>
                                       policy.Add(TransportConfig.PrefixString + ".transport_instance_id",
                                                  WanOptions.WanId));
            }
            else
            {
                Console.Error.Write(ClassLoggingString + " Wan ID is required");
                return(false);
            }

            if (WanOptions.SecureWan)
            {
                qos = qos.WithProperty(policy =>
                                       policy.Add(TransportConfig.PrefixString + ".enable_security",
                                                  "1"));

                ConfigureSecurityFiles(ref qos);
            }

            return(true);
        }
Esempio n. 12
0
 public static void TestDefaultDomainParticipantQos(DomainParticipantQos qos)
 {
     Assert.IsNotNull(qos.EntityFactory);
     Assert.IsNotNull(qos.UserData);
     Assert.IsTrue(qos.EntityFactory.AutoenableCreatedEntities);
     Assert.IsNotNull(qos.UserData.Value);
     Assert.AreEqual(0, qos.UserData.Value.Count());
 }
        /// <summary>
        /// Create a new domain participant.
        /// </summary>
        /// <param name="domainId"></param>
        /// <param name="qos"></param>
        /// <param name="listener"></param>
        /// <param name="statuses">Of which status changes the listener should be
        ///                        notified. A null collection signifies all status 
        ///                        changes</param>
        /// <returns></returns>

        public override DomainParticipant CreateParticipant(int domainId, DomainParticipantQos qos, DomainParticipantListener listener, ICollection<Type> statuses)
        {
            DomainParticipant dp = new DomainParticipantImpl(domainId, qos, listener, this.bootstrap_);
            if (((DomainParticipantFactoryQosImpl)this.Qos).EntityFactoryQosPolicy.IsAutoEnableCreatedEntities())
                dp.Enable();

            return dp;
        }
        private DomainParticipantQos ConfigureTcpTransport(DomainParticipantQos initialQos)
        {
            var qos = initialQos.WithTransportBuiltin(policy =>
                                                      policy.Mask = TransportBuiltinMask.None);

            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add("dds.transport.load_plugins", TransportConfig.PrefixString);

            if (!string.IsNullOrEmpty(TcpOptions.ServerBindPort))
            {
                properties.Add(TransportConfig.PrefixString + ".server_bind_port",
                               TcpOptions.ServerBindPort);
            }

            if (TcpOptions.WanNetwork)
            {
                properties.Add(TransportConfig.PrefixString + ".parent.classid",
                               "NDDS_TRANSPORT_CLASSID_TCPV4_WAN");

                if (TcpOptions.ServerBindPort != "0")
                {
                    if (!string.IsNullOrEmpty(TcpOptions.PublicAddress))
                    {
                        properties.Add(TransportConfig.PrefixString + ".public_address",
                                       TcpOptions.PublicAddress);
                    }
                    else
                    {
                        Console.Error.WriteLine(ClassLoggingString
                                                + " Public Address is required if Server Bind Port != 0");
                        return(null);
                    }
                }
            }

            if (TransportConfig.Kind == Transport.Tlsv4)
            {
                if (TcpOptions.WanNetwork)
                {
                    properties.Add(TransportConfig.PrefixString + ".parent.classid",
                                   "NDDS_TRANSPORT_CLASSID_TLSV4_WAN");
                }
                else
                {
                    properties.Add(TransportConfig.PrefixString + ".parent.classid",
                                   "NDDS_TRANSPORT_CLASSID_TLSV4_LAN");
                }

                ConfigureSecurityFiles(ref qos);
            }

            qos = qos.WithProperty(Property.FromDictionary(properties));

            return(qos);
        }
Esempio n. 15
0
        /// <summary>
        /// This operation creates a new IDomainParticipant which will join the domain
        /// identified by domainId, with the desired DomainParticipantQos and attaches
        /// the specified IDomainParticipantListener to it and uses the given communication
        /// StatusKind mask.
        /// </summary>
        /// <remarks>
        /// <i><b>Identifying the Domain</b></i><br>
        /// The IDomainParticipant will attach to the Domain that is specified by the
        /// domainId parameter. This parameter consists of an integer specified in the Id tag
        /// in the configuration file. Note that to make multiple connections to a Domain (create
        /// multiple Participants for the same Domain) within a single process, all of the
        /// Participants must use the same identification (i.e. all use the same domain Id).
        ///
        /// The constant DDS.DomainId.Default can be used for this parameter. If this is done
        /// the value of Id tag from the configuration file specified by the environment variable
        /// called OSPL_URI will be used.
        ///
        /// It is recommended to use this domain Id in conjunction with the OSPL_URI
        /// environment variable instead of hard-coding a domain Id into your application,
        /// since this gives you much more flexibility in the deployment phase of your product.<br>
        /// See also Section 1.3.2.1, The OSPL_URI environment variable, in the Deployment
        /// Guide.
        ///
        /// <i><b>Communication Status</b></i><br>
        /// For each communication status, the StatusChangedFlag flag is initially set to
        /// false. It becomes true whenever that communication status changes. For each
        /// communication status activated in the mask , the associated
        /// IDomainParticipantListener operation is invoked and the communication
        /// status is reset to false , as the listener implicitly accesses the status which is passed
        /// as a parameter to that operation. The fact that the status is reset prior to calling the
        /// listener means that if the application calls the Get<status_name>Status from
        /// inside the listener it will see the status already reset.
        ///
        /// The following statuses are applicable to the IDomainParticipant
        /// - DDS.StatusKind InconsistentTopic (propagated)
        /// - DDS.StatusKind OfferedDeadlineMissed (propagated)
        /// - DDS.StatusKind RequestedDeadlineMissed (propagated)
        /// - DDS.StatusKind OfferedIncompatibleQos (propagated)
        /// - DDS.StatusKind RequestedIncompatibleQos (propagated)
        /// - DDS.StatusKind SampleLost (propagated)
        /// - DDS.StatusKind SampleRejected (propagated)
        /// - DDS.StatusKind DataOnReaders (propagated)
        /// - DDS.StatusKind DataAvailable (propagated)
        /// - DDS.StatusKind LivelinessLost (propagated)
        /// - DDS.StatusKind LivelinessChanged (propagated)
        /// - DDS.StatusKind PublicationMatched (propagated)
        /// - DDS.StatusKind SubscriptionMatched (propagated)
        ///
        /// Be aware that the PublicationMatched and SubscriptionMatched
        /// statuses are not applicable when the infrastructure does not have the
        /// information available to determine connectivity. This is the case when OpenSplice
        /// is configured not to maintain discovery information in the Networking Service. (See
        /// the description for the NetworkingService/Discovery/enabled property in
        /// the Deployment Manual for more information about this subject.) In this case the
        /// operation will return NULL.
        ///
        /// Status bits are declared as a constant and can be used by the application in an OR
        /// operation to create a tailored mask. The special constant 0 can
        /// be used to indicate that the created entity should not respond to any of its available
        /// statuses. The DDS will therefore attempt to propagate these statuses to its factory.
        ///
        /// <i><b>Status Propagation</b></i><br>
        /// The Data Distribution Service will trigger the most specific and relevant Listener.<br>
        /// In other words, in case a communication status is also activated on the Listener of
        /// a contained entity, the Listener on that contained entity is invoked instead of the
        /// IDomainParticipantListener. This means that a status change on a contained
        /// entity only invokes the IDomainParticipantListener if the contained entity
        /// itself does not handle the trigger event generated by the status change.
        ///
        /// The statuses DataOnReaders and DataAvailable are
        /// “Read Communication Statuses” and are an exception to all other plain
        /// communication statuses: they have no corresponding status structure that can be
        /// obtained with a Get<status_name>Status operation and they are mutually
        /// exclusive. When new information becomes available to a IDataReader, the Data
        /// Distribution Service will first look in an attached and activated
        /// ISubscriberListener or IDomainParticipantListener (in that order) for the
        /// DataOnReaders. In case the DataOnReaders can not be
        /// handled, the Data Distribution Service will look in an attached and activated
        /// IDataReaderListener, ISubscriberListener or IDomainParticipantListener for
        /// the DataAvailable (in that order).
        /// </remarks>
        /// @param domainId The ID of the Domain to which the IDomainParticipant is joined.
        ///                 This should be the ID as specified in the configuration file.
        /// @param qos      a DomainParticipantQos for the new IDomainParticipant. When
        ///                 this set of QosPolicy settings is inconsistent, no
        ///                 IDomainParticipant is created.
        /// @param listener A IDomainParticipantListener instance which will be attached to
        ///                 the new IDomainParticipant. It is permitted to use null as the
        ///                 value of the listener: this behaves as a IDomainParticipantListener
        ///                 whose operations perform no action.
        /// @param mask     A bit-mask in which each bit enables the invocation of the
        ///                 IDomainParticipantListener for a certain status.
        /// @return The newly created IDomainParticipant. In case of an error a null is returned.
        public IDomainParticipant CreateParticipant(
            DomainId domainId,
            DomainParticipantQos qos,
            IDomainParticipantListener listener,
            StatusKind mask)
        {
            DomainParticipant participant = null;
            ReturnCode        result;

            ReportStack.Start();
            result = QosManager.checkQos(qos);
            if (result == DDS.ReturnCode.Ok)
            {
                if (domainId != DDS.DomainId.Invalid)
                {
                    lock (singleton_lock)
                    {
                        participant = new OpenSplice.DomainParticipant();
                        result      = participant.init(domainId, qos);
                        if (result == ReturnCode.Ok)
                        {
                            result = participant.SetListener(listener, mask);
                        }
                        else
                        {
                            participant = null;
                        }

                        if (result == ReturnCode.Ok)
                        {
                            participantList.Add(participant);
                            if (myQos.EntityFactory.AutoenableCreatedEntities)
                            {
                                result = participant.Enable();
                            }
                        }
                    }
                }
                else
                {
                    ReportStack.Report(DDS.ReturnCode.BadParameter,
                                       "DomainParticipant is using an invalid domain identifier (" + domainId + ").");
                }
            }

            if (result != ReturnCode.Ok && participant != null)
            {
                // Ignore result because we prefer the original error.
                DeleteParticipant(participant);
                participant = null;
            }

            ReportStack.Flush(null, result != ReturnCode.Ok);
            return(participant);
        }
Esempio n. 16
0
        public static DomainParticipantQos CreateNonDefaultDomainParticipantQos()
        {
            DomainParticipantQos qos = new DomainParticipantQos();

            qos.EntityFactory.AutoenableCreatedEntities = false;
            qos.UserData.Value = new List <byte> {
                0x42
            };

            return(qos);
        }
Esempio n. 17
0
        public IPublisher CreatePublisher(IPublisherListener listener, StatusKind mask)
        {
            IPublisher publisher = null;

            if (listener != null)
            {
                // Note: we use the same gapi lister as the DataWriter since the
                // publisher doesn't add anything unique
                OpenSplice.Gapi.gapi_publisherDataWriterListener gapiListener;
                PublisherDataWriterListenerHelper listenerHelper = new PublisherDataWriterListenerHelper();
                listenerHelper.Listener = listener;
                listenerHelper.CreateListener(out gapiListener);
                using (PublisherDataWriterListenerMarshaler listenerMarshaler =
                           new PublisherDataWriterListenerMarshaler(ref gapiListener))
                {
                    IntPtr gapiPtr = Gapi.DomainParticipant.create_publisher(
                        GapiPeer,
                        Gapi.NativeConstants.GapiPublisherQosDefault,
                        listenerMarshaler.GapiPtr,
                        mask);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        publisher = new Publisher(gapiPtr, listenerHelper);
                    }
                }
            }
            else
            {
                IntPtr gapiPtr = Gapi.DomainParticipant.create_publisher(
                    GapiPeer,
                    Gapi.NativeConstants.GapiPublisherQosDefault,
                    IntPtr.Zero,
                    mask);
                if (gapiPtr != IntPtr.Zero)
                {
                    publisher = new Publisher(gapiPtr);
                }
            }

            if (publisher != null)
            {
                DomainParticipantQos dpQos  = null;
                ReturnCode           result = GetQos(ref dpQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        publisher.Enable();
                    }
                }
            }

            return(publisher);
        }
Esempio n. 18
0
        GetParticipantQos(
            ref DomainParticipantQos participantQos,
            string id)
        {
            NamedDomainParticipantQos pQos = new NamedDomainParticipantQos();
            GCHandle   qosHandle           = GCHandle.Alloc(pQos, GCHandleType.Normal);
            ReturnCode result = OpenSplice.Common.QosProvider.GetParticipantQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));

            participantQos = pQos.DomainparticipantQos;
            qosHandle.Free();
            return(result);
        }
Esempio n. 19
0
        /// <summary>
        /// Create Domain Participant
        /// </summary>
        /// <param name="partitionName">Create the participant and assign the partition name.</param>
        public void createParticipant(String partitionName)
        {
            dpf   = DomainParticipantFactory.Instance;
            dpQos = new DomainParticipantQos();
            dpf.GetDefaultParticipantQos(ref dpQos);

            ErrorHandler.checkHandle(dpf, "DomainParticipantFactory.Instance");

            participant = dpf.CreateParticipant(null, dpQos);
            ErrorHandler.checkHandle(participant, "DomainParticipantFactory.CreateParticipant");
            this.partitionName = partitionName;
        }
Esempio n. 20
0
        /// <summary>
        /// Create Domain Participant
        /// </summary>
        /// <param name="partitionName">Create the participant and assign the partition name.</param>
        public void createParticipant(String partitionName)
        {
            dpf = DomainParticipantFactory.Instance;
            dpQos = new DomainParticipantQos();
            dpf.GetDefaultParticipantQos(ref dpQos);
            
            ErrorHandler.checkHandle(dpf, "DomainParticipantFactory.Instance");

            participant = dpf.CreateParticipant(DDS.DomainId.Default,dpQos);
            ErrorHandler.checkHandle(participant, "DomainParticipantFactory.CreateParticipant");
            this.partitionName = partitionName;
        }
Esempio n. 21
0
        public ISubscriber CreateSubscriber(ISubscriberListener listener, StatusKind mask)
        {
            ISubscriber subscriber = null;

            if (listener != null)
            {
                OpenSplice.Gapi.gapi_subscriberListener gapiListener;
                SubscriberListenerHelper listenerHelper = new SubscriberListenerHelper();
                listenerHelper.Listener = listener;
                listenerHelper.CreateListener(out gapiListener);
                using (SubscriberListenerMarshaler listenerMarshaler =
                           new SubscriberListenerMarshaler(ref gapiListener))
                {
                    IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                        GapiPeer,
                        Gapi.NativeConstants.GapiSubscriberQosDefault,
                        listenerMarshaler.GapiPtr,
                        mask);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        subscriber = new Subscriber(gapiPtr, listenerHelper);
                    }
                }
            }
            else
            {
                IntPtr gapiPtr = Gapi.DomainParticipant.create_subscriber(
                    GapiPeer,
                    Gapi.NativeConstants.GapiSubscriberQosDefault,
                    IntPtr.Zero,
                    mask);
                if (gapiPtr != IntPtr.Zero)
                {
                    subscriber = new Subscriber(gapiPtr);
                }
            }

            if (subscriber != null)
            {
                DomainParticipantQos dpQos  = null;
                ReturnCode           result = GetQos(ref dpQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        subscriber.Enable();
                    }
                }
            }

            return(subscriber);
        }
Esempio n. 22
0
        public void TestGetDefaultDomainParticipantQos()
        {
            DomainParticipantQos qos = TestHelper.CreateNonDefaultDomainParticipantQos();

            ReturnCode result = AssemblyInitializer.Factory.GetDefaultDomainParticipantQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);
            TestHelper.TestDefaultDomainParticipantQos(qos);

            // Test with null parameter
            result = AssemblyInitializer.Factory.GetDefaultDomainParticipantQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
Esempio n. 23
0
        /// <summary>
        /// Creates a DomainParticipant, Topic, Publisher and DataWriter.
        /// </summary>
        public HelloWorldPublisher(
            int domainId,
            string expectedPassword,
            string topicName)
        {
            // Save the expected password. We will only communicate with
            // subscriptions that send this password via discovery.
            this.expectedPassword = expectedPassword;

            // Configure the participant QoS to increase the user data max length
            DomainParticipantQos participantQos =
                DomainParticipantFactory.Instance.DefaultParticipantQos
                .WithResourceLimits(policy => policy.ParticipantUserDataMaxLength = 1024);

            // Create the participant
            participant = DomainParticipantFactory.Instance.CreateParticipant(
                domainId,
                qos: participantQos,
                preEnableAction: p =>
            {
                // The preEnableAction is executed right before the participant
                // is enabled and communication starts. By looking up the
                // built-in discovery readers here we ensure that
                // that they will receive all the discovery information.
                participantReader = p.BuiltinSubscriber
                                    .LookupDataReader <ParticipantBuiltinTopicData>(
                    Subscriber.ParticipantBuiltinTopicName);

                // The DataAvailable event is called when another participant
                // is discovered and before this participant has started
                // communicating with it
                participantReader.DataAvailable += OnNewParticipant;

                subscriptionReader = p.BuiltinSubscriber
                                     .LookupDataReader <SubscriptionBuiltinTopicData>(
                    Subscriber.SubscriptionBuiltinTopicName);

                subscriptionReader.DataAvailable += OnNewSubscription;
            }
                );

            // Create a topic, a publisher and a writer
            Topic <HelloWorld> topic     = participant.CreateTopic <HelloWorld>(topicName);
            Publisher          publisher = participant.CreatePublisher();

            writer = publisher.CreateDataWriter(topic);
        }
        private static void RegisterDomain(Topic <T> topicInstance, string domain)
        {
            lock (_locker)
            {
                DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
                ErrorHandler.CheckHandle(dpf, "DDS.DomainParticipantFactory.Instance");
                var dpQos = new DomainParticipantQos();
                dpf.GetDefaultParticipantQos(ref dpQos);
                topicInstance.Participant = dpf.CreateParticipant(domain, dpQos) ??
                                            (dpf.LookupParticipant(domain) ?? dpf.CreateParticipant(domain, dpQos));

                if (topicInstance.Participant == null)
                {
                    throw new Exception("DDS NOT started, please start / restart your DDS!");
                }
            }
        }
        private void ConfigureDtlsTransport(ref DomainParticipantQos qos)
        {
            qos = qos.WithTransportBuiltin(policy =>
                                           policy.Mask = Rti.Dds.Core.Policy.TransportBuiltinMask.None);

            qos = qos.WithProperty(policy =>
            {
                policy.Add("dds.transport.load_plugins",
                           TransportConfig.PrefixString);
                policy.Add(TransportConfig.PrefixString + ".library",
                           "nddstransporttls");
                policy.Add(TransportConfig.PrefixString + ".create_function",
                           "NDDS_Transport_DTLS_create");
            });

            ConfigureSecurityFiles(ref qos);
        }
        /*
         * Gets the MessageSizeMax given the name (String) of a transport from a
         * DDS_DomainParticipantQos object. If the value is not present, returns
         * DEFAULT_MESSAGE_SIZE_MAX.
         */
        private static ulong GetTransportMessageSizeMax(
            String targetTransportName,
            DomainParticipantQos qos)
        {
            string propertyName = TransportConfigMap[targetTransportName].PrefixString + ".parent.message_size_max";

            if (qos.Property.Value.TryGetValue(
                    propertyName,
                    out var propertyEntry))
            {
                return(Convert.ToUInt64(propertyEntry.Value));
            }
            else
            {
                return(DefaultMessageSizeMax);
            }
        }
Esempio n. 27
0
        public ReturnCode SetQos(DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    result = Gapi.DomainParticipant.set_qos(
                        GapiPeer,
                        marshaler.GapiPtr);
                }
            }
            return(result);
        }
Esempio n. 28
0
        public void BasicRoundTrip()
        {
            var serializer = new JsonCommonSerializer();

            var factory = DomainParticipantFactory.get_instance();

            var serverQos = new DomainParticipantQos();

            factory.get_default_participant_qos(serverQos);

            //serverQos.transport_builtin.mask = 0; // disable built-in transports
            //serverQos.property_qos.value


            serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" });
            var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE);

            var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest");
            var serverRouter    = new DefaultMessageRouter(serverTransport, serializer);

            serverRouter.AddService <EverytingToOwin.IMyService>(new EverytingToOwin.MyService());

            var clientQos = new DomainParticipantQos();

            factory.get_default_participant_qos(clientQos);
            clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" });

            var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE);

            var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse");
            var clientRouter    = new DefaultMessageRouter(clientTransport, serializer);
            var proxy           = clientRouter.AddInterface <EverytingToOwin.IMyService>();

            var result = proxy.Add(3, 4).Result;

            Assert.Equal(7, result);

            clientRouter.Dispose();
            clientTransport.Dispose();
            factory.delete_participant(ref clientParticipant);

            serverRouter.Dispose();
            serverTransport.Dispose();
            factory.delete_participant(ref serverParticipant);
        }
        public ReturnCode SetDefaultParticipantQos(DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    // Invoke the corresponding gapi function.
                    result = OpenSplice.Gapi.DomainParticipantFactory.set_default_participant_qos(
                        GapiPeer,
                        marshaler.GapiPtr);
                }
            }
            return(result);
        }
        public ReturnCode GetDefaultParticipantQos(ref DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                // Invoke the corresponding gapi function.
                result = OpenSplice.Gapi.DomainParticipantFactory.get_default_participant_qos(GapiPeer, marshaler.GapiPtr);

                // When no error occured, copy the QoS settings from the gapi Qos representation.
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return(result);
        }
Esempio n. 31
0
        public void TestGetKeyValue()
        {
            // Call GetKeyValue with HandleNil
            ParticipantBuiltinTopicData data = default;
            SampleInfo info = new SampleInfo();
            ReturnCode ret  = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil);

            Assert.AreEqual(ReturnCode.BadParameter, ret);

            DomainParticipantQos qos = new DomainParticipantQos();

            qos.UserData.Value = new byte[] { 0x42 };
            DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos);

            Assert.IsNotNull(otherParticipant);
            otherParticipant.BindRtpsUdpTransportConfig();

            Assert.IsTrue(_participant.WaitForParticipants(1, 20_000));
            Assert.IsTrue(otherParticipant.WaitForParticipants(1, 20_000));

            // Get the for an existing instance
            ret = _dr.ReadNextSample(ref data, info);
            Assert.AreEqual(ReturnCode.Ok, ret);
            Assert.AreEqual(1, data.UserData.Value.Count);
            Assert.AreEqual(0x42, data.UserData.Value.First());

            ParticipantBuiltinTopicData aux = default;

            ret = _dr.GetKeyValue(ref aux, info.InstanceHandle);
            Assert.AreEqual(ReturnCode.Ok, ret);
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]);
            }

            ret = otherParticipant.DeleteContainedEntities();
            Assert.AreEqual(ReturnCode.Ok, ret);

            ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant);
            Assert.AreEqual(ReturnCode.Ok, ret);
        }
Esempio n. 32
0
		public void BasicRoundTrip()
		{
			var serializer = new JsonCommonSerializer();

			var factory = DomainParticipantFactory.get_instance();

			var serverQos = new DomainParticipantQos();
			factory.get_default_participant_qos(serverQos);
			
			//serverQos.transport_builtin.mask = 0; // disable built-in transports
			//serverQos.property_qos.value


			serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" });
			var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE);

			var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest");
			var serverRouter = new DefaultMessageRouter(serverTransport, serializer);
			serverRouter.AddService<EverytingToOwin.IMyService>(new EverytingToOwin.MyService());

			var clientQos = new DomainParticipantQos();
			factory.get_default_participant_qos(clientQos);
			clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" });

			var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE);

			var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse");
			var clientRouter = new DefaultMessageRouter(clientTransport, serializer);
			var proxy = clientRouter.AddInterface<EverytingToOwin.IMyService>();

			var result = proxy.Add(3, 4).Result;
			Assert.Equal(7, result);

			clientRouter.Dispose();
			clientTransport.Dispose();
			factory.delete_participant(ref clientParticipant);
			
			serverRouter.Dispose();
			serverTransport.Dispose();
			factory.delete_participant(ref serverParticipant);
		}
Esempio n. 33
0
        GetParticipantQos(
            ref DomainParticipantQos participantQos,
            string id)
        {
            ReportStack.Start();
            NamedDomainParticipantQos pQos = new NamedDomainParticipantQos();
            GCHandle   qosHandle           = GCHandle.Alloc(pQos, GCHandleType.Normal);
            ReturnCode result = qpResultToReturnCode(
                OpenSplice.Common.QosProvider.GetParticipantQos(cmnQpPtr, id, GCHandle.ToIntPtr(qosHandle)));

            if (result == ReturnCode.Ok)
            {
                participantQos = pQos.DomainparticipantQos;
            }
            else
            {
                ReportStack.Report(result, "Could not copy DomainParticipantQos.");
            }
            qosHandle.Free();
            ReportStack.Flush(null, result != ReturnCode.Ok);
            return(result);
        }
        /// <summary>
        /// Creates a DomainParticipant, Topic, Subscriber and DataReader<HelloWorld>.
        /// </summary>
        public HelloWorldSubscriber(int domainId, string password, string topicName)
        {
            // Configure the DomainParticipantQos add the UserData policy to it.
            // We're simply converting the input string into bytes, assuming
            // that only ASCII characters are used to keep the example simple.
            // We also set the maximum user data length.
            DomainParticipantQos participantQos =
                DomainParticipantFactory.Instance.DefaultParticipantQos
                .WithUserData(new UserData(password.Select(c => (byte)c)))
                .WithResourceLimits(policy => policy.ParticipantUserDataMaxLength = 1024);

            // Create the participant with the QoS
            participant = DomainParticipantFactory.Instance
                          .CreateParticipant(domainId, participantQos);

            Topic <HelloWorld> topic = participant.CreateTopic <HelloWorld>(topicName);

            // Create a subscriber and a DataReader
            Subscriber subscriber = participant.CreateSubscriber();

            reader = subscriber.CreateDataReader(topic);
        }
        /**************************************************************************/

        private void SetAllowInterfacesList(ref DomainParticipantQos qos)
        {
            if (!string.IsNullOrEmpty(parameters.AllowInterfaces))
            {
                if (TransportConfig.Kind == Transport.None)
                {
                    Console.Error.WriteLine(ClassLoggingString
                                            + " Ignoring -nic/-allowInterfaces option.");
                    return;
                }

                if (TransportConfig.Kind == Transport.Udpv4Udpv6Shmem ||
                    TransportConfig.Kind == Transport.Udpv4Udpv6)
                {
                    qos = qos.WithProperty(policy =>
                                           policy.Add(
                                               "dds.transport.UDPv4.builtin.parent.allow_interfaces",
                                               parameters.AllowInterfaces));

                    qos = qos.WithProperty(policy =>
                                           policy.Add(
                                               "dds.transport.UDPv6.builtin.parent.allow_interfaces",
                                               parameters.AllowInterfaces));
                }
                else
                {
                    string propertyName = TransportConfig.PrefixString;

                    if (TransportConfig.Kind == Transport.Wanv4)
                    {
                        propertyName += ".parent";
                    }
                    propertyName += ".parent.allow_interfaces";

                    qos = qos.WithProperty(policy =>
                                           policy.Add(propertyName, parameters.AllowInterfaces));
                }
            }
        }
 public IDomainParticipant CreateParticipant(
     DomainId domainId,
     DomainParticipantQos qos)
 {
     return CreateParticipant(domainId, qos, null, 0);
 }
Esempio n. 37
0
 GetParticipantQos (
     ref DomainParticipantQos participantQos,
     string id)
 {
     NamedDomainParticipantQos pQos = new NamedDomainParticipantQos();
     GCHandle qosHandle = GCHandle.Alloc(pQos, GCHandleType.Normal);
     ReturnCode result = OpenSplice.Common.QosProvider.GetParticipantQos(GapiPeer, id, GCHandle.ToIntPtr(qosHandle));
     participantQos = pQos.DomainparticipantQos;
     qosHandle.Free();
     return result;
 }
 public override void SetDefaultParticipantQos(DomainParticipantQos qos)
 {
     if (QosHelper.IsValid(qos) && QosHelper.IsConsistent(qos))
     {
         this.default_participant_qos_ = qos;
     }
     else
     {
         throw new InconsistentPolicyException();
     }
 }
Esempio n. 39
0
        public ReturnCode GetQos(ref DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler =
                    new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                result = Gapi.DomainParticipant.get_qos(
                        GapiPeer,
                        marshaler.GapiPtr);

                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return result;
        }
Esempio n. 40
0
 public Spdp(int domain, GUID id, DomainParticipantQos qos, DiscoveryImpl disco)
 { }
        public ReturnCode GetDefaultParticipantQos(ref DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                // Invoke the corresponding gapi function.
                result = OpenSplice.Gapi.DomainParticipantFactory.get_default_participant_qos(GapiPeer, marshaler.GapiPtr);

                // When no error occured, copy the QoS settings from the gapi Qos representation.
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return result;
        }
Esempio n. 42
0
        public void Run()
        {
#if DBCallTests
            DDS.Test.DatabaseTests();
#endif

            Console.WriteLine("Press enter to enter...");
            Console.ReadLine();
            Data.DataTest detectionData = new Data.DataTest();
            detectionData.TestId = 3214;
            detectionData.Emergency = true;
            detectionData.TestStr = "not really";
            //detectionData.SeqInt[3] = 23;
#if TestMarshaling

            //Tactical.DetectionTypeSupport support = new Tactical.DetectionTypeSupport();
            //Tactical.Detection cachedObj = new Tactical.Detection();
            //support.Copy(cachedObj, detectionData);

            //SampleMarshaler marshaler = SampleMarshalerFactory.CreateMarshaler(detectionData);

            //using (SampleMarshalHelper helper = new SampleMarshalHelper(marshaler))
            //{
            //    DDS.OpenSplice.Gapi.Test.test_detection(helper.GapiPtr);

            //    Tactical.Detection detectionData2 = new Tactical.Detection();
            //    SampleMarshaler marshaler2 = SampleMarshalerFactory.CreateMarshaler(detectionData2);
            //    marshaler2.CopyOut(helper.GapiPtr, 0);
            //}

            //Duration d = new Duration(234, 2343);
            //int sec;
            //uint nanosec;
            //DDS.OpenSplice.Gapi.Test.test_duration(d, out sec, out nanosec);
            
            //LivelinessChangedStatus status;
            //DDS.OpenSplice.Gapi.Test.get_liveliness_changed_status(out status);
            
            //Time t = new Time(1, 2);
            //int size = Marshal.SizeOf(t);
            //IntPtr ptr = Marshal.AllocHGlobal(size);
            //Marshal.StructureToPtr(t, ptr, true);
#endif

            //DDS.Test.TestDataReaderQos();
			//DDS.Test.TestTopicQos();

            // Create a DomainParticipantFactory
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
            Console.WriteLine("DomainParticipantFactory: " + dpf);

            // Tailor the DomainPartipantFactoryQos;
            DomainParticipantFactoryQos dpfQos = null;
            ReturnCode result = dpf.GetQos(ref dpfQos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpfQos.EntityFactory.AutoenableCreatedEntities);

            dpfQos.EntityFactory.AutoenableCreatedEntities = false;
            result = dpf.SetQos(dpfQos);
            Console.WriteLine("DomainParticipantFactory.set_qos: {0}", result);

            // Get the QOS settings for the Factory...  Check values without additional changes
            DomainParticipantFactoryQos dpf2Qos = null;
            result = dpf.GetQos(ref dpf2Qos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
			Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpf2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create the domainParticipant itself.
            DomainParticipantQos dpQos = new DomainParticipantQos();
            dpQos.UserData.Value = new byte[] { (byte)1, (byte)2, (byte)3 };
            dpQos.EntityFactory.AutoenableCreatedEntities = true;
            dpQos.ListenerScheduling.SchedulingClass.Kind = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.ListenerScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.ListenerScheduling.SchedulingPriority = 0;
            dpQos.WatchdogScheduling.SchedulingClass.Kind = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.WatchdogScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.WatchdogScheduling.SchedulingPriority = 4;

            IDomainParticipant dp = dpf.CreateParticipant(DDS.DomainId.Default, dpQos);
            Console.Write("DomainParticipant: ");
            Console.WriteLine(dp != null ? "yes" : "no");


            if (dp.ContainsEntity(0))
            {
                Console.WriteLine("contains_entity with nil handle incorrect");
            }
            if (dp.ContainsEntity(100))
            {
                Console.WriteLine("contains_entity with incorrect handle incorrect");
            }

            Time currentTime;
            dp.GetCurrentTime(out currentTime);
            Console.WriteLine("Current Local Time: {0}", currentTime.ToDatetime().ToLocalTime());

            // And look up this DomainParticipant.
            IDomainParticipant dp2 = dpf.LookupParticipant(null);

            DomainParticipantQos dp2Qos = null;

            Console.Write("lookup DomainParticipant: ");
            Console.WriteLine(dp2 != null ? "Success" : "Fail");
            result = dp2.GetQos(ref dp2Qos);
            Console.WriteLine("DomainParticipant.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantQos.entity_factory.autoenable_created_entities: " + dp2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create a new PublisherQos and set some values...
            PublisherQos publisherQos = new PublisherQos();
            publisherQos.EntityFactory.AutoenableCreatedEntities = true;
            publisherQos.Partition.Name = new string[] { "howdy" }; //, "neighbor", "partition" };

            // true not supported in 4.1 ??
            publisherQos.Presentation.OrderedAccess = false;

            // Create the Publisher
            dp.Enable();
            IPublisher publisher = dp.CreatePublisher(publisherQos);
            Console.WriteLine("Create Publisher: {0}", publisher);

            //DataWriterQos dwQos;
            //publisher.GetDefaultDataWriterQos(out dwQos);


            // Create a Detection Type Support and register it's type
            Data.DataTestTypeSupport support = new Data.DataTestTypeSupport();

            string test2 = support.TypeName;
            Console.WriteLine("Register Typesupport");
            result = support.RegisterType(dp, support.TypeName);
            Console.WriteLine("Register Typesupport Result: {0}", result);

            // Create a topic for the Detection type
            TopicQos topicQos = null;
            result = dp.GetDefaultTopicQos(ref topicQos);

			//topicQos.Ownership.Kind = OwnershipQosPolicyKind.ExclusiveOwnershipQos;

			//DDS.Test.TestTopicQos2(ref topicQos);

            // Add a listener to the topic
            ITopic topic = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos,
                this, StatusKind.InconsistentTopic);

            topicQos.History.Depth = 5;

            ITopic topic2 = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos);

            //			ErrorCode errorCode;
            //			string msg;
            //			result = ErrorInfo.Update();
            //			result = ErrorInfo.GetCode(out errorCode);
            //			result = ErrorInfo.GetMessage(out msg);

            // Create a DataWriter for the topic
            Data.IDataTestDataWriter dataWriter = publisher.CreateDataWriter(topic) as Data.IDataTestDataWriter;

            // Create a SubscriberQos object and set the partition name
            SubscriberQos subscriberQos = null;
            result = dp.GetDefaultSubscriberQos(ref subscriberQos);
            subscriberQos.Partition.Name = new string[] { "howdy" };

            // Create the subscriber
            ISubscriber sub = dp.CreateSubscriber(subscriberQos);
            // Verify that the subsciber was created...
            if (sub == null)
            {
                Console.WriteLine("Subscriber not created");
                return;
            }

            DDS.DataReaderQos readerQos = null;
            sub.GetDefaultDataReaderQos(ref readerQos);

            //readerQos.SubscriptionKeys.KeyList = new string[] { "test" };
            //readerQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;
            //readerQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            // Create a DataReader for the Detection topic
            Data.IDataTestDataReader dataReader = sub.CreateDataReader(topic, readerQos, this, StatusKind.DataAvailable)
                as Data.IDataTestDataReader;

            // Create a filtered detection topic (only read detections that have an id != 4)
            IContentFilteredTopic filteredTopic = dp.CreateContentFilteredTopic("Another", topic, "TestId <> %0", "4");

			string[] testParams = null;
			result = filteredTopic.GetExpressionParameters(ref testParams);
			result = filteredTopic.SetExpressionParameters("hello", "test");
			result = filteredTopic.GetExpressionParameters(ref testParams);

            // Create a DataReader to read the filtered topic
            IDataReader reader2 = sub.CreateDataReader(filteredTopic);

            IQueryCondition queryCondition = dataReader.CreateQueryCondition(
                "TestId = %0",
                "234");

            // just for testing...
            //GC.Collect();

            // WaitSet
            WaitSet waitSet = new WaitSet();

            // either use status conditions...or
            IStatusCondition sc = reader2.StatusCondition;
            sc.SetEnabledStatuses(StatusKind.DataAvailable);
            waitSet.AttachCondition(sc);

            IStatusCondition sc2 = reader2.StatusCondition;

            // read conditions...
            // IReadCondition readCond = reader2.CreateReadCondition();
            // waitSet.AttachCondition(readCond);

            ICondition[] cond = null;
            //waitSet.Wait(ref cond, Duration.Infinite);


            Console.WriteLine("Press enter to write data");
            Console.ReadLine();

            detectionData.SequenceTest = new int[1];// new System.Collections.Generic.List<int>();
			//detectionData.SequenceTest.Add(4);
            detectionData.SequenceTest[0] = 4;

            // Write detection data
            result = dataWriter.Write(detectionData);

            detectionData = new Data.DataTest();
            detectionData.TestId = 234;
            dataWriter.Write(detectionData, InstanceHandle.Nil);

            detectionData = new Data.DataTest();
            detectionData.TestId = 235;
            dataWriter.Write(detectionData);

			detectionData = new Data.DataTest();
			detectionData.TestId = 236;
			dataWriter.Write(detectionData);

			detectionData = new Data.DataTest();
			detectionData.TestId = 237;
			dataWriter.Write(detectionData);

            Console.WriteLine("Press enter to read data");
            Console.ReadLine();

            // Read the data
            SampleInfo[] infos = null;
            Data.DataTest[] dataValues = null;

//            result = dataReader.ReadWithCondition(ref dataValues, ref infos, DDS.Length.Unlimited, queryCondition);

            result = dataReader.Read(ref dataValues, ref infos);
            Console.WriteLine("dataReader: {0}", dataReader);

            if (dataValues != null)
            {
                Console.WriteLine("Number of samples received: {0}", dataValues.Length);
                for (int index = 0; index < dataValues.Length; index++)
                {
                    Console.WriteLine("TestId: {0}, ProviderId: {1}, Emergency: {2}, TestStr: {3}", dataValues[index].TestId,
                                      dataValues[index].ProviderId, dataValues[index].Emergency, dataValues[index].TestStr);
                    Console.WriteLine("info: ValidData: {0},  InstHandle: {1},  PubHandle:{2},  SourceTS: {3}, ArrivalTS: {4}, sample: {5}, view: {6}, instance: {7}",
                                      infos[index].ValidData,
                                      infos[index].InstanceHandle, infos[index].PublicationHandle,
                                      infos[index].SourceTimestamp, infos[index].ArrivalTimestamp,
                                      infos[index].SampleState, infos[index].ViewState, infos[index].InstanceState);
                }
            }
            Console.WriteLine("Press enter to cleanup");
            Console.ReadLine();

            Console.WriteLine("DeleteContainedEntities");
            result = dp.DeleteContainedEntities();

            // If you don't use DeleteContainedEntities then you must delete everything that was created
            //result = sub.DeleteDataReader(dataReader);
            //result = publisher.DeleteDataWriter(dataWriter);

            //result = dp.DeleteTopic(topic);
            //result = dp.DeletePublisher(publisher);

            //result = dp.DeleteSubscriber(sub);

            Console.WriteLine("DeleteParticipant");
            result = dpf.DeleteParticipant(dp);

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

        }
Esempio n. 43
0
 public abstract void SetDefaultParticipantQos(DomainParticipantQos qos);
Esempio n. 44
0
 /// <summary>
 /// Create a new domain participant.
 /// </summary>
 /// <param name="domainId"></param>
 /// <param name="qos"></param>
 /// <param name="listener"></param>
 /// <param name="statuses">Of which status changes the listener should be
 ///                        notified. A null collection signifies all status 
 ///                        changes</param>
 /// <returns></returns>
 public abstract DomainParticipant CreateParticipant(
         int domainId,
         DomainParticipantQos qos,
         DomainParticipantListener listener,
         ICollection<Type> statuses);
Esempio n. 45
0
 internal static void CopyOut(IntPtr from, ref DomainParticipantQos to)
 {
     if (to == null) to = new DomainParticipantQos();
     UserDataQosPolicyMarshaler.CopyOut(from, ref to.UserData, offset_user_data);
     EntityFactoryQosPolicyMarshaler.CopyOut(from, ref to.EntityFactory, offset_entity_factory);
     SchedulingQosPolicyMarshaler.CopyOut(from, ref to.WatchdogScheduling, offset_watchdog_scheduling);
     SchedulingQosPolicyMarshaler.CopyOut(from, ref to.ListenerScheduling, offset_listener_scheduling);
 }
Esempio n. 46
0
		public void Benchmark()
		{
			var serializer = new JsonCommonSerializer();

			var factory = DomainParticipantFactory.get_instance();

			var serverQos = new DomainParticipantQos();
			factory.get_default_participant_qos(serverQos);
			serverQos.discovery.initial_peers.from_array(new[] { "1@localhost" });

			const int maxBufferSize = 1 << 24; // 16MB
			serverQos.receiver_pool.buffer_size = 65530; // max allowed
			//serverQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
			serverQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;
			//serverQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
			serverQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;

			var len = serverQos.property_qos.value.length + 3;
			serverQos.property_qos.value.ensure_length(len, len);
			serverQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() });
			serverQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = serverQos.receiver_pool.buffer_size.ToString() });
			serverQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = serverQos.receiver_pool.buffer_size.ToString() });

			//serverQos.resource_limits.type_code_max_serialized_length = maxBufferSize;
			serverQos.resource_limits.type_object_max_serialized_length = maxBufferSize;
			serverQos.resource_limits.type_object_max_deserialized_length = maxBufferSize;

			var serverParticipant = factory.create_participant(0, serverQos, null, StatusMask.STATUS_MASK_NONE);
			var controller = serverParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME);
			var flowProperty = new FlowControllerProperty_t();
			controller.get_property(flowProperty);
			flowProperty.token_bucket.period = Duration_t.from_millis(50);
			controller.set_property(flowProperty);

			var serverTransport = serverParticipant.GenerateTransportSource("serverResponse", "clientRequest");
			var serverRouter = new DefaultMessageRouter(serverTransport, serializer);
			serverRouter.AddService<ISumService>(new SumService());

			var clientQos = new DomainParticipantQos();
			factory.get_default_participant_qos(clientQos);
			clientQos.discovery.initial_peers.from_array(new[] { "1@localhost" });

			clientQos.receiver_pool.buffer_size = 65530; // max allowed
			//clientQos.discovery_config.publication_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
			clientQos.discovery_config.publication_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;
			//clientQos.discovery_config.subscription_writer_publish_mode.kind = PublishModeQosPolicyKind.ASYNCHRONOUS_PUBLISH_MODE_QOS;
			clientQos.discovery_config.subscription_writer_publish_mode.flow_controller_name = FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME;

			len = clientQos.property_qos.value.length + 3;
			clientQos.property_qos.value.ensure_length(len, len);
			clientQos.property_qos.value.set_at(len - 3, new Property_t { name = "dds.transport.UDPv4.builtin.recv_socket_buffer_size", value = maxBufferSize.ToString() });
			clientQos.property_qos.value.set_at(len - 2, new Property_t { name = "dds.transport.UDPv4.builtin.parent.message_size_max", value = clientQos.receiver_pool.buffer_size.ToString() });
			clientQos.property_qos.value.set_at(len - 1, new Property_t { name = "dds.transport.UDPv4.builtin.send_socket_buffer_size", value = clientQos.receiver_pool.buffer_size.ToString() });

			//clientQos.resource_limits.type_code_max_serialized_length = maxBufferSize;
			clientQos.resource_limits.type_object_max_serialized_length = maxBufferSize;
			clientQos.resource_limits.type_object_max_deserialized_length = maxBufferSize;

			var clientParticipant = factory.create_participant(0, clientQos, null, StatusMask.STATUS_MASK_NONE);
			controller = clientParticipant.lookup_flowcontroller(FlowController.FIXED_RATE_FLOW_CONTROLLER_NAME);
			flowProperty = new FlowControllerProperty_t();
			controller.get_property(flowProperty);
			flowProperty.token_bucket.period = Duration_t.from_millis(50);
			controller.set_property(flowProperty);


			var clientTransport = clientParticipant.GenerateTransportSource("clientRequest", "serverResponse");
			var clientRouter = new DefaultMessageRouter(clientTransport, serializer);
			var proxy = clientRouter.AddInterface<ISumService>();

			const int randCnt = 100;
			var rand = new Random(42);
			var randoms = new int[randCnt];
			for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000);

			var sw = new Stopwatch();
			long timeFromClient = 0, timeToClient = 0;
			const int cnt = 1000;
			for (int j = 0; j < cnt; j++)
			{
				sw.Start();
				var sum = proxy.Sum(randoms).Result;
				sw.Stop();
				Assert.Equal(randoms.Sum(), sum);
				for (int i = 0; i < randCnt; i++) randoms[i] = rand.Next(10000000, 20000000);
				var times = proxy.TimeDiff(Stopwatch.GetTimestamp()).Result;
				timeFromClient += times.Item1;
				timeToClient += Stopwatch.GetTimestamp() - times.Item2;
			}

			_testOutputHelper.WriteLine("Completed {0} sum passes in {1}ms", cnt, sw.ElapsedMilliseconds);
			_testOutputHelper.WriteLine("Client to server latency: {0}us", timeFromClient / cnt / 10);
			_testOutputHelper.WriteLine("Server to client latency: {0}us", timeToClient / cnt / 10);

			//sw.Reset();
			//var tree = new SumServiceTree();
			//SumServiceTree.FillTree(tree, rand, 2);
			//_testOutputHelper.WriteLine("Starting large message transfer.");
			//sw.Start();
			//var result = proxy.Increment(tree).Result;
			//sw.Stop();
			//Assert.Equal(tree.Leaf + 1, result.Leaf);
			//_testOutputHelper.WriteLine("Completed large transfer in {0}ms", sw.Elapsed.TotalMilliseconds);

			clientRouter.Dispose();
			clientTransport.Dispose();
			factory.delete_participant(ref clientParticipant);

			serverRouter.Dispose();
			serverTransport.Dispose();
			factory.delete_participant(ref serverParticipant);
		}
        public IDomainParticipant CreateParticipant(
            DomainId domainId,
            DomainParticipantQos qos,
            IDomainParticipantListener listener,
            StatusKind mask)
        {
            IDomainParticipant participant = null;
            string className = null;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                if (marshaler.CopyIn(qos) == ReturnCode.Ok)
                {
                    if (listener != null)
                    {
                        OpenSplice.Gapi.gapi_domainParticipantListener gapiListener;
                        DomainParticipantListenerHelper listenerHelper = new DomainParticipantListenerHelper();
                        listenerHelper.Listener = listener;
                        listenerHelper.CreateListener(out gapiListener);
                        using (DomainParticipantListenerMarshaler listenerMarshaler = 
                                new DomainParticipantListenerMarshaler(ref gapiListener))
                        {
                            // Invoke the corresponding gapi function.
                            IntPtr gapiParticipant = OpenSplice.Gapi.DomainParticipantFactory.create_participant(
                                    GapiPeer,
                                    domainId,
                                    marshaler.GapiPtr,
                                    listenerMarshaler.GapiPtr,
                                    mask,
                                    IntPtr.Zero,
                                    IntPtr.Zero,
                                    IntPtr.Zero,
                                    className);
                            if (gapiParticipant != IntPtr.Zero)
                            {
                                participant = new OpenSplice.DomainParticipant(gapiParticipant, listenerHelper);
                            }
                        }
                    }
                    else
                    {
                        // Invoke the corresponding gapi function.
                        IntPtr gapiParticipant = OpenSplice.Gapi.DomainParticipantFactory.create_participant(
                            GapiPeer,
                            domainId,
                            marshaler.GapiPtr,
                            IntPtr.Zero,
                            mask,
                            IntPtr.Zero,
                            IntPtr.Zero,
                            IntPtr.Zero,
                            className);
                        if (gapiParticipant != IntPtr.Zero)
                        {
                            participant = new OpenSplice.DomainParticipant(gapiParticipant);
                        }
                    }
                }
            }

            if (participant != null)
            {
                DomainParticipantFactoryQos dpfQos = null;
                ReturnCode result = GetQos(ref dpfQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpfQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        participant.Enable();
                    }
                }
            }       
                
            return participant;
        }
        public ReturnCode SetDefaultParticipantQos(DomainParticipantQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.DomainParticipantQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    // Invoke the corresponding gapi function.
                    result = OpenSplice.Gapi.DomainParticipantFactory.set_default_participant_qos(
                            GapiPeer,
                            marshaler.GapiPtr);
                }
            }
            return result;
        }
Esempio n. 49
0
 public ReturnCode GetQos(ref DomainParticipantQos qos)
 {
     return realParticipant.GetQos(ref qos);
 }
Esempio n. 50
0
 internal void CopyOut(ref DomainParticipantQos to)
 {
     CopyOut(GapiPtr, ref to);
 }
Esempio n. 51
0
 internal DDS.ReturnCode CopyIn(DomainParticipantQos from)
 {
     cleanupRequired = true;
     return CopyIn(from, GapiPtr);
 }
Esempio n. 52
0
 public ReturnCode SetQos(DomainParticipantQos qos)
 {
     return realParticipant.SetQos(qos);
 }
Esempio n. 53
0
 public virtual bool UpdateDomainParticipantQos(int domain, int articipantId, DomainParticipantQos qos)
 {
     throw new NotImplementedException();
 }