public void OnDataAvailable(IDataReader entityInterface)
        {
            Msg[]        msgList = null;
            SampleInfo[] infoSeq = null;

            status = msgDR.Read(ref msgList, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.New, InstanceStateKind.Any);
            ErrorHandler.checkStatus(status, "DataReader.Read");

            if (msgList != null && msgList.Length > 0)
            {
                Console.WriteLine("=== [ListenerDataListener::OnDataAvailable] - msgList.Length : {0}", msgList.Length);
                foreach (Msg msg in msgList)
                {
                    Console.WriteLine("    --- Message Received ---");
                    Console.WriteLine("    userId : {0}", msg.userID);
                    Console.WriteLine("    message : \\ {0}", msg.message);
                }
                status = msgDR.ReturnLoan(ref msgList, ref infoSeq);
                ErrorHandler.checkStatus(status, "DataReader.ReturnLoan");
            }
            guardCond.SetTriggerValue(true);
        }
Example #2
0
        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);
                    Console.WriteLine(" sample_state   : {0}", sSampleState[index((int)infoSeq[j].SampleState)]);
                    Console.WriteLine(" instance_state : {0}", sInstanceState[index((int)infoSeq[j].InstanceState)]);
                    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();
        }
Example #3
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();
        }
Example #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("Durability");
                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");

                // create Subscriber
                mgr.createSubscriber();
                mgr.createReader(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();
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            OsplConfiguration.SetOsplConfiguration();

            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();
        }
Example #6
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Insufficient number of arguments.");
                usage();
            }
            else
            {
                DDSEntityManager mgr           = new DDSEntityManager("Durability");
                String           partitionName = "Durability Example";
                DDS.Duration     timeout       = new DDS.Duration(40, 0);
                ReturnCode       status;

                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
                if (args[0].Equals("persistent"))
                {
                    mgr.createTopic("PersistentCSDurabilityData_Msg");
                }
                else
                {
                    mgr.createTopic("CSDurabilityData_Msg");
                }

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

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

                status = DurabilityDataReader.WaitForHistoricalData(timeout);
                ErrorHandler.checkStatus(status, "DurabilityDataReader.WaitForHistoricalData");

                Msg[]            msgSeq    = null;
                DDS.SampleInfo[] infoSeq   = null;
                Boolean          terminate = false;
                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(msgSeq[i].content);
                            if (msgSeq[i].content.Equals("9"))
                            {
                                terminate = true;
                                break;
                            }
                        }
                    }
                    status = DurabilityDataReader.ReturnLoan(ref msgSeq, ref infoSeq);
                    ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan");
                }

                // For single process mode wait some time to ensure persistent data is stored to disk
                Thread.Sleep(2000);

                // clean up
                mgr.getSubscriber().DeleteDataReader(DurabilityDataReader);
                mgr.deleteSubscriber();
                mgr.deleteTopic();
                mgr.deleteParticipant();
            }
        }