internal CacheChange NewChange(ChangeKind kind, Data data, InstanceHandle instance) { var change = new CacheChange() { WriterGuid = Id, SequenceNumber = SequenceNumber.Increment(), Kind = kind, InstanceHandle = instance, Data = data }; var message = new Message() { Header = new Header() { Protocol = ProtocolId.ProtocolRTPS, Version = ProtocolVersion.v22, Vendor = VendorId.Unknown, GuidPrefix = new GuidPrefix() } }; message.AddSubMessage(new DataSubMessage(data)); message.AddSubMessage(new HeartbeatSubMessage()); Channel.Send(message); return change; }
public static extern ReturnCode read_next_instance_w_condition( IntPtr _this, IntPtr data_values, IntPtr info_seq, int max_samples, InstanceHandle a_handle, IntPtr a_condition);
public static extern ReturnCode read_next_instance( IntPtr _this, IntPtr data_values, IntPtr info_seq, int max_samples, InstanceHandle a_handle, SampleStateKind sample_states, ViewStateKind view_states, InstanceStateKind instance_states);
public static ReturnCode GetKeyValue( DataReader reader, ref object key, InstanceHandle instanceHandle) { GCHandle tmpGCHandleData = GCHandle.Alloc(key, GCHandleType.Normal); ReturnCode result = Gapi.FooDataReader.get_key_value( reader.GapiPeer, GCHandle.ToIntPtr(tmpGCHandleData), instanceHandle); tmpGCHandleData.Free(); return result; }
public static ReturnCode Dispose( DataWriter writer, object instanceData, InstanceHandle instanceHandle) { GCHandle tmpGCHandle = GCHandle.Alloc(instanceData, GCHandleType.Normal); ReturnCode result = Gapi.FooDataWriter.dispose( writer.GapiPeer, GCHandle.ToIntPtr(tmpGCHandle), instanceHandle); tmpGCHandle.Free(); return result; }
public static ReturnCode DisposeWithTimestamp( DataWriter writer, object instanceData, InstanceHandle instanceHandle, Time sourceTimestamp) { GCHandle tmpGCHandle = GCHandle.Alloc(instanceData, GCHandleType.Normal); ReturnCode result = Gapi.FooDataWriter.dispose_w_timestamp( writer.GapiPeer, GCHandle.ToIntPtr(tmpGCHandle), instanceHandle, ref sourceTimestamp); tmpGCHandle.Free(); return result; }
public static extern ReturnCode ignore_topic( IntPtr _this, InstanceHandle handle);
public static void Write(IntPtr to, int offset, InstanceHandle from) { Marshal.WriteInt64(to, offset, from); }
public static extern ReturnCode get_discovered_participant_data( IntPtr _this, IntPtr participant_data, InstanceHandle handle);
public static extern ReturnCode get_matched_publication_data( IntPtr _this, IntPtr publication_data, InstanceHandle publication_handle);
public void AddReference(InstanceHandle handle) { if (referenceList.ContainsKey(handle.Instance)) return; referenceList.Add(handle.Instance, handle); handle.MarkReferredBy(this); }
public void TestBeginEndCoherentChanges() { // Initialize entities var participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(participant); participant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = participant.CreateTopic(nameof(TestBeginEndCoherentChanges), typeName); Assert.IsNotNull(topic); Assert.IsNull(topic.Listener); Assert.AreEqual(nameof(TestBeginEndCoherentChanges), topic.Name); Assert.AreEqual(typeName, topic.TypeName); PublisherQos pQos = new PublisherQos(); pQos.Presentation.CoherentAccess = true; pQos.Presentation.OrderedAccess = true; pQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.TopicPresentationQos; Publisher publisher = participant.CreatePublisher(pQos); Assert.IsNotNull(publisher); SubscriberQos sQos = new SubscriberQos(); sQos.Presentation.CoherentAccess = true; sQos.Presentation.OrderedAccess = true; sQos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.TopicPresentationQos; Subscriber subscriber = participant.CreateSubscriber(sQos); Assert.IsNotNull(subscriber); DataWriter writer = publisher.CreateDataWriter(topic); Assert.IsNotNull(writer); TestStructDataWriter dataWriter = new TestStructDataWriter(writer); DataReaderQos drQos = new DataReaderQos(); drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; drQos.History.Kind = HistoryQosPolicyKind.KeepAllHistoryQos; DataReader reader = subscriber.CreateDataReader(topic, drQos); Assert.IsNotNull(reader); TestStructDataReader dataReader = new TestStructDataReader(reader); Assert.IsTrue(reader.WaitForPublications(1, 5_000)); Assert.IsTrue(writer.WaitForSubscriptions(1, 5_000)); // Call EndCoherentChanges without calling first SuspendPublications result = publisher.EndCoherentChanges(); Assert.AreEqual(ReturnCode.PreconditionNotMet, result); // Begin coherent access and write samples result = publisher.BeginCoherentChanges(); Assert.AreEqual(ReturnCode.Ok, result); for (int i = 1; i <= 5; i++) { TestStruct sample = new TestStruct { Id = i, ShortField = (short)i, }; InstanceHandle handle = dataWriter.RegisterInstance(sample); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); result = dataWriter.Write(sample, handle); Assert.AreEqual(ReturnCode.Ok, result); } System.Threading.Thread.Sleep(1_000); // Check that not samples arrived List <TestStruct> data = new List <TestStruct>(); List <SampleInfo> sampleInfos = new List <SampleInfo>(); // TODO - OpenDDS Issue: // Coherent sets for PRESENTATION QoS not Currently implemented on RTPS // result = dataReader.Read(data, sampleInfos); // Assert.AreEqual(ReturnCode.NoData, result); // End coherent access and check the samples result = publisher.EndCoherentChanges(); Assert.AreEqual(ReturnCode.Ok, result); System.Threading.Thread.Sleep(1_000); data = new List <TestStruct>(); sampleInfos = new List <SampleInfo>(); result = dataReader.Read(data, sampleInfos); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsTrue(data.Count > 0); Assert.AreEqual(data.Count, sampleInfos.Count); for (int i = 0; i < data.Count; i++) { Assert.IsTrue(sampleInfos[i].ValidData); Assert.AreEqual(i + 1, data[i].Id); Assert.AreEqual(i + 1, data[i].ShortField); } result = participant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, result); if (AssemblyInitializer.Factory != null) { result = AssemblyInitializer.Factory.DeleteParticipant(participant); Assert.AreEqual(ReturnCode.Ok, result); } }
public void TestSuspendResumePublications() { // Initialize entities TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = _participant.CreateTopic(nameof(TestSuspendResumePublications), typeName); Assert.IsNotNull(topic); Assert.IsNull(topic.Listener); Assert.AreEqual(nameof(TestSuspendResumePublications), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Publisher publisher = _participant.CreatePublisher(); Assert.IsNotNull(publisher); Subscriber subscriber = _participant.CreateSubscriber(); Assert.IsNotNull(subscriber); DataWriter writer = publisher.CreateDataWriter(topic); Assert.IsNotNull(writer); TestStructDataWriter dataWriter = new TestStructDataWriter(writer); DataReaderQos drQos = new DataReaderQos(); drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; drQos.History.Kind = HistoryQosPolicyKind.KeepAllHistoryQos; DataReader reader = subscriber.CreateDataReader(topic, drQos); Assert.IsNotNull(reader); TestStructDataReader dataReader = new TestStructDataReader(reader); Assert.IsTrue(reader.WaitForPublications(1, 5_000)); Assert.IsTrue(writer.WaitForSubscriptions(1, 5_000)); // Call ResumePublications without calling first SuspendPublications result = publisher.ResumePublications(); Assert.AreEqual(ReturnCode.PreconditionNotMet, result); // Suspend publications and write samples result = publisher.SuspendPublications(); Assert.AreEqual(ReturnCode.Ok, result); for (int i = 1; i <= 5; i++) { // OpenDDS issue: cannot register more than one instance during SuspendPublications. // Looks like that the control messages are never delivered and the controlTracker never get free during delete_datawriter TestStruct sample = new TestStruct { Id = 1, ShortField = (short)i, }; InstanceHandle handle = dataWriter.RegisterInstance(sample); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); result = dataWriter.Write(sample, handle); Assert.AreEqual(ReturnCode.Ok, result); } System.Threading.Thread.Sleep(2_000); // Check that not samples arrived List <TestStruct> data = new List <TestStruct>(); List <SampleInfo> sampleInfos = new List <SampleInfo>(); result = dataReader.Read(data, sampleInfos); Assert.AreEqual(ReturnCode.NoData, result); // Resume publication and check the samples result = publisher.ResumePublications(); Assert.AreEqual(ReturnCode.Ok, result); System.Threading.Thread.Sleep(2_000); data = new List <TestStruct>(); sampleInfos = new List <SampleInfo>(); result = dataReader.Read(data, sampleInfos); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsTrue(data.Count > 0); Assert.AreEqual(data.Count, sampleInfos.Count); for (int i = 0; i < data.Count; i++) { Assert.IsTrue(sampleInfos[i].ValidData); Assert.AreEqual(i + 1, data[i].ShortField); } }
static void Main(string[] args) { OsplConfiguration.SetOsplConfiguration(); DDSEntityManager mgr = new DDSEntityManager("HelloWorld"); String partitionName = "HelloWorld example"; // create Domain Participant mgr.createParticipant(partitionName); mgr.setAutoDispose(false); // create Type MsgTypeSupport msgTS = new MsgTypeSupport(); mgr.registerType(msgTS); // create Topic mgr.createTopic("HelloWorldData_Msg"); // create Publisher mgr.createPublisher(); // create DataWriter mgr.createWriter(); // Publish Events IDataWriter dwriter = mgr.getWriter(); MsgDataWriter helloWorldWriter = dwriter as MsgDataWriter; Msg msgInstance = new Msg(); msgInstance.userID = 1; msgInstance.message = "Hello World"; InstanceHandle handle = helloWorldWriter.RegisterInstance(msgInstance); ErrorHandler.checkHandle(handle, "MsgDataWriter.RegisterInstance"); Console.WriteLine("=== [Publisher] writing a message containing :"); Console.WriteLine(" userID : {0}", msgInstance.userID); Console.WriteLine(" Message : \" {0} \"", msgInstance.message); ReturnCode status = helloWorldWriter.Write(msgInstance, handle); ErrorHandler.checkStatus(status, "MsgDataWriter.Write"); try { Thread.Sleep(2); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine(ex.StackTrace); } status = helloWorldWriter.UnregisterInstance(msgInstance, handle); // Clean up mgr.getPublisher().DeleteDataWriter(helloWorldWriter); mgr.deletePublisher(); mgr.deleteTopic(); mgr.deleteParticipant(); }
private static SqlWorkflowInstanceStore CreateInstanceStore(WorkflowHandlerBase workflowInstance, out InstanceHandle ownerHandle) { try { //WriteDebug("CreateInstanceStore: " + workflowInstance.WorkflowInstanceGuid + ", nodeId: " + workflowInstance.Id); var store = new SqlWorkflowInstanceStore(ConnectionString); ownerHandle = store.CreateInstanceHandle(); var wfHostTypeName = GetWorkflowHostTypeName(workflowInstance); var WorkflowHostTypePropertyName = GetWorkflowHostTypePropertyName(); var ownerCommand = new CreateWorkflowOwnerCommand() { InstanceOwnerMetadata = { { WorkflowHostTypePropertyName, new InstanceValue(wfHostTypeName) } } }; var owner = store.Execute(ownerHandle, ownerCommand, TimeSpan.FromSeconds(30)).InstanceOwner; ownerHandle.Free(); store.DefaultInstanceOwner = owner; return(store); } catch (Exception e) { WriteError("CreateInstanceStore", e); throw; } }
internal static object ConvertFromNativeLayer(object value, SharedInstanceHandle sharedParentHandle = null, CimInstance parent = null, bool clone = false) { InstanceHandle instanceHandle; InstanceHandle instanceHandle1; InstanceHandle instanceHandle2 = value as InstanceHandle; if (instanceHandle2 == null) { InstanceHandle[] instanceHandleArray = value as InstanceHandle[]; if (instanceHandleArray == null) { return(value); } else { CimInstance[] cimInstanceArray = new CimInstance[(int)instanceHandleArray.Length]; for (int i = 0; i < (int)instanceHandleArray.Length; i++) { InstanceHandle instanceHandle3 = instanceHandleArray[i]; if (instanceHandle3 != null) { CimInstance[] cimInstance = cimInstanceArray; int num = i; if (clone) { instanceHandle = instanceHandle3.Clone(); } else { instanceHandle = instanceHandle3; } cimInstance[num] = new CimInstance(instanceHandle, sharedParentHandle); if (parent != null) { cimInstanceArray[i].SetCimSessionComputerName(parent.GetCimSessionComputerName()); cimInstanceArray[i].SetCimSessionInstanceId(parent.GetCimSessionInstanceId()); } } else { cimInstanceArray[i] = null; } } return(cimInstanceArray); } } else { if (clone) { instanceHandle1 = instanceHandle2.Clone(); } else { instanceHandle1 = instanceHandle2; } CimInstance cimInstance1 = new CimInstance(instanceHandle1, sharedParentHandle); if (parent != null) { cimInstance1.SetCimSessionComputerName(parent.GetCimSessionComputerName()); cimInstance1.SetCimSessionInstanceId(parent.GetCimSessionInstanceId()); } return(cimInstance1); } }
internal CimInstance(InstanceHandle handle, SharedInstanceHandle parentHandle) { this._CimSessionInstanceID = Guid.Empty; this._myHandle = new SharedInstanceHandle(handle, parentHandle); }
public void TestOnSampleLost() { using (ManualResetEventSlim evt = new ManualResetEventSlim(false)) { DataReader reader = null; int count = 0; int totalCount = 0; int totalCountChange = 0; // Attach to the event _listener.SampleLost += (r, s) => { reader = r; totalCount = s.TotalCount; totalCountChange = s.TotalCountChange; count++; evt.Set(); }; // Prepare QoS for the test DataReaderQos drQos = new DataReaderQos(); drQos.Reliability.Kind = ReliabilityQosPolicyKind.BestEffortReliabilityQos; drQos.DestinationOrder.Kind = DestinationOrderQosPolicyKind.BySourceTimestampDestinationOrderQos; drQos.History.Kind = HistoryQosPolicyKind.KeepLastHistoryQos; drQos.History.Depth = 1; ReturnCode result = _reader.SetQos(drQos); Assert.AreEqual(ReturnCode.Ok, result); // Enable entities result = _writer.Enable(); Assert.AreEqual(ReturnCode.Ok, result); result = _reader.Enable(); Assert.AreEqual(ReturnCode.Ok, result); // Wait for discovery Assert.IsTrue(_reader.WaitForPublications(1, 5_000)); Assert.IsTrue(_writer.WaitForSubscriptions(1, 5_000)); // Write two samples of the same instances InstanceHandle handle = _dataWriter.RegisterInstance(new TestStruct { Id = 1 }); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); Timestamp time = DateTime.Now.ToTimestamp(); result = _dataWriter.Write(new TestStruct { Id = 1 }, handle, time); Assert.AreEqual(ReturnCode.Ok, result); Thread.Sleep(100); time = DateTime.Now.Subtract(TimeSpan.FromSeconds(10)).ToTimestamp(); result = _dataWriter.Write(new TestStruct { Id = 1 }, handle, time); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsTrue(evt.Wait(20_000)); Assert.AreEqual(1, count); Assert.AreEqual(_reader, reader); Assert.AreEqual(1, totalCount); Assert.AreEqual(1, totalCountChange); // Remove the listener to avoid extra messages result = _subscriber.SetListener(null); Assert.AreEqual(ReturnCode.Ok, result); } }
public static extern byte contains_entity( IntPtr _this, InstanceHandle a_handle);
internal void Cancel() { Fx.Assert(InstanceHandle != null, "InstanceHandleReference already cancelled."); InstanceHandle = null; }
internal override MiResult NativeMoveNext(OperationHandle operationHandle, out CimClass currentItem, out bool moreResults, out MiResult operationResult, out string errorMessage, out InstanceHandle errorDetailsHandle) { ClassHandle classHandle = null; currentItem = null; MiResult @class = OperationMethods.GetClass(operationHandle, out classHandle, out moreResults, out operationResult, out errorMessage, out errorDetailsHandle); if (classHandle != null && !classHandle.IsInvalid) { if (!base.ShortenLifetimeOfResults) { classHandle = classHandle.Clone(); } currentItem = new CimClass(classHandle); } return(@class); }
public void MarkReferredBy(InstanceHandle handle) { referredList.Add(handle.Instance, handle); }
internal override MiResult NativeMoveNext(OperationHandle operationHandle, out CimInstance currentItem, out bool moreResults, out MiResult operationResult, out string errorMessage, out InstanceHandle errorDetailsHandle) { InstanceHandle instanceHandle = null; currentItem = null; MiResult instance = OperationMethods.GetInstance(operationHandle, out instanceHandle, out moreResults, out operationResult, out errorMessage, out errorDetailsHandle); if (instanceHandle != null && !instanceHandle.IsInvalid) { if (!base.ShortenLifetimeOfResults) { instanceHandle = instanceHandle.Clone(); } currentItem = new CimInstance(instanceHandle, null); currentItem.SetCimSessionComputerName(this._CimSessionComputerName); currentItem.SetCimSessionInstanceId(this._CimSessionInstanceID); } return(instance); }
public void TestOnSubscriptionMatched() { int count = 0; DataReader firstDataReader = null; int firstTotalCount = 0; int firstTotalCountChange = 0; int firstCurrentCount = 1; int firstCurrentCountChange = 1; InstanceHandle firstHandle = InstanceHandle.HandleNil; DataReader secondDataReader = null; int secondTotalCount = 1; int secondTotalCountChange = 1; int secondCurrentCount = 0; int secondCurrentCountChange = 0; InstanceHandle secondHandle = InstanceHandle.HandleNil; // Attach to the event _listener.SubscriptionMatched += (r, s) => { if (count == 0) { // Liveliness alive firstDataReader = r; firstTotalCount = s.TotalCount; firstTotalCountChange = s.TotalCountChange; firstCurrentCount = s.CurrentCount; firstCurrentCountChange = s.CurrentCountChange; firstHandle = s.LastPublicationHandle; } else { // Liveliness not alive secondDataReader = r; secondTotalCount = s.TotalCount; secondTotalCountChange = s.TotalCountChange; secondCurrentCount = s.CurrentCount; secondCurrentCountChange = s.CurrentCountChange; secondHandle = s.LastPublicationHandle; } count++; }; // Enable entities ReturnCode result = _writer.Enable(); Assert.AreEqual(ReturnCode.Ok, result); result = _reader.Enable(); Assert.AreEqual(ReturnCode.Ok, result); //// Wait for discovery //bool found = _writer.WaitForSubscriptions(1, 1000); //Assert.IsTrue(found); // Check subscription matched call Thread.Sleep(1500); Assert.AreEqual(1, count); Assert.AreEqual(_reader, firstDataReader); Assert.AreEqual(1, firstTotalCount); Assert.AreEqual(1, firstTotalCountChange); Assert.AreEqual(1, firstCurrentCount); Assert.AreEqual(1, firstCurrentCountChange); Assert.AreEqual(_writer.InstanceHandle, firstHandle); // Delete the writer result = _publisher.DeleteDataWriter(_writer); Assert.AreEqual(ReturnCode.Ok, result); // Check subscription matched call Thread.Sleep(500); Assert.AreEqual(2, count); Assert.AreEqual(_reader, secondDataReader); Assert.AreEqual(1, secondTotalCount); Assert.AreEqual(0, secondTotalCountChange); Assert.AreEqual(0, secondCurrentCount); Assert.AreEqual(-1, secondCurrentCountChange); Assert.AreEqual(_writer.InstanceHandle, secondHandle); // Remove the listener to avoid extra messages result = _subscriber.SetListener(null); Assert.AreEqual(ReturnCode.Ok, result); }
public ReturnCode IgnoreTopic(InstanceHandle handle) { return(realParticipant.IgnoreTopic(handle)); }
public static extern ReturnCode get_discovered_topic_data( IntPtr _this, IntPtr topic_data, InstanceHandle handle);
public ReturnCode IgnoreSubscription(InstanceHandle handle) { return(realParticipant.IgnoreSubscription(handle)); }
public static extern ReturnCode get_matched_subscription_data( IntPtr _this, IntPtr subscription_data, InstanceHandle subscription_handle);
public bool ContainsEntity(InstanceHandle a_handle) { return(realParticipant.ContainsEntity(a_handle)); }
private static void TestExisting(Oms oms) { InstanceHandle ihInventItem = oms.GetInstance(LocalInstanceGuids.Classes.InventoryItem); string title = oms.GetInstanceTitle(ihInventItem); string title2 = oms.GetTranslationValue(ihInventItem, oms.GetInstance(KnownRelationshipGuids.Class__has_title__Translatable_Text_Constant), oms.GetInstance(KnownInstanceGuids.Languages.English)); }
internal InstanceHandleReference(InstanceHandle instanceHandle) { Fx.Assert(instanceHandle != null, "Null instanceHandle provided to InstanceHandleReference."); InstanceHandle = instanceHandle; }
public static extern ReturnCode ignore_participant( IntPtr _this, InstanceHandle handle);
public static extern ReturnCode ignore_subscription( IntPtr _this, InstanceHandle handle);
static void Main(string[] args) { DDSEntityManager mgr = new DDSEntityManager("ContentFilteredTopic"); String partitionName = "ContentFilteredTopic example"; // create Domain Participant mgr.createParticipant(partitionName); mgr.setAutoDispose(true); // create Type StockTypeSupport msgTS = new StockTypeSupport(); mgr.registerType(msgTS); // create Topic mgr.createTopic("StockTrackerExclusive"); // create Publisher mgr.createPublisher(); // create DataWriter mgr.createWriter(); // Publish Events IDataWriter dwriter = mgr.getWriter(); StockDataWriter ContentFilteredTopicDataWriter = dwriter as StockDataWriter; Stock geStock = new Stock(); Stock msftStock = new Stock(); ReturnCode writeStatus; geStock.ticker = "GE"; geStock.price = 12.00f; msftStock.ticker = "MSFT"; msftStock.price = 25.00f; InstanceHandle geHandle = ContentFilteredTopicDataWriter.RegisterInstance(geStock); InstanceHandle msHandle = ContentFilteredTopicDataWriter.RegisterInstance(msftStock); for (int i = 0; i < 20; i++) { geStock.price += 0.5f; msftStock.price += 1.5f; Console.WriteLine("=== [ContentFilteredTopicDataPublisher] sends 2 stockQuotes : (GE, {0}) (MSFT, {1})", geStock.price, msftStock.price); writeStatus = ContentFilteredTopicDataWriter.Write(geStock, geHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write"); writeStatus = ContentFilteredTopicDataWriter.Write(msftStock, msHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write"); Thread.Sleep(100); } geStock.price = -1.0f; msftStock.price = -1.0f; writeStatus = ContentFilteredTopicDataWriter.Write(geStock, geHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write GE"); writeStatus = ContentFilteredTopicDataWriter.Write(msftStock, msHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write MSFT"); Console.WriteLine("Market Closed"); ContentFilteredTopicDataWriter.UnregisterInstance(geStock, geHandle); ContentFilteredTopicDataWriter.UnregisterInstance(msftStock, msHandle); mgr.getPublisher().DeleteDataWriter(ContentFilteredTopicDataWriter); mgr.deletePublisher(); mgr.deleteTopic(); mgr.deleteParticipant(); }
static void Main(string[] args) { DDSEntityManager mgr = new DDSEntityManager("QueryCondition"); String partitionName = "QueryCondition example"; // create Domain Participant mgr.createParticipant(partitionName); // create Type StockTypeSupport msgTS = new StockTypeSupport(); mgr.registerType(msgTS); // create Topic mgr.createTopic("StockTrackerExclusive"); // create Publisher mgr.createPublisher(); // create DataWriter mgr.createWriter(); // Publish Events IDataWriter dwriter = mgr.getWriter(); StockDataWriter QueryConditionDataWriter = dwriter as StockDataWriter; Stock geStock = new Stock(); Stock msftStock = new Stock(); ReturnCode writeStatus; geStock.ticker = "GE"; geStock.price = 12.00f; msftStock.ticker = "MSFT"; msftStock.price = 25.00f; // Register Instances InstanceHandle geHandle = QueryConditionDataWriter.RegisterInstance(geStock); ErrorHandler.checkHandle(geHandle, "DataWriter.RegisterInstance (GE)"); InstanceHandle msHandle = QueryConditionDataWriter.RegisterInstance(msftStock); ErrorHandler.checkHandle(msHandle, "DataWriter.RegisterInstance (MSFT)"); for (int i = 0; i < 20; i++) { geStock.price += 0.5f; msftStock.price += 1.5f; writeStatus = QueryConditionDataWriter.Write(geStock, InstanceHandle.Nil); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write"); writeStatus = QueryConditionDataWriter.Write(msftStock, InstanceHandle.Nil); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write"); Thread.Sleep(100); Console.WriteLine("GE : {0} MSFT {1}", String.Format("{0:0.#}", geStock.price), String.Format("{0:0.#}", msftStock.price)); } geStock.price = -1.0f; msftStock.price = -1.0f; // Write samples writeStatus = QueryConditionDataWriter.Write(geStock, InstanceHandle.Nil); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write (GE)"); writeStatus = QueryConditionDataWriter.Write(msftStock, InstanceHandle.Nil); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Write (MS)"); // Dispose Instances writeStatus = QueryConditionDataWriter.Dispose(geStock, geHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Dispose (GE)"); writeStatus = QueryConditionDataWriter.Dispose(msftStock, msHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.Dispose (MS)"); // Unregister Instances writeStatus = QueryConditionDataWriter.UnregisterInstance(geStock, geHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.UnregisterInstance (GE)"); writeStatus = QueryConditionDataWriter.UnregisterInstance(msftStock, msHandle); ErrorHandler.checkStatus(writeStatus, "StockDataWriter.UnregisterInstance(MS)"); // Clean up mgr.getPublisher().DeleteDataWriter(QueryConditionDataWriter); mgr.deletePublisher(); mgr.deleteTopic(); mgr.deleteParticipant(); }
private void RemoveHandle(InstanceHandle handle) { Items.Remove(handle); foreach (var item in handle.referredList.Values.ToArray()) item.RemoveReference(handle); foreach (var item in handle.referenceList.Values.ToArray()) item.UnmarkReferredBy(handle); }
public static ReturnCode TakeNextInstanceWithCondition( DataReader reader, ref object[] data, ref SampleInfo[] sampleInfos, int maxSamples, InstanceHandle instanceHandle, IReadCondition condition) { ReturnCode result = ReturnCode.Ok; using (DataReaderMarshaler marshaler = new DataReaderMarshaler(data, sampleInfos, ref maxSamples, ref result)) { if (result == ReturnCode.Ok) { result = Gapi.FooDataReader.take_next_instance_w_condition( reader.GapiPeer, marshaler.dataValuesPtr, marshaler.sampleInfosPtr, maxSamples, instanceHandle, ((ReadCondition)condition).GapiPeer); marshaler.CopyOut(ref data, ref sampleInfos); } } return result; }
public void RemoveReference(InstanceHandle handle) { if (referenceList.ContainsKey(handle.Instance)) { referenceList.Remove(handle.Instance); handle.UnmarkReferredBy(this); } }
public void TestOnRequestedDeadlineMissed() { // Prepare qos for the test DataWriterQos dwQos = new DataWriterQos(); dwQos.Deadline.Period = new Duration { Seconds = 1 }; ReturnCode result = _writer.SetQos(dwQos); Assert.AreEqual(ReturnCode.Ok, result); DataReaderQos drQos = new DataReaderQos(); drQos.Deadline.Period = new Duration { Seconds = 1 }; drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; result = _reader.SetQos(drQos); Assert.AreEqual(ReturnCode.Ok, result); // Enable entities result = _writer.Enable(); Assert.AreEqual(ReturnCode.Ok, result); result = _reader.Enable(); Assert.AreEqual(ReturnCode.Ok, result); // Wait for discovery bool found = _writer.WaitForSubscriptions(1, 1000); Assert.IsTrue(found); // Attach to the event int count = 0; DataReader reader = null; int totalCount = 0; int totalCountChange = 0; InstanceHandle lastInstanceHandle = InstanceHandle.HandleNil; _listener.RequestedDeadlineMissed += (r, s) => { reader = r; totalCount = s.TotalCount; totalCountChange = s.TotalCountChange; lastInstanceHandle = s.LastInstanceHandle; count++; }; // Write an instance _dataWriter.Write(new TestStruct { Id = 1 }); // After half second deadline should not be lost yet System.Threading.Thread.Sleep(500); Assert.AreEqual(0, count); // After one second and a half one deadline should be lost System.Threading.Thread.Sleep(1000); Assert.AreEqual(1, count); Assert.AreEqual(_reader, reader); Assert.AreEqual(1, totalCount); Assert.AreEqual(1, totalCountChange); Assert.AreNotEqual(InstanceHandle.HandleNil, lastInstanceHandle); }
public void UnmarkReferredBy(InstanceHandle handle) { referredList.Remove(handle.Instance); }
public void TestOnSampleRejected() { int count = 0; DataReader dataReader = null; int totalCount = 0; int totalCountChange = 0; InstanceHandle lastInstanceHandle = InstanceHandle.HandleNil; SampleRejectedStatusKind lastReason = SampleRejectedStatusKind.NotRejected; // Attach to the event _listener.SampleRejected += (r, s) => { dataReader = r; totalCount = s.TotalCount; totalCountChange = s.TotalCountChange; lastInstanceHandle = s.LastInstanceHandle; lastReason = s.LastReason; count++; }; // Prepare QoS for the test DataReaderQos drQos = new DataReaderQos(); drQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; drQos.ResourceLimits.MaxInstances = 1; drQos.ResourceLimits.MaxSamples = 1; drQos.ResourceLimits.MaxSamplesPerInstance = 1; ReturnCode result = _reader.SetQos(drQos); Assert.AreEqual(ReturnCode.Ok, result); // Enable entities result = _writer.Enable(); Assert.AreEqual(ReturnCode.Ok, result); result = _reader.Enable(); Assert.AreEqual(ReturnCode.Ok, result); // Wait for discovery bool found = _writer.WaitForSubscriptions(1, 1000); Assert.IsTrue(found); // Write two samples of the same instances for (int i = 1; i <= 2; i++) { result = _dataWriter.Write(new TestStruct { Id = 1 }); Assert.AreEqual(ReturnCode.Ok, result); result = _dataWriter.WaitForAcknowledgments(new Duration { Seconds = 5 }); Assert.AreEqual(ReturnCode.Ok, result); } System.Threading.Thread.Sleep(100); Assert.AreEqual(1, count); Assert.AreEqual(_reader, dataReader); Assert.AreEqual(1, totalCount); Assert.AreEqual(1, totalCountChange); Assert.AreNotEqual(InstanceHandle.HandleNil, lastInstanceHandle); Assert.AreEqual(SampleRejectedStatusKind.RejectedBySamplesPerInstanceLimit, lastReason); // Remove the listener to avoid extra messages result = _subscriber.SetListener(null); Assert.AreEqual(ReturnCode.Ok, result); }
public static ReturnCode TakeNextInstance( DataReader reader, ref object[] data, ref SampleInfo[] sampleInfos, int maxSamples, InstanceHandle instanceHandle, SampleStateKind sampleStates, ViewStateKind viewStates, InstanceStateKind instanceStates) { ReturnCode result = ReturnCode.Ok; using (DataReaderMarshaler marshaler = new DataReaderMarshaler(data, sampleInfos, ref maxSamples, ref result)) { if (result == ReturnCode.Ok) { result = Gapi.FooDataReader.take_next_instance( reader.GapiPeer, marshaler.dataValuesPtr, marshaler.sampleInfosPtr, maxSamples, instanceHandle, sampleStates, viewStates, instanceStates); marshaler.CopyOut(ref data, ref sampleInfos); } } return result; }
public void TestOnLivelinessChanged() { int count = 0; DataReader firstDataReader = null; int firstAliveCount = 0; int firstAliveCountChange = 0; int firstNotAliveCount = 1; int firstNotAliveCountChange = 1; InstanceHandle firstLastPublicationHandle = InstanceHandle.HandleNil; DataReader secondDataReader = null; int secondAliveCount = 1; int secondAliveCountChange = 1; int secondNotAliveCount = 0; int secondNotAliveCountChange = 0; InstanceHandle secondLastPublicationHandle = InstanceHandle.HandleNil; // Attach to the event _listener.LivelinessChanged += (r, s) => { Assert.AreEqual(_reader, r); if (count == 0) { // Liveliness alive firstDataReader = r; firstAliveCount = s.AliveCount; firstAliveCountChange = s.AliveCountChange; firstNotAliveCount = s.NotAliveCount; firstNotAliveCountChange = s.NotAliveCountChange; firstLastPublicationHandle = s.LastPublicationHandle; } else { // Liveliness not alive secondDataReader = r; secondAliveCount = s.AliveCount; secondAliveCountChange = s.AliveCountChange; secondNotAliveCount = s.NotAliveCount; secondNotAliveCountChange = s.NotAliveCountChange; secondLastPublicationHandle = s.LastPublicationHandle; } count++; }; // Prepare the QoS for the test DataReaderQos drQos = new DataReaderQos(); drQos.Liveliness.LeaseDuration = new Duration { Seconds = 1 }; ReturnCode result = _reader.SetQos(drQos); Assert.AreEqual(ReturnCode.Ok, result); DataWriterQos dwQos = new DataWriterQos(); dwQos.Liveliness.Kind = LivelinessQosPolicyKind.ManualByTopicLivelinessQos; dwQos.Liveliness.LeaseDuration = new Duration { Seconds = 1 }; result = _writer.SetQos(dwQos); Assert.AreEqual(ReturnCode.Ok, result); // Enable entities result = _writer.Enable(); Assert.AreEqual(ReturnCode.Ok, result); result = _reader.Enable(); Assert.AreEqual(ReturnCode.Ok, result); // Wait for discovery bool found = _writer.WaitForSubscriptions(1, 1000); Assert.IsTrue(found); // Assert liveliness in the writer result = _writer.AssertLiveliness(); Assert.AreEqual(ReturnCode.Ok, result); // After half second liveliness should not be lost yet Thread.Sleep(500); Assert.AreEqual(1, count); Assert.IsNotNull(firstDataReader); Assert.AreEqual(_reader, firstDataReader); Assert.AreEqual(1, firstAliveCount); Assert.AreEqual(1, firstAliveCountChange); Assert.AreEqual(0, firstNotAliveCount); Assert.AreEqual(0, firstNotAliveCountChange); Assert.AreEqual(_writer.InstanceHandle, firstLastPublicationHandle); // After one second and a half one liveliness should be lost Thread.Sleep(1000); Assert.AreEqual(2, count); Assert.IsNotNull(secondDataReader); Assert.AreEqual(_reader, secondDataReader); Assert.AreEqual(0, secondAliveCount); Assert.AreEqual(-1, secondAliveCountChange); Assert.AreEqual(1, secondNotAliveCount); Assert.AreEqual(1, secondNotAliveCountChange); Assert.AreEqual(_writer.InstanceHandle, secondLastPublicationHandle); // Remove the listener to avoid extra messages result = _subscriber.SetListener(null); Assert.AreEqual(ReturnCode.Ok, result); }
public static extern ReturnCode get_key_value( IntPtr _this, IntPtr key_holder, InstanceHandle handle);
internal CimSubscriptionResult(InstanceHandle handle, string bookmark, string machineId) { this._resultInstance = new CimInstance(handle, null); this._bookmark = bookmark; this._machineId = machineId; }