/// <summary>
        /// Creates a shared memory region view.
        /// </summary>
        /// <param name="sharedMemoryMapName"></param>
        /// <param name="sharedMemorySize"></param>
        /// <returns></returns>
        /// <typeparam name="T">Memory region type.</typeparam>
        public static SharedMemoryRegionView <T> Create <T>(string sharedMemoryMapName, ulong sharedMemorySize)
            where T : ICodegenProxy, new()
        {
            var memoryRegionView = new SharedMemoryRegionView <T>(SharedMemoryMapView.Create(sharedMemoryMapName, sharedMemorySize));

            MlosProxyInternal.MemoryRegionInitializer <T> memoryRegionInitializer = default;
            memoryRegionInitializer.Initalize(memoryRegionView);
            return(memoryRegionView);
        }
        /// <summary>
        /// Creates or opens a shared memory region view.
        /// </summary>
        /// <param name="sharedMemoryMapName"></param>
        /// <param name="sharedMemorySize"></param>
        /// <returns></returns>
        /// <typeparam name="T">Memory region type.</typeparam>
        public static SharedMemoryRegionView <T> CreateOrOpen <T>(string sharedMemoryMapName, ulong sharedMemorySize)
            where T : ICodegenProxy, new()
        {
            try
            {
                return(new SharedMemoryRegionView <T>(SharedMemoryMapView.Open(sharedMemoryMapName, sharedMemorySize)));
            }
            catch (FileNotFoundException)
            {
                var memoryRegionView = new SharedMemoryRegionView <T>(SharedMemoryMapView.Create(sharedMemoryMapName, sharedMemorySize));

                MlosProxyInternal.MemoryRegionInitializer <T> memoryRegionInitializer = default;
                memoryRegionInitializer.Initalize(memoryRegionView);
                return(memoryRegionView);
            }
        }
Exemple #3
0
        /// <summary>
        /// Always create...
        /// </summary>
        /// <returns>InterProcessMlosContext instance.</returns>
        public static InterProcessMlosContext Create()
        {
            // Create or open the memory mapped files.
            //
            SharedMemoryRegionView <MlosProxyInternal.GlobalMemoryRegion> globalMemoryRegionView = SharedMemoryRegionView.Create <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize);
            SharedMemoryMapView controlChannelMemoryMapView  = SharedMemoryMapView.Create(ControlChannelMemoryMapName, SharedMemorySize);
            SharedMemoryMapView feedbackChannelMemoryMapView = SharedMemoryMapView.Create(FeedbackChannelMemoryMapName, SharedMemorySize);
            SharedMemoryRegionView <MlosProxyInternal.SharedConfigMemoryRegion> sharedConfigMemoryMapView = SharedMemoryRegionView.Create <MlosProxyInternal.SharedConfigMemoryRegion>(SharedConfigMemoryMapName, SharedMemorySize);

            // Create channel synchronization primitives.
            //
            NamedEvent controlChannelNamedEvent  = NamedEvent.CreateOrOpen(ControlChannelSemaphoreName);
            NamedEvent feedbackChannelNamedEvent = NamedEvent.CreateOrOpen(FeedbackChannelSemaphoreName);

            return(new InterProcessMlosContext(
                       globalMemoryRegionView,
                       controlChannelMemoryMapView,
                       feedbackChannelMemoryMapView,
                       sharedConfigMemoryMapView,
                       controlChannelNamedEvent,
                       feedbackChannelNamedEvent));
        }