Example #1
0
        public virtual void ReaderCopy(Gapi.gapi_Seq samples, Gapi.gapi_readerInfo readerInfo)
        {
            int samplesToRead = 0;
            IntPtr dataSampleBuf = IntPtr.Zero;

            if (samples != null)
            {
                samplesToRead = (int) samples._length;
                dataSampleBuf = samples._buffer;
            }

            // Restore GCHandle types from IntPtr types.
            GCHandle tmpGCHandleData = GCHandle.FromIntPtr(readerInfo.data_buffer);
            object[] sampleDataArray = tmpGCHandleData.Target as object[];

            GCHandle tmpGCHandleInfo = GCHandle.FromIntPtr(readerInfo.info_buffer);
            SampleInfo[] sampleInfoArray = tmpGCHandleInfo.Target as SampleInfo[];

            if (sampleDataArray == null || sampleDataArray.Length != samplesToRead)
            {
                // Initialize the arrays using recycled elements of the pre-allocated ones.
                object[] targetData = SampleReaderAlloc(samplesToRead);
                initObjectSeq(sampleDataArray, targetData);
                sampleDataArray = targetData;
                SampleInfo[] targetSampleInfo = new SampleInfo[samplesToRead];
                initObjectSeq(sampleInfoArray, targetSampleInfo);
                sampleInfoArray = targetSampleInfo;

                // Point the GCHandle types to the newly allocated arrays.
                tmpGCHandleData.Target = sampleDataArray;
                tmpGCHandleInfo.Target = sampleInfoArray;
            }

            // copy the data into our sampleDataArray and sampleInfoArray
            IntPtr samplePtr;
            object sampleObj;
            int cursor = 0;
            for (int i = 0; i < samplesToRead; i++)
            {
                // Copy the samples.
                samplePtr = ReadIntPtr(dataSampleBuf, cursor + offset_data);
                sampleObj = sampleDataArray[i];
                CopyOut(samplePtr, ref sampleObj, 0);
                sampleDataArray[i] = sampleObj;

                // Copy the sample info
                SampleInfoMarshaler.CopyOut(dataSampleBuf, ref sampleInfoArray[i],
                        cursor + offset_sampleInfo);
                cursor += dataSampleSize;
            }
        }
        public static void CopyIn(ref Gapi.gapi_domainParticipantListener from, IntPtr to, int offset)
        {
            // Set listener_data field
            BaseMarshaler.Write(to, offset + offset_listener_data, IntPtr.Zero);

            // Set callback fields
            BaseMarshaler.Write(to, offset + offset_on_inconsistent_topic, MarshalHelper.GetIntPtrForDelegate(from.on_inconsistent_topic));
            BaseMarshaler.Write(to, offset + offset_on_offered_deadline_missed, MarshalHelper.GetIntPtrForDelegate(from.on_offered_deadline_missed));
            BaseMarshaler.Write(to, offset + offset_on_offered_incompatible_qos, MarshalHelper.GetIntPtrForDelegate(from.on_offered_incompatible_qos));
            BaseMarshaler.Write(to, offset + offset_on_liveliness_lost, MarshalHelper.GetIntPtrForDelegate(from.on_liveliness_lost));
            BaseMarshaler.Write(to, offset + offset_on_publication_match, MarshalHelper.GetIntPtrForDelegate(from.on_publication_match));
            BaseMarshaler.Write(to, offset + offset_on_requested_deadline_missed, MarshalHelper.GetIntPtrForDelegate(from.on_requested_deadline_missed));
            BaseMarshaler.Write(to, offset + offset_on_requested_incompatible_qos, MarshalHelper.GetIntPtrForDelegate(from.on_requested_incompatible_qos));
            BaseMarshaler.Write(to, offset + offset_on_sample_rejected, MarshalHelper.GetIntPtrForDelegate(from.on_sample_rejected));
            BaseMarshaler.Write(to, offset + offset_on_liveliness_changed, MarshalHelper.GetIntPtrForDelegate(from.on_liveliness_changed));
            BaseMarshaler.Write(to, offset + offset_on_data_available, MarshalHelper.GetIntPtrForDelegate(from.on_data_available));
            BaseMarshaler.Write(to, offset + offset_on_subscription_match, MarshalHelper.GetIntPtrForDelegate(from.on_subscription_match));
            BaseMarshaler.Write(to, offset + offset_on_sample_lost, MarshalHelper.GetIntPtrForDelegate(from.on_sample_lost));
            BaseMarshaler.Write(to, offset + offset_on_data_on_readers, MarshalHelper.GetIntPtrForDelegate(from.on_data_on_readers));
        }