public InterfaceDescription GetInterface(string name) { IntPtr iface = alljoyn_busattachment_getinterface(_busAttachment, name); InterfaceDescription ret = (iface != IntPtr.Zero ? new InterfaceDescription(iface) : null); return(ret); }
public void AddInterfaceTest() { BusAttachment bus = new BusAttachment("addinterface", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); bus.CreateInterfacesFromXml(emptyIntf); InterfaceDescription[] annIntf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.Annotated", annIntf, false); annIntf[0].AddMethod("method", "ss", "s", "in1,in2,out1", (byte)0, ""); annIntf[0].AddProperty("property", "s", (byte)PropAccessType.PROP_ACCESS_RW); annIntf[0].AddSignal("signal", "suy", "str,uint,byte", (byte)0, ""); annIntf[0].AddAnnotation("org.freedesktop.DBus.Deprecated", "false"); annIntf[0].AddMemberAnnotation("method", "org.freedesktop.DBus.Method.NoReply", "true"); annIntf[0].AddPropertyAnnotation("property", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true"); annIntf[0].Activate(); BusObject busObj = new BusObject(bus, "/addinterfaces", false); busObj.AddInterface(bus.GetInterface("org.alljoyn.Signals")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Methods")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Properties")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Empty")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Annotated")); }
/// <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 AddInterfaceTest() { BusAttachment bus = new BusAttachment("addinterface", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); bus.CreateInterfacesFromXml(emptyIntf); InterfaceDescription[] annIntf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.Annotated", annIntf, false); annIntf[0].AddMethod("method", "ss", "s", "in1,in2,out1", (byte)0, ""); annIntf[0].AddProperty("property", "s", (byte)PropAccessType.PROP_ACCESS_RW); annIntf[0].AddSignal("signal", "suy", "str,uint,byte", (byte)0, ""); annIntf[0].AddAnnotation("org.freedesktop.DBus.Deprecated", "false"); annIntf[0].AddMemberAnnotation("method", "org.freedesktop.DBus.Method.NoReply", "true"); annIntf[0].AddPropertyAnnotation("property", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true"); annIntf[0].Activate(); BusObject busObj = new BusObject(bus, "/addinterfaces", false); busObj.AddInterface(bus.GetInterface("org.alljoyn.Signals")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Methods")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Properties")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Empty")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Annotated")); }
/// <summary> /// Create the BusAttachment, interface, setup the BusListener and other AllJoyn intialization /// tasks. /// </summary> /// <param name="name">The name for the BusAttachment.</param> private void InitializeAllJoyn(string name) { InterfaceDescription[] iface = new InterfaceDescription[1]; this.Bus = new BusAttachment(name, true, 4); // Create a secure interface. this.Bus.CreateInterface(App.InterfaceName, iface, true); iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty); iface[0].Activate(); this.Listeners = new Listeners(this.Bus); this.Bus.RegisterBusListener(this.Listeners); this.Listeners.FoundAdvertisedName += this.FoundAdvertisedName; this.Bus.Start(); // Enable security. // Note the location of the keystore file has been specified and the // isShared parameter is being set to true. So this keystore file can // be used by multiple applications. this.AuthenticationListener = new AuthListener(this.Bus); this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals; this.AuthenticationListener.AuthenticationComplete += this.AuthComplete; this.Bus.EnablePeerSecurity( App.SecurityType, this.AuthenticationListener, "/.alljoyn_keystore/s_central.ks", true); this.ConnectOp = this.Bus.ConnectAsync(App.ConnectSpec); this.ConnectOp.Completed = new AsyncActionCompletedHandler(this.BusConnected); }
/// <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 <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 MethodDispatcherBuildResult Build(InterfaceDescription interfaceDescription) { var context = new CodeBuilderContext( assemblyName: this.CodeBuilder.Names.GetMethodDispatcherAssemblyName(interfaceDescription .InterfaceType), assemblyNamespace: this.CodeBuilder.Names.GetMethodDispatcherAssemblyNamespace(interfaceDescription .InterfaceType), enableDebugging: CodeBuilderAttribute.IsDebuggingEnabled(interfaceDescription.InterfaceType)); var result = new MethodDispatcherBuildResult(context); // build dispatcher class var classBuilder = CodeBuilderUtils.CreateClassBuilder( context.ModuleBuilder, ns: context.AssemblyNamespace, className: this.CodeBuilder.Names.GetMethodDispatcherClassName(interfaceDescription.InterfaceType), baseType: this.MethodDispatcherBaseType); this.AddOnDispatchAsyncMethod(classBuilder, interfaceDescription); this.AddOnDispatchMethod(classBuilder, interfaceDescription); var methodNameMap = GetMethodNameMap(interfaceDescription); // create the dispatcher type, instantiate and initialize it result.MethodDispatcherType = classBuilder.CreateTypeInfo().AsType(); result.MethodDispatcher = (TMethodDispatcher)Activator.CreateInstance(result.MethodDispatcherType); var v2MethodDispatcherBase = (MethodDispatcherBase)result.MethodDispatcher; v2MethodDispatcherBase.Initialize( interfaceDescription, methodNameMap); context.Complete(); return(result); }
public void UpdateKnownTypeDetail(InterfaceDescription interfaceDescription, MethodBodyTypesBuildResult methodBodyTypesBuildResult) { var responseKnownTypes = new List <Type>(); var requestKnownType = new List <Type>(); foreach (var entry in interfaceDescription.Methods) { if (TypeUtility.IsTaskType(entry.ReturnType) && entry.ReturnType.GetTypeInfo().IsGenericType) { var returnType = entry.MethodInfo.ReturnType.GetGenericArguments()[0]; if (!responseKnownTypes.Contains(returnType)) { responseKnownTypes.Add(returnType); } } requestKnownType.AddRange(entry.MethodInfo.GetParameters() .ToList() .Select(p => p.ParameterType) .Except(requestKnownType)); } var knownType = new InterfaceDetails { Id = interfaceDescription.Id, ServiceInterfaceType = interfaceDescription.InterfaceType, RequestKnownTypes = requestKnownType, ResponseKnownTypes = responseKnownTypes, MethodNames = interfaceDescription.Methods.ToDictionary(item => item.Name, item => item.Id), RequestWrappedKnownTypes = methodBodyTypesBuildResult.GetRequestBodyTypes(), ResponseWrappedKnownTypes = methodBodyTypesBuildResult.GetResponseBodyTypes(), }; this.UpdateKnownTypes(interfaceDescription.Id, interfaceDescription.InterfaceType.FullName, knownType); }
protected static IReadOnlyDictionary <int, string> GetMethodNameMap(InterfaceDescription interfaceDescription) { var methodNameMap = interfaceDescription.Methods.ToDictionary( methodDescription => methodDescription.Id, methodDescription => methodDescription.Name); return(new ReadOnlyDictionary <int, string>(methodNameMap)); }
private void BuildGetMethodMetadata(InterfaceDescription interfaceDescription, OperationDescription method) { Output .Append("private IList<object> ") .Append(GetMethodMetadataName(method)) .AppendLine("()") .AppendLine("{"); using (Output.Indent()) { Output .AppendLine("var metadata = new List<object>();") .AppendLine("ServiceGetMetadata(metadata);"); var implementation = method.Method.Source; if (SyntaxTools.IsInterface(_contract.ContractInterface)) { Output .Append("// copy attributes from method ") .Append(interfaceDescription.InterfaceType.Name) .Append(".") .AppendLine(implementation.Name); } else { implementation = _contract.ContractInterface.GetInterfaceImplementation(method.Method.Source); Output .Append("// copy attributes from method ") .Append(implementation.Name) .Append(", implementation of ") .Append(interfaceDescription.InterfaceType.Name) .Append(".") .AppendLine(method.Method.Name); } var length = Output.Length; foreach (var attribute in FilterAttributes(implementation.GetAttributes())) { Output.Append("metadata.Add("); WriteNewAttribute(Output, attribute); Output.AppendLine(");"); } if (Output.Length == length) { Output.AppendLine("// no applicable attributes found"); } Output .Append(GetMethodMetadataName(method)) .AppendLine("Override(metadata);") .AppendLine("return metadata;"); } Output.AppendLine("}"); }
/// <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); }
public AddMatchBusObj(BusAttachment bus) { this.busObj = new BusObject(bus, "/test", false); InterfaceDescription[] intf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.addmatchtest", intf, false); intf[0].AddSignal("testSig", "s", "str", (byte)0, ""); intf[0].Activate(); this.busObj.AddInterface(intf[0]); MessageReceiver receiver = new MessageReceiver(bus); receiver.SignalHandler += new MessageReceiverSignalHandler(this.SigHandle); bus.RegisterSignalHandler(receiver, intf[0].GetSignal("testSig"), ""); bus.RegisterBusObject(this.busObj); }
public AddMatchBusObj(BusAttachment bus) { this.busObj = new BusObject(bus, "/test", false); InterfaceDescription[] intf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.addmatchtest", intf, false); intf[0].AddSignal("testSig", "s", "str", (byte)0, ""); intf[0].Activate(); this.busObj.AddInterface(intf[0]); MessageReceiver receiver = new MessageReceiver(bus); receiver.SignalHandler += new MessageReceiverSignalHandler(this.SigHandle); bus.RegisterSignalHandler(receiver, intf[0].GetSignal("testSig"), ""); bus.RegisterBusObject(this.busObj); }
public QStatus CreateInterface(string interfaceName, bool secure, out InterfaceDescription iface) { IntPtr interfaceDescription; int qstatus = alljoyn_busattachment_createinterface(_busAttachment, interfaceName, ref interfaceDescription, secure ? 1 : 0); if (qstatus == 0) { iface = new InterfaceDescription(interfaceDescription); } else { iface = null; } return(qstatus); }
private void AddOnDispatchAsyncMethod( TypeBuilder classBuilder, InterfaceDescription interfaceDescription, MethodBodyTypesBuildResult methodBodyTypesBuildResult) { var dispatchMethodImpl = CodeBuilderUtils.CreateProtectedMethodBuilder( classBuilder, "OnDispatchAsync", typeof(Task <IActorResponseMessageBody>), typeof(int), // methodid typeof(object), // remoted object typeof(IActorRequestMessageBody), // requestBody typeof(IActorMessageBodyFactory), // remotingmessageBodyFactory typeof(CancellationToken)); // CancellationToken var ilGen = dispatchMethodImpl.GetILGenerator(); var castedObject = ilGen.DeclareLocal(interfaceDescription.InterfaceType); ilGen.Emit(OpCodes.Ldarg_2); // load remoted object ilGen.Emit(OpCodes.Castclass, interfaceDescription.InterfaceType); ilGen.Emit(OpCodes.Stloc, castedObject); // store casted result to local 0 foreach (var methodDescription in interfaceDescription.Methods) { if (!TypeUtility.IsTaskType(methodDescription.ReturnType)) { continue; } var elseLable = ilGen.DefineLabel(); this.AddIfMethodIdInvokeAsyncBlock( ilGen: ilGen, elseLabel: elseLable, castedObject: castedObject, methodDescription: methodDescription, interfaceName: interfaceDescription.InterfaceType.FullName, methodBodyTypes: methodBodyTypesBuildResult.MethodBodyTypesMap[methodDescription.Name]); ilGen.MarkLabel(elseLable); } ilGen.ThrowException(typeof(MissingMethodException)); }
/// <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> /// 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 void CreateInterfaceTest() { BusAttachment bus = new BusAttachment("interfacetest", true, 4); InterfaceDescription[] secureIntf = new InterfaceDescription[1]; InterfaceDescription[] nonsecureIntf = new InterfaceDescription[1]; bus.CreateInterface("secureIntf", secureIntf, true); bus.CreateInterface("nonsecureIntf", nonsecureIntf, false); secureIntf[0].AddMethod("foo", "say", "ab", "str,arr1,arr2", (byte)0, ""); nonsecureIntf[0].AddSignal("bar", "say", "str,arr1", (byte)0, ""); secureIntf[0].Activate(); nonsecureIntf[0].Activate(); Assert.IsNotNull(bus.GetInterface("secureIntf")); Assert.IsNotNull(bus.GetInterface("nonsecureIntf")); InterfaceDescription[] intfs = new InterfaceDescription[12]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("secureIntf")); //bus.DeleteInterface(bus.GetInterface("nonsecureIntf")); //Assert.IsNull(bus.GetInterface("secureIntf")); //Assert.IsNull(bus.GetInterface("nonsecureIntf")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[2]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); // TODO: It doesn't seem like you can create multiple interfaces at a time //InterfaceDescription[] multiIntf = new InterfaceDescription[5]; //bus.CreateInterface("multiIntf", multiIntf, false); try { InterfaceDescription nonExisting = bus.GetInterface("notThere"); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } }
private void AddOnDispatchMethod( TypeBuilder classBuilder, InterfaceDescription interfaceDescription, MethodBodyTypesBuildResult methodBodyTypesBuildResult) { var dispatchMethodImpl = CodeBuilderUtils.CreateProtectedMethodBuilder( classBuilder, "OnDispatch", typeof(void), typeof(int), // method id typeof(object), // remote object typeof(object)); // message body var ilGen = dispatchMethodImpl.GetILGenerator(); var castedObject = ilGen.DeclareLocal(interfaceDescription.InterfaceType); ilGen.Emit(OpCodes.Ldarg_2); // load object ilGen.Emit(OpCodes.Castclass, interfaceDescription.InterfaceType); ilGen.Emit(OpCodes.Stloc, castedObject); // store casted result to local 0 foreach (var methodDescription in interfaceDescription.Methods) { if (!TypeUtility.IsVoidType(methodDescription.ReturnType)) { continue; } var elseLable = ilGen.DefineLabel(); this.AddIfMethodIdInvokeBlock( ilGen: ilGen, elseLabel: elseLable, castedObject: castedObject, methodDescription: methodDescription, requestBodyType: methodBodyTypesBuildResult.MethodBodyTypesMap[methodDescription.Name] .RequestBodyType); ilGen.MarkLabel(elseLable); } ilGen.ThrowException(typeof(MissingMethodException)); }
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="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); }
public InterfaceDescription[] GetInterfaces() { UIntPtr numIfaces = alljoyn_busattachment_getinterfaces(_busAttachment, IntPtr.Zero, (UIntPtr)0); IntPtr[] ifaces = new IntPtr[(int)numIfaces]; GCHandle gch = GCHandle.Alloc(ifaces, GCHandleType.Pinned); UIntPtr numIfacesFilled = alljoyn_busattachment_getinterfaces(_busAttachment, gch.AddrOfPinnedObject(), numIfaces); gch.Free(); if (numIfaces != numIfacesFilled) { // Warn? } InterfaceDescription[] ret = new InterfaceDescription[(int)numIfacesFilled]; for (int i = 0; i < ret.Length; i++) { ret[i] = new InterfaceDescription(ifaces[i]); } return(ret); }
/// <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="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="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="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="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); }
public MethodBodyTypesBuildResult Build(InterfaceDescription interfaceDescription) { var context = new CodeBuilderContext( assemblyName: this.CodeBuilder.Names.GetMethodBodyTypesAssemblyName(interfaceDescription.InterfaceType), assemblyNamespace: this.CodeBuilder.Names.GetMethodBodyTypesAssemblyNamespace(interfaceDescription.InterfaceType), enableDebugging: CodeBuilderAttribute.IsDebuggingEnabled(interfaceDescription.InterfaceType)); var result = new MethodBodyTypesBuildResult(context) { MethodBodyTypesMap = new Dictionary <string, MethodBodyTypes>(), }; foreach (var method in interfaceDescription.Methods) { result.MethodBodyTypesMap.Add( method.Name, Build(this.CodeBuilder.Names, context, method)); } context.Complete(); return(result); }
public ServiceBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); busAtt.RegisterBusObject(this.busObject); }
public void CreateInterfacesFromXMLTest() { BusAttachment bus = new BusAttachment("xmlinterfaces", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); InterfaceDescription i = bus.GetInterface("org.alljoyn.Signals"); Assert.IsNotNull(i); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Methods")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Properties")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Mixed")); InterfaceDescription[] intfs = new InterfaceDescription[14]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); Assert.IsNotNull(intfs[2]); Assert.IsNotNull(intfs[3]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Signals")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Methods")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Properties")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Mixed")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Signals")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Methods")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Properties")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Mixed")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[14]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); //Assert.IsNull(nullIntfs[2]); //Assert.IsNull(nullIntfs[3]); }
private void AddCreateResponseBodyMethod( TypeBuilder classBuilder, InterfaceDescription interfaceDescription, MethodBodyTypesBuildResult methodBodyTypesBuildResult) { var methodBuilder = CodeBuilderUtils.CreateProtectedMethodBuilder( classBuilder, "CreateWrappedResponseBody", typeof(object), // responseBody - return value typeof(int), // methodId typeof(object)); // retval from the invoked method on the remoted object var ilGen = methodBuilder.GetILGenerator(); foreach (var methodDescription in interfaceDescription.Methods) { var methodBodyTypes = methodBodyTypesBuildResult.MethodBodyTypesMap[methodDescription.Name]; if (methodBodyTypes.ResponseBodyType == null) { continue; } var elseLabel = ilGen.DefineLabel(); this.AddIfMethodIdCreateResponseBlock( ilGen, elseLabel, methodDescription.Id, methodBodyTypes.ResponseBodyType); ilGen.MarkLabel(elseLabel); } // return null; (if method id's do not match) ilGen.Emit(OpCodes.Ldnull); ilGen.Emit(OpCodes.Ret); }
/** * Send a signal. * * @param destination The unique or well-known bus name or the signal recipient (NULL for broadcast signals) * @param sessionId A unique SessionId for this AllJoyn session instance * @param signal Interface member of signal being emitted. * @param args The arguments for the signal (can be NULL) * @return * - QStatus.OK if successful * - An error status otherwise */ protected QStatus Signal(string destination, uint sessionId, InterfaceDescription.Member signal, MsgArg args) { return alljoyn_busobject_signal(_busObject, destination, sessionId, signal._member, args.UnmanagedPtr, (UIntPtr)args.Length, 0, 0, IntPtr.Zero); }
/** * Add a method handler to this object. The interface for the method handler must have already * been added by calling AddInterface(). * * @param member Interface member implemented by handler. * @param handler Method handler. * * @return * - QStatus.OK if the method handler was added. * - An error status otherwise */ public QStatus AddMethodHandler(InterfaceDescription.Member member, MethodHandler handler) { InternalMethodHandler internalMethodHandler = (IntPtr bus, IntPtr m, IntPtr msg) => { MethodHandler h = handler; h(new InterfaceDescription.Member(m), new Message(msg)); }; _methodHandlerDelegateRefHolder.Add(internalMethodHandler); GCHandle membGch = GCHandle.Alloc(member._member, GCHandleType.Pinned); MethodEntry entry; entry.member = membGch.AddrOfPinnedObject(); entry.method_handler = Marshal.GetFunctionPointerForDelegate(internalMethodHandler); GCHandle gch = GCHandle.Alloc(entry, GCHandleType.Pinned); QStatus ret = alljoyn_busobject_addmethodhandlers(_busObject, gch.AddrOfPinnedObject(), (UIntPtr)1); gch.Free(); membGch.Free(); return ret; }
/** * Add an interface to this object. If the interface has properties this will also add the * standard property access interface. An interface must be added before its method handlers can be * added. Note that the Peer interface (org.freedesktop.DBus.peer) is implicit on all objects and * cannot be explicitly added, and the Properties interface (org.freedesktop,DBus.Properties) is * automatically added when needed and cannot be explicitly added. * * Once an object is registered, it should not add any additional interfaces. Doing so would * confuse remote objects that may have already introspected this object. * * @param iface The interface to add * * @return * - QStatus.OK if the interface was successfully added. * - QStatus.BUS_IFACE_ALREADY_EXISTS if the interface already exists. * - An error status otherwise */ public QStatus AddInterface(InterfaceDescription iface) { return alljoyn_busobject_addinterface(_busObject, iface.UnmanagedPtr); }
/** * Create an interface description with a given name. * * Typically, interfaces that are implemented by BusObjects are created here. * Interfaces that are implemented by remote objects are added automatically by * the bus if they are not already present via ProxyBusObject.IntrospectRemoteObject(). * * Because interfaces are added both explicitly (via this method) and implicitly * (via @c ProxyBusObject.IntrospectRemoteObject), there is the possibility that creating * an interface here will fail because the interface already exists. If this happens, the * QStatus.BUS_IFACE_ALREADY_EXISTS will be returned and NULL will be returned in the iface [OUT] * parameter. * * Interfaces created with this method need to be activated using InterfaceDescription.Activate() * once all of the methods, signals, etc have been added to the interface. The interface will * be unaccessible (via BusAttachment.GetInterfaces() or BusAttachment.GetInterface()) until * it is activated. * * @param interfaceName The requested interface name. * @param secPolicy * security policy of this interface it can be: * - InterfaceDescription.SecurityPolicy.Inherit * - InterfaceDescription.SecurityPolicy.Required * - InterfaceDescription.SecurityPolicy.Off * If SecurityPolicy.Required the interface is secure and * method calls and signals will be encrypted. * If SecurityPolicy.Inherit the interface will gain the * security level of the BusObject implementing the interface * IF SecurityPolicy.Off authentication is not applicable to * the interface. * @param[out] iface * - Interface description * - NULL if cannot be created. * * @return * - QStatus.OK if creation was successful. * - QStatus.BUS_IFACE_ALREADY_EXISTS if requested interface already exists * @see ProxyBusObject.IntrospectRemoteObject, InterfaceDescription.Activate, BusAttachment.GetInterface */ public QStatus CreateInterface(string interfaceName, InterfaceDescription.SecurityPolicy secPolicy, out InterfaceDescription iface) { IntPtr interfaceDescription = new IntPtr(); int qstatus = alljoyn_busattachment_createinterface_secure(_busAttachment, interfaceName, ref interfaceDescription, secPolicy); if (qstatus == 0) { iface = new InterfaceDescription(interfaceDescription); } else { iface = null; } return qstatus; }
/// <summary> /// Create the BusAttachment, interface, setup the BusListener and other AllJoyn intialization /// tasks. /// </summary> /// <param name="name">The name for the BusAttachment.</param> private void InitializeAllJoyn(string name) { InterfaceDescription[] iface = new InterfaceDescription[1]; this.Bus = new BusAttachment(name, true, 4); // Create a secure interface. this.Bus.CreateInterface(App.InterfaceName, iface, true); iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty); iface[0].Activate(); this.Listeners = new Listeners(this.Bus); this.Bus.RegisterBusListener(this.Listeners); this.Listeners.FoundAdvertisedName += this.FoundAdvertisedName; this.Bus.Start(); // Enable security. // Note the location of the keystore file has been specified and the // isShared parameter is being set to true. So this keystore file can // be used by multiple applications. this.AuthenticationListener = new AuthListener(this.Bus); this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals; this.AuthenticationListener.AuthenticationComplete += this.AuthComplete; this.Bus.EnablePeerSecurity( App.SecurityType, this.AuthenticationListener, "/.alljoyn_keystore/s_central.ks", true); this.ConnectOp = this.Bus.ConnectAsync(App.ConnectSpec); this.ConnectOp.Completed = new AsyncActionCompletedHandler(this.BusConnected); }
/// <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(); } }
/// <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(); } }
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(); } }
public ServiceBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); busAtt.RegisterBusObject(this.busObject); }
/** * Add an interface to this object. If the interface has properties this will also add the * standard property access interface. An interface must be added before its method handlers can be * added. Note that the Peer interface (org.freedesktop.DBus.peer) is implicit on all objects and * cannot be explicitly added, and the Properties interface (org.freedesktop,DBus.Properties) is * automatically added when needed and cannot be explicitly added. * * Once an object is registered, it should not add any additional interfaces. Doing so would * confuse remote objects that may have already introspected this object. * * @param iface The interface to add * * @return * - QStatus.OK if the interface was successfully added. * - QStatus.BUS_IFACE_ALREADY_EXISTS if the interface already exists. * - An error status otherwise */ public QStatus AddInterface(InterfaceDescription iface) { return(alljoyn_busobject_addinterface(_busObject, iface.UnmanagedPtr)); }
public void CreateInterfacesFromXMLTest() { BusAttachment bus = new BusAttachment("xmlinterfaces", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); InterfaceDescription i = bus.GetInterface("org.alljoyn.Signals"); Assert.IsNotNull(i); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Methods")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Properties")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Mixed")); InterfaceDescription[] intfs = new InterfaceDescription[14]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); Assert.IsNotNull(intfs[2]); Assert.IsNotNull(intfs[3]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Signals")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Methods")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Properties")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Mixed")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Signals")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Methods")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Properties")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Mixed")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[14]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); //Assert.IsNull(nullIntfs[2]); //Assert.IsNull(nullIntfs[3]); }
public void CreateInterfaceTest() { BusAttachment bus = new BusAttachment("interfacetest", true, 4); InterfaceDescription[] secureIntf = new InterfaceDescription[1]; InterfaceDescription[] nonsecureIntf = new InterfaceDescription[1]; bus.CreateInterface("secureIntf", secureIntf, true); bus.CreateInterface("nonsecureIntf", nonsecureIntf, false); secureIntf[0].AddMethod("foo", "say", "ab", "str,arr1,arr2", (byte)0, ""); nonsecureIntf[0].AddSignal("bar", "say", "str,arr1", (byte)0, ""); secureIntf[0].Activate(); nonsecureIntf[0].Activate(); Assert.IsNotNull(bus.GetInterface("secureIntf")); Assert.IsNotNull(bus.GetInterface("nonsecureIntf")); InterfaceDescription[] intfs = new InterfaceDescription[12]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("secureIntf")); //bus.DeleteInterface(bus.GetInterface("nonsecureIntf")); //Assert.IsNull(bus.GetInterface("secureIntf")); //Assert.IsNull(bus.GetInterface("nonsecureIntf")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[2]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); // TODO: It doesn't seem like you can create multiple interfaces at a time //InterfaceDescription[] multiIntf = new InterfaceDescription[5]; //bus.CreateInterface("multiIntf", multiIntf, false); try { InterfaceDescription nonExisting = bus.GetInterface("notThere"); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } }
/** * Send a signal. * * @param destination The unique or well-known bus name or the signal recipient (NULL for broadcast signals) * @param sessionId A unique SessionId for this AllJoyn session instance * @param signal Interface member of signal being emitted. * @param args The arguments for the signal (can be NULL) * @param timeToLife If non-zero this specifies in milliseconds the useful lifetime for this * signal. If delivery of the signal is delayed beyond the timeToLive due to * network congestion or other factors the signal may be discarded. There is * no guarantee that expired signals will not still be delivered. * @param flags Logical OR of the message flags for this signals. The following flags apply to signals: * - If ALLJOYN_FLAG_SESSIONLESS is set the signal will be sent out to any listener without * requireing a connected session * - If ALLJOYN_FLAG_GLOBAL_BROADCAST is set broadcast signal (null destination) will be * forwarded across bus-to-bus connections. * - If ALLJOYN_FLAG_COMPRESSED is set the header is compressed for destinations that can * handle header compression. * - If ALLJOYN_FLAG_ENCRYPTED is set the message is authenticated and the payload if any * is encrypted. * @param msg The sent signal message is returned to the caller. * @return * - QStatus.OK if successful * - An error status otherwise */ protected QStatus Signal(string destination, uint sessionId, InterfaceDescription.Member signal, MsgArg args, ushort timeToLife, byte flags, Message msg) { return alljoyn_busobject_signal(_busObject, destination, sessionId, signal._member, args.UnmanagedPtr, (UIntPtr)args.Length, timeToLife, flags, msg.UnmanagedPtr); }
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(); } }
private static extern int alljoyn_busobject_signal(IntPtr bus, [MarshalAs(UnmanagedType.LPStr)] string destination, uint sessionId, InterfaceDescription._Member signal, IntPtr msgArgs, UIntPtr numArgs, ushort timeToLive, byte flags, IntPtr msg);
public QStatus CreateInterface(string interfaceName, bool secure, out InterfaceDescription iface) { IntPtr interfaceDescription; int qstatus = alljoyn_busattachment_createinterface(_busAttachment, interfaceName, ref interfaceDescription, secure ? 1 : 0); if(qstatus == 0) { iface = new InterfaceDescription(interfaceDescription); } else { iface = null; } return qstatus; }
public SignalBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); MessageReceiver msgReceiver1 = new MessageReceiver(busAtt); msgReceiver1.SignalHandler += new MessageReceiverSignalHandler(this.StringSig); busAtt.RegisterSignalHandler(msgReceiver1, intf[0].GetSignal("string"), ""); MessageReceiver msgReceiver2 = new MessageReceiver(busAtt); msgReceiver2.SignalHandler += new MessageReceiverSignalHandler(this.ByteSig); busAtt.RegisterSignalHandler(msgReceiver2, intf[0].GetSignal("byte"), ""); MessageReceiver msgReceiver3 = new MessageReceiver(busAtt); msgReceiver3.SignalHandler += new MessageReceiverSignalHandler(this.BoolSig); busAtt.RegisterSignalHandler(msgReceiver3, intf[0].GetSignal("bool"), ""); MessageReceiver msgReceiver4 = new MessageReceiver(busAtt); msgReceiver4.SignalHandler += new MessageReceiverSignalHandler(this.Int16Sig); busAtt.RegisterSignalHandler(msgReceiver4, intf[0].GetSignal("int16"), ""); MessageReceiver msgReceiver5 = new MessageReceiver(busAtt); msgReceiver5.SignalHandler += new MessageReceiverSignalHandler(this.Uint16Sig); busAtt.RegisterSignalHandler(msgReceiver5, intf[0].GetSignal("uint16"), ""); MessageReceiver msgReceiver6 = new MessageReceiver(busAtt); msgReceiver6.SignalHandler += new MessageReceiverSignalHandler(this.Int32Sig); busAtt.RegisterSignalHandler(msgReceiver6, intf[0].GetSignal("int32"), ""); MessageReceiver msgReceiver7 = new MessageReceiver(busAtt); msgReceiver7.SignalHandler += new MessageReceiverSignalHandler(this.Uint32Sig); busAtt.RegisterSignalHandler(msgReceiver7, intf[0].GetSignal("uint32"), ""); MessageReceiver msgReceiver8 = new MessageReceiver(busAtt); msgReceiver8.SignalHandler += new MessageReceiverSignalHandler(this.Int64Sig); busAtt.RegisterSignalHandler(msgReceiver8, intf[0].GetSignal("int64"), ""); MessageReceiver msgReceiver9 = new MessageReceiver(busAtt); msgReceiver9.SignalHandler += new MessageReceiverSignalHandler(this.Uint64Sig); busAtt.RegisterSignalHandler(msgReceiver9, intf[0].GetSignal("uint64"), ""); MessageReceiver msgReceiver10 = new MessageReceiver(busAtt); msgReceiver10.SignalHandler += new MessageReceiverSignalHandler(this.DoubleSig); busAtt.RegisterSignalHandler(msgReceiver10, intf[0].GetSignal("double"), ""); MessageReceiver msgReceiver11 = new MessageReceiver(busAtt); msgReceiver11.SignalHandler += new MessageReceiverSignalHandler(this.DArrarySig); busAtt.RegisterSignalHandler(msgReceiver11, intf[0].GetSignal("dArray"), ""); MessageReceiver msgReceiver12 = new MessageReceiver(busAtt); msgReceiver12.SignalHandler += new MessageReceiverSignalHandler(this.BYIStructSig); busAtt.RegisterSignalHandler(msgReceiver12, intf[0].GetSignal("byiStruct"), ""); MessageReceiver msgReceiver13 = new MessageReceiver(busAtt); msgReceiver13.SignalHandler += new MessageReceiverSignalHandler(this.ISDictSig); busAtt.RegisterSignalHandler(msgReceiver13, intf[0].GetSignal("isDict"), ""); busAtt.RegisterBusObject(this.busObject); }
public QStatus DeleteInterface(InterfaceDescription iface) { return alljoyn_busattachment_deleteinterface(_busAttachment, iface.UnmanagedPtr); }
/// <summary> /// Initializes the global bus attachment /// </summary> private void InitializeAllJoyn() { InterfaceDescription[] iface = new InterfaceDescription[1]; this.Bus = new BusAttachment("SRPSecurityServiceA", true, 4); this.Bus.CreateInterface(App.InterfaceName, iface, true); iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty); iface[0].Activate(); this.BusObject = new SecureBusObject(this.Bus, iface); this.Listeners = new Listeners(this.Bus); this.Listeners.NameOwnerChange += this.NameOwnerChanged; this.Listeners.AcceptSessionJoiner += this.AcceptSessionJoiner; this.Bus.RegisterBusListener(this.Listeners); this.Bus.Start(); // Enable security. // Note the location of the keystore file has been specified and the // isShared parameter is being set to true. So this keystore file can // be used by multiple applications. this.AuthenticationListener = new AuthListener(this.Bus); this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals; this.Bus.EnablePeerSecurity( App.SecurityType, this.AuthenticationListener, "/.alljoyn_keystore/s_central.ks", true); this.Bus.ConnectAsync(App.ConnectSpec).AsTask().Wait(); SessionOpts sessionOpts = new SessionOpts( TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY); ushort[] portOut = new ushort[1]; this.Bus.BindSessionPort(App.ServicePort, portOut, sessionOpts, this.Listeners); try { uint flags = (uint)RequestNameType.DBUS_NAME_REPLACE_EXISTING + (uint)RequestNameType.DBUS_NAME_DO_NOT_QUEUE; this.Bus.RequestName(App.ServiceName, flags); } catch (COMException ce) { QStatus exceptionStatus = AllJoynException.GetErrorCode(ce.HResult); string error = string.Format( "Well known name '{0}' was not accepted. QStatus = 0x{1:X}", App.ServiceName, exceptionStatus); System.Diagnostics.Debug.WriteLine(error); App.OutputLine(error); } this.Bus.AdvertiseName(App.ServiceName, sessionOpts.TransportMask); App.OutputLine(string.Format("Name is being advertised as: '{0}'.", App.ServiceName)); }
public InterfaceDescription[] GetInterfaces() { UIntPtr numIfaces = alljoyn_busattachment_getinterfaces(_busAttachment, IntPtr.Zero, (UIntPtr)0); IntPtr[] ifaces = new IntPtr[(int)numIfaces]; GCHandle gch = GCHandle.Alloc(ifaces, GCHandleType.Pinned); UIntPtr numIfacesFilled = alljoyn_busattachment_getinterfaces(_busAttachment, gch.AddrOfPinnedObject(), numIfaces); gch.Free(); if(numIfaces != numIfacesFilled) { // Warn? } InterfaceDescription[] ret = new InterfaceDescription[(int)numIfacesFilled]; for(int i = 0; i < ret.Length; i++) { ret[i] = new InterfaceDescription(ifaces[i]); } return ret; }
/** * Register a signal handler. * * Signals are forwarded to the signalHandler if sender, interface, member and path * qualifiers are ALL met. * * @param handler The signal handler method. * @param member The interface/member of the signal. * @param srcPath The object path of the emitter of the signal or NULL for all paths. * @return QStatus.OK */ public QStatus RegisterSignalHandler(SignalHandler handler, InterfaceDescription.Member member, string srcPath) { InternalSignalHandler internalSignalHandler = (IntPtr m, IntPtr s, IntPtr msg) => { SignalHandler h = handler; h(new InterfaceDescription.Member(m), Marshal.PtrToStringAnsi(s), new Message(msg)); }; _signalHandlerDelegateRefHolder.Add(handler, internalSignalHandler); QStatus ret = alljoyn_busattachment_registersignalhandler(_busAttachment, Marshal.GetFunctionPointerForDelegate(internalSignalHandler), member._member, srcPath); return ret; }
public QStatus CreateInterface(string interfaceName, bool secure, out InterfaceDescription iface) { IntPtr interfaceDescription = new IntPtr(); int qstatus = 1; if (secure == true) { qstatus = alljoyn_busattachment_createinterface_secure(_busAttachment, interfaceName, ref interfaceDescription, InterfaceDescription.SecurityPolicy.Required); } else { qstatus = alljoyn_busattachment_createinterface(_busAttachment, interfaceName, ref interfaceDescription); } if (qstatus == 0) { iface = new InterfaceDescription(interfaceDescription); } else { iface = null; } return qstatus; }
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); }
/** * Unregister a signal handler. * * Remove the signal handler that was registered with the given parameters. * * @param handler The signal handler method. * @param member The interface/member of the signal. * @param srcPath The object path of the emitter of the signal or NULL for all paths. * @return QStatus.OK */ public QStatus UnregisterSignalHandler(SignalHandler handler, InterfaceDescription.Member member, string srcPath) { QStatus ret = QStatus.OS_ERROR; if (_signalHandlerDelegateRefHolder.ContainsKey(handler)) { ret = alljoyn_busattachment_unregistersignalhandler(_busAttachment, Marshal.GetFunctionPointerForDelegate(_signalHandlerDelegateRefHolder[handler]), member._member, srcPath); _signalHandlerDelegateRefHolder.Remove(handler); } return ret; }
public SignalBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); MessageReceiver msgReceiver1 = new MessageReceiver(busAtt); msgReceiver1.SignalHandler += new MessageReceiverSignalHandler(this.StringSig); busAtt.RegisterSignalHandler(msgReceiver1, intf[0].GetSignal("string"), ""); MessageReceiver msgReceiver2 = new MessageReceiver(busAtt); msgReceiver2.SignalHandler += new MessageReceiverSignalHandler(this.ByteSig); busAtt.RegisterSignalHandler(msgReceiver2, intf[0].GetSignal("byte"), ""); MessageReceiver msgReceiver3 = new MessageReceiver(busAtt); msgReceiver3.SignalHandler += new MessageReceiverSignalHandler(this.BoolSig); busAtt.RegisterSignalHandler(msgReceiver3, intf[0].GetSignal("bool"), ""); MessageReceiver msgReceiver4 = new MessageReceiver(busAtt); msgReceiver4.SignalHandler += new MessageReceiverSignalHandler(this.Int16Sig); busAtt.RegisterSignalHandler(msgReceiver4, intf[0].GetSignal("int16"), ""); MessageReceiver msgReceiver5 = new MessageReceiver(busAtt); msgReceiver5.SignalHandler += new MessageReceiverSignalHandler(this.Uint16Sig); busAtt.RegisterSignalHandler(msgReceiver5, intf[0].GetSignal("uint16"), ""); MessageReceiver msgReceiver6 = new MessageReceiver(busAtt); msgReceiver6.SignalHandler += new MessageReceiverSignalHandler(this.Int32Sig); busAtt.RegisterSignalHandler(msgReceiver6, intf[0].GetSignal("int32"), ""); MessageReceiver msgReceiver7 = new MessageReceiver(busAtt); msgReceiver7.SignalHandler += new MessageReceiverSignalHandler(this.Uint32Sig); busAtt.RegisterSignalHandler(msgReceiver7, intf[0].GetSignal("uint32"), ""); MessageReceiver msgReceiver8 = new MessageReceiver(busAtt); msgReceiver8.SignalHandler += new MessageReceiverSignalHandler(this.Int64Sig); busAtt.RegisterSignalHandler(msgReceiver8, intf[0].GetSignal("int64"), ""); MessageReceiver msgReceiver9 = new MessageReceiver(busAtt); msgReceiver9.SignalHandler += new MessageReceiverSignalHandler(this.Uint64Sig); busAtt.RegisterSignalHandler(msgReceiver9, intf[0].GetSignal("uint64"), ""); MessageReceiver msgReceiver10 = new MessageReceiver(busAtt); msgReceiver10.SignalHandler += new MessageReceiverSignalHandler(this.DoubleSig); busAtt.RegisterSignalHandler(msgReceiver10, intf[0].GetSignal("double"), ""); MessageReceiver msgReceiver11 = new MessageReceiver(busAtt); msgReceiver11.SignalHandler += new MessageReceiverSignalHandler(this.DArrarySig); busAtt.RegisterSignalHandler(msgReceiver11, intf[0].GetSignal("dArray"), ""); MessageReceiver msgReceiver12 = new MessageReceiver(busAtt); msgReceiver12.SignalHandler += new MessageReceiverSignalHandler(this.BYIStructSig); busAtt.RegisterSignalHandler(msgReceiver12, intf[0].GetSignal("byiStruct"), ""); MessageReceiver msgReceiver13 = new MessageReceiver(busAtt); msgReceiver13.SignalHandler += new MessageReceiverSignalHandler(this.ISDictSig); busAtt.RegisterSignalHandler(msgReceiver13, intf[0].GetSignal("isDict"), ""); busAtt.RegisterBusObject(this.busObject); }
private static extern int alljoyn_busattachment_unregistersignalhandler(IntPtr bus, IntPtr signalHandler, InterfaceDescription._Member member, [MarshalAs(UnmanagedType.LPStr)] string srcPath);
internal void Initialize(InterfaceDescription description, IReadOnlyDictionary <int, string> methodMap) { this.SetInterfaceId(description.Id); this.SetMethodNameMap(methodMap); }
/// <summary> /// Initializes the global bus attachment /// </summary> private void InitializeAllJoyn() { InterfaceDescription[] iface = new InterfaceDescription[1]; this.Bus = new BusAttachment("SRPSecurityServiceA", true, 4); this.Bus.CreateInterface(App.InterfaceName, iface, true); iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty); iface[0].Activate(); this.BusObject = new SecureBusObject(this.Bus, iface); this.Listeners = new Listeners(this.Bus); this.Listeners.NameOwnerChange += this.NameOwnerChanged; this.Listeners.AcceptSessionJoiner += this.AcceptSessionJoiner; this.Bus.RegisterBusListener(this.Listeners); this.Bus.Start(); // Enable security. // Note the location of the keystore file has been specified and the // isShared parameter is being set to true. So this keystore file can // be used by multiple applications. this.AuthenticationListener = new AuthListener(this.Bus); this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals; this.Bus.EnablePeerSecurity( App.SecurityType, this.AuthenticationListener, "/.alljoyn_keystore/s_central.ks", true); this.Bus.ConnectAsync(App.ConnectSpec).AsTask().Wait(); SessionOpts sessionOpts = new SessionOpts( TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY); ushort[] portOut = new ushort[1]; this.Bus.BindSessionPort(App.ServicePort, portOut, sessionOpts, this.Listeners); try { uint flags = (uint)RequestNameType.DBUS_NAME_REPLACE_EXISTING + (uint)RequestNameType.DBUS_NAME_DO_NOT_QUEUE; this.Bus.RequestName(App.ServiceName, flags); } catch (COMException ce) { QStatus exceptionStatus = AllJoynException.GetErrorCode(ce.HResult); string error = string.Format( "Well known name '{0}' was not accepted. QStatus = 0x{1:X}", App.ServiceName, exceptionStatus); System.Diagnostics.Debug.WriteLine(error); App.OutputLine(error); } this.Bus.AdvertiseName(App.ServiceName, sessionOpts.TransportMask); App.OutputLine(string.Format("Name is being advertised as: '{0}'.", App.ServiceName)); }