예제 #1
0
        /// <summary>
        /// Updates the SharedVariable object with data provided from the blackboard due to a subscription
        /// </summary>
        /// <param name="variableType">The type of the variable specified by blackboard</param>
        /// <param name="variableName">The name of the variable specified by blackboard</param>
        /// <param name="isArray">Value that indicates if the variable specified by blackboard is an array</param>
        /// <param name="arraySize">The size of the variable specified by blackboard if it is an array</param>
        /// <param name="sData">The serialized data contained in the report</param>
        /// <param name="reportType">The type of report</param>
        /// <param name="subscriptionType">The type of subscription</param>
        /// <param name="writer">The name of the module which performed the write/create operation</param>
        /// <param name="ex">When this method returns contains null if the variable was updated successfully, or the exception to be thrown if the update failed</param>
        /// <returns>true if variable was updated successfully, false otherwise</returns>
        internal bool Update(string variableType, bool isArray, int arraySize, string variableName, string sData, SharedVariableReportType reportType,
                             SharedVariableSubscriptionType subscriptionType, string writer, out Exception ex)
        {
            SharedVariableReport report;
            SharedVariableInfo   variableInfo;

            variableInfo = new SharedVariableInfo(variableType, variableName, isArray, arraySize);
            report       = new SharedVariableReport(variableInfo, sData, reportType, subscriptionType, writer);
            return(Update(report, out ex));
        }
예제 #2
0
        /// <summary>
        /// Deserializes an ISharedVariableInfo object from a string
        /// </summary>
        /// <param name="serialized">String that contains the data to be deserialized</param>
        /// <param name="info">When this method returns contains a ISharedVariableInfo object created from the
        /// information provided in the input string if the serialization succeded,
        /// or false if the serialization failed</param>
        /// <param name="ex">When this method returns contains null if the variable information was deserialized
        /// successfully, or the exception to be thrown if the deserialization failed</param>
        /// <returns>true if the deserialization succeded, false otherwise</returns>
        public static bool Deserialize(string serialized, out SharedVariableInfo info, out Exception ex)
        {
            int cc = 0;

            string[]           writers;
            SubscriptionInfo[] subscriptions;
            DateTime           creationTime;

            info = null;
            ex   = null;
            if (String.IsNullOrEmpty(serialized))
            {
                ex = new ArgumentNullException("Invalid input string");
                return(false);
            }

            // 1. Deserialize variable information
            if (!DeserializeSVInfo(serialized, ref cc, out info, out ex))
            {
                info = null;
                return(false);
            }

            if (!DeserializeCreationTime(serialized, ref cc, out creationTime, out ex))
            {
                info = null;
                return(false);
            }

            // 2. Deserialize writers
            if (!DeserializeWriters(serialized, ref cc, out writers, out ex))
            {
                info = null;
                return(false);
            }

            // 3. Deserialize subscriptions information
            if (!DeserializeSubscriptions(info, serialized, ref cc, out subscriptions, out ex))
            {
                info = null;
                return(false);
            }

            // 4. Integrate package
            info.creationTime   = creationTime;
            info.subscriptions  = subscriptions;
            info.allowedWriters = writers;
            return(true);
        }
예제 #3
0
        private static bool DeserializeSubscription(SharedVariableInfo svInfo, string serialized, ref int cc, out SubscriptionInfo subscription, out Exception ex)
        {
            //int bcc;
            string subscriber;
            SharedVariableSubscriptionType sType;
            SharedVariableReportType       rType;
            string writer = null;

            subscription = null;
            if (!Scanner.ReadChar('{', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '{'");
                return(false);
            }

            if (!DeserializeSubscriber(serialized, ref cc, out subscriber, out ex))
            {
                return(false);
            }
            if (!DeserializeSubscriptionType(serialized, ref cc, out sType, out ex))
            {
                return(false);
            }
            if (!DeserializeReportType(serialized, ref cc, out rType, out ex))
            {
                return(false);
            }
            if ((sType == SharedVariableSubscriptionType.WriteModule) && !DeserializeSubscriptionWriter(serialized, ref cc, out writer, out ex))
            {
                return(false);
            }

            if (!Scanner.ReadChar('}', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '}'");
                return(false);
            }

            subscription                  = new SubscriptionInfo(svInfo);
            subscription.ModuleName       = subscriber;
            subscription.SubscriptionType = sType;
            subscription.ReportType       = rType;
            subscription.WriterModule     = writer;
            return(true);
        }
예제 #4
0
        /// <summary>
        /// Queries the Blackboard for updated information (writers and subscriptions) about the Shared Variable
        /// </summary>
        /// <param name="timeout">The amout of time to wait for a stat confirmation from blackboard</param>
        /// <param name="ex">When this method returns contains null if the variable information was
        /// updated successfully, or the exception to be thrown if the update failed</param>
        /// <returns>true if the information was updated successfully, false otherwise</returns>
        protected internal bool UpdateInfo(int timeout, out Exception ex)
        {
            Command            cmdStatVar;
            Response           rspStatVar;
            SharedVariableInfo varInfo;

            ex = null;
            if (this.CommandManager == null)
            {
                ex = new Exception("Cannot communicate with blackboard");
                return(false);
            }

            cmdStatVar = new Command("stat_var", this.Name);
            if (!this.CommandManager.SendAndWait(cmdStatVar, timeout, out rspStatVar))
            {
                ex = new Exception("No response from blackboard");
                return(false);
            }
            if (!rspStatVar.Success)
            {
                ex = new Exception("Unsupported command" + this.Name);
                return(false);
            }

            if (!SharedVariableInfo.Deserialize(rspStatVar.Parameters, out varInfo, out ex))
            {
                return(false);
            }

            if ((String.Compare(this.Name, varInfo.Name, false) != 0) ||
                (String.Compare(this.TypeName, varInfo.TypeName, false) != 0))
            {
                ex = new Exception("Invalid response. Variable type/name mismatch.");
                return(false);
            }

            this.creationTime   = varInfo.CreationTime;
            this.allowedWriters = varInfo.AllowedWriters;
            this.subscriptions  = varInfo.Subscriptions;
            return(true);
        }
예제 #5
0
        private static bool DeserializeSVInfo(string serialized, ref int cc, out SharedVariableInfo info, out Exception ex)
        {
            string variableType;
            string variableName;
            ushort uLength;
            int    length  = -1;
            bool   isArray = false;

            // 1. Initialize output values
            info = null;
            ex   = null;

            // 2. Extract variable type
            if (!Parser.XtractIdentifier(serialized, ref cc, out variableType))
            {
                ex = new Exception("Expected identifier (variable type)");
                return(false);
            }

            // 3. Get variable array data
            if (Scanner.ReadChar('[', serialized, ref cc))
            {
                length = Scanner.XtractUInt16(serialized, ref cc, out uLength) ? uLength : -1;
                if (!Scanner.ReadChar(']', serialized, ref cc))
                {
                    ex = new Exception("Expected ']'");
                    return(false);
                }
                isArray = true;
            }

            // 4. Get variable name
            Parser.SkipSpaces(serialized, ref cc);
            if (!Parser.XtractIdentifier(serialized, ref cc, out variableName))
            {
                ex = new Exception("Expected identifier (variable name)");
                return(false);
            }

            info = new SharedVariableInfo(variableType, variableName, isArray, length);
            return(true);
        }
예제 #6
0
        private static bool GetVariableInfo(ref string parameters, out ISharedVariableInfo info, out string data, out Exception ex)
        {
            SharedVariableInfo varInfo;
            string             type;
            bool   isArray;
            int    size;
            string name;
            int    cc;

            info    = null;
            ex      = null;
            data    = null;
            varInfo = new SharedVariableInfo();

            // 1. Get variable type
            cc = 0;
            if (!GetVariableType(ref parameters, ref cc, out type, out isArray, out size, out ex))
            {
                return(false);
            }
            varInfo.TypeName = type;
            varInfo.IsArray  = isArray;
            varInfo.Length   = size;

            // 2. Get variable name
            if (!GetVariableName(ref parameters, ref cc, out name, out ex))
            {
                return(false);
            }
            varInfo.Name = name;

            // 3. Get variable data
            if (!GetVariableData(ref parameters, ref cc, out data, out ex))
            {
                return(false);
            }

            info = varInfo;
            return(true);
        }
예제 #7
0
        private static bool DeserializeSubscriptions(SharedVariableInfo svInfo, string serialized, ref int cc, out SubscriptionInfo[] subscriptions, out Exception ex)
        {
            SubscriptionInfo        subscription;
            List <SubscriptionInfo> lstSubscription;

            subscriptions = null;
            ex            = null;
            Scanner.SkipSpaces(serialized, ref cc);
            if (!Scanner.ReadString("subscriptions=", serialized, ref cc))
            {
                return(true);
            }

            if (!Scanner.ReadChar('{', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '{'");
                return(false);
            }

            lstSubscription = new List <SubscriptionInfo>();
            while ((cc < serialized.Length) && (serialized[cc] == '{'))
            {
                if (!DeserializeSubscription(svInfo, serialized, ref cc, out subscription, out ex))
                {
                    return(false);
                }
                lstSubscription.Add(subscription);
            }

            if (!Scanner.ReadChar('}', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '}'");
                return(false);
            }

            subscriptions = lstSubscription.ToArray();
            return(true);
        }
        private static bool GetVariableInfo(ref string parameters, out ISharedVariableInfo info, out string data, out Exception ex)
        {
            SharedVariableInfo varInfo;
            string type;
            bool isArray;
            int size;
            string name;
            int cc;

            info = null;
            ex = null;
            data = null;
            varInfo = new SharedVariableInfo();

            // 1. Get variable type
            cc = 0;
            if (!GetVariableType(ref parameters, ref cc, out type, out isArray, out size, out ex))
                return false;
            varInfo.TypeName = type;
            varInfo.IsArray = isArray;
            varInfo.Length = size;

            // 2. Get variable name
            if (!GetVariableName(ref parameters, ref cc, out name, out ex))
                return false;
            varInfo.Name = name;

            // 3. Get variable data
            if (!GetVariableData(ref parameters, ref cc, out data, out ex))
                return false;

            info = varInfo;
            return true;
        }
        private static bool DeserializeSVInfo(string serialized, ref int cc, out SharedVariableInfo info, out Exception ex)
        {
            string variableType;
            string variableName;
            ushort uLength;
            int length = -1;
            bool isArray = false;

            // 1. Initialize output values
            info = null;
            ex = null;

            // 2. Extract variable type
            if (!Parser.XtractIdentifier(serialized, ref cc, out variableType))
            {
                ex = new Exception("Expected identifier (variable type)");
                return false;
            }

            // 3. Get variable array data
            if (Scanner.ReadChar('[', serialized, ref cc))
            {
                length = Scanner.XtractUInt16(serialized, ref cc, out uLength) ? uLength : -1;
                if (!Scanner.ReadChar(']', serialized, ref cc))
                {
                    ex = new Exception("Expected ']'");
                    return false;
                }
                isArray = true;
            }

            // 4. Get variable name
            Parser.SkipSpaces(serialized, ref cc);
            if (!Parser.XtractIdentifier(serialized, ref cc, out variableName))
            {
                ex = new Exception("Expected identifier (variable name)");
                return false;
            }

            info = new SharedVariableInfo(variableType, variableName, isArray, length);
            return true;
        }
예제 #10
0
        private static bool DeserializeSubscriptions(SharedVariableInfo svInfo, string serialized, ref int cc, out SubscriptionInfo[] subscriptions, out Exception ex)
        {
            SubscriptionInfo subscription;
            List<SubscriptionInfo> lstSubscription;

            subscriptions = null;
            ex = null;
            Scanner.SkipSpaces(serialized, ref cc);
            if (!Scanner.ReadString("subscriptions=", serialized, ref cc))
                return true;

            if (!Scanner.ReadChar('{', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '{'");
                return false;
            }

            lstSubscription = new List<SubscriptionInfo>();
            while ((cc < serialized.Length) && (serialized[cc] == '{'))
            {
                if (!DeserializeSubscription(svInfo, serialized, ref cc, out subscription, out ex))
                    return false;
                lstSubscription.Add(subscription);
            }

            if (!Scanner.ReadChar('}', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '}'");
                return false;
            }

            subscriptions = lstSubscription.ToArray();
            return true;
        }
예제 #11
0
        private static bool DeserializeSubscription(SharedVariableInfo svInfo, string serialized, ref int cc, out SubscriptionInfo subscription, out Exception ex)
        {
            //int bcc;
            string subscriber;
            SharedVariableSubscriptionType sType;
            SharedVariableReportType rType;
            string writer = null;

            subscription = null;
            if (!Scanner.ReadChar('{', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '{'");
                return false;
            }

            if (!DeserializeSubscriber(serialized, ref cc, out subscriber, out ex))
                return false;
            if (!DeserializeSubscriptionType(serialized, ref cc, out sType, out ex))
                return false;
            if (!DeserializeReportType(serialized, ref cc, out rType, out ex))
                return false;
            if ((sType == SharedVariableSubscriptionType.WriteModule) && !DeserializeSubscriptionWriter(serialized, ref cc, out writer, out ex))
                return false;

            if (!Scanner.ReadChar('}', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment, expected '}'");
                return false;
            }

            subscription = new SubscriptionInfo(svInfo);
            subscription.ModuleName = subscriber;
            subscription.SubscriptionType = sType;
            subscription.ReportType = rType;
            subscription.WriterModule = writer;
            return true;
        }
예제 #12
0
        /// <summary>
        /// Deserializes an ISharedVariableInfo object from a string
        /// </summary>
        /// <param name="serialized">String that contains the data to be deserialized</param>
        /// <param name="info">When this method returns contains a ISharedVariableInfo object created from the
        /// information provided in the input string if the serialization succeded,
        /// or false if the serialization failed</param>
        /// <param name="ex">When this method returns contains null if the variable information was deserialized
        /// successfully, or the exception to be thrown if the deserialization failed</param>
        /// <returns>true if the deserialization succeded, false otherwise</returns>
        public static bool Deserialize(string serialized, out SharedVariableInfo info, out Exception ex)
        {
            int cc = 0;
            string[] writers;
            SubscriptionInfo[] subscriptions;
            DateTime creationTime;

            info = null;
            ex = null;
            if (String.IsNullOrEmpty(serialized))
            {
                ex = new ArgumentNullException("Invalid input string");
                return false;
            }

            // 1. Deserialize variable information
            if (!DeserializeSVInfo(serialized, ref cc, out info, out ex))
            {
                info = null;
                return false;
            }

            if (!DeserializeCreationTime(serialized, ref cc, out creationTime, out ex))
            {
                info = null;
                return false;
            }

            // 2. Deserialize writers
            if (!DeserializeWriters(serialized, ref cc, out writers, out ex))
            {
                info = null;
                return false;
            }

            // 3. Deserialize subscriptions information
            if (!DeserializeSubscriptions(info, serialized, ref cc, out subscriptions, out ex))
            {
                info = null;
                return false;
            }

            // 4. Integrate package
            info.creationTime = creationTime;
            info.subscriptions = subscriptions;
            info.allowedWriters = writers;
            return true;
        }
예제 #13
0
 /// <summary>
 /// Deserializes an ISharedVariableInfo object from a string
 /// </summary>
 /// <param name="serialized">String that contains the data to be deserialized</param>
 /// <param name="info">When this method returns contains a ISharedVariableInfo object created from the
 /// information provided in the input string if the serialization succeded,
 /// or false if the serialization failed</param>
 /// <returns>true if the deserialization succeded, false otherwise</returns>
 public static bool Deserialize(string serialized, out SharedVariableInfo info)
 {
     Exception ex;
     return Deserialize(serialized, out info, out ex);
 }
예제 #14
0
        /// <summary>
        /// Deserializes an ISharedVariableInfo object from a string
        /// </summary>
        /// <param name="serialized">String that contains the data to be deserialized</param>
        /// <param name="info">When this method returns contains a ISharedVariableInfo object created from the
        /// information provided in the input string if the serialization succeded,
        /// or false if the serialization failed</param>
        /// <returns>true if the deserialization succeded, false otherwise</returns>
        public static bool Deserialize(string serialized, out SharedVariableInfo info)
        {
            Exception ex;

            return(Deserialize(serialized, out info, out ex));
        }