/// <summary> /// Initializes a new instance of the ChatSessionObject class. /// </summary> /// <param name="bus">The BusAttachment to be associated with.</param> /// <param name="path">The path for the BusObject.</param> /// <param name="host">The instance of the MainPage which handles the UI for this /// application.</param> public ChatSessionObject(BusAttachment bus, string path, MainPage host) { try { this.hostPage = host; this.busObject = new BusObject(bus, path, false); /* Add the interface to this object */ InterfaceDescription[] ifaceArr = new InterfaceDescription[1]; bus.CreateInterface(ChatServiceInterfaceName, ifaceArr, false); ifaceArr[0].AddSignal("Chat", "s", "str", 0, string.Empty); ifaceArr[0].Activate(); InterfaceDescription chatIfc = bus.GetInterface(ChatServiceInterfaceName); this.busObject.AddInterface(chatIfc); this.chatSignalReceiver = new MessageReceiver(bus); this.chatSignalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); this.chatSignalMember = chatIfc.GetMember("Chat"); bus.RegisterSignalHandler(this.chatSignalReceiver, this.chatSignalMember, path); } catch (System.Exception ex) { QStatus errCode = AllJoyn.AllJoynException.GetErrorCode(ex.HResult); string errMsg = AllJoyn.AllJoynException.GetErrorMessage(ex.HResult); this.hostPage.DisplayStatus("Create ChatSessionObject Error : " + errMsg); } }
/// <summary> /// Initializes a new instance of the ChatSessionObject class. /// </summary> /// <param name="bus">The BusAttachment to be associated with.</param> /// <param name="path">The path for the BusObject.</param> /// <param name="host">The instance of the MainPage which handles the UI for this /// application.</param> public ChatSessionObject(BusAttachment bus, string path, MainPage host) { try { this.hostPage = host; this.busObject = new BusObject(bus, path, false); /* Add the interface to this object */ InterfaceDescription[] ifaceArr = new InterfaceDescription[1]; bus.CreateInterface(ChatServiceInterfaceName, ifaceArr, false); ifaceArr[0].AddSignal("Chat", "s", "str", 0, string.Empty); ifaceArr[0].Activate(); InterfaceDescription chatIfc = bus.GetInterface(ChatServiceInterfaceName); this.busObject.AddInterface(chatIfc); this.chatSignalReceiver = new MessageReceiver(bus); this.chatSignalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); this.chatSignalMember = chatIfc.GetMember("Chat"); bus.RegisterSignalHandler(this.chatSignalReceiver, this.chatSignalMember, path); } catch (System.Exception ex) { QStatus errCode = AllJoyn.AllJoynException.GetErrorCode(ex.HResult); string errMsg = AllJoyn.AllJoynException.GetErrorMessage(ex.HResult); this.hostPage.DisplayStatus("Create ChatSessionObject Error : " + errMsg); } }
public void TestInterfaceMemberDifferentImplementations() { var nodeContainer = new NodeContainer(); var instance1 = new InterfaceMember { Member1 = 3, Member2 = new Implem1 { Member2Implem1 = new SimpleClass() } }; var instance2 = new InterfaceMember { Member1 = 3, Member2 = new Implem2 { Member2Implem2 = new SimpleClass() } }; var source = nodeContainer.GetOrCreateNode(instance1); var target = nodeContainer.GetOrCreateNode(instance2); var linker = new TestLinker(); linker.LinkGraph(source, target); var expectedLinks = new Dictionary <IGraphNode, IGraphNode> { { source, target }, { source.GetChild(nameof(InterfaceMember.Member1)), target.GetChild(nameof(InterfaceMember.Member1)) }, { source.GetChild(nameof(InterfaceMember.Member2)), target.GetChild(nameof(InterfaceMember.Member2)) }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget(), target.GetChild(nameof(InterfaceMember.Member2)).GetTarget() }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member1Common)), target.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member1Common)) }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member2Implem1)), null }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member2Implem1)).GetTarget(), null }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member2Implem1)).GetTarget().GetChild(nameof(SimpleClass.Member1)), null }, { source.GetChild(nameof(InterfaceMember.Member2)).GetTarget().GetChild(nameof(Implem1.Member2Implem1)).GetTarget().GetChild(nameof(SimpleClass.Member2)), null }, }; VerifyLinks(expectedLinks, linker); }
public void CatHandler(InterfaceMember member, Message message) { string ret = message.GetArg(0).Value.ToString() + message.GetArg(1).Value.ToString(); MsgArg retArg = new MsgArg("s", new object[] { ret }); this.busObject.MethodReply(message, new MsgArg[] { retArg }); }
/// <summary> /// Initializes a new instance of the <see cref="SignalConsumerBusListener" /> class /// </summary> /// <param name="bus">object responsible for connecting to and optionally managing a message /// bus</param> /// <param name="foundNameEvent">event to set when the well-known name being queried /// is found</param> public SignalConsumerBusListener(BusAttachment bus, AutoResetEvent foundNameEvent) { SessionidList = new List <uint>(); this.busAtt = bus; this.foundName = foundNameEvent; this.busListener = new BusListener(bus); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); this.sessionListener = new SessionListener(this.busAtt); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); MessageReceiver signalReceiver = new MessageReceiver(bus); signalReceiver.SignalHandler += this.NameChangedSignalHandler; InterfaceDescription interfaceDescription2 = bus.GetInterface(SignalConsumerGlobals.InterfaceName); InterfaceMember signalMember = interfaceDescription2.GetSignal("nameChanged"); bus.RegisterSignalHandler(signalReceiver, signalMember, string.Empty); }
public static string FormatSignature(InterfaceMember member) { var f = new WebIDLFormatter(); f.Visit(member, signatureOnly: true); return(f._sb.ToString()); }
/// <summary> /// called when a signal has been sent from the signal service indicated 'name' property has /// changed. It prints out new value to UI /// </summary> /// <param name="member">Interface member for signal received</param> /// <param name="path">path to the source of the signal</param> /// <param name="msg">new value of the 'name' property</param> public void NameChangedSignalHandler(InterfaceMember member, string path, Message msg) { MsgArg msgArg = msg.GetArg(0); string newName = msgArg.Value as string; App.OutputLine(string.Empty); App.OutputLine("/////////////////////////////Name Change Signal/////////////////////////////////"); App.OutputLine("A Name Changed signal was recieved from '" + SignalConsumerGlobals.WellKnownServiceName + path + "' with a new value of '" + newName + "'"); }
private InterfaceMember Resolve(InterfaceMember member) { return(member.DecomposeWithResult( @const => { var t = Resolve(@const.Type, @const.ExtendedAttributes); return InterfaceMember.Const(@const.Name, t.Item1, @const.Value, t.Item2.Select(Resolve)); }, operation => { var t = Resolve(operation.ReturnType, operation.ExtendedAttributes); return InterfaceMember.Operation(operation.Name, t.Item1, operation.Arguments.Select(Resolve), operation.Qualifiers, t.Item2.Select(Resolve)); }, attribute => { var t = Resolve(attribute.Type, attribute.ExtendedAttributes); return InterfaceMember.Attribute(attribute.Name, t.Item1, attribute.Qualifiers, t.Item2.Select(Resolve)); }, jsonifier => InterfaceMember.Jsonifier(jsonifier.ExtendedAttributes.Select(Resolve)) )); }
/// <summary> /// Called when another session application sends a chat signal containing a message which /// is printed out to the user. /// </summary> /// <param name="member">Method or signal interface member entry.</param> /// <param name="srcPath">Object path of signal emitter.</param> /// <param name="message">The received message.</param> private void ChatSignalHandler(InterfaceMember member, string srcPath, Message message) { if (this.ChatEcho) { string output = string.Format("RX message from {0}[{1}]: {2}", message.Sender, message.SessionId, message.GetArg(0).Value.ToString()); this.sessionOps.Output(output); } }
/// <summary> /// Create a message receiver and add the signal handler to the receiver. /// Then register the signal handler. /// </summary> private void AddSignalHandler() { InterfaceMember member = this.Interface[0].GetSignal(ClientGlobals.SignalName); // Add the File Transfer Signal handler this.Receiver = new MessageReceiver(this.Bus); this.Receiver.SignalHandler += new MessageReceiverSignalHandler(this.FileTransfer); this.Bus.RegisterSignalHandler(this.Receiver, member, string.Empty); this.Bus.RegisterBusObject(this.BusObject); }
/// <summary> /// Initializes a new instance of the <see cref="SecureBusObject" /> class. /// </summary> /// <param name="busAtt">Object responsible for connecting to and optionally managing a /// message bus.</param> /// <param name="iface">The interface used by the service that is implemented by this /// class.</param> public SecureBusObject(BusAttachment busAtt, InterfaceDescription[] iface) { this.BusObject = new BusObject(busAtt, App.ServicePath, false); this.BusObject.AddInterface(iface[0]); InterfaceMember pingMember = iface[0].GetMember("Ping"); MessageReceiver pingReceiver = new MessageReceiver(busAtt); pingReceiver.MethodHandler += new MessageReceiverMethodHandler(this.PingMethodHandler); BusObject.AddMethodHandler(pingMember, pingReceiver); busAtt.RegisterBusObject(this.BusObject); }
/// <summary> /// Responds to a ping request. /// </summary> /// <param name="member">The parameter is not used.</param> /// <param name="message">arguments sent by the client</param> private void PingMethodHandler(InterfaceMember member, Message message) { string output = message.GetArg(0).Value as string; App.OutputLine(string.Format("Ping : {0}", output)); App.OutputLine(string.Format("Reply : {0}", output)); object[] args = { output }; MsgArg msgReply = new MsgArg("s", args); this.BusObject.MethodReply(message, new MsgArg[] { msgReply }); }
/// <summary> /// Responds to a ping request. /// </summary> /// <param name="member">The parameter is not used.</param> /// <param name="message">arguments sent by the client</param> private void PingMethodHandler(InterfaceMember member, Message message) { string output = message.GetArg(0).Value as string; App.OutputLine(string.Format("Ping : {0}", output)); App.OutputLine(string.Format("Reply : {0}", output)); object[] args = { output }; MsgArg msgReply = new MsgArg("s", args); this.BusObject.MethodReply(message, new MsgArg[] { msgReply }); }
/// <summary> /// The method to handle a signal. If the message is for the active chat channel this device is /// on then the message is forwarded to the user interface page. /// </summary> /// <param name="member">The parameter is not used.</param> /// <param name="path">The parameter is not used.</param> /// <param name="msg">The msg from the other end.</param> public void ChatSignalHandler(InterfaceMember member, string path, Message msg) { if (this.hostPage != null && msg != null && msg.SessionId == this.hostPage.SessionId && msg.Sender != msg.RcvEndpointName) { string sender = msg.Sender; var content = msg.GetArg(0).Value; if (content != null) { this.hostPage.OnChat(this.hostPage.SessionId, sender + ": ", content.ToString()); } } }
private void Visit(InterfaceMember member, bool signatureOnly) { member.Decompose( @const => { if (!signatureOnly) { Visit(@const.ExtendedAttributes, ExtendedAttributeMode.Member); } _sb.Append("const "); Visit(@const.Type); if (!signatureOnly) { _sb.Append(" " + @const.Name + " = "); } Visit(@const.Value); }, operation => { if (!signatureOnly) { Visit(operation.ExtendedAttributes, ExtendedAttributeMode.Member); } Visit(operation.Qualifiers); Visit(operation.ReturnType); _sb.Append(" " + (operation.Name ?? "")); Visit(operation.Arguments); }, attribute => { if (!signatureOnly) { Visit(attribute.ExtendedAttributes, ExtendedAttributeMode.Member); } Visit(attribute.Qualifiers); _sb.Append("attribute "); Visit(attribute.Type); _sb.Append(" " + attribute.Name); }, jsonifier => { if (!signatureOnly) { Visit(jsonifier.ExtendedAttributes, ExtendedAttributeMode.Member); } _sb.Append("jsonifier"); } ); if (!signatureOnly) { _sb.AppendLine(";"); } }
/// <summary> /// concatenates two strings sent by the client and returns the result /// </summary> /// <param name="member">Member of the interface which message contains</param> /// <param name="message">arguments sent by the client</param> public void CatMethodHandler(InterfaceMember member, Message message) { MsgArg msg = message.GetArg(0); MsgArg msg2 = message.GetArg(1); string val = msg.Value as string; string val2 = msg2.Value as string; App.OutputLine("//////////////////////////////////////////////////////////////////"); App.OutputLine("Cat Method was called by '" + message.Sender + "' given '" + val + "' and '" + val2 + "' as arguments."); string ret = val + val2; object[] obj = { ret }; MsgArg msgReply = new MsgArg("s", obj); this.BusObject.MethodReply(message, new MsgArg[] { msgReply }); App.OutputLine("The value '" + ret + "' was returned to '" + message.Sender + "'."); }
public void SayHiHandler(InterfaceMember member, Message message) { Assert.AreEqual("hello", message.GetArg(0).Value.ToString()); MsgArg retArg = new MsgArg("s", new object[] { "aloha" }); try { // BUGBUG: Throws exception saying signature of the msgArg is not what was expected, but its correct. this.busObject.MethodReplyWithQStatus(message, QStatus.ER_OK); } catch (Exception ex) { string err = AllJoynException.GetExceptionMessage(ex.HResult); Assert.IsFalse(true); } }
/// <summary> /// Concatenate the two string arguments and return the result to the caller /// </summary> /// <param name="member">Method interface member entry.</param> /// <param name="message">The received method call message containing the two strings /// to concatenate</param> public void Cat(InterfaceMember member, Message message) { try { string arg1 = message.GetArg(0).Value as string; string arg2 = message.GetArg(1).Value as string; MsgArg retArg = new MsgArg("s", new object[] { arg1 + arg2 }); this.busObject.MethodReply(message, new MsgArg[] { retArg }); this.DebugPrint("Method Reply successful (ret=" + arg1 + arg2 + ")"); } catch (Exception ex) { var errMsg = AllJoynException.GetErrorMessage(ex.HResult); this.DebugPrint("Method Reply unsuccessful: " + errMsg); } }
/// <summary> /// Initializes a new instance of the <see cref="SignalServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public SignalServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, SignalServiceGlobals.ServicePath, false); this.name = string.Empty; InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalServiceGlobals.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(); this.BusObject.AddInterface(interfaceDescription[0]); App.OutputLine("Interface created and added to the Bus Object."); this.signalMember = interfaceDescription[0].GetSignal("nameChanged"); this.BusObject.Set += this.SetHandler; busAtt.RegisterBusObject(this.BusObject); App.OutputLine("Bus Object and property set handlers Registered."); }
/// <summary> /// concatenates two strings sent by the client and returns the result /// </summary> /// <param name="member">Member of the interface which message contains</param> /// <param name="message">arguments sent by the client</param> public void CatMethodHandler(InterfaceMember member, Message message) { MsgArg msg = message.GetArg(0); MsgArg msg2 = message.GetArg(1); string val = msg.Value as string; string val2 = msg2.Value as string; App.OutputLine("//////////////////////////////////////////////////////////////////"); App.OutputLine("Cat Method was called by '" + message.Sender + "' given '" + val + "' and '" + val2 + "' as arguments."); string ret = val + val2; object[] obj = { ret }; MsgArg msgReply = new MsgArg("s", obj); this.BusObject.MethodReply(message, new MsgArg[] { msgReply }); App.OutputLine("The value '" + ret + "' was returned to '" + message.Sender + "'."); }
/// <summary> /// Initializes a new instance of the <see cref="SignalServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public SignalServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, SignalServiceGlobals.ServicePath, false); this.name = string.Empty; InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalServiceGlobals.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(); this.BusObject.AddInterface(interfaceDescription[0]); App.OutputLine("Interface created and added to the Bus Object."); this.signalMember = interfaceDescription[0].GetSignal("nameChanged"); this.BusObject.Set += this.SetHandler; busAtt.RegisterBusObject(this.BusObject); App.OutputLine("Bus Object and property set handlers Registered."); }
public MethodHandlerBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.methodhandler", intf, false); intf[0].AddMethod("cat", "ss", "s", "in1,in2,out", (byte)0, ""); intf[0].AddMethod("sayhi", "s", "s", "in,out", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); this.catMember = intf[0].GetMethod("cat"); this.sayHiMember = intf[0].GetMethod("sayhi"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatHandler); MessageReceiver sayHiReceiver = new MessageReceiver(busAtt); sayHiReceiver.MethodHandler += new MessageReceiverMethodHandler(this.SayHiHandler); try { busObject.AddMethodHandler(null, catReceiver); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } try { busObject.AddMethodHandler(intf[0].GetMethod("cat"), null); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } busObject.AddMethodHandler(intf[0].GetMethod("cat"), catReceiver); busObject.AddMethodHandler(intf[0].GetMethod("sayhi"), sayHiReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="MyBusObject"/> class /// </summary> /// <param name="busAtt">Message bus for the sessions app</param> /// <param name="ops">Session Operations object for this application</param> public MyBusObject(BusAttachment busAtt, SessionOperations ops) { this.busObject = new BusObject(busAtt, BusObjectPath, false); this.sessionOps = ops; this.ChatEcho = true; // Implement the 'Chat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SessionInterfaceName, intfDescription, false); intfDescription[0].AddSignal("Chat", "s", "str", (byte)0, string.Empty); intfDescription[0].Activate(); this.chatSignal = intfDescription[0].GetSignal("Chat"); this.busObject.AddInterface(intfDescription[0]); // Register chat signal handler MessageReceiver signalReceiver = new MessageReceiver(busAtt); signalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); busAtt.RegisterSignalHandler(signalReceiver, this.chatSignal, string.Empty); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceBusObject"/> class. /// </summary> /// <param name="busAtt">Message bus for the stress operation using this</param> /// <param name="op">Stress operation using this bus object</param> public ServiceBusObject(BusAttachment busAtt, StressOperation op) { this.stressOp = op; this.busObject = new BusObject(busAtt, ServicePath, false); // Implement the 'cat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(InterfaceName, intfDescription, false); intfDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); intfDescription[0].Activate(); this.busObject.AddInterface(intfDescription[0]); // Register 'cat' method handler InterfaceMember catMethod = intfDescription[0].GetMethod("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.Cat); this.busObject.AddMethodHandler(catMethod, catReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="BasicServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public BasicServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, BasicServiceGlobals.ServicePath, false); // Create 'cat' interface InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(BasicServiceGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); interfaceDescription[0].Activate(); // Create and register the 'cat' method handlers this.BusObject.AddInterface(interfaceDescription[0]); InterfaceMember catMember = interfaceDescription[0].GetMember("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatMethodHandler); this.BusObject.AddMethodHandler(catMember, catReceiver); App.OutputLine("Created 'cat' interface and registered method handlers."); busAtt.RegisterBusObject(this.BusObject); }
/// <summary> /// Initializes a new instance of the <see cref="MyBusObject"/> class /// </summary> /// <param name="busAtt">Message bus for the sessions app</param> /// <param name="ops">Session Operations object for this application</param> public MyBusObject(BusAttachment busAtt, SessionOperations ops) { this.busObject = new BusObject(busAtt, BusObjectPath, false); this.sessionOps = ops; this.ChatEcho = true; // Implement the 'Chat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SessionInterfaceName, intfDescription, false); intfDescription[0].AddSignal("Chat", "s", "str", (byte)0, string.Empty); intfDescription[0].Activate(); this.chatSignal = intfDescription[0].GetSignal("Chat"); this.busObject.AddInterface(intfDescription[0]); // Register chat signal handler MessageReceiver signalReceiver = new MessageReceiver(busAtt); signalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); busAtt.RegisterSignalHandler(signalReceiver, this.chatSignal, string.Empty); busAtt.RegisterBusObject(this.busObject); }
public void TestInterfaceMemberDifferentImplementations() { var nodeContainer = new NodeContainer(); var instance1 = new InterfaceMember { Member1 = 3, Member2 = new Implem1 { Member2Implem1 = new SimpleClass() } }; var instance2 = new InterfaceMember { Member1 = 3, Member2 = new Implem2 { Member2Implem2 = new SimpleClass() } }; var source = nodeContainer.GetOrCreateNode(instance1); var target = nodeContainer.GetOrCreateNode(instance2); var linker = new TestLinker(); linker.LinkGraph(source, target); var expectedLinks = new Dictionary<IGraphNode, IGraphNode> { { source, target }, { source.TryGetChild(nameof(InterfaceMember.Member1)), target.TryGetChild(nameof(InterfaceMember.Member1)) }, { source.TryGetChild(nameof(InterfaceMember.Member2)), target.TryGetChild(nameof(InterfaceMember.Member2)) }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target, target.TryGetChild(nameof(InterfaceMember.Member2)).Target }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member1Common)), target.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member1Common)) }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member2Implem1)), null }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member2Implem1)).Target, null }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member2Implem1)).Target.TryGetChild(nameof(SimpleClass.Member1)), null }, { source.TryGetChild(nameof(InterfaceMember.Member2)).Target.TryGetChild(nameof(Implem1.Member2Implem1)).Target.TryGetChild(nameof(SimpleClass.Member2)), null }, }; VerifyLinks(expectedLinks, linker); }
/// <summary> /// Called when another session application sends a chat signal containing a message which /// is printed out to the user. /// </summary> /// <param name="member">Method or signal interface member entry.</param> /// <param name="srcPath">Object path of signal emitter.</param> /// <param name="message">The received message.</param> private void ChatSignalHandler(InterfaceMember member, string srcPath, Message message) { if (this.ChatEcho) { string output = string.Format("RX message from {0}[{1}]: {2}", message.Sender, message.SessionId, message.GetArg(0).Value.ToString()); this.sessionOps.Output(output); } }
public void ISDictSig(InterfaceMember member, string srcPath, Message message) { }
public void SigHandle(InterfaceMember member, string srcPath, Message message) { Assert.IsTrue(MatchValid); calledHandle.Set(); }
public static InterfaceMemberViewModel ToViewModel(this InterfaceMember model) { return(new InterfaceMemberViewModel(model)); }
public void BYIStructSig(InterfaceMember member, string srcPath, Message message) { }
public void BYIStructSig(InterfaceMember member, string srcPath, Message message) { }
public void ISDictSig(InterfaceMember member, string srcPath, Message message) { }
public void SigHandle(InterfaceMember member, string srcPath, Message message) { Assert.IsTrue(MatchValid); calledHandle.Set(); }
public void CatHandler(InterfaceMember member, Message message) { string ret = message.GetArg(0).Value.ToString() + message.GetArg(1).Value.ToString(); MsgArg retArg = new MsgArg("s", new object[] { ret }); this.busObject.MethodReply(message, new MsgArg[] { retArg }); }
private void Visit(InterfaceMember member, bool signatureOnly) { member.Decompose( @const => { if (!signatureOnly) Visit(@const.ExtendedAttributes, ExtendedAttributeMode.Member); _sb.Append("const "); Visit(@const.Type); if (!signatureOnly) _sb.Append(" " + @const.Name + " = "); Visit(@const.Value); }, operation => { if (!signatureOnly) Visit(operation.ExtendedAttributes, ExtendedAttributeMode.Member); Visit(operation.Qualifiers); Visit(operation.ReturnType); _sb.Append(" " + (operation.Name ?? "")); Visit(operation.Arguments); }, attribute => { if (!signatureOnly) Visit(attribute.ExtendedAttributes, ExtendedAttributeMode.Member); Visit(attribute.Qualifiers); _sb.Append("attribute "); Visit(attribute.Type); _sb.Append(" " + attribute.Name); }, jsonifier => { if (!signatureOnly) Visit(jsonifier.ExtendedAttributes, ExtendedAttributeMode.Member); _sb.Append("jsonifier"); } ); if (!signatureOnly) _sb.AppendLine(";"); }
/// <summary> /// called when a signal has been sent from the signal service indicated 'name' property has /// changed. It prints out new value to UI /// </summary> /// <param name="member">Interface member for signal received</param> /// <param name="path">path to the source of the signal</param> /// <param name="msg">new value of the 'name' property</param> public void NameChangedSignalHandler(InterfaceMember member, string path, Message msg) { MsgArg msgArg = msg.GetArg(0); string newName = msgArg.Value as string; App.OutputLine(string.Empty); App.OutputLine("/////////////////////////////Name Change Signal/////////////////////////////////"); App.OutputLine("A Name Changed signal was recieved from '" + SignalConsumerGlobals.WellKnownServiceName + path + "' with a new value of '" + newName + "'"); }
public static string FormatSignature(InterfaceMember member) { var f = new WebIDLFormatter(); f.Visit(member, signatureOnly: true); return f._sb.ToString(); }
public InterfaceMemberViewModel(InterfaceMember model) { Wrapped = model; }
/// <summary> /// Concatenate the two string arguments and return the result to the caller /// </summary> /// <param name="member">Method interface member entry.</param> /// <param name="message">The received method call message containing the two strings /// to concatenate</param> public void Cat(InterfaceMember member, Message message) { try { string arg1 = message.GetArg(0).Value as string; string arg2 = message.GetArg(1).Value as string; MsgArg retArg = new MsgArg("s", new object[] { arg1 + arg2 }); this.busObject.MethodReply(message, new MsgArg[] { retArg }); this.DebugPrint("Method Reply successful (ret=" + arg1 + arg2 + ")"); } catch (Exception ex) { var errMsg = AllJoynException.GetErrorMessage(ex.HResult); this.DebugPrint("Method Reply unsuccessful: " + errMsg); } }
/// <summary> /// Consumes 'FileTransfer' signals form the service and extracts the data to write to an /// output file. /// </summary> /// <param name="member">Method or signal interface member entry.</param> /// <param name="srcPath">Object path of signal emitter.</param> /// <param name="message">The received message.</param> private async void FileTransfer(InterfaceMember member, string srcPath, Message message) { UInt32 currentIndex = (UInt32)message.GetArg(1).Value; while (currentIndex != this.lastIndex + 1) { await Task.Yield(); } byte[] data = message.GetArg(2).Value as byte[]; if (null != data) { if (0 != data.Count()) { string mess = string.Format("Array Num : {0} Size : {1}", currentIndex, data.Count()); App.OutputLine(mess); bool openSuccess = null != this.Writer; if (!openSuccess && 1 == currentIndex) { this.FileWriteError = false; openSuccess = await this.OpenStreamAsync(message); } if (openSuccess) { mess = string.Format("Writing Array Num : {0}", currentIndex); App.OutputLine(mess); this.WriteToFile(data); } else { this.FileWriteError = true; mess = string.Format("File was not open for writing array {0}.", currentIndex); App.OutputLine(mess); } } else { // Done with this transfer prepare for another. this.lastIndex = 0; if (this.FileWriteError) { App.OutputLine("File transfer was unsuccessful!", true); } else { App.OutputLine("The file was transfered successfully.", true); } if (null != this.Writer) { this.Writer.Flush(); this.Writer.Dispose(); this.Writer = null; } } } else { App.OutputLine("Unable to retrieve data array from message arg 2."); this.FileWriteError = true; } this.lastIndex = currentIndex; }
/// <summary> /// Connects to the bus, finds the service and calls the 'cat' with the two /// arguments "Hello " and "World!" /// </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 (!runningClient) { Task task = new Task(async() => { try { runningClient = true; busAtt = new BusAttachment("ClientApp", true, 4); this.OutputLine("BusAttachment Created."); BasicClientBusListener basicClientBusListener = new BasicClientBusListener(busAtt, foundNameEvent); busAtt.RegisterBusListener(basicClientBusListener); this.OutputLine("BusListener Registered."); /* Create and register the bundled daemon. The client process connects to daemon over tcp connection */ busAtt.Start(); await busAtt.ConnectAsync(BasicClientGlobals.ConnectSpec); this.OutputLine("Bundled Daemon Registered."); this.OutputLine("BusAttachment Connected to " + BasicClientGlobals.ConnectSpec + "."); busAtt.FindAdvertisedName(BasicClientGlobals.WellKnownServiceName); foundNameEvent.WaitOne(); /* Configure session properties and request a session with device with wellKnownName */ SessionOpts sessionOpts = new SessionOpts( BasicClientGlobals.SessionProps.TrType, BasicClientGlobals.SessionProps.IsMultiPoint, BasicClientGlobals.SessionProps.PrType, BasicClientGlobals.SessionProps.TmType); SessionOpts[] sOptsOut = new SessionOpts[1]; JoinSessionResult joinResults = await busAtt.JoinSessionAsync( BasicClientGlobals.WellKnownServiceName, BasicClientGlobals.SessionProps.SessionPort, basicClientBusListener, sessionOpts, sOptsOut, null); QStatus status = joinResults.Status; if (QStatus.ER_OK != status) { this.OutputLine("Joining a session with the Service was unsuccessful."); } else { this.OutputLine("Join Session was successful (sessionId=" + joinResults.SessionId + ")."); } // Create the proxy for the service interface by introspecting the service bus object ProxyBusObject proxyBusObject = new ProxyBusObject(busAtt, BasicClientGlobals.WellKnownServiceName, BasicClientGlobals.ServicePath, 0); if (QStatus.ER_OK == status) { IntrospectRemoteObjectResult introResult = await proxyBusObject.IntrospectRemoteObjectAsync(null); status = introResult.Status; if (QStatus.ER_OK != status) { this.OutputLine("Introspection of the service bus object failed."); } else { this.OutputLine("Introspection of the service bus object was successful."); } } if (QStatus.ER_OK == status) { // Call 'cat' method with the two string to be concatenated ("Hello" and " World!") MsgArg[] catMe = new MsgArg[2]; catMe[0] = new MsgArg("s", new object[] { "Hello" }); catMe[1] = new MsgArg("s", new object[] { " World!" }); InterfaceDescription interfaceDescription = proxyBusObject.GetInterface(BasicClientGlobals.InterfaceName); InterfaceMember interfaceMember = interfaceDescription.GetMember("cat"); this.OutputLine("Calling the 'cat' method of the service with args 'Hello' and ' World!'"); MethodCallResult callResults = await proxyBusObject.MethodCallAsync(interfaceMember, catMe, null, 100000, 0); Message msg = callResults.Message; if (msg.Type == AllJoynMessageType.MESSAGE_METHOD_RET) { string strRet = msg.GetArg(0).Value as string; this.OutputLine("Sender '" + msg.Sender + "' returned the value '" + strRet + "'"); } else { this.OutputLine("The 'cat' method call produced errors of type: " + msg.Type.ToString()); } } TearDown(); } catch (Exception ex) { QStatus s = AllJoynException.GetErrorCode(ex.HResult); } }); task.Start(); } }
public MethodHandlerBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.methodhandler", intf, false); intf[0].AddMethod("cat", "ss", "s", "in1,in2,out", (byte)0, ""); intf[0].AddMethod("sayhi", "s", "s", "in,out", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); this.catMember = intf[0].GetMethod("cat"); this.sayHiMember = intf[0].GetMethod("sayhi"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatHandler); MessageReceiver sayHiReceiver = new MessageReceiver(busAtt); sayHiReceiver.MethodHandler += new MessageReceiverMethodHandler(this.SayHiHandler); try { busObject.AddMethodHandler(null, catReceiver); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } try { busObject.AddMethodHandler(intf[0].GetMethod("cat"), null); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } busObject.AddMethodHandler(intf[0].GetMethod("cat"), catReceiver); busObject.AddMethodHandler(intf[0].GetMethod("sayhi"), sayHiReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// The method to handle a signal. If the message is for the active chat channel this device is /// on then the message is forwarded to the user interface page. /// </summary> /// <param name="member">The parameter is not used.</param> /// <param name="path">The parameter is not used.</param> /// <param name="msg">The msg from the other end.</param> public void ChatSignalHandler(InterfaceMember member, string path, Message msg) { if (this.hostPage != null && msg != null && msg.SessionId == this.hostPage.SessionId && msg.Sender != msg.RcvEndpointName) { string sender = msg.Sender; var content = msg.GetArg(0).Value; if (content != null) { this.hostPage.OnChat(this.hostPage.SessionId, sender + ": ", content.ToString()); } } }
public void SayHiHandler(InterfaceMember member, Message message) { Assert.AreEqual("hello", message.GetArg(0).Value.ToString()); MsgArg retArg = new MsgArg("s", new object[] { "aloha" }); try { // BUGBUG: Throws exception saying signature of the msgArg is not what was expected, but its correct. this.busObject.MethodReplyWithQStatus(message, QStatus.ER_OK); } catch (Exception ex) { #if DEBUG string err = AllJoynException.GetErrorMessage(ex.HResult); #else QStatus err = AllJoynException.FromCOMException(ex.HResult); #endif Assert.IsFalse(true); } }
public void Uint64Sig(InterfaceMember member, string srcPath, Message message) { }
public void DoubleSig(InterfaceMember member, string srcPath, Message message) { }
public void DArrarySig(InterfaceMember member, string srcPath, Message message) { }
public void Uint64Sig(InterfaceMember member, string srcPath, Message message) { }
/// <summary> /// Run the client stress op which stresses the bus attachment in a client type /// configuration which find the well-known service name and calls the 'cat' /// method /// </summary> /// <param name="isMultipoint">True if operation uses multipoint sessions</param> private void RunClient(bool isMultipoint) { try { ClientBusListener clientBusListener = new ClientBusListener(this.busAtt, this, this.foundName); this.busAtt.FindAdvertisedName(ServiceName); this.DebugPrint("Looking for WKN : " + ServiceName); this.foundName.WaitOne(12000); SessionOpts optsIn = new SessionOpts( TrafficType.TRAFFIC_MESSAGES, isMultipoint, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY); SessionOpts[] optsOut = new SessionOpts[1]; Task <JoinSessionResult> joinTask = this.busAtt.JoinSessionAsync( this.DiscoveredName, ServicePort, (SessionListener)clientBusListener, optsIn, optsOut, null).AsTask <JoinSessionResult>(); joinTask.Wait(); JoinSessionResult joinResult = joinTask.Result; QStatus status = joinResult.Status; ProxyBusObject proxyBusObj = null; if (QStatus.ER_OK == status) { this.DebugPrint("JoinSession with " + this.DiscoveredName + " was successful (sessionId=" + joinResult.SessionId + ")"); proxyBusObj = new ProxyBusObject(this.busAtt, this.DiscoveredName, ServicePath, joinResult.SessionId); Task <IntrospectRemoteObjectResult> introTask = proxyBusObj.IntrospectRemoteObjectAsync(null).AsTask <IntrospectRemoteObjectResult>(); introTask.Wait(); IntrospectRemoteObjectResult introResult = introTask.Result; status = introResult.Status; if (QStatus.ER_OK == status) { this.DebugPrint("Introspection of the service was successfull"); MsgArg hello = new MsgArg("s", new object[] { "Hello " }); MsgArg world = new MsgArg("s", new object[] { "World!" }); InterfaceMember catMethod = proxyBusObj.GetInterface(InterfaceName).GetMethod("cat"); byte flags = (byte)0; Task <MethodCallResult> catTask = proxyBusObj.MethodCallAsync(catMethod, new MsgArg[] { hello, world }, null, 5000, flags).AsTask <MethodCallResult>(); catTask.Wait(); MethodCallResult catResult = catTask.Result; if (catResult.Message.Type == AllJoynMessageType.MESSAGE_METHOD_RET) { this.DebugPrint(this.DiscoveredName + ".cat ( path=" + ServicePath + ") returned \"" + catResult.Message.GetArg(0).Value.ToString() + "\""); } else { this.DebugPrint("Method call on " + this.DiscoveredName + ".cat failed (ReturnType=" + catResult.Message.Type.ToString() + ")"); } } else { this.DebugPrint("Introspection was unsuccessful: " + status.ToString()); } } else { this.DebugPrint("Join Session was unsuccessful: " + status.ToString()); } this.busAtt.CancelFindAdvertisedName(ServiceName); this.busAtt.UnregisterBusListener(clientBusListener); this.DebugPrint("Successfully unraveled the client operation"); } catch (ArgumentNullException ex) { this.DebugPrint(">>>> TIMEOUT, Client could not find WKN >>>>"); } catch (Exception ex) { var errMsg = AllJoynException.GetErrorMessage(ex.HResult); this.DebugPrint(">>>> Client Execution Error >>>> " + errMsg); } }