Beispiel #1
0
		} //	end ctr


		//-
		#endregion

		#region //	Public Methods
		//------------------------

		/// <summary>
		///  Adds a namespace element as child to a namespace element
		/// </summary>
		/// <param name="aChild">Child to be added. Checks if the child provided is a <see cref="DaAddressSpaceElement"/></param>
		/// <returns>
		/// <line>true	- Child successfully. </line>
		/// <line>false	- Child was not added. If fails, the Child should be released by the user.</line>
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="AddChild"]/doc/*'
		///	/>
		public override bool AddChild(AddressSpaceElement aChild)
		{
			if (!HasChildren)
			{
				Application.Instance.Trace(
					EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
					"DaAddressSpaceElement.AddChild", "This element does not allow childred");
				return false;
			} //	end if

			DaAddressSpaceElement child = aChild as DaAddressSpaceElement;

			if (child == null)
			{
				Application.Instance.Trace(
					EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
					"DaAddressSpaceElement.AddChild", "Invalid child provided");
				return false;
			} //	end if

			//	only add the child if no handle assigned
			if (child.ObjectHandle == 0)
			{
				OTSAddressSpaceElementData data = new OTSAddressSpaceElementData();

				data.m_name = Marshal.StringToCoTaskMemUni(child.Name);
				data.m_itemID = Marshal.StringToCoTaskMemUni(
					Name + Application.Instance.AddressSpaceDelimiter + child.Name);

				data.m_accessRights = (byte) child.AccessRights;
				data.m_ioMode = (byte) child.IoMode;
				data.m_datatype = ValueQT.GetVartype(child.Datatype);
				data.m_hasChildren = Convert.ToByte(child.HasChildren);
				data.m_isBrowsable = Convert.ToByte(child.IsBrowsable);
				data.m_elementType = (byte) EnumAddressSpaceElementType.DA;
				data.m_userData = child.UserData;

				Application.Instance.DaAddressSpaceRoot.AddElementToArray(child);

				int result = OTBFunctions.OTSAddAddressSpaceElement(m_objectHandle, data, out child.m_objectHandle);
				Marshal.FreeCoTaskMem(data.m_name);
				Marshal.FreeCoTaskMem(data.m_itemID);

				if (!ResultCode.SUCCEEDED(result))
				{
					result = Application.Instance.DaAddressSpaceRoot.RemoveElementFromArray(child);
					System.Diagnostics.Debug.Assert(ResultCode.SUCCEEDED(result),
					                                "RemoveElementFromArray has failed");
					return false;
				} //	end if ... else
			}
			else
			{
				Application.Instance.DaAddressSpaceRoot.AddElementToArray(child);
			} //	end if ... else

			//	end if

			return base.AddChild(aChild);
		} //	end AddChild
		} //	end CreateInternalAeAddressSpaceElement


		/// <summary>
		/// Toolkit internal creator of a <see cref="DaRequest"/>. By overloading this method, the user can determine creation of custom Request objects.
		/// </summary>
		/// <returns></returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="Creator"]/
		///		method[@name="CreateRequest"]/doc/*'
		///	/>
		public virtual DaRequest CreateRequest(
			EnumTransactionType aTransactionType,
			uint aSessionHandle,
			DaAddressSpaceElement anElement,
			int aPropertyId,
			uint aRequestHandle)
		{
			return new DaRequest(aTransactionType, aSessionHandle, anElement, aPropertyId, aRequestHandle);
		} //	end CreateRequest
Beispiel #3
0
		} //	end AddChild


		/// <summary>
		/// Removes the child if there is any. The entire branch of the aChild will be removed as well from the address space.
		/// </summary>
		/// <param name="aChild">AddressSpaceElement child to be removed from this instance</param>
		/// <returns>
		/// true	- aChild removed
		/// false	- aChild was not removed
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceElement"]/
		///		method[@name="RemoveChild"]/doc/*'
		///	/>
		public override bool RemoveChild(AddressSpaceElement aChild)
		{
			if (!HasChildren)
			{
				//	just log a warning, but proceed then with the removal attempt
				Application.Instance.Trace(
					EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
					"DaAddressSpaceElement.RemoveChild", "This element does not allow childred");
			} //	end if

			DaAddressSpaceElement child = aChild as DaAddressSpaceElement;

			if (child == null)
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild", "Invalid child provided");
				return false;
			} //	end if

			if (child.HasChildren)
			{
				//	Remove the clildren of the child
				ArrayList otherChildren = child.GetChildren();

				foreach (AddressSpaceElement element in otherChildren)
				{
					child.RemoveChild(element);
				} //	end for
			} //	end if

			int result = OTBFunctions.OTSRemoveAddressSpaceElement(child.ObjectHandle);
			if (!ResultCode.SUCCEEDED(result))
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild",
				                           "OTSRemoveAddressSpaceElement has failed with code" + result.ToString());
				return false;
			} //	end if

			result = Application.Instance.DaAddressSpaceRoot.RemoveElementFromArray(child);
			if (!ResultCode.SUCCEEDED(result))
			{
				Application.Instance.Trace(EnumTraceLevel.WRN, EnumTraceGroup.OPCSERVER,
				                           "DaAddressSpaceElement.RemoveChild",
				                           "RemoveElementFromArray has failed with code" + result.ToString());
				return false;
			} //	end if

			return base.RemoveChild(aChild);
		} //	end RemoveChild
		//-----------------------------

		/// <summary>
		/// Default public constructor
		/// </summary>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaRequest"]/
		///		ctor[@name="DaRequest"]/doc/*'
		///	/>
		public DaRequest(
			EnumTransactionType aTransactionType,
			uint aSessionHandle,
			DaAddressSpaceElement anElement,
			int aPropertyId,
			uint aRequestHandle)
		{
			m_transactionType = aTransactionType;
			m_sessionHandle = aSessionHandle;
			m_requestHandle = aRequestHandle;
			m_propertyId = aPropertyId;
			m_addressSpaceElement = anElement;
			m_transactionKey = 0;
			m_result = EnumResultCode.E_NOTIMPL;
			m_requestState = EnumRequestState.CREATED;

			if (m_addressSpaceElement != null)
			{
				OTBFunctions.OTSAckRequestElement(m_addressSpaceElement.ObjectHandle);
			}
		} //	end ctr
Beispiel #5
0
		//-
		#endregion

		#region //	Internal Methods
		//--------------------------

		/// <summary>
		/// called to change the items structure
		/// </summary>
		internal uint ChangeItems(uint aCount, IntPtr anItemDataPointer)
		{
			bool errorFound = false;

			if (anItemDataPointer == IntPtr.Zero || aCount == 0)
			{
				return (uint) EnumResultCode.S_FALSE;
			} //	end if

			IntPtr currentPointer = anItemDataPointer;

			lock (m_elements.SyncRoot) // enumerating
			{
				for (int i = 0; i < aCount; i++)
				{
					OTSItemData itemData = (OTSItemData) Marshal.PtrToStructure(currentPointer, typeof (OTSItemData));
					currentPointer = new IntPtr(currentPointer.ToInt64() + Marshal.SizeOf(typeof (OTSItemData)));

					DaAddressSpaceElement element = GetElementFromArray(itemData.m_object.m_userData) as DaAddressSpaceElement;

					if (element != null)
					{
						bool active = itemData.m_active != 0;
						element.Change(active, itemData.m_sampleRate);
					}
					else
					{
						errorFound = true;
					} //	end if ... else
				} //	end for
			}

			if (this.ActivationStateUpdated != null)
			{
				this.ActivationStateUpdated();
			} //	end if

			return (uint) (errorFound ? EnumResultCode.E_FAIL : EnumResultCode.S_OK);
		} //	end ChangeItems
Beispiel #6
0
		} //	end ValuesChanged


		/// <summary>
		/// Set a new set of ValueQT values to the Elements provided.
		/// </summary>
		/// <param name="anElementsList">the list of elements.</param>
		/// <param name="aValueList">the ValueQT for each element in the list.</param>
		/// <returns>
		/// E_INVALIDARG - Invalid valueQT was passed
		/// S_OK - Value changed
		/// OTS_E_EXCEPTION - Unexpected error occurred
		/// </returns>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaAddressSpaceRoot"]/
		///		method[@name="ValuesChanged.list"]/doc/*'
		///	/>
		public virtual int ValuesChanged(ArrayList anElementsList, ArrayList aValueList)
		{
			int count = anElementsList.Count;
			if (count == 0)
			{
				return (int) EnumResultCode.S_FALSE;
			} //	end if

			if (count != aValueList.Count)
			{
				return (int) EnumResultCode.S_FALSE;
			} //	end if

			DaAddressSpaceElement[] elementList = new DaAddressSpaceElement[count];
			ValueQT[] valueList = new ValueQT[count];

			for (int index = 0; index < count; index++)
			{
				elementList[index] = anElementsList[index] as DaAddressSpaceElement;
				valueList[index] = aValueList[index] as ValueQT;
			} //	end foreach

			return ValuesChanged(elementList, valueList);
		} //	end ValuesChanged