Exemple #1
0
        public void SendMsgToCamera(string cameraControl, string cameraFriendlyName)
        {
            if (cameraFriendlyNames.ContainsKey(cameraFriendlyName))
            {
                VPort cameraPort = cameraFriendlyNames[cameraFriendlyName];

                if (registeredCameras.ContainsKey(cameraPort))
                {
                    IList <VParamType> retVal = null;

                    if (cameraControl.Equals(RolePTZCamera.OpZommOutName) || cameraControl.Equals(RolePTZCamera.OpZoomInName))
                    {
                        retVal = cameraPort.Invoke(RolePTZCamera.RoleName, cameraControl, new List <VParamType>(),
                                                   ControlPort, registeredCameras[cameraPort].Capability, ControlPortCapability);
                    }
                    else
                    {
                        retVal = cameraPort.Invoke(RolePTCamera.RoleName, cameraControl, new List <VParamType>(),
                                                   ControlPort, registeredCameras[cameraPort].Capability, ControlPortCapability);
                    }

                    if (retVal.Count != 0 && retVal[0].Maintype() == (int)ParamType.SimpleType.error)
                    {
                        logger.Log("Got error while controlling camera {0} with controlType {1}: {2}", cameraFriendlyName, cameraControl, retVal[0].Value().ToString());
                    }
                }
            }
        }
        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;
                    }
                }
            }
        }
Exemple #3
0
 public IListContract <IParamType> Invoke(string roleName, string opName, IListContract <IParamType> parameters, IPort p, ICapability reqCap, ICapability respCap)
 {
     return(CollectionAdapters.ToIListContract <VParamType, IParamType>(_view.Invoke(roleName, opName,
                                                                                     CollectionAdapters.ToIList <IParamType, VParamType>(parameters, BaseTypeAdapter.C2V, BaseTypeAdapter.V2C),
                                                                                     PortAdapter.C2V(p),
                                                                                     CapabilityAdapter.C2V(reqCap),
                                                                                     CapabilityAdapter.C2V(respCap)),
                                                                        BaseTypeAdapter.V2C, BaseTypeAdapter.C2V));
 }
Exemple #4
0
        /// <summary>
        /// Called by (app) modules to invoke operations
        /// </summary>
        /// <param name="toPort"></param>
        /// <param name="role"></param>
        /// <param name="opName"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public IList <VParamType> Invoke(VPort toPort, Role role, string opName, params ParamType[] values)
        {
            //first check the store if we have the capability
            VCapability capability = GetCapabilityFromStore(toPort);

            //if not, then try to get it from the platform
            if (capability == null)
            {
                capability = GetCapabilityFromPlatform(toPort);
            }

            //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());
            }

            //check the number of parameters
            if (values.Length != operation.Parameters().Count)
            {
                throw new ArgumentException("Incorrect number of arguments for operation " + opName);
            }

            //check the types of arguments
            for (int index = 0; index < values.Length; index++)
            {
                if ((values[index].Maintype() != operation.Parameters()[index].Maintype()))
                {
                    throw new ArgumentException(String.Format("Argument {0} is of invalid type. Expected {1}. Got {2}.", index, (ParamType.SimpleType)operation.Parameters()[index].Maintype(), (ParamType.SimpleType)values[index].Maintype()));
                }
            }

            //now invoke the operation
            IList <VParamType> retVals = toPort.Invoke(role.Name(), opName, values, ControlPort, capability, ControlPortCapability);

            //if we got an error, pass it along
            if (retVals.Count >= 1 && retVals[0].Maintype() == (int)ParamType.SimpleType.error)
            {
                return(retVals);
            }

            //if we didn't get an error, sanity check the return values

            //check the number of elements
            if (retVals.Count != operation.ReturnValues().Count)
            {
                throw new ArgumentException("Incorrect number of return values for operation " + opName);
            }

            //check the types of elements in return values
            for (int index = 0; index < retVals.Count; index++)
            {
                if ((retVals[index].Maintype() != operation.ReturnValues()[index].Maintype()))
                {
                    throw new ArgumentException(String.Format("Return value {0} is of invalid type. Expected {1}. Got {2}.", index, (ParamType.SimpleType)operation.ReturnValues()[index].Maintype(), (ParamType.SimpleType)retVals[index].Maintype()));
                }
            }

            //otherwise, lets return these values
            return(retVals);
        }