예제 #1
0
        /// <summary>
        /// Creates a <see cref="ReadCondition" /> to read samples with the desired sample states, view states and instance states.
        /// </summary>
        /// <param name="sampleStates">The desired sample states mask.</param>
        /// <param name="viewStates">The desired view states mask.</param>
        /// <param name="instanceStates">The desired instance states mask.</param>
        /// <returns>The newly created <see cref="ReadCondition" /> on success, otherwise <see langword="null"/>.</returns>
        public ReadCondition CreateReadCondition(SampleStateMask sampleStates, ViewStateMask viewStates, InstanceStateMask instanceStates)
        {
            IntPtr native = UnsafeNativeMethods.CreateReadCondition(_native, sampleStates, viewStates, instanceStates);

            ReadCondition readCondition = null;

            if (native != IntPtr.Zero)
            {
                readCondition = new ReadCondition(native, this);
                _conditions.Add(readCondition);
            }

            return(readCondition);
        }
예제 #2
0
        /// <summary>
        /// Creates a <see cref="QueryCondition" /> with the desired sample states, view states and instance states.
        /// </summary>
        /// <remarks>
        /// The returned <see cref="QueryCondition" /> will be attached and belong to the <see cref="DataReader" />.
        /// </remarks>
        /// <param name="sampleStates">The desired sample states mask.</param>
        /// <param name="viewStates">The desired view states mask.</param>
        /// <param name="instanceStates">The desired instance states mask.</param>
        /// <param name="queryExpression">The query string, which must be a subset of the SQL query language.</param>
        /// <param name="queryParameters">A sequence of strings which are the parameter values used in the SQL query string. The number of values in queryParameters must be equal or greater than the highest referenced n token in the queryExpression.</param>
        /// <returns>The newly created <see cref="QueryCondition" /> on success, otherwise <see langword="null"/>.</returns>
        public QueryCondition CreateQueryCondition(SampleStateMask sampleStates, ViewStateMask viewStates, InstanceStateMask instanceStates, string queryExpression, params string[] queryParameters)
        {
            IntPtr         seq        = IntPtr.Zero;
            IList <string> parameters = queryParameters.ToList();

            parameters.StringSequenceToPtr(ref seq, false);

            IntPtr native = UnsafeNativeMethods.CreateQueryCondition(_native, sampleStates, viewStates, instanceStates, queryExpression, seq);

            QueryCondition queryCondition = null;

            if (native != IntPtr.Zero)
            {
                queryCondition = new QueryCondition(native, this);
                _conditions.Add(queryCondition);
            }

            return(queryCondition);
        }
예제 #3
0
        /// <summary>
        /// Allows the application to access the <see cref="DataReader" /> objects that contain samples with the specified sampleStates,
        /// viewStates, and instanceStates.
        /// </summary>
        /// <remarks>
        /// <para>If the <see cref="PresentationQosPolicy" /> of the <see cref="Subscriber" /> to which the <see cref="DataReader" /> belongs has the
        /// <see cref="PresentationQosPolicy.AccessScope" /> set to <see cref="PresentationQosPolicyAccessScopeKind.GroupPresentationQos" />,
        /// this operation should only be invoked inside a <see cref="BeginAccess" />/<see cref="EndAccess" /> block. Otherwise it will return the error
        /// <see cref="ReturnCode.PreconditionNotMet" />.</para>
        /// <para>Depending on the setting of the <see cref="PresentationQosPolicy" />, the returned collection of <see cref="DataReader" /> objects may
        /// be a 'set' containing each <see cref="DataReader" /> at most once in no specified order, or a 'list' containing each <see cref="DataReader" /> one or more
        /// times in a specific order.
        /// <list type="number">
        /// <item><description>If <see cref="PresentationQosPolicy.AccessScope" /> is <see cref="PresentationQosPolicyAccessScopeKind.InstancePresentationQos" /> or
        /// <see cref="PresentationQosPolicyAccessScopeKind.TopicPresentationQos" /> the returned collection behaves as a 'set'.</description></item>
        /// <item><description>If <see cref="PresentationQosPolicy.AccessScope" /> is <see cref="PresentationQosPolicyAccessScopeKind.GroupPresentationQos" /> and
        /// <see cref="PresentationQosPolicy.OrderedAccess" /> is set to <see langword="true"/>, then the returned collection behaves as a 'list'.</description></item>
        /// </list></para>
        /// <para>This difference is due to the fact that, in the second situation it is required to access samples belonging to different <see cref="DataReader" />
        /// objects in a particular order. In this case, the application should process each <see cref="DataReader" /> in the same order it appears in the
        /// 'list' and Read or Take exactly one sample from each <see cref="DataReader" />.</para>
        /// </remarks>
        /// <param name="readers">The <see cref="DataReader" /> collection to be filled up.</param>
        /// <param name="sampleStates">The returned <see cref="DataReader" /> in the collection must contain samples that have one of the sample states.</param>
        /// <param name="viewStates">The returned <see cref="DataReader" /> in the collection must contain samples that have one of the view states.</param>
        /// <param name="instanceStates">The returned <see cref="DataReader" /> in the collection must contain samples that have one of the instance states.</param>
        /// <returns>The <see cref="ReturnCode" /> that indicates the operation result.</returns>
        public ReturnCode GetDataReaders(IList <DataReader> readers, SampleStateMask sampleStates, ViewStateMask viewStates, InstanceStateMask instanceStates)
        {
            if (readers == null)
            {
                return(ReturnCode.BadParameter);
            }

            readers.Clear();

            IntPtr     ptr = IntPtr.Zero;
            ReturnCode ret = UnsafeNativeMethods.GetDataReaders(_native, ref ptr, sampleStates, viewStates, instanceStates);

            if (ret == ReturnCode.Ok && !ptr.Equals(IntPtr.Zero))
            {
                IList <IntPtr> lst = new List <IntPtr>();
                MarshalHelper.PtrToSequence(ptr, ref lst);
                if (lst != null)
                {
                    foreach (IntPtr ptrReader in lst)
                    {
                        IntPtr ptrEnity = DataReader.NarrowBase(ptrReader);

                        var entity = EntityManager.Instance.Find(ptrEnity);
                        if (entity is DataReader dataReader)
                        {
                            readers.Add(dataReader);
                        }
                        else
                        {
                            readers.Add(new DataReader(ptrReader));
                        }
                    }
                }
            }

            return(ret);
        }