本文整理汇总了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();
}
}
示例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();
}
}