Ejemplo n.º 1
0
        private void initPublisher(String pub, int strength)
        {
            mgr = new DDSEntityManager("Ownership");
            String partitionName = "Ownership example";

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

            // create Type
            StockTypeSupport stkTS = new StockTypeSupport();

            mgr.registerType(stkTS);

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

            // create Publisher
            mgr.createPublisher();

            // create DataWriter
            mgr.createWriter();
            dwriter             = mgr.getWriter();
            OwnershipDataWriter = dwriter as StockDataWriter;

            msft           = new Stock();
            msft.ticker    = "MSFT";
            msft.publisher = pub;
            msft.strength  = strength;
            msftHandle     = OwnershipDataWriter.RegisterInstance(msft);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DDSEntityManager     mgr    = new DDSEntityManager("Listener");
            ReturnCode           status = ReturnCode.Error;
            ListenerDataListener myListener;
            String partitionName = "Listener Example";
            int    count         = 0;

            // 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, Duration.Infinite);
                myListener.guardCond.SetTriggerValue(false);
                ++count;
            }

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

            mgr.getSubscriber().DeleteDataReader(myListener.MsgDR);
            mgr.deleteSubscriber();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
Ejemplo n.º 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 Publisher
            mgr.createPublisher();

            // create DataWriter
            mgr.createWriter();

            // Publish Events

            IDataWriter   dwriter       = mgr.getWriter();
            MsgDataWriter WaitSetWriter = dwriter as MsgDataWriter;

            // Write the first message
            Msg msgInstance = new Msg();

            msgInstance.userID  = 1;
            msgInstance.message = "First hello";

            Console.WriteLine("=== [Publisher] writing a message containing :");
            Console.WriteLine("    userID  : {0}", msgInstance.userID);
            Console.WriteLine("    Message : \" {0} ", msgInstance.message);

            ReturnCode status = WaitSetWriter.Write(msgInstance, InstanceHandle.Nil);

            ErrorHandler.checkStatus(status, "MsgDataWriter.Write");

            Thread.Sleep(500);

            // Write another message
            msgInstance.message = "Hello again";
            status = WaitSetWriter.Write(msgInstance, InstanceHandle.Nil);
            ErrorHandler.checkStatus(status, "MsgDataWriter.Write");

            Console.WriteLine("=== [Publisher] writing a message containing :");
            Console.WriteLine("    userID  : {0}", msgInstance.userID);
            Console.WriteLine("    Message : {0}", msgInstance.message);
            Thread.Sleep(500);

            // Clean up
            mgr.getPublisher().DeleteDataWriter(WaitSetWriter);
            mgr.deletePublisher();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            DDSEntityManager mgr           = new DDSEntityManager("Listener");
            String           partitionName = "Listener Example";

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

            // create Type
            MsgTypeSupport msgTS = new MsgTypeSupport();

            mgr.registerType(msgTS);

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

            // create Publisher
            mgr.createPublisher();

            // create DataWriter
            mgr.createWriter();

            // Publish Events
            IDataWriter   dwriter        = mgr.getWriter();
            MsgDataWriter listenerWriter = dwriter as MsgDataWriter;

            ReturnCode status      = ReturnCode.Error;
            Msg        msgInstance = new Msg();

            msgInstance.userID  = 1;
            msgInstance.message = "Hello World";

            Console.WriteLine("=== [ListenerDataPublisher] writing a message containing :");
            Console.WriteLine("    userID  : {0}", msgInstance.userID);
            Console.WriteLine("    Message : \"" + msgInstance.message + "\"");

            InstanceHandle msgHandle = listenerWriter.RegisterInstance(msgInstance);

            ErrorHandler.checkHandle(msgHandle, "DataWriter.RegisterInstance");
            status = listenerWriter.Write(msgInstance, InstanceHandle.Nil);
            ErrorHandler.checkStatus(status, "DataWriter.Write");

            Thread.Sleep(2);

            // clean up

            status = listenerWriter.Dispose(msgInstance, msgHandle);
            ErrorHandler.checkStatus(status, "DataWriter.Dispose");
            status = listenerWriter.UnregisterInstance(msgInstance, msgHandle);
            ErrorHandler.checkStatus(status, "DataWriter.UnregisterInstance");

            mgr.getPublisher().DeleteDataWriter(listenerWriter);
            mgr.deletePublisher();
            mgr.deleteTopic();
            mgr.deleteParticipant();
        }
Ejemplo n.º 5
0
        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("ContentFilteredTopic");
            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
            mgr.createContentFilter("MyStockTopic", topic, args[0]);
            Console.WriteLine("=== [ContentFilteredTopicDataSubscriber] Subscription filter : ticker = '{0}'", args[0]);
            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader(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();
        }
        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>");
            }
            else
            {
                ITopic           topic;
                DDSEntityManager mgr           = new DDSEntityManager("QueryCondition");
                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");

                // create Subscriber
                mgr.createSubscriber();

                // create DataReader
                mgr.createReader(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();
            }
        }
Ejemplo n.º 7
0
        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("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();
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            bool automatic = true;

            if (args.Length > 1)
            {
                automatic = args[0].Equals("true");
            }

            string           hostName;
            DDSEntityManager mgr = new DDSEntityManager("BuiltInTopics");

            // create domain participant
            mgr.createParticipant("BuiltInTopics");

            // Resolve the built-in Subscriber
            ISubscriber builtInSubscriber = mgr.getParticipant().BuiltInSubscriber;

            // Lookup the DataReader for the DCPSParticipant built-in Topic
            IDataReader reader = builtInSubscriber.LookupDataReader("DCPSParticipant");

            // Cast the DataReader to a ParticipantBuiltInTopicDataReader
            ParticipantBuiltinTopicDataDataReader participantReader = reader as ParticipantBuiltinTopicDataDataReader;

            ErrorHandler.checkHandle(participantReader, "ParticipantBuiltInTopicDataReader narrow");

            // Allocate a new typed seq for data samples
            ParticipantBuiltinTopicData[] data = null;

            // Allocate a new seq for sample infos
            SampleInfo[] info = null;

            Console.WriteLine("=== [BuiltInTopicsDataSubscriber] : Waiting for historical data ... ");
            participantReader.WaitForHistoricalData(Duration.Infinite);
            Console.WriteLine("=== [BuiltInTopicsDataSubscriber] : done");

            // Create a new ReadCondition for the reader that matches all samples
            IReadCondition readCond = participantReader.CreateReadCondition(SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);

            ErrorHandler.checkHandle(readCond, "DataReader.CreateReadCondition");

            // Create a waitset and add the ReadCondition created above
            WaitSet    aWaitSet = new WaitSet();
            ReturnCode status   = aWaitSet.AttachCondition(readCond);

            ErrorHandler.checkStatus(status, "WaitSet.AttachCondition");

            // Initialize and pre-allocate the seq used to obtain the triggered Conditions.
            ICondition[] condSeq = new ICondition[0];

            // Allocate a map store node information later on
            // The key of map is the id of the node and the value is the
            // number of active participants on that node. A Dictionary is used
            // as an UnorderedMap.
            Dictionary <int, int> nodes = new Dictionary <int, int>();

            // Allocate a map to store node information later on.
            // The key of the map is the id of the node and the value is the
            // name of the node. A Dictionary is used as an UnorderedMap.
            Dictionary <int, string> nodeNames = new Dictionary <int, string>();

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

            // Block the current thread until the attached condition becomes true
            // or the user interrupts.
            status = aWaitSet.Wait(ref condSeq, Duration.Infinite);
            ErrorHandler.checkStatus(status, "WaitSet.Wait");

            bool done = false;

            // Continue processing until interrupted.
            while (!done)
            {
                // Take all the available data from the reader
                status = participantReader.Take(ref data, ref info, Length.Unlimited,
                                                SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(status, "ParticipantBuiltinTopicDataDataReader.Take");

                // Verify the data has been taken
                if (status == ReturnCode.Ok)
                {
                    // Iterate the list of taken samples.
                    for (int i = 0; i < data.Length; i++)
                    {
                        // Resolve the node identification
                        int nodeId = data[i].Key[0];

                        // Initialise the number of participants for a node
                        int participantCount = 0;

                        // Check if we saw a participant for the node before.
                        if (nodes.ContainsKey(nodeId))
                        {
                            participantCount = nodes[nodeId];
                        }

                        // Check sample info to see whether the instance is ALIVE.
                        if (info[i].InstanceState == InstanceStateKind.Alive)
                        {
                            // The splicedaemon publishes the host-name in the
                            // user_data field
                            if (data[i].UserData.Value.Length != 0)
                            {
                                hostName          = Encoding.UTF8.GetString(data[i].UserData.Value);
                                nodeNames[nodeId] = hostName;
                            }
                            else
                            {
                                hostName = null;
                            }

                            // Increase the number of participants.
                            participantCount++;

                            // Update the number of participants for the node.
                            nodes[nodeId] = participantCount;

                            // If it's the first participant, report the node is up.
                            if (participantCount == 1)
                            {
                                Console.WriteLine("=== [BuiltInTopicsDataSubscriber] Node ' {0} ' started (Total nodes running: {1} ) participantCount = {2}",
                                                  nodeId, nodes.Count, participantCount);
                            }
                            if (hostName != null)
                            {
                                Console.WriteLine("=== [BuiltInTopicsDataSubscriber] Hostname for node ' {0} ' is hostname: {1}", nodeId, hostName);
                            }
                        }
                        else
                        {
                            // Decrease the number of participants.
                            participantCount--;

                            // If no more participants exist, report the node is down.
                            if (participantCount == 0)
                            {
                                hostName = nodeNames[nodeId];
                                nodeNames.Remove(nodeId);
                                nodes.Remove(nodeId);

                                if (hostName != null)
                                {
                                    Console.WriteLine("=== [BuiltInTopicsDataSubscriber] Node {0} ({1}) stopped (Total nodes running: ({2})",
                                                      nodeId, hostName, nodes.Count);
                                }
                                else
                                {
                                    Console.WriteLine("=== [BuiltInTopicsDataSubscriber] Node {0} stopped (Total nodes running : {1})",
                                                      nodeId, nodes.Count);
                                }
                            }
                            else if (participantCount > 0)
                            {
                                nodes[nodeId] = participantCount;
                            }
                        }
                    }
                }

                status = participantReader.ReturnLoan(ref data, ref info);
                ErrorHandler.checkStatus(status, "ParticipantReader.ReturnLoan");

                if (!automatic)
                {
                    // Block the current thread until the attached condition becomes
                    // true or the user interrupts.
                    Console.WriteLine("=== [BuiltInTopicsDataSubscriber] Waiting ... ");
                    status = aWaitSet.Wait(ref condSeq, Duration.Infinite);
                    done   = (status != ReturnCode.Ok);
                }
                else
                {
                    done = true;
                }
            }

            // Delete read condition
            status = participantReader.DeleteReadCondition(readCond);
            ErrorHandler.checkStatus(status, "DataReader.DeleteReadCondition");

            // Recursively delete all entities in the DomainParticipant.
            mgr.getParticipant().DeleteContainedEntities();

            // Delete DomainParticipant
            mgr.getDomainParticipantFactory().DeleteParticipant(mgr.getParticipant());
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Insufficient number of arguments.");
                usage();
                Environment.Exit(-1);
            }
            else
            {
                String  durabilityKind  = args[0];
                Boolean autodisposeFlag = Boolean.Parse(args[1].ToString());
                Boolean automaticFlag   = Boolean.Parse(args[2].ToString());

                DDSEntityManager mgr           = new DDSEntityManager("Durability");
                String           partitionName = "Durability example";

                // Set the Durability Kind
                mgr.setDurabilityKind(durabilityKind);

                // Set the auto dispose flag
                mgr.setAutoDispose(autodisposeFlag);

                Thread.Sleep(1000);

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

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

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

                // create Publisher
                mgr.createPublisher();

                // create DataWriter
                mgr.createWriter();

                // Publish Events
                IDataWriter   dwriter   = mgr.getWriter();
                MsgDataWriter msgWriter = dwriter as MsgDataWriter;

                Msg []            DurabilityDataMsg = new Msg[10];
                InstanceHandle [] handle            = new InstanceHandle [10];

                ReturnCode status = ReturnCode.Error;

                for (int x = 0; x < 10; x++)
                {
                    DurabilityDataMsg[x]         = new Msg();
                    DurabilityDataMsg[x].id      = x;
                    DurabilityDataMsg[x].content = x.ToString();

                    Console.WriteLine("Storing {0}", DurabilityDataMsg[x].content);

                    handle[x] = msgWriter.RegisterInstance(DurabilityDataMsg[x]);
                    ErrorHandler.checkHandle(handle[x], "DataWriter.RegisterInstance");
                    status = msgWriter.Write(DurabilityDataMsg[x], handle[x]);
                    ErrorHandler.checkStatus(status, "DataWriter.Write");
                }

                if (!automaticFlag)
                {
                    char c = (char)0;
                    Console.WriteLine("Enter E to exit");
                    while (c != 'E')
                    {
                        c = (char)Console.Read();
                    }
                }
                else
                {
                    Console.WriteLine("=== sleeping 10s...");
                    Thread.Sleep(10000);
                }


                // Clean up
                status = mgr.getPublisher().DeleteDataWriter(msgWriter);
                ErrorHandler.checkStatus(status, "Publisher.DeleteDatWriter");
                mgr.deletePublisher();
                mgr.deleteTopic();
                mgr.deleteParticipant();
            }
        }
Ejemplo n.º 14
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();
            }
        }
        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();
        }
Ejemplo n.º 16
0
        // Create the DDS worker thread here.
        public static void OpenSpliceWorker(Form mainForm)
        {// Initialize the DDS Code first
            bool             done = false;
            DDSEntityManager mgr  = new DDSEntityManager("HelloWorld");

//            String partitionName = "";
//            if (GlobalData.DDSPartitionName.Length > 0)
//            {// Use the glbal name
//                partitionName = GlobalData.DDSPartitionName;
//            } else
//            {
//                partitionName = "ADLINK";
//            }
            //
            // create default Hello World Topic
            //
            // create Domain Participant
            // set QOS for entity manager...
            mgr.setDurabilityKind("transient");
            mgr.createParticipant(GlobalData.DDSPartitionName);
            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();
            //
            // NOW CREATE NEW DDS DATA RECEIVER
            //
            // NOW Create another HelloWorld.Msg with a different topic name.
            //
            DDSEntityManager ADSBDatamgr = new DDSEntityManager("ADSBLinesData");

            // create Domain Participant
            ADSBDatamgr.createParticipant(GlobalData.DDSPartitionName);
            // create Type DM::Aircraft_Config
            Aircraft_ConfigTypeSupport AircraftConfigMsg = new DM.Aircraft_ConfigTypeSupport();

            //MsgTypeSupport msgTS2 = new MsgTypeSupport();
            ADSBDatamgr.registerType(AircraftConfigMsg);
            //ADSBDatamgr.registerType(msgTS2);
            // create Topic
            ADSBDatamgr.createTopic("ADSBLinesData");
            // create Subscriber
            ADSBDatamgr.createSubscriber();
            //            ADSBDatamgr.createPublisher();
            // create DataReader
            ADSBDatamgr.createReader(false);
            IDataReader ADSBLinesReader = ADSBDatamgr.getReader();
            Aircraft_ConfigDataReader ADSBLinesDataReader = ADSBLinesReader as Aircraft_ConfigDataReader;
            Aircraft_Config           ADSBLinesmsg        = null;

            Aircraft_Config[] ADSBLinesmsgSeq  = null;
            DDS.SampleInfo[]  ADSBLinesinfoSeq = null;

            // Publish Events
            IDataWriter   dwriter          = mgr.getWriter();
            MsgDataWriter helloWorldWriter = dwriter as MsgDataWriter;

            Msg msgInstance = new Msg();

            msgInstance.userID  = 1;
            msgInstance.message = "Update Locations"; // "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");

            // main write loop here...
            //try
            //{
            //    Thread.Sleep(2);
            //}
            //catch (ArgumentOutOfRangeException ex)
            //{
            //    Console.WriteLine(ex.ToString());
            //    Console.WriteLine(ex.StackTrace);
            //}
            while (!done)
            {// sleep and write samples from the main screen.
                Thread.Sleep(500);

                if (GlobalData.ischanged == true)
                {// main thread has written data values, so update data
                    Console.WriteLine("GLOBAL DATA HAS CHANGED!!!");
                    msgInstance.lattitued_ul = GlobalData.upleft_lat;
                    msgInstance.longitude_ul = GlobalData.upleft_lng;
                    msgInstance.lattitude_lr = GlobalData.btmright_lat;
                    msgInstance.longitude_lr = GlobalData.btmright_lng;
                    Console.WriteLine("Upper left Lat" + msgInstance.lattitued_ul.ToString());
                    Console.WriteLine("Upper left Lng" + msgInstance.longitude_ul.ToString());
                    Console.WriteLine("Lower Right Lat" + msgInstance.lattitude_lr.ToString());
                    Console.WriteLine("Lower Right Lng" + msgInstance.longitude_lr.ToString());
                    ReturnCode dds_status = helloWorldWriter.Write(msgInstance, handle);
                    Console.WriteLine("HELLO WORLD DDS WRITE ERROR = " + dds_status.ToString());
                    ErrorHandler.checkStatus(dds_status, "MsgDataWriter.Write");

                    GlobalData.ischanged = false;
                } // globaldata.ischange = true
                // now read DDS Data lines topic.
                //
                // get new DDS Values here...
                status = ADSBLinesDataReader.Take(ref ADSBLinesmsgSeq, ref ADSBLinesinfoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any);
                ErrorHandler.checkStatus(status, "DataReader.Take");
                if (ADSBLinesmsgSeq.Length > 0)
                {
                    for (int x = 0; x < ADSBLinesmsgSeq.Length; x++)
                    {
                        if (ADSBLinesinfoSeq[x].ValidData)
                        {// read the data!
                            ADSBLinesmsg                 = ADSBLinesmsgSeq[x];
                            GlobalData.DDS_Lines         = ADSBLinesmsg.tailNumber;
                            GlobalData.DDS_Data_Received = true;

/*                            Console.WriteLine("=== [Subscriber] message received : " + x.ToString());
 *                          Console.WriteLine("    lattitued_ul  : " + msgSeq[x].lattitued_ul.ToString());
 *                          Console.WriteLine("    longitude_ul  : " + msgSeq[x].longitude_ul.ToString());
 *                          Console.WriteLine("    lattitued_lr  : " + msgSeq[x].lattitude_lr.ToString());
 *                          Console.WriteLine("    longitude_lr  : " + msgSeq[x].longitude_lr.ToString());
 *                          Console.WriteLine("    Message : \"" + msgSeq[x].message + "\"");
 */
                            //                        status = HelloWorldDataReader.ReturnLoan(ref msgSeq, ref infoSeq);
                            //ErrorHandler.checkStatus(status, "DataReader.ReturnLoan");
                            //                            System.Threading.Thread.Sleep(2000);

/*                            lamin = msgSeq[x].lattitude_lr;  //32.3382F;
 *                          lomin = msgSeq[x].longitude_ul;  //- 121.8863F;
 *                          lamax = msgSeq[x].lattitued_ul;  //35.3382F;
 *                          lomax = msgSeq[x].longitude_lr;  // - 116.8863F;  */}
                    }
                }

                if (GlobalData.WorkerThreadIsRunning == false)
                {// signal thread to shut down...
                    done = true;
                }
            }

            // end of main write loop

            // Clean up
            status = helloWorldWriter.UnregisterInstance(msgInstance, handle);

            mgr.getPublisher().DeleteDataWriter(helloWorldWriter);
            mgr.deletePublisher();
            mgr.deleteTopic();
            mgr.deleteParticipant();

            return;
        }
Ejemplo n.º 17
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();
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            DDSEntityManager mgr           = new DDSEntityManager("Ownership");
            String           partitionName = "Ownership example";

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

            // create Type
            StockTypeSupport msgTS = new StockTypeSupport();

            mgr.registerType(msgTS);

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

            // create Subscriber
            mgr.createSubscriber();

            // create DataReader
            mgr.createReader(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)
        {
            bool       autodispose_flag = false;
            String     writer_action;
            ReturnCode status = ReturnCode.Error;

            if (args.Length < 2)
            {
                usage();
            }
            else if ((!args[0].Equals("true")) &&
                     (!args[0].Equals("false")) &&
                     (!args[1].Equals("dispose")) &&
                     (!args[1].Equals("unregister")) &&
                     (!args[1].Equals("stoppub")))
            {
                usage();
            }
            else
            {
                autodispose_flag = Boolean.Parse(args[0]);
                writer_action    = args[1];

                // DDS Helper class instance for Msg Topic
                DDSEntityManager mgr = new DDSEntityManager("Lifecycle");

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

                // Set AutoDispose Flag
                mgr.setAutoDispose(autodispose_flag);

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

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

                // Create Publisher
                mgr.createPublisher();

                // Create DataWriter(s)
                mgr.createWriter();

                // Publish Samples
                IDataWriter   dwriter                 = mgr.getWriter();
                MsgDataWriter LifecycleWriter         = dwriter as MsgDataWriter;
                IDataWriter   dwriter_stopper         = mgr.getWriterStopper();
                MsgDataWriter LifecycleWriter_stopper = dwriter_stopper as MsgDataWriter;

                if (writer_action.Equals("dispose"))
                {
                    // Send Msg (topic to monitor)
                    Msg msgInstance = new Msg();
                    msgInstance.userID       = 1;
                    msgInstance.message      = "Lifecycle_1";
                    msgInstance.writerStates = "SAMPLE_SENT -> INSTANCE_DISPOSED -> DATAWRITER_DELETED";
                    Console.WriteLine("=== [Publisher]  :");
                    Console.WriteLine("    userID   : {0}", msgInstance.userID);
                    Console.WriteLine("    Message  : \"{0}\"", msgInstance.message);
                    Console.WriteLine("    writerStates  : \"{0}\"", msgInstance.writerStates);
                    status = LifecycleWriter.Write(msgInstance, InstanceHandle.Nil);
                    ErrorHandler.checkStatus(status, "MsDataWriter.Write");
                    Thread.Sleep(500);
                    Console.WriteLine("=== [Publisher]  : SAMPLE_SENT");

                    // Dispose instance
                    status = LifecycleWriter.Dispose(msgInstance, InstanceHandle.Nil);
                    ErrorHandler.checkStatus(status, "MsDataWriter.Dispose");
                    Console.WriteLine("=== [Publisher]  : INSTANCE_DISPOSED");
                }
                else if (writer_action.Equals("unregister"))
                {
                    // Send Msg (topic to monitor)
                    Msg msgInstance = new Msg();
                    msgInstance.userID       = 2;
                    msgInstance.message      = "Lifecycle_2";
                    msgInstance.writerStates = "SAMPLE_SENT -> INSTANCE_UNREGISTERED -> DATAWRITER_DELETED";
                    Console.WriteLine("=== [Publisher]  :");
                    Console.WriteLine("    userID   : {0}", msgInstance.userID);
                    Console.WriteLine("    Message  : \"{0}\"", msgInstance.message);
                    Console.WriteLine("    writerStates  : \"{0}\"", msgInstance.writerStates);
                    status = LifecycleWriter.Write(msgInstance, InstanceHandle.Nil);
                    ErrorHandler.checkStatus(status, "MsDataWriter.Write");
                    Thread.Sleep(500);
                    Console.WriteLine("=== [Publisher]  : SAMPLE_SENT");

                    // Unregister instance : the auto_dispose_unregistered_instances flag
                    // is currently ignored and the instance is never disposed automatically
                    status = LifecycleWriter.UnregisterInstance(msgInstance, InstanceHandle.Nil);
                    ErrorHandler.checkStatus(status, "MsDataWriter.UnregisterInstance");
                    Console.WriteLine("=== [Publisher]  : INSTANCE_UNREGISTERED");
                }
                else if (writer_action.Equals("stoppub"))
                {
                    Msg msgInstance = new Msg();
                    msgInstance.userID       = 3;
                    msgInstance.message      = "Lifecycle_3";
                    msgInstance.writerStates = "SAMPLE_SENT -> DATAWRITER_DELETED";
                    Console.WriteLine("=== [Publisher]  :");
                    Console.WriteLine("    userID   : {0}", msgInstance.userID);
                    Console.WriteLine("    Message  : \"{0}\"", msgInstance.message);
                    Console.WriteLine("    writerStates  : \"{0}\"", msgInstance.writerStates);
                    status = LifecycleWriter.Write(msgInstance, InstanceHandle.Nil);
                    ErrorHandler.checkStatus(status, "MsDataWriter.Write");
                    Thread.Sleep(500);
                    Console.WriteLine("=== [Publisher]  : SAMPLE_SENT");
                }

                // Let the subscriber treat the previous writer state !!!
                Console.WriteLine("=== [Publisher] waiting 500ms to let the subscriber treat the previous write state ...");
                Thread.Sleep(500);

                // Remove the DataWriter
                mgr.deleteWriter(LifecycleWriter);
                Thread.Sleep(500);
                Console.WriteLine("=== [Publisher]  : DATAWRITER_DELETED");

                // Stop the subscriber
                Msg stopMsg = new Msg();
                stopMsg.userID       = 4;
                stopMsg.message      = "Lifecycle_4";
                stopMsg.writerStates = "STOPPING_SUBSCRIBER";
                Console.WriteLine("=== [Publisher]  :");
                Console.WriteLine("    userID   : {0}", stopMsg.userID);
                Console.WriteLine("    Message  : \"{0}\"", stopMsg.message);
                Console.WriteLine("    writerStates  : \"{0}\"", stopMsg.writerStates);
                status = LifecycleWriter_stopper.Write(stopMsg, InstanceHandle.Nil);
                ErrorHandler.checkStatus(status, "MsDataWriter.Write");
                Thread.Sleep(500);

                // Remove the DataWriter stopper
                mgr.deleteWriter(LifecycleWriter_stopper);

                // Remove the Publisher
                mgr.deletePublisher();

                // Remove the Topic
                mgr.deleteTopic();

                // Remove the participant
                mgr.deleteParticipant();
            }
        }