/// <summary> /// Unsubscribe from an operation exported by this port. Somebody else cannot unsubscribe /// you unless they have the same response capability that was used to create the subscription. /// </summary> /// <param name="roleName">The name of the role that contains the operation</param> /// <param name="opName">The name of the operation being subscribed to</param> /// <param name="fromPort">The port to unsubscribe</param> /// <param name="respCap">The response capability that was used in the subscription</param> /// <returns>true if the port was subscribed and is now unsubscribed, /// false if the port was not subscribed</returns> public override bool Unsubscribe(string roleName, string opName, HomeOS.Hub.Platform.Views.VPort fromPort, HomeOS.Hub.Platform.Views.VCapability respCap) { lock (this.subscribedPorts) { OperationKey roleOpPair = new OperationKey(opName); if (!this.subscribedPorts.ContainsKey(roleOpPair)) { return(true); } foreach (SubscriptionInfo sub in subscribedPorts[roleOpPair]) { if (sub.subscribedPort.Equals(fromPort) && sub.notifyCapability.Equals(respCap)) { this.subscribedPorts[roleOpPair].Remove(sub); if (subscribedPorts[roleOpPair].Count == 0) { subscribedPorts.Remove(roleOpPair); } logger.Log("Role Op pair: (" + roleName + "," + opName + ") removed from subscribed ports"); return(true); } } return(false); } }
/// <summary> /// Invoke an operation exported by the port /// </summary> /// <param name="roleName">The name of the role that contains the operation</param> /// <param name="opName">The name of the operation being subscribed to</param> /// <param name="parameters">The list of parameters to call the operation with</param> /// <param name="fromPort">The port from which subscription is being issued (usually the ControlPort of the calling module) </param> /// <param name="reqCap">The capability for the port to which subscription is being issued</param> /// <param name="respCap">The capability that the notifications should use</param> /// <returns>The list of return values</returns> public override IList <HomeOS.Hub.Platform.Views.VParamType> Invoke(string roleName, string opName, IList <HomeOS.Hub.Platform.Views.VParamType> parameters, HomeOS.Hub.Platform.Views.VPort p, HomeOS.Hub.Platform.Views.VCapability reqCap, HomeOS.Hub.Platform.Views.VCapability respCap) { TimeSpan timeout = Constants.nominalTimeout; IList <HomeOS.Hub.Platform.Views.VParamType> retval = null; OperationKey roleOpPair = new OperationKey(opName); if (!operationDelegates.ContainsKey(roleOpPair) || operationDelegates[roleOpPair] == null) { retval = new List <HomeOS.Hub.Platform.Views.VParamType>(); retval.Add(new ParamType(ParamType.SimpleType.error, Constants.OpDoesNotExistName)); } else { SafeThread call = new SafeThread(delegate() { retval = operationDelegates[roleOpPair](roleName, opName, parameters); }, this + "." + opName, logger); //call.Name = this + "." + opName; call.Start(); call.Join(timeout); if (retval == null) { retval = new List <HomeOS.Hub.Platform.Views.VParamType>(); retval.Add(new ParamType(ParamType.SimpleType.error, Constants.OpNullResponse)); } } return(retval); }
/// <summary> /// Subscribe to an notifications from this port /// </summary> /// <param name="roleName">The name of the role that contains the operation</param> /// <param name="opName">The name of the operation being subscribed to</param> /// <param name="fromPort">The port from which subscription is being issued (usually the ControlPort of the calling module) </param> /// <param name="reqCap">The capability for the port to which subscription is being issued</param> /// <param name="respCap">The capability that the notifications should use</param> /// <returns>Whether the subscription succeeded</returns> public override bool Subscribe(string roleName, string opName, HomeOS.Hub.Platform.Views.VPort fromPort, HomeOS.Hub.Platform.Views.VCapability reqCap, HomeOS.Hub.Platform.Views.VCapability respCap) { SubscriptionInfo tmp = new SubscriptionInfo(fromPort, reqCap, respCap); lock (this.subscribedPorts) { OperationKey roleOpPair = new OperationKey(opName); //if we don't have anyone subscribed create the list if (!this.subscribedPorts.ContainsKey(roleOpPair)) { this.subscribedPorts[roleOpPair] = new List <SubscriptionInfo>(); } if (this.ValidateCapability(reqCap)) { //if a subscription already exists remove it first if (this.subscribedPorts[roleOpPair].Contains(tmp)) { this.subscribedPorts[roleOpPair].Remove(tmp); } this.subscribedPorts[roleOpPair].Add(tmp); return(true); } else { logger.Log("WARNING: Capability check failed in Subscribe"); return(false); } } }
public SubscriptionInfo(HomeOS.Hub.Platform.Views.VPort p, HomeOS.Hub.Platform.Views.VCapability subCap, HomeOS.Hub.Platform.Views.VCapability notCap) { this.subscriptionCapbility = subCap; this.subscribedPort = p; this.notifyCapability = notCap; }
/// <summary> /// The function that is called when a notification is issued in response to subscriptions /// </summary> /// <param name="roleName">The name of the role for which the notification is issued</param> /// <param name="opName">The name of the operation for which the notification is issued</param> /// <param name="retVals">The list of return values that are part of the notification</param> /// <param name="srcPort">The port from which the notification is being sent</param> /// <param name="respCap">The capability that the notification was sent with</param> public override void AsyncReturn(string roleName, string opName, IList <HomeOS.Hub.Platform.Views.VParamType> retVals, HomeOS.Hub.Platform.Views.VPort srcPort, HomeOS.Hub.Platform.Views.VCapability respCap) { if (ValidateCapability(respCap)) { handler(roleName, opName, retVals, srcPort); } else { logger.Log("WARNING: Capability check failed in AsynReturn"); } }