void InitSwitch(VPort switchPort, SwitchType switchType, bool isColored) { logger.Log("{0} adding switch {1} {2}", this.ToString(), switchType.ToString(), switchPort.ToString()); SwitchInfo switchInfo = new SwitchInfo(); switchInfo.Capability = GetCapability(switchPort, Constants.UserSystem); switchInfo.Level = 0; switchInfo.Type = switchType; switchInfo.IsColored = isColored; switchInfo.Color = Color.Black; registeredSwitches.Add(switchPort, switchInfo); string switchFriendlyName = switchPort.GetInfo().GetFriendlyName(); switchFriendlyNames.Add(switchFriendlyName, switchPort); if (switchInfo.Capability != null) { IList <VParamType> retVals; if (switchType == SwitchType.Multi) { retVals = switchPort.Invoke(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName, null, ControlPort, switchInfo.Capability, ControlPortCapability); switchPort.Subscribe(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName, ControlPort, switchInfo.Capability, ControlPortCapability); if (retVals[0].Maintype() < 0) { logger.Log("SwitchController could not get current level for {0}", switchFriendlyName); } else { switchInfo.Level = (double)retVals[0].Value(); } } else { retVals = switchPort.Invoke(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpGetName, null, ControlPort, switchInfo.Capability, ControlPortCapability); switchPort.Subscribe(RoleSwitchBinary.RoleName, RoleSwitchBinary.OpGetName, ControlPort, switchInfo.Capability, ControlPortCapability); if (retVals[0].Maintype() < 0) { logger.Log("SwitchController could not get current level for {0}", switchFriendlyName); } else { bool boolLevel = (bool)retVals[0].Value(); switchInfo.Level = (boolLevel) ? 1 : 0; } } } }
//called when the lock is acquired and cameraPort is non-existent in the dictionary private void InitCamera(VPort cameraPort) { VCapability capability = GetCapability(cameraPort, Constants.UserSystem); //return if we didn't get a capability if (capability == null) { logger.Log("{0} didn't get a capability for {1}", this.ToString(), cameraPort.ToString()); return; } //otherwise, add this to our list of cameras logger.Log("{0} adding camera port {1}", this.ToString(), cameraPort.ToString()); CameraInfo cameraInfo = new CameraInfo(); cameraInfo.Capability = capability; cameraInfo.LastImageBytes = new byte[0]; cameraInfo.VideoWriter = null; cameraInfo.CurrVideoStartTime = DateTime.MinValue; cameraInfo.CurrVideoEndTime = DateTime.MinValue; registeredCameras.Add(cameraPort, cameraInfo); string cameraFriendlyName = cameraPort.GetInfo().GetFriendlyName(); cameraFriendlyNames.Add(cameraFriendlyName, cameraPort); cameraPort.Subscribe(RoleCamera.RoleName, RoleCamera.OpGetVideo, ControlPort, cameraInfo.Capability, ControlPortCapability); }
public override void PortRegistered(VPort port) { lock (this) { if (Role.ContainsRole(port, RoleValve.RoleName)) { VCapability capability = GetCapability(port, Constants.UserSystem); if (registeredValves.ContainsKey(port)) { registeredValves[port] = capability; } else { registeredValves.Add(port, capability); } if (capability != null) { port.Subscribe(RoleSensor.RoleName, RoleSensor.OpGetName, this.ControlPort, capability, this.ControlPortCapability); } } } }
/// <summary> /// called by (app) modules to subscribe to another port's role and operation pair /// </summary> /// <param name="port"></param> /// <param name="role"></param> /// <param name="opName"></param> /// <returns></returns> protected bool Subscribe(VPort port, Role role, string opName) { //first check the store if we have the capability VCapability capability = GetCapabilityFromStore(port); //if not, then try to get it from the platform if (capability == null) { capability = GetCapabilityFromPlatform(port); } //if capability is still null, throw exception if (capability == null) { throw new AccessViolationException("This module does not have access to this port"); } var operation = role.GetOperation(opName); if (operation == null) { throw new InvalidOperationException(opName + " is not a valid operation for Role " + role.Name()); } if (!operation.Subscribeable()) { throw new InvalidOperationException(opName + " is not a subscribable operation for Role " + role.Name()); } return(port.Subscribe(role.Name(), opName, ControlPort, capability, ControlPortCapability)); }
public bool Subscribe(string roleName, string opName, IPort fromPort, ICapability reqCap, ICapability respCap) { return(_view.Subscribe(roleName, opName, PortAdapter.C2V(fromPort), CapabilityAdapter.C2V(reqCap), CapabilityAdapter.C2V(respCap))); }
public override void PortRegistered(VPort port) { lock (this) { if (Role.ContainsRole(port, RoleCamera.RoleName)) { VCapability capability = GetCapability(port, Constants.UserSystem); if (cameraPorts.ContainsKey(port)) { cameraPorts[port] = capability; } else { cameraPorts.Add(port, capability); } logger.Log("{0} added camera port {1}", this.ToString(), port.ToString()); } //lets not monitor switches //if (Role.ContainsRole(port, RoleSwitchMultiLevel.RoleName)) //{ // if (port.GetInfo().GetFriendlyName().Equals(switchFriendlyName, StringComparison.CurrentCultureIgnoreCase)) // { // switchPort = port; // switchPortCapability = GetCapability(port, Constants.UserSystem); // if (switchPortCapability != null) // { // switchPort.Subscribe(RoleSwitchMultiLevel.RoleName, RoleSwitchMultiLevel.OpGetName, // this.ControlPort, switchPortCapability, this.ControlPortCapability); // } // } //} if (Role.ContainsRole(port, RoleSensor.RoleName)) { //if (port.GetInfo().GetFriendlyName().Equals(sensorFriendlyName, StringComparison.CurrentCultureIgnoreCase)) //{ // sensorPort = port; VCapability capability = GetCapability(port, Constants.UserSystem); if (registeredSensors.ContainsKey(port)) { registeredSensors[port] = capability; } else { registeredSensors.Add(port, capability); } if (capability != null) { port.Subscribe(RoleSensor.RoleName, RoleSensor.OpGetName, this.ControlPort, capability, this.ControlPortCapability); } //} } } }