context: // The OpenSplice DDS Community Edition project.
  //
  // Copyright (C) 2006 to 2011 PrismTech Limited and its licensees.
  // Copyright (C) 2009  L-3 Communications / IS
  // 
  //  This library is free software; you can redistribute it and/or
  //  modify it under the terms of the GNU Lesser General Public
  //  License Version 3 dated 29 June 2007, as published by the
  //  Free Software Foundation.
  // 
  //  This library is distributed in the hope that it will be useful,
  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  //  Lesser General Public License for more details.
  // 
  //  You should have received a copy of the GNU Lesser General Public
  //  License along with OpenSplice DDS Community Edition; if not, write to the Free Software
  //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  
  using System;
  using DDS;
  using System.Runtime.InteropServices;
  
  using DDS.OpenSplice.CustomMarshalers;
  namespace testNamespace
  {
      class TestBinding : DomainParticipantListener
      {
          public static void Main()
          {
              TestBinding binding = new TestBinding();
              binding.Run();
          }
  
          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;
  
gt: 			result = filteredTopic.GetExpressionParameters(ref testParams);