Esempio n. 1
0
        private RtecEventComm.PushConsumer RegisterConsumer(RtecEventChannelAdmin.ProxyPushSupplier supplier)
        {
            EchoEventConsumerImpl servant =
                new EchoEventConsumerImpl(m_logger);

            string objectURI = "consumer";

            RemotingServices.Marshal(servant, objectURI);

            RtecEventComm.PushConsumer consumer = (RtecEventComm.PushConsumer)servant;

            // ------------------------------------------------------
            // Connect as a consumer
            ///------------------------------------------------------
            RtecEventChannelAdmin.ConsumerQOS qos = new RtecEventChannelAdmin.ConsumerQOS();
            qos.is_gateway   = false;
            qos.dependencies = new RtecEventChannelAdmin.Dependency[2];

            qos.dependencies[0]                       = new RtecEventChannelAdmin.Dependency();
            qos.dependencies[0].@event                = new RtecEventComm._Event();
            qos.dependencies[0][email protected]           = new RtecEventData();
            qos.dependencies[0][email protected]_value = 0;
            qos.dependencies[0][email protected]      = 0;
            qos.dependencies[0][email protected]   = new byte[1];
            qos.dependencies[0][email protected]         = new RtecEventComm.EventHeader();
            qos.dependencies[0][email protected]    = 9;
            qos.dependencies[0][email protected]  = 0;
            qos.dependencies[0].rt_info               = 0;

            qos.dependencies[1]                       = new RtecEventChannelAdmin.Dependency();
            qos.dependencies[1].@event                = new RtecEventComm._Event();
            qos.dependencies[1][email protected]           = new RtecEventData();
            qos.dependencies[1][email protected]_value = 0;
            //qos.Dependencies[1].Event.Data.AnyValue.InsertLong(0);
            qos.dependencies[1][email protected]     = 0;
            qos.dependencies[1][email protected]  = new byte[1];
            qos.dependencies[1][email protected]        = new RtecEventComm.EventHeader();
            qos.dependencies[1][email protected]   = 17;
            qos.dependencies[1][email protected] = 1;
            qos.dependencies[1].rt_info = 0;

            supplier.connect_push_consumer(consumer, qos);
            return(consumer);
        }
Esempio n. 2
0
        private void StartListening()
        {
            IiopChannel channel = null;

            RtecEventChannelAdmin.ProxyPushSupplier supplier = null;
            RtecEventComm.PushConsumer consumer = null;

            try {
                string host = txtHost.Text;
                int    port = Convert.ToInt32(txtHostPort.Text);
                m_logger.Log("HostName : " + host);
                m_logger.Log("Port : " + port.ToString());

                IDictionary property = new Hashtable();
                channel = new IiopChannel(0);

                ChannelServices.RegisterChannel(channel, false);
                CorbaInit     init        = CorbaInit.GetInit();
                NamingContext nameService = (NamingContext)RemotingServices.Connect(typeof(NamingContext),
                                                                                    String.Format("corbaloc:iiop:{0}:{1}/NameService", host, port));

                RtecEventChannelAdmin.EventChannel ec = ResolveEventChannel(nameService);
                if (ec != null)
                {
                    m_logger.Log("Found the EchoEventChannel");

                    //Obtain a reference to the consumer administration object
                    RtecEventChannelAdmin.ConsumerAdmin admin = ec.for_consumers();
                    // Obtain a reference to the push supplier proxy.
                    supplier = admin.obtain_push_supplier();
                    consumer = RegisterConsumer(supplier);


                    m_logger.Log("Ready to Receive Messages...");
                    this.Run = true;
                    while (this.Run)
                    {
                        Thread.Sleep(1);
                    }
                }
                else
                {
                    m_logger.Log("Not Found the EchoEventChannel");
                }
            } catch (Exception exception) {
                m_logger.Log(exception.Message);
                BtnListen.Enabled = true;
            } finally {
                if (supplier != null)
                {
                    supplier.disconnect_push_supplier();
                }
                if (consumer != null)
                {
                    consumer.disconnect_push_consumer();
                    RemotingServices.Disconnect((MarshalByRefObject)consumer);
                }
                ChannelServices.UnregisterChannel(channel);
                m_logger.Log("Cleanup event consumer complete.");
            }
        }