static void Main(string[] args)
        {
            DDSEntityManager mgr = new DDSEntityManager("HelloWorld");
            String partitionName = "HelloWorld example";

            // create Domain Participant
            mgr.createParticipant(partitionName);

            // create Type
            MsgTypeSupport msgTS = new MsgTypeSupport();
            mgr.registerType(msgTS);

            // create Topic
            mgr.createTopic("HelloWorldData_Msg");

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader(false);

            IDataReader dreader = mgr.getReader();
            MsgDataReader HelloWorldDataReader = dreader as MsgDataReader;

            Msg[] msgSeq = null;
            DDS.SampleInfo[] infoSeq = null;
            Boolean terminate = false;
            ReturnCode status;

            Console.WriteLine("=== [Subscriber] Ready ...");
            int count = 0;
            while (!terminate && count < 1500)
            {
                status = HelloWorldDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(status, "DataReader.Take");
                for (int i = 0; i < msgSeq.Length; i++)
                {
                    if (infoSeq[i].ValidData)
                    {
                        Console.WriteLine("=== [Subscriber] message received :");
                        Console.WriteLine("    userID  : {0}", msgSeq[i].userID);
                        Console.WriteLine("    Message : \"" + msgSeq[i].message + "\"");

                        terminate = true;
                    }                                        
                }
                status = HelloWorldDataReader.ReturnLoan(ref msgSeq, ref infoSeq);
                ErrorHandler.checkStatus(status, "DataReader.ReturnLoan");
                Thread.Sleep(200);
                ++count;
            }

            Thread.Sleep(2);

            // clean up
            mgr.getSubscriber().DeleteDataReader(HelloWorldDataReader);
            mgr.deleteSubscriber();       
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
        static void Main(string[] args)
        {
            DDSEntityManager mgr = new DDSEntityManager("Listener");
            ReturnCode status = ReturnCode.Error;
            ListenerDataListener myListener;
            String partitionName = "Listener Example";
            int count = 0;
            Duration wait_timeout = new Duration(0, 200000000);

            // create Domain Participant
            mgr.createParticipant(partitionName);

            // create Type
            MsgTypeSupport msgTS = new MsgTypeSupport();
            mgr.registerType(msgTS);

            // create Topic
            mgr.createTopic("ListenerData_Msg");

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader(false);

            IDataReader dreader = mgr.getReader();

            myListener = new ListenerDataListener();
            myListener.MsgDR = dreader as MsgDataReader;

            Console.WriteLine("=== [ListenerDataSubscriber] SetListener");
            StatusKind kind = StatusKind.DataAvailable | StatusKind.RequestedDeadlineMissed;

            status = myListener.MsgDR.SetListener(myListener, kind);
            ErrorHandler.checkStatus(status, "DataReader.SetListener");

            Console.WriteLine("=== [ListenerDataSubscriber] Ready...");
            myListener.terminated = false;

            WaitSet ws = new WaitSet();
            ws.AttachCondition(myListener.guardCond);
            ICondition[] cond = null;


            while (!myListener.terminated && count < 1500)
            {
                Console.WriteLine("=== [SubscriberUsingListener] waiting waitset ...");
                ws.Wait(ref cond, wait_timeout);
                myListener.guardCond.SetTriggerValue(false);
                ++count;
            }

            Console.WriteLine("===[ListenerDataSubscriber] Market Closed.");

            mgr.getSubscriber().DeleteDataReader(myListener.MsgDR);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("*** [ContentFilteredTopicDataSubscriber] Subscription string not specified");
                Console.WriteLine("*** usage : ContentFilteredTopicDataSubscriber <subscription_string>");
                Environment.Exit(-1);
            }

            ITopic topic;
            DDSEntityManager mgr = new DDSEntityManager();
            String partitionName = "ContentFilteredTopic example";

            // Create DomainParticipant
            mgr.createParticipant(partitionName);

            // Create Type
            StockTypeSupport msgTS = new StockTypeSupport();
            mgr.registerType(msgTS);

            // Create Topic
            topic = mgr.createTopic("StockTrackerExclusive", "ContentFilteredTopic");

            // ContentFilteredTopic
            mgr.createContentFilter("MyStockTopic", topic, args[0]);
            Console.WriteLine("=== [ContentFilteredTopicDataSubscriber] Subscription filter : ticker = '{0}'",args[0]);
            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader("ContentFilteredTopic", true);

            // Read Events
            IDataReader dreader = mgr.getReader();
            StockDataReader WaitSetReader = dreader as StockDataReader;

            // Create WaitSet
            IWaitSet w = new WaitSet();

            // Status Condition
            IStatusCondition status;
            status = dreader.StatusCondition;
            status.SetEnabledStatuses(StatusKind.DataAvailable);

            ReturnCode result = ReturnCode.Error;
            result = w.AttachCondition(status);
            ErrorHandler.checkHandle(status, "DataReader.StatusCondition");
            ErrorHandler.checkStatus(result, "WaitSet.AttachCondition");

            DDS.ICondition[] conditionList;
            DDS.SampleInfo[] infoSeq;
            Stock[] stockSeq;

            Console.WriteLine("=== [ContentFilteredTopicDataSubscriber] Ready ...");

            bool terminate = false;
            int count = 0;
            while (!terminate && count < 1500)
            {
                /**
                 * Wait until data will be available
                 */
                Duration wait_timeout = new Duration(Duration.InfiniteSec, Duration.InfiniteNanoSec);
                conditionList = null;
                result = w.Wait(ref conditionList, wait_timeout);
                ErrorHandler.checkStatus(result, "WaitSet.Wait");

                stockSeq = null;
                infoSeq = null;

                /**
                 * Read Data
                 */
                result = WaitSetReader.Take(ref stockSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(result, "StockDataReader.Take");

                /**
                 * Display Data
                 */
                for (int i=0; i < stockSeq.Length; i++)
                {
                    if (infoSeq[i].ValidData)
                    {
                        if (stockSeq[i].price == -1)
                        {
                            // We read the last expected sample => exit
                            terminate = true;
                            break;
                        }
                        Console.WriteLine("=== [ContentFilteredTopicDataSubscriber] receives stockQuote :  ( {0} , {1} )",
                                          stockSeq[i].ticker, stockSeq[i].price);
                    }
                }
                result = WaitSetReader.ReturnLoan(ref stockSeq, ref infoSeq);
                ErrorHandler.checkStatus(result, "StockDataReader.ReturnLoan");
                Thread.Sleep(200);
                ++count;
            }

            Console.WriteLine("=== [ContentFilteredTopicDataSubscriber] Market Closed");

            // clean up
            mgr.getSubscriber().DeleteDataReader(WaitSetReader);
            mgr.deleteSubscriber();
            mgr.deleteContentFilteredTopic();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Insufficient number of arguments.");
                usage();
                Environment.Exit(-1);
            }
            else
            {
                DDSEntityManager mgr = new DDSEntityManager();
                String partitionName = "Durability Example";

                String durabilityKind = args[0];

                // create Domain Participant
                mgr.createParticipant(partitionName);

                // set the durability kind
                mgr.setDurabilityKind(durabilityKind);

                // create Type
                MsgTypeSupport msgTS = new MsgTypeSupport();
                mgr.registerType(msgTS);

                // create Topic
                mgr.createTopic("DurabilityData_Msg", "Durability");

                // create Subscriber
                mgr.createSubscriber();
                mgr.createReader("Durability", false);

                IDataReader dreader = mgr.getReader();
                MsgDataReader DurabilityDataReader = dreader as MsgDataReader;

                Msg[] msgSeq = null;
                DDS.SampleInfo[] infoSeq = null;
                Boolean terminate = false;
                ReturnCode status;
                Console.WriteLine("=== [Subscriber] Ready ...");
                while (!terminate)
                {
                    status = DurabilityDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                    ErrorHandler.checkStatus(status, "DataReader.Take");
                    for (int i = 0; i < msgSeq.Length; i++)
                    {
                        if (infoSeq[i].ValidData)
                        {
                            Console.WriteLine("{0} : {1}", msgSeq[i].id, msgSeq[i].content);
                            if (msgSeq[i].content.Equals("9"))
                            {
                                terminate = true;
                                break;
                            }
                        }
                    }
                    status = DurabilityDataReader.ReturnLoan(ref msgSeq, ref infoSeq);
                    ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan");
                }
                // clean up
                mgr.getSubscriber().DeleteDataReader(DurabilityDataReader);
                mgr.deleteSubscriber();
                mgr.deleteTopic();
                mgr.deleteParticipant();
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            DDSEntityManager mgr = new DDSEntityManager();
            String partitionName = "Ownership example";

            // create Domain Participant
            mgr.createParticipant(partitionName);

            // create Type
            StockTypeSupport msgTS = new StockTypeSupport();
            mgr.registerType(msgTS);

            // create Topic
            mgr.createTopic("StockTrackerExclusive", "Ownership");

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader("Ownership", false);

            // Read Events
            IDataReader dreader = mgr.getReader();
            StockDataReader OwnershipDataReader = dreader as StockDataReader;

            Stock[] msgSeq = null;
            DDS.SampleInfo[] infoSeq = null;

            Console.WriteLine("===[Subscriber] Ready ...");
            Console.WriteLine("   Ticker   Price   Publisher   ownership strength");

            Boolean terminate = false;
            ReturnCode status = ReturnCode.Error;
            int count = 0;
            while (!terminate && count < 1500)
            {
                OwnershipDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any,
                                          ViewStateKind.Any, InstanceStateKind.Any);
                for (int i = 0; i < msgSeq.Length; i++)
                {
                    if (infoSeq[i].ValidData)
                    {
                        if (msgSeq[i].price < -0.0f)
                        {
                            terminate = true;
                            break;
                        }
                        Console.WriteLine("   {0} {1}   {2}     {3}", msgSeq[i].ticker,
                                          msgSeq[i].price, msgSeq[i].publisher, msgSeq[i].strength);
                    }
                }
                status = OwnershipDataReader.ReturnLoan(ref msgSeq, ref infoSeq);
                ErrorHandler.checkStatus(status, "StockDataReader.ReturnLoan");
                Thread.Sleep(2);
                ++count;
                Thread.Sleep(200);
            }
            Console.WriteLine("===[Subscriber] Market Closed");

            // clean up
            mgr.getSubscriber().DeleteDataReader(OwnershipDataReader);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
        static void Main(string[] args)
        {
            String[] sSampleState = { "READ_SAMPLE_STATE", "NOT_READ_SAMPLE_STATE" };
            String[] sViewState = { "NEW_VIEW_STATE", "NOT_NEW_VIEW_STATE" };
            String[] sInstanceState = { "ALIVE_INSTANCE_STATE", "NOT_ALIVE_DISPOSED_INSTANCE_STATE", "NOT_ALIVE_NO_WRITERS_INSTANCE_STATE" };

            bool closed = false;
            int nbIter = 1;
            int nbIterMax = 100;

            ReturnCode status = ReturnCode.Error;
            
            Msg[] msgList = null;
            SampleInfo[] infoSeq = null;
            
            DDSEntityManager mgr = new DDSEntityManager("Lifecycle");

            // Create domain participant
            String partitionName = "Lifecycle example";
            mgr.createParticipant(partitionName);          

            // Create type
            MsgTypeSupport mt = new MsgTypeSupport();
            mgr.registerType(mt);

            // Create Topic
            String topicName = "Lifecycle_Msg";
            mgr.createTopic(topicName);

            // Create Subscriber
            mgr.createSubscriber();
            mgr.createReader(false);

            IDataReader dreader = mgr.getReader();
            MsgDataReader LifecycleReader = dreader as MsgDataReader;
            ErrorHandler.checkHandle(LifecycleReader, "MsgDataReader narrow");

            Console.WriteLine("=== [Subscriber] Ready ...");

            while (!closed && (nbIter < nbIterMax))
            {
                status = LifecycleReader.Read(ref msgList, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(status, "MsgDataReader.Read");

                for (int j = 0; j < msgList.Length; j++)
                {
                    Console.WriteLine(" Message        : {0}", msgList[j].message);
                    Console.WriteLine(" writerStates   : {0}", msgList[j].writerStates);
                    Console.WriteLine(" valida data    : {0}", infoSeq[j].ValidData);
                    string str = "sample_state:" + sSampleState[index((int)infoSeq[j].SampleState)] + "-view_state:" + sViewState[index((int)infoSeq[j].ViewState)] + "-instance_state:" + sInstanceState[index((int)infoSeq[j].InstanceState)];
                    Console.WriteLine(str);
                    Thread.Sleep(200);
                    closed = msgList[j].writerStates.Equals("STOPPING_SUBSCRIBER");
                }
                status = LifecycleReader.ReturnLoan(ref msgList, ref infoSeq);
                ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan");
                Thread.Sleep(20);
                nbIter++;
            }

            Console.WriteLine("=== [Subscriber] stopping after {0} iterations - closed={1}", nbIter, closed.ToString());
            if (nbIter == nbIterMax)
                Console.WriteLine("*** Error : max {0} iterations reached", nbIterMax);

            // Clean-up         
            mgr.getSubscriber().DeleteDataReader(LifecycleReader);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
        static void Main(string[] args)
        {
            String[] sSampleState = { "READ_SAMPLE_STATE", "NOT_READ_SAMPLE_STATE" };
            String[] sViewState = { "NEW_VIEW_STATE", "NOT_NEW_VIEW_STATE" };
            String[] sInstanceState = { "ALIVE_INSTANCE_STATE", "NOT_ALIVE_DISPOSED_INSTANCE_STATE", "NOT_ALIVE_NO_WRITERS_INSTANCE_STATE" };

            WriterState[] WriterStateList = null;
            SampleInfo[] ws_infoSeq = null;
            Msg[] msgList = null;
            SampleInfo[] infoSeq = null;

            //------------------ WriterState topic --------------------//
            DDSEntityManager mgrWs = new DDSEntityManager();

            // Create domain participant
            String partitionName = "Lifecycle";
            mgrWs.createParticipant(partitionName);

            // Create Type
            WriterStateTypeSupport wst = new WriterStateTypeSupport();
            mgrWs.registerType(wst);

            // Create Topic
            String wsTopicName = "WriterState_Msg";
            mgrWs.createTopic(wsTopicName, "Lifecycle");

            // Create Subscriber
            mgrWs.createSubscriber();

            // Create DataReader
            mgrWs.createReader("Lifecycle", false);

            IDataReader dwsReader = mgrWs.getReader();
            WriterStateDataReader WriterStateReader = dwsReader as WriterStateDataReader;
            ErrorHandler.checkHandle(WriterStateReader, "WriterStateDataReader narrow");

            //------------------ Msg topic --------------------//
            DDSEntityManager mgr = new DDSEntityManager();

            // Create domain participant
            mgr.createParticipant(partitionName);

            // Create type
            MsgTypeSupport mt = new MsgTypeSupport();
            mgr.registerType(mt);

            // Create Topic
            String topicName = "Lifecycle_Msg";
            mgr.createTopic(topicName, "Lifecycle");

            // Create Subscriber
            mgr.createSubscriber();
            mgr.createReader("Lifecycle", false);

            IDataReader dreader = mgr.getReader();
            MsgDataReader LifecycleReader = dreader as MsgDataReader;
            ErrorHandler.checkHandle(WriterStateReader, "MsgDataReader narrow");

            Console.WriteLine("=== [Subscriber] Ready ...");

            bool closed = false;
            bool writerStateChg = true;
            String sWriterState = "";
            ReturnCode status = ReturnCode.Error;

            while (!closed)
            {
                // WriterState topic
                status = WriterStateReader.Take(ref WriterStateList, ref ws_infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(status, "WriterStateReader.Take");

                for (int j = 0; j < WriterStateList.Length; j++)
                {
                    if (ws_infoSeq[j].ValidData)
                    {
                        Console.WriteLine("--- WriterState : {0}", WriterStateList[j].state);
                        closed = WriterStateList[j].state.Equals("STOPPING SUBSCRIBER");
                        writerStateChg = sWriterState.Equals(WriterStateList[j].state);
                        sWriterState = WriterStateList[j].state;
                        Thread.Sleep(200);
                    }
                }
                status = WriterStateReader.ReturnLoan(ref WriterStateList, ref ws_infoSeq);
                ErrorHandler.checkStatus(status, "WriterStateDataReader.ReturnLoan");
                Thread.Sleep(2);

                // Lifecycle Topic
                if (writerStateChg)
                {
                    status = LifecycleReader.Read(ref msgList, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                    ErrorHandler.checkStatus(status, "MsgDataReader.Read");

                    for (int j = 0; j < msgList.Length; j++)
                    {
                        Console.WriteLine(" Message        : {0}", msgList[j].message);
                        Console.WriteLine(" valida data    : {0}", infoSeq[j].ValidData);
                        Console.WriteLine(" sample_state   : {0}", sSampleState[index((int)infoSeq[j].SampleState)]);
                        Console.WriteLine(" view_state     : {0}", sViewState[index((int)infoSeq[j].ViewState)]);
                        Console.WriteLine(" instance_state : {0}", sInstanceState[index((int)infoSeq[j].InstanceState)]);
                        Thread.Sleep(200);
                    }
                    status = LifecycleReader.ReturnLoan(ref msgList, ref infoSeq);
                    ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan");
                    Thread.Sleep (2);
                    writerStateChg = false;
                }
            }

            // Clean-up Msg Entities
            mgr.getSubscriber().DeleteDataReader(LifecycleReader);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();

            // Clean-up WriterState Entities
            mgrWs.getSubscriber().DeleteDataReader(WriterStateReader);
            mgrWs.deleteSubscriber();
            mgrWs.deleteTopic();
            mgrWs.deleteParticipant();
        }
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Bad args number");
                Console.WriteLine("*** [QueryConditionDataQuerySubscriber] Query string not specified");
                Console.WriteLine("*** usage : QueryConditionDataQuerySubscriber <query_string>");
                Environment.Exit(-1);
            }

            ITopic topic;
            DDSEntityManager mgr = new DDSEntityManager();
            String partitionName = "QueryCondition example";
            String QueryConditionDataToSubscribe = args[0];

            // Create DomainParticipant
            mgr.createParticipant(partitionName);

            // Create Type
            StockTypeSupport msgTS = new StockTypeSupport();
            mgr.registerType(msgTS);

            // Create Topic
            topic = mgr.createTopic("StockTrackerExclusive", "QueryCondition");

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader("QueryCondition", false);

            // Read Events
            IDataReader dreader = mgr.getReader();
            StockDataReader QueryConditionDataReader = dreader as StockDataReader;

            String[] queryStr = { QueryConditionDataToSubscribe };

            Console.WriteLine("=== [QueryConditionDataQuerySubscriber] Query : ticker = {0}", QueryConditionDataToSubscribe);
            IQueryCondition qc = QueryConditionDataReader.CreateQueryCondition(
                SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any, "ticker=%0", queryStr);

            Console.WriteLine("=== [QueryConditionDataQuerySubscriber] Ready ...");

            DDS.SampleInfo[] infoSeq = null;
            Stock[] stockSeq = null;

            ReturnCode status = ReturnCode.Error;
            bool terminate = false;
            int count = 0;
            Console.WriteLine("=== [QueryConditionDataQuerySubscriber] Ready ...");
            while (!terminate && count < 1500)
            {
                // Take Sample with Condition
                status = QueryConditionDataReader.TakeWithCondition(ref stockSeq, ref infoSeq,
                    Length.Unlimited, qc);
                ErrorHandler.checkStatus(status, "DataReader.TakeWithCondition");

                /**
                 * Display Data
                 */
                for (int i=0; i<stockSeq.Length; i++)
                {
                    if (infoSeq[i].ValidData)
                    {
                        if (stockSeq[i].price == -1.0f)
                        {
                            terminate = true;
                            break;
                        }
                        Console.WriteLine("{0} : {1}", stockSeq[i].ticker, String.Format("{0:0.#}", stockSeq[i].price));
                    }
                }
                status = QueryConditionDataReader.ReturnLoan(ref stockSeq, ref infoSeq);
                ErrorHandler.checkStatus(status, "DataReader.ReturnLoan");
                Thread.Sleep(200);
                ++count;
            }

            Console.WriteLine("=== [QueryConditionDataQuerySubscriber] Market Closed");

            // clean up
            QueryConditionDataReader.DeleteReadCondition(qc);
            mgr.getSubscriber().DeleteDataReader(QueryConditionDataReader);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            DDSEntityManager mgr = new DDSEntityManager("WaitSet");
            String partitionName = "WaitSet example";

            // create Domain Participant
            mgr.createParticipant(partitionName);

            // create Type
            MsgTypeSupport msgTS = new MsgTypeSupport();
            mgr.registerType(msgTS);

            // create Topic
            mgr.createTopic("WaitSetData_Msg");

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader(false);

            // Read Events

            IDataReader dreader = mgr.getReader();
            MsgDataReader WaitSetReader = dreader as MsgDataReader;

            // Create a WaitSet
            WaitSet w = new WaitSet();

            // Create a ReadCondition
            IReadCondition readCond = WaitSetReader.CreateReadCondition(SampleStateKind.NotRead, ViewStateKind.New, InstanceStateKind.Alive);
            ErrorHandler.checkHandle(readCond, "DataReader.CreateReadCondition");

            // Create a QueryCondition
            String[] queryStr = { "Hello again" };
            Console.WriteLine("=== [WaitSetDataSubscriber] Query : message = \"Hello again");
            IQueryCondition queryCond = WaitSetReader.CreateQueryCondition("message=%0", queryStr);
            ErrorHandler.checkHandle(queryCond, "DataReader.CreateQueryCondition");

            // Obtain a StatusCondition
            IStatusCondition statusCond;
            statusCond = dreader.StatusCondition;
            statusCond.SetEnabledStatuses(StatusKind.LivelinessChanged);
            ErrorHandler.checkHandle(statusCond, "DataReader.StatusCondition");

            GuardCondition escape;
            escape = new GuardCondition();

            ReturnCode result;
            result = w.AttachCondition(statusCond);
            ErrorHandler.checkStatus(result, "WaitSet.AttachCondition (status)");
            result = w.AttachCondition(readCond);
            ErrorHandler.checkStatus(result, "WaitSet.AttachCondition (read)");
            result = w.AttachCondition(queryCond);
            ErrorHandler.checkStatus(result, "WaitSet.AttachCondition (query)");
            result = w.AttachCondition(escape);
            ErrorHandler.checkStatus(result, "WaitSet.AttachCondition (guard)");

            /* Initialize and pre-allocate the GuardList used to obtain
               the triggered Conditions. */
            ICondition[] guardList = new ICondition[4];

            DDS.SampleInfo[] infoSeq = null;
            Msg[] msgSeq = null;

            bool escaped = false;
            bool writerLeft = false;
            int prevCount = 0;
            int count = 0;
            Console.WriteLine("=== [WaitSetDataSubscriber] Ready ...");
            while (!escaped && count < 20 )
            {
                /**
                 * Wait until data will be available
                 */
                Duration wait_timeout = new Duration(Duration.InfiniteSec, Duration.InfiniteNanoSec);
                result = w.Wait(ref guardList, wait_timeout);
                ErrorHandler.checkStatus(result, "WaitSet.Wait");

                /* Walk over all guards to display information */
                foreach (ICondition guard in guardList)
                {
                    if (guard == readCond)
                    {
                        result = WaitSetReader.ReadWithCondition(ref msgSeq, ref infoSeq,
                                                                 Length.Unlimited, readCond);
                        ErrorHandler.checkStatus(result, "WaitSetReader.ReadWithCondition");
                        foreach (Msg msg in msgSeq)
                        {
                            Console.WriteLine("   --- New message received ---   ");
                            Console.WriteLine("   userID: {0}", msg.userID);
                            Console.WriteLine("   Message :  \"{0}", msg.message);
                        }
                        result = WaitSetReader.ReturnLoan(ref msgSeq, ref infoSeq);
                        ErrorHandler.checkStatus(result, "WaitSet.ReturnLoan");
                    }
                    else if (guard == queryCond)
                    {
                        result = WaitSetReader.TakeWithCondition(ref msgSeq, ref infoSeq,
                                                                 Length.Unlimited, queryCond);
                        ErrorHandler.checkStatus(result, "WaitSetReader.TakeWithCondition");
                        foreach (Msg msg in msgSeq)
                        {
                            Console.WriteLine("   --- New message received with QueryCondition ---   ");
                            Console.WriteLine("   userID: {0}", msg.userID);
                            Console.WriteLine("   Message : \" {0}", msg.message);
                        }
                        result = WaitSetReader.ReturnLoan(ref msgSeq, ref infoSeq);
                        ErrorHandler.checkStatus(result, "WaitSet.ReturnLoan");
                    }
                    else if (guard == statusCond)
                    {
                        LivelinessChangedStatus livelinessStatus = new LivelinessChangedStatus();
                        result = WaitSetReader.GetLivelinessChangedStatus(ref livelinessStatus);
                        ErrorHandler.checkStatus(result, "DataReader.getLivelinessChangedStatus");
                        if (livelinessStatus.AliveCount < prevCount)
                        {
                            Console.WriteLine("!!! A WaitSetDataWriter lost its liveliness");
                            writerLeft = true;
                            Console.WriteLine("Triggering escape condition.");
                            ReturnCode status = escape.SetTriggerValue(true);
                        }
                        else
                        {
                            Console.WriteLine("!!! A WaitSetDataWriter joined");
                        }
                        prevCount = livelinessStatus.AliveCount;
                    }
                    else if (guard == escape)
                    {
                        Console.WriteLine("WaitSetSubscriber has terminated.");
                        escaped = true;
                        ReturnCode status = escape.SetTriggerValue(false);
                    }
                    else
                    {
                        // Unknown Condition
                    }
                }
                ++count;
            }

            // Detach all Conditions from the WaitSet
            result = w.DetachCondition(escape);
            ErrorHandler.checkStatus(result, "WaitSet.DetachCondition (escape)");
            result = w.DetachCondition(readCond);
            ErrorHandler.checkStatus(result, "WaitSet.DetachCondition (readCond)");
            result = w.DetachCondition(queryCond);
            ErrorHandler.checkStatus(result, "WaitSet.DetachCondition (queryCond)");
            result = w.DetachCondition(statusCond);
            ErrorHandler.checkStatus(result, "WaitSet.DetachCondition (statusCond)");

            Console.WriteLine("=== [Subscriber] Closed");
            // clean up
            WaitSetReader.DeleteReadCondition(readCond);
            WaitSetReader.DeleteReadCondition(queryCond);
            mgr.getSubscriber().DeleteDataReader(WaitSetReader);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }