/// <summary> /// Handles the SubscriptionAdded event of the suscrptions collection /// </summary> /// <param name="collection">The suscrptions collection</param> /// <param name="subscription">The subscription added</param> protected virtual void subscriptions_SubscriptionAdded(SharedVariableSubscriptionList collection, SharedVariableSubscription subscription) { if (subscription.SubscriptionType == SharedVariableSubscriptionType.Creation) { ReportCreationSubscribers(); } }
/// <summary> /// Initializes a new Instance of SharedVariable /// </summary> /// <param name="owner">The IModule object which this SharedVariable object is bound to</param> /// <param name="type">The type of the variable</param> /// <param name="name">The name of the variable</param> /// <param name="isArray">Indicates if the variable is an array</param> /// <param name="arraySize">If the variable is an array, the size of the array or -1 if the variable is not an array. Also a -1 value can be used to indicate dynamic size arrays</param> public SharedVariable(IModuleClient owner, string type, string name, bool isArray, int arraySize) { if (owner == null) { throw new ArgumentNullException("owner"); } if (name == null) { throw new ArgumentNullException("name"); } if (arraySize < -1) { throw new ArgumentOutOfRangeException("arraySize"); } if ((type == null) || type.StartsWith("var[")) { type = "var"; } if (!RxVarNameValidator.IsMatch(name)) { throw new ArgumentException("Invalid variable name", "name"); } this.owner = owner; this.type = type; this.name = name; this.size = -1; if (type == "var") { this.isArray = false; this.size = -1; } else { if (this.isArray = isArray) { this.size = arraySize; } else { this.size = -1; } } this.allowedWriters = new List <string>(); #if SharedVarsStoredAsRawString data = String.Empty; #else data = new byte[size]; #endif subscriptions = new SharedVariableSubscriptionList(this); subscriptions.SubscriptionAdded += new SubscriptionAddedRemovedEventHandler(subscriptions_SubscriptionAdded); rwLock = new ReaderWriterLock(); this.creationTime = DateTime.Now; }
/// <summary> /// Gets a standard SharedVariableInfo for serialization /// </summary> /// <returns></returns> public Robotics.API.SharedVariableInfo GetInfo() { Robotics.API.SharedVariableInfo info; Robotics.API.SubscriptionInfo[] subscriptions; Robotics.API.SharedVariableSubscriptionType sType; Robotics.API.SharedVariableReportType rType; info = new Robotics.API.SharedVariableInfo(this.Type, this.Name, this.IsArray, this.Size); info.CreationTime = this.creationTime; if (this.AllowedWriters.Count > 0) { info.AllowedWriters = this.AllowedWriters.ToArray(); } if (this.Subscriptions.Count < 1) { return(info); } subscriptions = new Robotics.API.SubscriptionInfo[this.Subscriptions.Count]; for (int i = 0; i < this.Subscriptions.Count; ++i) { switch (this.Subscriptions[i].SubscriptionType) { case SharedVariableSubscriptionType.Creation: sType = Robotics.API.SharedVariableSubscriptionType.Creation; break; case SharedVariableSubscriptionType.WriteAny: sType = Robotics.API.SharedVariableSubscriptionType.WriteAny; break; case SharedVariableSubscriptionType.WriteModule: sType = Robotics.API.SharedVariableSubscriptionType.WriteModule; break; default: case SharedVariableSubscriptionType.WriteOthers: sType = Robotics.API.SharedVariableSubscriptionType.WriteOthers; break; } switch (this.Subscriptions[i].ReportType) { case SharedVariableReportType.Notify: rType = Robotics.API.SharedVariableReportType.Notify; break; default: case SharedVariableReportType.SendContent: rType = Robotics.API.SharedVariableReportType.SendContent; break; } subscriptions[i] = new Robotics.API.SubscriptionInfo( info, this.Subscriptions[i].Subscriber.Name, sType, rType ); //if (this.Subscriptions[i].SubscriptionType == SharedVariableSubscriptionType.WriteModule) // subscriptions[i].WriterModule = this.Subscriptions[i].WriterModule; } return(info); }