Esempio n. 1
0
        public override object Clone()
        {
            OPSMessage cloneResult = new OPSMessage();

            FillClone(cloneResult);
            return(cloneResult);
        }
Esempio n. 2
0
        // ---------------------------------------------------------------------------
        // Callbacks for the Data Classes that we subscribe to (from COpsHelper<T> classes)

        public void SubscriberNewData(Subscriber sender, PizzaData data)
        {
            OPSMessage mess = sender.GetMessage();

            Log("[Topic: " + sender.GetTopic().GetName() + "] Pizza:: Cheese: " + data.cheese +
                ",  Tomato sauce: " + data.tomatoSauce + ", SpareBytes: " + data.spareBytes.Length +
                ", From " + mess.GetSourceIP() + ":" + mess.GetSourcePort());

            byte b        = 0;
            int  numBytes = data.spareBytes.Length;

            for (int i = 0; i < numBytes; i++)
            {
                if (data.spareBytes[i] != b)
                {
                    Log("######### spareBytes error");
                    break;
                }
                if (b < 255)
                {
                    b++;
                }
                else
                {
                    b = 0;
                }
            }
        }
Esempio n. 3
0
        public void SubscriberNewData(Subscriber sender, VessuvioData data)
        {
            OPSMessage mess = sender.GetMessage();

            Log("[Topic: " + sender.GetTopic().GetName() + "] Vessuvio:: Cheese: " + data.cheese +
                ",  Tomato sauce: " + data.tomatoSauce + ", Ham length: " + data.ham.Length +
                ", From " + mess.GetSourceIP() + ":" + mess.GetSourcePort());
        }
Esempio n. 4
0
        //
        private void SubscriberNewData(Subscriber sender, OPSObject data)
        {
            OPSMessage mess = sender.GetMessage();

            if (client != null)
            {
                client.SubscriberNewData(sender, (T)data);
            }
        }
Esempio n. 5
0
        public override void FillClone(OPSObject cloneO)
        {
            base.FillClone(cloneO);
            OPSMessage cloneResult = (OPSMessage)cloneO;

            cloneResult.SetKey(this.GetKey());
            cloneResult.messageType       = this.messageType;
            cloneResult.publisherPriority = this.publisherPriority;
            cloneResult.publicationID     = this.publicationID;
            cloneResult.publisherName     = this.publisherName;
            cloneResult.topicName         = this.topicName;
            cloneResult.topLevelKey       = this.topLevelKey;
            cloneResult.address           = this.address;
            cloneResult.data = (OPSObject)this.data.Clone();
        }
Esempio n. 6
0
        public void SubscriberNewData(Subscriber sender, ExtraAllt data)
        {
            OPSMessage mess = sender.GetMessage();

            String str = "";

            if (data.shs.Count > 1)
            {
                str = ", shs[1]: " + data.shs.ElementAt(1);
            }

            Log("[Topic: " + sender.GetTopic().GetName() + "] ExtraAllt:: Cheese: " + data.cheese +
                ", Tomato sauce: " + data.tomatoSauce +
                str +
                ", Num strings: " + data.strings.Count() +
                ", From " + mess.GetSourceIP() + ":" + mess.GetSourcePort());
        }
Esempio n. 7
0
        private void SubscriberNewData(ChildDataSubscriber sender, ChildData data)
        {
            OPSMessage msg = sender.GetMessage();

            if (msg != null)
            {
                ChildData cd3 = (ChildData)msg.GetData();
                AssertTRUE(cd3 != null, "No received data (" + msg.GetPublisherName() + ")");
                if (cd3 != null)
                {
                    Log("Received Data from " + msg.GetPublisherName() + ": ");
                    CheckObjects(cd1, cd3);
                }
            }
            else
            {
                LogError("Callback without message");
            }
        }
Esempio n. 8
0
        public void DoTest()
        {
            // ===========================================
            cd1 = new ChildData();
            ChildData cd2 = new ChildData();
            ChildData cd3 = new ChildData();

            // ==============================================================
            LogNL("Test initial state...");
            CheckEmpty(cd1);
            CheckEmpty(cd2);
            CheckEmpty(cd3);

            CheckObjects(cd1, cd2);
            LogNL("Finished ");

            LogNL("Test cloning...");
            FillChildData(cd1);
            cd1.FillClone(cd2);
            CheckObjects(cd1, cd2);

            LogNL("Finished ");

            // ==============================================================
            LogNL("Serialize filled object");
            byte[]          bytes = new byte[Globals.MAX_SEGMENT_SIZE];
            WriteByteBuffer buf   = new WriteByteBuffer(bytes, Globals.MAX_SEGMENT_SIZE, true);
            OPSArchiverOut  ao    = new OPSArchiverOut(buf, false);

            LogNL("  Position()= " + buf.Position());
            ao.Inout <ChildData>("data", cd1);
            LogNL("  optNonVirt = false, Position()= " + buf.Position());
            AssertEQ(buf.Position(), 3150, "Serialized size error");

            buf = new WriteByteBuffer(bytes, Globals.MAX_SEGMENT_SIZE, true);
            ao  = new OPSArchiverOut(buf, true);
            LogNL("  Position()= " + buf.Position());
            ao.Inout <ChildData>("data", cd1);
            LogNL("  optNonVirt = true,  Position()= " + buf.Position());
            AssertEQ(buf.Position(), 2591, "Serialized size error");
            LogNL("Serialize finished");

            // Create a new stream to write to the file
            //BinaryWriter Writer = new BinaryWriter(File.OpenWrite(@"csharp-dump-opt.bin"));
            //Writer.Write(bytes, 0, buf.Position());
            //Writer.Flush();
            //Writer.Close();

            // ==============================================================
            LogNL("Test publish/subscribe");

            Logger.ExceptionLogger.AddLogger(logger);

            if (File.Exists("ops_config.xml"))
            {
                LogNL("Using config file in CWD");
            }
            else
            {
                string cwd = Environment.CurrentDirectory;
                int    pos = cwd.IndexOf("Example");
                if (pos > 0)
                {
                    cwd = cwd.Substring(0, pos) + "Examples/OPSIdls/TestAll/ops_config.xml";
                    LogNL("Using config file: " + cwd);
                    OPSConfigRepository.Add(cwd);
                }
            }

            participant = Participant.GetInstance("TestAllDomain");
            if (participant == null)
            {
                LogNL("Create participant failed. do you have ops_config.xml on your rundirectory?");
                return;
            }
            participant.AddTypeSupport(new TestAllTypeFactory());

            {
                // Setup & start subscriber w polling
                Topic topic = participant.CreateTopic("ChildTopic");
                sub = new ChildDataSubscriber(topic);
                sub.Start();

                // Setup & start publisher
                pub = new ChildDataPublisher(topic);
                pub.SetName("C#");
                pub.Start();

                Thread.Sleep(100);

                // Publish data
                pub.Write(cd1);

                // Check that sent data isn't affected by publish
                CheckObjects(cd1, cd2);

                // Check received values against sent values
                sub.WaitForNextData(500);
                OPSMessage msg = sub.GetMessage();
                if (msg != null)
                {
                    cd3 = (ChildData)msg.GetData();
                }
                AssertTRUE((msg != null) && (cd3 != null), "No received data");

                if ((msg != null) && (cd3 != null))
                {
                    CheckObjects(cd1, cd3);
                }

                LogNL("Finished ");

                sub.newData += new ChildDataEventHandler(SubscriberNewData);

                // Create a timer with a 5 second interval.
                aTimer = new System.Timers.Timer(5000);
                // Hook up the Elapsed event for the timer.
                aTimer.Elapsed  += OnTimedEvent;
                aTimer.AutoReset = true;
                aTimer.Enabled   = true;
            }
        }
Esempio n. 9
0
 public override object Clone()
 {
     OPSMessage cloneResult = new OPSMessage();
     FillClone(cloneResult);
     return cloneResult;
 }