当前位置: 首页>>代码示例>>C#>>正文


C# BusAttachment.AddMatch方法代码示例

本文整理汇总了C#中BusAttachment.AddMatch方法的典型用法代码示例。如果您正苦于以下问题:C# BusAttachment.AddMatch方法的具体用法?C# BusAttachment.AddMatch怎么用?C# BusAttachment.AddMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BusAttachment的用法示例。


在下文中一共展示了BusAttachment.AddMatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMatchTest

        public void AddMatchTest()
        {
            BusAttachment bus = new BusAttachment("addmatch", true, 4);
            AddMatchBusObj busObj = new AddMatchBusObj(bus);
            BusListener bl = new BusListener(bus);
            bus.RegisterBusListener(bl);
            busObj.MatchValid = true;
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();

            BusAttachment service = new BusAttachment("service", true, 4);
            BusObject busObj2 = new BusObject(service, "/serviceTest", false);
            InterfaceDescription[] intf = new InterfaceDescription[1];
            service.CreateInterface("org.alljoyn.addmatchtest", intf, false);
            intf[0].AddSignal("testSig", "s", "str", (byte)0, "");
            intf[0].Activate();
            busObj2.AddInterface(intf[0]);
            service.RegisterBusObject(busObj2);
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.addmatch", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(43, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, 
                ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionPortListener(service));
            service.AdvertiseName("org.alljoyn.addmatch", TransportMaskType.TRANSPORT_ANY);

            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
                {
                    if (namePrefix == "org.alljoyn.addmatch")
                    {
                        foundService.Set();
                    }
                });
            bus.FindAdvertisedName("org.alljoyn.addmatch");

            foundService.WaitOne();
            Task<JoinSessionResult> join = bus.JoinSessionAsync("org.alljoyn.addmatch", 43, new SessionListener(bus),
                            new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY),
                            new SessionOpts[1], null).AsTask<JoinSessionResult>();
            join.Wait();
            Assert.IsTrue(QStatus.ER_OK != join.Result.Status);

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }

            bus.RemoveMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = false;
            for (int i = 0; i < 10; i++)
            {
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
            }

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = true;
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }
        }
开发者ID:kalperin,项目名称:alljoyn_core,代码行数:69,代码来源:BusAttachmentTests.cs

示例2: Button_RunClick

        /// <summary>
        /// Connects to the bus and registers a signal handler for when the 'name' property changes.
        /// </summary>
        /// <param name="sender">UI control which signaled the click event.</param>
        /// <param name="e">arguments associated with the click event.</param>
        private void Button_RunClick(object sender, RoutedEventArgs e)
        {
            if (busAtt == null)
            {
                Task task = new Task(async () =>
                {
                    try
                    {
                        busAtt = new BusAttachment("SignalConsumerApp", true, 4);

                        // create and activate the interface
                        InterfaceDescription[] interfaceDescription = new InterfaceDescription[1];
                        busAtt.CreateInterface(SignalConsumerGlobals.InterfaceName, interfaceDescription, false);
                        interfaceDescription[0].AddSignal("nameChanged", "s", "newName", (byte)0, string.Empty);
                        interfaceDescription[0].AddProperty("name", "s", (byte)PropAccessType.PROP_ACCESS_RW);
                        interfaceDescription[0].Activate();

                        busListener = new SignalConsumerBusListener(busAtt, foundNameEvent);
                        OutputLine("BusAttachment and BusListener Created.");
                        busAtt.RegisterBusListener(busListener);
                        OutputLine("BusListener Registered.");

                        busAtt.Start();
                        busAtt.ConnectAsync(SignalConsumerGlobals.ConnectSpec).AsTask().Wait();
                        OutputLine("Bundled Daemon Registered.");
                        OutputLine("BusAttachment Connected to " + SignalConsumerGlobals.ConnectSpec + ".");

                        busAtt.FindAdvertisedName(SignalConsumerGlobals.WellKnownServiceName);
                        foundNameEvent.WaitOne();

                        /* Configure session properties and request a session with device with wellKnownName */
                        SessionOpts sessionOpts = new SessionOpts(
                            SignalConsumerGlobals.SessionProps.TrType,
                            SignalConsumerGlobals.SessionProps.IsMultiPoint,
                            SignalConsumerGlobals.SessionProps.PrType,
                            SignalConsumerGlobals.SessionProps.TmType);
                        SessionOpts[] sessionOptsOut = new SessionOpts[1];
                        OutputLine("Requesting a session with the well known service name.");
                        JoinSessionResult joinResult = await busAtt.JoinSessionAsync(
                            SignalConsumerGlobals.WellKnownServiceName, 
                            SignalConsumerGlobals.SessionProps.SessionPort, 
                            busListener, 
                            sessionOpts, 
                            sessionOptsOut, 
                            null);

                        if (QStatus.ER_OK == joinResult.Status)
                        {
                            OutputLine("Join Session was successful (sessionId=" + joinResult.SessionId + ").");
                            busAtt.AddMatch("type='signal',interface='org.alljoyn.Bus.signal_sample',member='nameChanged'");
                            OutputLine("Subscribed to the 'nameChanged' signal.");
                        }
                        else
                        {
                            OutputLine("Join Session was unsuccessful.");
                        }
                    }
                    catch (Exception ex)
                    {
                        OutputLine("Errors were produced while establishing the application.");
                        QStatus status = AllJoynException.GetErrorCode(ex.HResult);
                        busAtt = null;
                    }
                });
                task.Start();
            }
        }
开发者ID:peterdocter,项目名称:Coco2dxDemo,代码行数:72,代码来源:MainPage.xaml.cs


注:本文中的BusAttachment.AddMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。