Stores data concerning an OPC read or write request.
Ejemplo n.º 1
0
		} //	end HandleReadRequest


		/// <summary>
		/// Handles a write request for this property. This method is ment to be overriden. The default behavior
		/// marks the request as failed
		/// </summary>
		/// <param name="aRequest"></param>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaProperty"]/
		///		method[@name="HandleWriteRequest"]/doc/*'
		///	/>
		public virtual void HandleWriteRequest(DaRequest aRequest)
		{
			//	Ment to be obverriden, just return failed
			aRequest.Result = EnumResultCode.E_FAIL;
			aRequest.Value = null;
			aRequest.Complete();
		} //	end HandleWriteRequest
Ejemplo n.º 2
0
		} //	end Value


		//-
		#endregion

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

		/// <summary>
		/// Completes the request with the Value sorted within this object
		/// </summary>
		/// <include
		///		file='TBNS.doc.xml'
		///		path='//class[@name="DaConstantProperty"]/
		///		method[@name="HandleReadRequest"]/doc/*'
		///	/>
		public override void HandleReadRequest(DaRequest aRequest)
		{
			System.Diagnostics.Debug.Assert(aRequest.PropertyId == this.Id,
			                                "HandleRequest called with illegal request");

			aRequest.Result = EnumResultCode.S_OK;
			aRequest.Value = m_value;
			aRequest.Complete();
		} //	end HandleReadRequest
Ejemplo n.º 3
0
		} //	end ValuesChanged


		/// <summary>
		/// removes a specific request from the internal requests list
		/// </summary>
		/// <param name="aRequest">
		/// the request to be removed from the transactrion
		/// </param>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="RemoveRequest"]/doc/*'
		/// />
		public void RemoveRequest(DaRequest aRequest)
		{
			if (aRequest == null)
			{
				return;
			} //	end if

			lock (m_requestListJanitor)
			{
				m_requestList.Remove(aRequest);
			} //	end lock
		} //	end removeRequest
Ejemplo n.º 4
0
		} //	end CompleteRequests


		/// <summary>
		/// Marks the request identified by "requestHandle" completed, as it was internally handled (~cancelled) inside Toolkit Core
		/// </summary>
		/// <returns>
		/// S_OK - Request was found and marked completed
		/// E_NOTFOUND - Request was not found
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="requestCompletedInternally"]/doc/*'
		/// />
		public int findRequestByHandle(uint requestHandle, out DaRequest request)
		{
			request = null;
			DaRequest req;
			lock (m_requestListJanitor)
			{
				int count = m_requestList.Count;
				for (int i = 0; i < count; ++i)
				{
					req = m_requestList[i] as DaRequest;
					if ((req != null) && (req.RequestHandle == requestHandle))
					{
						request = req;
						return (int) EnumResultCode.S_OK;
					}
				}
			} //	end lock
			return (int) EnumResultCode.E_NOTFOUND;
		}
Ejemplo n.º 5
0
		} //	end CompleteRequest


		/// <summary>
		/// Changes the cache value for the Address space elements provided
		/// </summary>
		/// <returns>
		/// E_INVALIDARG - Invalid valueQT was passed
		/// S_OK - Value changed
		/// OTS_E_EXCEPTION - Unexpected error occurred
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="ValuesChanged"]/doc/*'
		/// />
		public int ValuesChanged()
		{
			int result;
			int count = 0;
			OTValueData[] values = null;
			uint[] handles = null;

			try
			{
				lock (m_requestListJanitor)
				{
					count = m_requestList.Count;

					values = new OTValueData[count];
					handles = new uint[count];

					for (int i = 0; i < count; i++)
					{
						OTValueData valueData = new OTValueData();
						DaRequest request = m_requestList[i] as DaRequest;

						if (request != null)
						{
							valueData.m_quality = (ushort) request.Value.Quality;
							valueData.m_timestamp = new OTDateTime(request.Value.TimeStamp);
							valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);

							Marshal.GetNativeVariantForObject(request.Value.Data, valueData.m_value);
							handles[i] = request.AddressSpaceElement.ObjectHandle;

							request.Result = EnumResultCode.S_OK;
						}
						else
						{
							valueData.m_quality = (ushort) EnumQuality.BAD;
							valueData.m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
							Marshal.GetNativeVariantForObject(null, valueData.m_value);
							handles[i] = 0;
						} //	end if ... else

						values[i] = valueData;
					} //	end for
					result = OTBFunctions.OTSValuesChanged(count, handles, values);
				} //	end lock
			}
			catch (Exception e)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR, EnumTraceGroup.OPCSERVER,
					"DaTransaction.ValuesChanged", "Exception caught: " + e.ToString());
				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				for (int i = 0; i < count; i++)
				{
					OTBFunctions.OTVariantClear(values[i].m_value);
					Marshal.FreeCoTaskMem(values[i].m_value);
				} //	end for
			} //	end try ... catch ... finally

			return result;
		} //	end ValuesChanged
Ejemplo n.º 6
0
		/// <summary>
		/// Completes a single request and removes it from the transaction
		/// </summary>
		/// <returns>
		/// S_OK - Everything was OK
		/// S_FALSE - Everything was OK
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="CompleteRequest"]/doc/*'
		/// />
		public int CompleteRequest(DaRequest aRequest)
		{
			int result = (int) EnumResultCode.E_FAIL;

			OTValueData[] values = new OTValueData[1];
			OTSRequestData[] requests = new OTSRequestData[1];
			int[] results = new int[1];

			try
			{
				DaRequest request = aRequest as DaRequest;

				if (request != null)
				{
					request.RequestState = EnumRequestState.COMPLETED;

					//	remove the request from the list
					RemoveRequest(request);

					requests[0].m_sessionHandle = request.SessionHandle;
					requests[0].m_propertyID = request.PropertyId;
					requests[0].m_requestHandle = request.RequestHandle;

					if (request.AddressSpaceElement != null)
					{
						requests[0].m_object.m_userData = (uint) request.AddressSpaceElement.UserData;
						requests[0].m_object.m_objectHandle = request.AddressSpaceElement.ObjectHandle;
					}
					else
					{
						requests[0].m_object.m_userData = 0;
						requests[0].m_object.m_objectHandle = 0;
					} //	end if ... else

					values[0] = new OTValueData();
					if (request.Value != null)
					{
						values[0].m_timestamp = new OTDateTime(request.Value.TimeStamp);
						values[0].m_quality = (ushort) request.Value.Quality;
						values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
						Marshal.GetNativeVariantForObject(request.Value.Data, values[0].m_value);

						results[0] = (int) request.Result;
					}
					else
					{
						values[0].m_quality = (ushort) EnumQuality.BAD;
						values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
						Marshal.GetNativeVariantForObject(null, values[0].m_value);
						results[0] = (int) EnumResultCode.E_UNEXPECTED;
					} //	end if ... else
				}
				else
				{
					requests[0].m_sessionHandle = 0;
					requests[0].m_propertyID = 0;
					requests[0].m_requestHandle = 0;
					requests[0].m_object.m_userData = 0;
					requests[0].m_object.m_objectHandle = 0;

					values[0] = new OTValueData();
					values[0].m_quality = (ushort) EnumQuality.BAD;
					values[0].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
					Marshal.GetNativeVariantForObject(null, values[0].m_value);
					results[0] = (int) EnumResultCode.E_UNEXPECTED;
				} //	end if ... else

				result = OTBFunctions.OTSCompleteRequests(1, requests, results, values);
			}
			catch (Exception e)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR, EnumTraceGroup.OPCSERVER,
					"DaTransaction.CompleteRequest", "Exception caught: " + e.ToString());

				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				if (this.IsEmpty)
				{
					Application.Instance.ReleaseTransaction(m_key);
				}
				OTBFunctions.OTVariantClear(values[0].m_value);
				Marshal.FreeCoTaskMem(values[0].m_value);
			} //	end try ... catch ... finally

			return result;
		} //	end CompleteRequest
Ejemplo n.º 7
0
		} //	end Session


		//-
		#endregion

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

		/// <summary>
		/// Completes all requests must be called while or after "handling" requests
		/// </summary>
		/// <returns>
		/// S_OK - Everything was OK
		/// S_FALSE - Everything was OK
		/// The Result should be checked with ResultCode.SUCCEEDED
		/// or with ResultCode.FAILED
		/// </returns>
		/// <include
		///  file='TBNS.doc.xml'
		///  path='//class[@name="DaTransaction"]/
		///  method[@name="CompleteRequests"]/doc/*'
		/// />
		public int CompleteRequests()
		{
			int result = (int) EnumResultCode.E_FAIL;

			int count = 0;
			OTValueData[] values = null;
			OTSRequestData[] requests = null;
			int[] results = null;

			try
			{
				lock (m_requestListJanitor)
				{
					count = m_requestList.Count;

					if (count == 0)
					{
						return (int) EnumResultCode.S_FALSE;
					} //	end if

					values = new OTValueData[count];
					requests = new OTSRequestData[count];
					results = new int[count];

					for (int i = 0; i < count; i++)
					{
						DaRequest request = m_requestList[i] as DaRequest;
						if (request != null)
						{
							requests[i].m_sessionHandle = request.SessionHandle;
							requests[i].m_propertyID = request.PropertyId;
							requests[i].m_requestHandle = request.RequestHandle;

							if (request.AddressSpaceElement != null)
							{
								requests[i].m_object.m_userData = (uint) request.AddressSpaceElement.UserData;
								requests[i].m_object.m_objectHandle = request.AddressSpaceElement.ObjectHandle;
							}
							else
							{
								requests[i].m_object.m_userData = 0;
								requests[i].m_object.m_objectHandle = 0;
							} //	end if ... else

							values[i] = new OTValueData();
							if (request.Value != null)
							{
								values[i].m_timestamp = new OTDateTime(request.Value.TimeStamp);
								values[i].m_quality = (ushort) request.Value.Quality;
								values[i].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
								Marshal.GetNativeVariantForObject(request.Value.Data, values[i].m_value);

								results[i] = (int) request.Result;
							}
							else
							{
								values[i].m_quality = (ushort) EnumQuality.BAD;
								values[i].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
								Marshal.GetNativeVariantForObject(null, values[i].m_value);
								results[i] = (int) EnumResultCode.E_UNEXPECTED;
							} //	end if ... else
						}
						else
						{
							requests[i].m_sessionHandle = 0;
							requests[i].m_propertyID = 0;
							requests[i].m_requestHandle = 0;
							requests[i].m_object.m_userData = 0;
							requests[i].m_object.m_objectHandle = 0;

							values[i] = new OTValueData();
							values[i].m_quality = (ushort) EnumQuality.BAD;
							values[i].m_value = Marshal.AllocCoTaskMem(ValueQT.VARIANT_SIZE);
							Marshal.GetNativeVariantForObject(null, values[i].m_value);
							results[i] = (int) EnumResultCode.E_UNEXPECTED;
						} //	end if ... else

						request.RequestState = EnumRequestState.COMPLETED;
					} //	end for

					m_requestList.Clear();
				} //	end lock

				result = OTBFunctions.OTSCompleteRequests(count, requests, results, values);
			}
			catch (Exception e)
			{
				Application.Instance.Trace(
					EnumTraceLevel.ERR, EnumTraceGroup.OPCSERVER,
					"DaTransaction.CompleteRequests", "Exception caught: " + e.ToString());

				result = (int) EnumResultCode.E_FAIL;
			}
			finally
			{
				Application.Instance.ReleaseTransaction(m_key);

				for (int i = 0; i < count; i++)
				{
					OTBFunctions.OTVariantClear(values[i].m_value);
					Marshal.FreeCoTaskMem(values[i].m_value);
				} //	end for
			} //	end try ... catch ... finally

			return result;
		} //	end CompleteRequests