コード例 #1
0
        private static bool GetSubscriptionType(ref string parameters, out SharedVariableSubscriptionType subscriptionType, out Exception ex)
        {
            int    pos;
            string sSubscriptionType;

            subscriptionType = SharedVariableSubscriptionType.WriteAny;
            ex = null;

            pos = parameters.LastIndexOf('%');
            if (pos == -1)
            {
                ex = new Exception("Invalid parameters. No subscription type found.");
                return(false);
            }
            sSubscriptionType = parameters.Substring(pos + 1).Trim();
            parameters        = parameters.Substring(0, pos);

            try { subscriptionType = (SharedVariableSubscriptionType)Enum.Parse(typeof(SharedVariableSubscriptionType), sSubscriptionType, true); }
            catch
            {
                ex = new Exception("Invalid parameters. Invalid subscription type.");
                return(false);
            }
            return(true);
        }
コード例 #2
0
ファイル: SubscriptionInfo.cs プロジェクト: ewin66/Robotics
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo
 /// Construtor provided for serialization purposes only
 /// </summary>
 /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
 internal SubscriptionInfo(ISharedVariableInfo variableInfo)
 {
     this.VariableInfo     = variableInfo;
     this.moduleName       = null;
     this.subscriptionType = SharedVariableSubscriptionType.None;
     this.reportType       = SharedVariableReportType.None;
     this.writerModule     = null;
 }
コード例 #3
0
ファイル: SubscriptionInfo.cs プロジェクト: ewin66/Robotics
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo.
 /// Default construtor provided for serialization purposes only
 /// </summary>
 public SubscriptionInfo()
 {
     this.variableInfo     = null;
     this.moduleName       = null;
     this.writerModule     = null;
     this.subscriptionType = SharedVariableSubscriptionType.None;
     this.reportType       = SharedVariableReportType.None;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of SharedVariableSubscription
 /// </summary>
 /// <param name="variableName">The name of the shared variable</param>
 /// <param name="subscriber">The IModule object that subscribes to the shared variable</param>
 /// <param name="subscriptionType">The type of subscription to the shared variable</param>
 /// <param name="reportType">The report type choosen by the subscriber</param>
 /// <param name="variableSize">The size the variable must match to send a subscription notification. A -1 value indicates any size</param>
 public SharedVariableSubscription(string variableName, IModuleClient subscriber, SharedVariableSubscriptionType subscriptionType, SharedVariableReportType reportType, int variableSize)
 {
     this.reportType       = reportType;
     this.subscriber       = subscriber;
     this.subscriptionType = subscriptionType;
     this.variableName     = variableName;
     this.variableSize     = variableSize;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo.
 /// Default construtor provided for serialization purposes only
 /// </summary>
 public SubscriptionInfo()
 {
     this.variableInfo = null;
     this.moduleName = null;
     this.writerModule = null;
     this.subscriptionType = SharedVariableSubscriptionType.None;
     this.reportType = SharedVariableReportType.None;
 }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of SubscriptionInfo
        /// </summary>
        /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
        /// <param name="moduleName">The name of the subscriber module</param>
        /// <param name="subscriptionType">The subscription type for the subscriber module</param>
        /// <param name="reportType">The report type for the subscription of the subscriber module</param>
        /// <param name="writerModule">The name of the writer module for subscription types which allows to set an specific module</param>
        public SubscriptionInfo(ISharedVariableInfo variableInfo, string moduleName,
			SharedVariableSubscriptionType subscriptionType, SharedVariableReportType reportType, string writerModule)
        {
            this.VariableInfo = variableInfo;
            this.ModuleName = moduleName;
            this.SubscriptionType = subscriptionType;
            this.ReportType = reportType;
            this.WriterModule = writerModule;
        }
コード例 #7
0
ファイル: SubscriptionInfo.cs プロジェクト: ewin66/Robotics
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo
 /// </summary>
 /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
 /// <param name="moduleName">The name of the subscriber module</param>
 /// <param name="subscriptionType">The subscription type for the subscriber module</param>
 /// <param name="reportType">The report type for the subscription of the subscriber module</param>
 /// <param name="writerModule">The name of the writer module for subscription types which allows to set an specific module</param>
 public SubscriptionInfo(ISharedVariableInfo variableInfo, string moduleName,
                         SharedVariableSubscriptionType subscriptionType, SharedVariableReportType reportType, string writerModule)
 {
     this.VariableInfo     = variableInfo;
     this.ModuleName       = moduleName;
     this.SubscriptionType = subscriptionType;
     this.ReportType       = reportType;
     this.WriterModule     = writerModule;
 }
コード例 #8
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));
        }
コード例 #9
0
		/// <summary>
		/// Initializes a new instance of SharedVariableSubscriptionReport
		/// </summary>
		/// <param name="variable">The SharedVariable object that generates this report</param>
		/// <param name="subscriptionType">The type of subscription of the report received</param>
		/// <param name="reportType">The type of report received</param>
		/// <param name="writer">The name of the module that performed the write or create operation</param>
		/// <param name="value">The value of the data contained in the report</param>
		public SharedVariableSubscriptionReport(SharedVariable variable, SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, string writer, T value)
		{
			if (variable == null)
				throw new ArgumentNullException();
			this.reportType = reportType;
			this.subscriptionType = subscriptionType;
			this.value = value;
			this.variable = variable;
			this.writer = writer;
		}
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of SharedVariableReport
        /// </summary>
        /// <param name="variableInfo">The information of the related shared variable</param>
        /// <param name="serializedData">The serialized value of the shared variable</param>
        /// <param name="reportType">The type of the report</param>
        /// <param name="subscriptionType">The type of the subscription</param>
        /// <param name="writer"> The name of the module which performed the write/create operation</param>
        public SharedVariableReport(ISharedVariableInfo variableInfo, string serializedData,
			SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, string writer)
        {
            if (variableInfo == null)
                throw new ArgumentNullException();
            this.serializedData = serializedData;
            this.variableInfo = variableInfo;
            this.reportType = reportType;
            this.subscriptionType = subscriptionType;
            this.writer = writer;
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of SharedVariableReport
 /// </summary>
 /// <param name="variableInfo">The information of the related shared variable</param>
 /// <param name="serializedData">The serialized value of the shared variable</param>
 /// <param name="reportType">The type of the report</param>
 /// <param name="subscriptionType">The type of the subscription</param>
 /// <param name="writer"> The name of the module which performed the write/create operation</param>
 public SharedVariableReport(ISharedVariableInfo variableInfo, string serializedData,
                             SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, string writer)
 {
     if (variableInfo == null)
     {
         throw new ArgumentNullException();
     }
     this.serializedData   = serializedData;
     this.variableInfo     = variableInfo;
     this.reportType       = reportType;
     this.subscriptionType = subscriptionType;
     this.writer           = writer;
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of SharedVariable
 /// </summary>
 /// <param name="commandManager">The CommandManager object used to communicate with the Blackboard</param>
 /// <param name="variableName">The name of the variable in the Blackboard</param>
 /// <param name="value">The value to store in the shared variable if it does not exist</param>
 /// <param name="initialize">Indicates if the shared variable will be automatically initialized if the commandManager is different from null</param>
 /// <remarks>If there is no variable with the provided name in the blackboard, a new variable with the asociated name is created</remarks>
 public SharedVariable(CommandManager commandManager, string variableName, T value, bool initialize)
 {
     this.initialized            = false;
     this.commandManager         = commandManager;
     this.subscriptionReportType = SharedVariableReportType.Unknown;
     this.subscriptionType       = SharedVariableSubscriptionType.Unknown;
     this.variableName           = variableName;
     this.lastUpdate             = DateTime.MinValue;
     this.defaultValue           = value;
     this.serializer             = null;
     this.deserializer           = null;
     if ((commandManager != null) && initialize)
     {
         Initialize(value);
     }
 }
コード例 #13
0
ファイル: Module.cs プロジェクト: ewin66/Robotics
 /// <summary>
 /// Adds a SharedVariable to the CommandManager of the module.
 /// If the shared variable is already registered, the reference is updated, otherwise a new shared variable of the type is created
 /// </summary>
 /// <param name="sharedVariable">A shared variable object used to create the new SharedVariable or update the reference</param>
 /// <param name="reportType">The type of report required for subscription</param>
 /// <param name="subscriptionType">The type of subscription</param>
 /// <param name="updateEventHandler">A delegate that represents the method that will handle the Updated event of the shared variable</param>
 public void AddSharedVariable <T>(ref T sharedVariable, SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, SharedVariableUpdatedEventHadler updateEventHandler) where T : SharedVariable
 {
     this.cmdMan.AddSharedVariable(ref sharedVariable, reportType, subscriptionType, updateEventHandler);
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo
 /// Construtor provided for serialization purposes only
 /// </summary>
 /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
 internal SubscriptionInfo(ISharedVariableInfo variableInfo)
 {
     this.VariableInfo = variableInfo;
     this.moduleName = null;
     this.subscriptionType = SharedVariableSubscriptionType.None;
     this.reportType = SharedVariableReportType.None;
     this.writerModule = null;
 }
コード例 #15
0
        private static bool DeserializeSubscriptionType(string serialized, ref int cc, out SharedVariableSubscriptionType sType, out Exception ex)
        {
            int bcc;

            ex    = null;
            sType = SharedVariableSubscriptionType.Unknown;
            if (!Scanner.ReadString(", sType=", serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment (subscription type), expected ','");
                return(false);
            }
            bcc = cc;
            if (!Scanner.AdvanceToChar(',', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment (subscription type), expected ','");
                return(false);
            }

            try
            {
                sType = (SharedVariableSubscriptionType)Enum.Parse(typeof(SharedVariableSubscriptionType), serialized.Substring(bcc, cc - bcc));
            }
            catch
            {
                ex = new Exception("Invalid value for subscription type");
                return(false);
            }
            return(true);
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new instance of SubscriptionInfo
        /// </summary>
        /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
        /// <param name="moduleName">The name of the subscriber module</param>
        /// <param name="subscriptionType">The subscription type for the subscriber module</param>
        /// <param name="reportType">The report type for the subscription of the subscriber module</param>
        public SubscriptionInfo(ISharedVariableInfo variableInfo, string moduleName,
			SharedVariableSubscriptionType subscriptionType, SharedVariableReportType reportType)
            : this(variableInfo, moduleName, subscriptionType, reportType, null)
        {
        }
コード例 #17
0
        private static bool GetSubscriptionType(ref string parameters, out SharedVariableSubscriptionType subscriptionType, out Exception ex)
        {
            int pos;
            string sSubscriptionType;

            subscriptionType = SharedVariableSubscriptionType.WriteAny;
            ex = null;

            pos = parameters.LastIndexOf('%');
            if (pos == -1)
            {
                ex = new Exception("Invalid parameters. No subscription type found.");
                return false;
            }
            sSubscriptionType = parameters.Substring(pos + 1).Trim();
            parameters = parameters.Substring(0, pos);

            try { subscriptionType = (SharedVariableSubscriptionType)Enum.Parse(typeof(SharedVariableSubscriptionType), sSubscriptionType, true); }
            catch
            {
                ex = new Exception("Invalid parameters. Invalid subscription type.");
                return false;
            }
            return true;
        }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of SharedVariableSubscription
 /// </summary>
 /// <param name="variableName">The name of the shared variable</param>
 /// <param name="subscriber">The IModule object that subscribes to the shared variable</param>
 /// <param name="subscriptionType">The type of subscription to the shared variable</param>
 /// <param name="variableSize">The size the variable must match to send a subscription notification. A -1 value indicates any size</param>
 public SharedVariableSubscription(string variableName, IModuleClient subscriber, SharedVariableSubscriptionType subscriptionType, int variableSize)
     : this(variableName, subscriber, subscriptionType, SharedVariableReportType.Notify, variableSize)
 {
 }
コード例 #19
0
        /// <summary>
        /// Creates a new SharedVariableSubscription object using the parameters included in a command
        /// </summary>
        /// <param name="command">Command which parameters will be parsed</param>
        /// <returns>A SharedVariableSubscription object that represents the subscription request</returns>
        public static SharedVariableSubscription Parse(Command command)
        {
            string var;
            string sType;
            string rType;
            SharedVariableReportType       reportType;
            SharedVariableSubscriptionType subscriptionType;
            int size;

            Match m = RxAddSubscriptionValidator.Match(command.Parameters);

            if (!m.Success)
            {
                throw new ArgumentException("Invalid parameters in command", "command");
            }

            var   = m.Result("${var}");
            sType = m.Result("${sType}");
            rType = m.Result("${rType}");
            if (!Int32.TryParse(m.Result("${size}"), out size))
            {
                size = -1;
            }

            #region Switch Subscription Type

            switch (sType)
            {
            case "creation":
                subscriptionType = SharedVariableSubscriptionType.Creation;
                break;

            case "writeany":
                subscriptionType = SharedVariableSubscriptionType.WriteAny;
                break;

            case "writeothers":
                subscriptionType = SharedVariableSubscriptionType.WriteOthers;
                break;

            case "writemodule":
                subscriptionType = SharedVariableSubscriptionType.WriteModule;
                throw new Exception("Unsupported option");
            //break;

            default:
                subscriptionType = SharedVariableSubscriptionType.WriteOthers;
                break;
            }

            #endregion

            #region Switch Report Type
            switch (rType)
            {
            case "content":

                reportType = SharedVariableReportType.SendContent;
                break;

            case "notify":
                reportType = SharedVariableReportType.Notify;
                break;

            default:
                reportType = SharedVariableReportType.Notify;
                break;
            }
            #endregion

            return(new SharedVariableSubscription(var, command.Source, subscriptionType, reportType, size));
        }
コード例 #20
0
        private static bool DeserializeSubscriptionType(string serialized, ref int cc, out SharedVariableSubscriptionType sType, out Exception ex)
        {
            int bcc;

            ex = null;
            sType = SharedVariableSubscriptionType.Unknown;
            if (!Scanner.ReadString(", sType=", serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment (subscription type), expected ','");
                return false;
            }
            bcc = cc;
            if (!Scanner.AdvanceToChar(',', serialized, ref cc))
            {
                ex = new Exception("Invalid subscriptions segment (subscription type), expected ','");
                return false;
            }

            try
            {
                sType = (SharedVariableSubscriptionType)Enum.Parse(typeof(SharedVariableSubscriptionType), serialized.Substring(bcc, cc - bcc));
            }
            catch
            {
                ex = new Exception("Invalid value for subscription type");
                return false;
            }
            return true;
        }
コード例 #21
0
 /// <summary>
 /// Request the blackbard to notify each time the shared variable is written
 /// </summary>
 /// <param name="reportType">The type of report. This afects the event that will be raised when the variable is written</param>
 /// <param name="subscriptionType">The type of subscription</param>
 /// <param name="timeout">The timeout for each subscription attempt</param>
 /// <param name="attempts">The number of subscription attempts to perform</param>
 public virtual void Subscribe(SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, TimeSpan timeout, int attempts)
 {
     Subscribe(reportType, subscriptionType, timeout.Milliseconds, attempts);
 }
コード例 #22
0
 /// <summary>
 /// Request the blackbard to notify each time the shared variable is written
 /// </summary>
 /// <param name="reportType">The type of report. This afects the event that will be raised when the variable is written</param>
 /// <param name="subscriptionType">The type of subscription</param>
 /// <param name="timeout">The timeout for each subscription attempt in milliseconds</param>
 /// <param name="attempts">The number of subscription attempts to perform</param>
 public abstract void Subscribe(SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, int timeout, int attempts);
コード例 #23
0
 /// <summary>
 /// Request the blackbard to notify each time the shared variable is written
 /// </summary>
 /// <param name="reportType">The type of report. This afects the event that will be raised when the variable is written</param>
 /// <param name="subscriptionType">The type of subscription</param>
 /// <param name="attempts">The number of subscription attempts to perform</param>
 public virtual void Subscribe(SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, int attempts)
 {
     Subscribe(reportType, subscriptionType, 500, attempts);
 }
コード例 #24
0
 /// <summary>
 /// Request the blackbard to notify each time the shared variable is written
 /// </summary>
 /// <param name="reportType">The type of report. This afects the event that will be raised when the variable is written</param>
 /// <param name="subscriptionType">The type of subscription</param>
 public virtual void Subscribe(SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType)
 {
     Subscribe(reportType, subscriptionType, 500, 3);
 }
コード例 #25
0
 /// <summary>
 /// Request the blackbard to notify each time the shared variable is written
 /// </summary>
 /// <param name="subscriptionType">The type of subscription</param>
 /// <remarks>The type of report is set to Notify and the type of subscription is set to WriteOthers</remarks>
 public virtual void Subscribe(SharedVariableSubscriptionType subscriptionType)
 {
     Subscribe(SharedVariableReportType.Notify, subscriptionType);
 }
コード例 #26
0
        /// <summary>
        /// Request the blackbard to notify each time the shared variable is written
        /// </summary>
        /// <param name="reportType">The type of report. This afects the event that will be raised when the variable is written</param>
        /// <param name="subscriptionType">The type of subscription</param>
        /// <param name="timeout">The timeout for each subscription attempt in milliseconds</param>
        /// <param name="attempts">The number of subscription attempts to perform</param>
        public override void Subscribe(SharedVariableReportType reportType, SharedVariableSubscriptionType subscriptionType, int timeout, int attempts)
        {
            if (this.commandManager == null)
            {
                throw new Exception("Cannot communicate with blackboard");
            }

            //if ((this.ValueChanged == null) && (this.WriteNotification == null))
            //	throw new Exception("Subscription failed. SharedVariable.ValueChanged or SharedVariable.WriteNotification events must be handled first");

            Command  cmdSubscribe;
            Response rspSubscribe;
            string   sType;
            string   rType;
            string   parameters;
            bool     success;
            int      count;

            #region Switch Subscription Type

            switch (subscriptionType)
            {
            case SharedVariableSubscriptionType.None:
                throw new ArgumentException("Invalid SharedVariableSubscriptionType value");
            //Unsubscribe();
            //return;

            case SharedVariableSubscriptionType.Unknown:
                throw new ArgumentException("Invalid SharedVariableSubscriptionType value");

            case SharedVariableSubscriptionType.Creation:
                sType = "creation";
                break;

            case SharedVariableSubscriptionType.WriteAny:
                sType = "writeany";
                break;

            case SharedVariableSubscriptionType.WriteOthers:
                sType = "writeothers";
                break;

            case SharedVariableSubscriptionType.WriteModule:
                sType = "writemodule";
                throw new Exception("Unsupported option");
            //break;

            default:
                sType            = "writeothers";
                subscriptionType = SharedVariableSubscriptionType.WriteOthers;
                break;
            }

            #endregion

            #region Switch Report Type
            switch (reportType)
            {
            case SharedVariableReportType.None:
                throw new ArgumentException("Invalid SharedVariableReportType value");
            //Unsubscribe();
            //return;

            case SharedVariableReportType.Unknown:
                throw new ArgumentException("Invalid SharedVariableReportType value");

            case SharedVariableReportType.SendContent:

                rType = "content";
                break;

            case SharedVariableReportType.Notify:
                rType = "notify";
                break;

            default:
                rType = "notify";
                break;
            }
            #endregion

            parameters = variableName + " subscribe=" + sType + " report=" + rType;

            cmdSubscribe = new Command("subscribe_var", parameters);
            success      = false;
            count        = 0;
            do
            {
                ++count;
                if (!commandManager.SendAndWait(cmdSubscribe, timeout, out rspSubscribe))
                {
                    continue;
                }
                success = rspSubscribe.Success;
            } while (!success && (count < attempts));

            if (!success)
            {
                if (rspSubscribe == null)
                {
                    throw new Exception("No response from blackboard");
                }
                throw new Exception("Subscription failed");
            }
            this.SubscriptionReportType = reportType;
            this.SubscriptionType       = subscriptionType;
        }
コード例 #27
0
ファイル: SubscriptionInfo.cs プロジェクト: ewin66/Robotics
 /// <summary>
 /// Initializes a new instance of SubscriptionInfo
 /// </summary>
 /// <param name="variableInfo">The object which contains information about the shared variable related to the subscription</param>
 /// <param name="moduleName">The name of the subscriber module</param>
 /// <param name="subscriptionType">The subscription type for the subscriber module</param>
 /// <param name="reportType">The report type for the subscription of the subscriber module</param>
 public SubscriptionInfo(ISharedVariableInfo variableInfo, string moduleName,
                         SharedVariableSubscriptionType subscriptionType, SharedVariableReportType reportType)
     : this(variableInfo, moduleName, subscriptionType, reportType, null)
 {
 }