/// <summary> /// Initializes a new instance of the <see cref="AnonymousMemoryMlosContext"/> class. /// </summary> /// <param name="globalMemoryRegionView"></param> /// <param name="controlChannelMemoryMapView"></param> /// <param name="feedbackChannelMemoryMapView"></param> /// <param name="sharedConfigMemoryRegionView"></param> /// <param name="controlChannelNamedEvent"></param> /// <param name="feedbackChannelNamedEvent"></param> /// <param name="fileDescriptorExchangeServer"></param> private AnonymousMemoryMlosContext( SharedMemoryRegionView <MlosProxyInternal.GlobalMemoryRegion> globalMemoryRegionView, SharedMemoryMapView controlChannelMemoryMapView, SharedMemoryMapView feedbackChannelMemoryMapView, SharedMemoryRegionView <MlosProxyInternal.SharedConfigMemoryRegion> sharedConfigMemoryRegionView, NamedEvent controlChannelNamedEvent, NamedEvent feedbackChannelNamedEvent, FileDescriptorExchangeServer fileDescriptorExchangeServer) { this.globalMemoryRegionView = globalMemoryRegionView ?? throw new ArgumentNullException(nameof(globalMemoryRegionView)); this.controlChannelMemoryMapView = controlChannelMemoryMapView ?? throw new ArgumentNullException(nameof(controlChannelMemoryMapView)); this.feedbackChannelMemoryMapView = feedbackChannelMemoryMapView ?? throw new ArgumentNullException(nameof(feedbackChannelMemoryMapView)); this.controlChannelNamedEvent = controlChannelNamedEvent ?? throw new ArgumentNullException(nameof(controlChannelNamedEvent)); this.feedbackChannelNamedEvent = feedbackChannelNamedEvent ?? throw new ArgumentNullException(nameof(feedbackChannelNamedEvent)); this.fileDescriptorExchangeServer = fileDescriptorExchangeServer; // Create the shared config manager. // SharedConfigManager = new SharedConfigManager(); // Register shared config memory region. // SharedConfigManager.RegisterSharedConfigMemoryRegion(sharedConfigMemoryRegionView); MlosProxyInternal.GlobalMemoryRegion globalMemoryRegion = globalMemoryRegionView.MemoryRegion(); // Increase the usage counter. When closing global shared memory, we will decrease the counter. // If there is no process using the shared memory, we will clean the OS resources. On Windows OS, // this is no-op; on Linux, we unlink created files. // globalMemoryRegion.AttachedProcessesCount.FetchAdd(1); // Create the control channel instance. // ControlChannel = new SharedChannel <InterProcessSharedChannelPolicy, SharedChannelSpinPolicy>( buffer: controlChannelMemoryMapView.Buffer, size: (uint)controlChannelMemoryMapView.MemSize, sync: globalMemoryRegion.ControlChannelSynchronization) { ChannelPolicy = { NotificationEvent = controlChannelNamedEvent }, }; // Create the feedback channel instance. // FeedbackChannel = new SharedChannel <InterProcessSharedChannelPolicy, SharedChannelSpinPolicy>( buffer: feedbackChannelMemoryMapView.Buffer, size: (uint)feedbackChannelMemoryMapView.MemSize, sync: globalMemoryRegion.FeedbackChannelSynchronization) { ChannelPolicy = { NotificationEvent = feedbackChannelNamedEvent }, }; }
public SharedChannel SaveChannel(SharedChannel channel) { if (channel == null) { return(null); } SharedChannel Result = null; SharedChannel channeltest = GetChannelByChannelName(channel.Channel); bool exists = channeltest != null; if (exists) { lock (this) { //"UPDATE TwitchChannel SET ChannelID=:channelid, CreatedDate=:createddate, ModifiedDate=:modifieddate, OwnerUserId=:owneruserid WHERE Channel=:channel;"; using (SQLiteCommand cmd = new SQLiteCommand(UpdateChannelSQL, m_conn)) { cmd.Parameters.Add(new SQLiteParameter(":channelid", channel.ChannelId)); cmd.Parameters.Add(new SQLiteParameter(":channel", channel.Channel)); cmd.Parameters.Add(new SQLiteParameter(":createddate", channel.CreatedDate)); // May have to set this to NULL if null cmd.Parameters.Add(new SQLiteParameter(":modifieddate", channel.ModifiedDate)); // May have to set this to NULL if null cmd.Parameters.Add(new SQLiteParameter(":owneruserid", channel.OwnerUserId)); cmd.ExecuteNonQuery(); } Result = channel; } } else { lock (this) { using (SQLiteCommand cmd = new SQLiteCommand(InsertChannelSQL, m_conn)) { cmd.Parameters.Add(new SQLiteParameter(":channelid", channel.ChannelId)); cmd.Parameters.Add(new SQLiteParameter(":channel", channel.Channel)); cmd.Parameters.Add(new SQLiteParameter(":createddate", channel.CreatedDate)); // May have to set this to NULL if null cmd.Parameters.Add(new SQLiteParameter(":modifieddate", channel.ModifiedDate)); // May have to set this to NULL if null cmd.Parameters.Add(new SQLiteParameter(":owneruserid", channel.OwnerUserId)); cmd.ExecuteNonQuery(); } } Result = GetChannelByChannelName(channel.Channel); } return(Result); }
public SharedChannel GetChannelById(int id) { if (id == 0) { return(null); } SharedChannel chan = null; lock (this) { chan = m_context.Database.SqlQuery <SharedChannel>(SelectChannelSQLByChannelName, new SQLiteParameter[] { new SQLiteParameter(":id", id) } ).FirstOrDefault(); } return(chan); }
public SharedChannel GetChannelByChannelName(string channelname) { // Must have a channel name. A channel name is required. Do nothing. Get Nothing ಠ_ಠ if (string.IsNullOrEmpty(channelname) || string.IsNullOrWhiteSpace(channelname)) { return(null); } SharedChannel chan = null; lock (this) { chan = m_context.Database.SqlQuery <SharedChannel>(SelectChannelSQLByChannelName, new SQLiteParameter[] { new SQLiteParameter(":channel", channelname) } ).FirstOrDefault(); } return(chan); }
/// <summary> /// Main. /// </summary> public static void RunAgent() { // Create the shared memory control channel. // var globalMemoryRegion = globalMemoryRegionView.MemoryRegion(); var controlChannel = new SharedChannel <InterProcessSharedChannelPolicy, SharedChannelSpinPolicy>( buffer: controlChannelMemoryMapView.Buffer, size: (uint)controlChannelMemoryMapView.MemSize, sync: globalMemoryRegion.ControlChannelSynchronization); controlChannel.ChannelPolicy.NotificationEvent = controlChannelNamedEvent; // Create a thread that will monitor the reconfiguration request queue // bool result = true; while (result) { result = controlChannel.WaitAndDispatchFrame(globalDispatchTable); } }
/// <summary> /// Initialize shared channel. /// </summary> public static void InitializeSharedChannel() { // Create or open the memory mapped files. // globalMemoryRegionView = SharedMemoryRegionView.CreateOrOpen <MlosProxyInternal.GlobalMemoryRegion>(GlobalMemoryMapName, SharedMemorySize); controlChannelMemoryMapView = SharedMemoryMapView.CreateOrOpen(ControlChannelMemoryMapName, SharedMemorySize); feedbackChannelMemoryMapView = SharedMemoryMapView.CreateOrOpen(FeedbackChannelMemoryMapName, SharedMemorySize); sharedConfigMemoryMapView = SharedMemoryRegionView.CreateOrOpen <MlosProxyInternal.SharedConfigMemoryRegion>(SharedConfigMemoryMapName, SharedMemorySize); // Create channel synchronization primitives. // controlChannelNamedEvent = NamedEvent.CreateOrOpen(ControlChannelSemaphoreName); feedbackChannelNamedEvent = NamedEvent.CreateOrOpen(FeedbackChannelSemaphoreName); // Setup feedback channel. // MlosProxyInternal.GlobalMemoryRegion globalMemoryRegion = globalMemoryRegionView.MemoryRegion(); // Enable channels. // globalMemoryRegion.ControlChannelSynchronization.TerminateChannel.Store(false); globalMemoryRegion.FeedbackChannelSynchronization.TerminateChannel.Store(false); var feedbackChannel = new SharedChannel <InterProcessSharedChannelPolicy, SharedChannelSpinPolicy>( buffer: feedbackChannelMemoryMapView.Buffer, size: (uint)feedbackChannelMemoryMapView.MemSize, sync: globalMemoryRegion.FeedbackChannelSynchronization); feedbackChannel.ChannelPolicy.NotificationEvent = feedbackChannelNamedEvent; // Set SharedConfig memory region. // SharedConfigManager.SetMemoryRegion(new MlosProxyInternal.SharedConfigMemoryRegion() { Buffer = sharedConfigMemoryMapView.MemoryRegion().Buffer }); // Setup MlosContext. // MlosContext.FeedbackChannel = feedbackChannel; MlosContext.SharedConfigManager = SharedConfigManager; // Initialize callbacks. // MlosProxyInternal.RegisterAssemblyRequestMessage.Callback = RegisterAssemblyCallback; MlosProxyInternal.RegisterMemoryRegionRequestMessage.Callback = RegisterMemoryRegionMessageCallback; MlosProxyInternal.RegisterSharedConfigMemoryRegionRequestMessage.Callback = RegisterSharedConfigMemoryRegionRequestMessageCallback; MlosProxy.TerminateReaderThreadRequestMessage.Callback = TerminateReaderThreadRequestMessageCallback; // Register Mlos.Core assembly. // RegisterAssembly(typeof(MlosContext).Assembly, dispatchTableBaseIndex: 0); // Register assemblies from the shared config. // Assembly Mlos.NetCore does not have a config, as it is always registered first. // for (uint index = 1; index < globalMemoryRegion.RegisteredSettingsAssemblyCount.Load(); index++) { RegisterSettingsAssembly(assemblyIndex: index); } }
public void DeleteChannel(SharedChannel chan) { DeleteChannel(chan.Channel); }
public void DeleteChannel(SharedChannel chan) { data.DeleteChannel(chan); }
public SharedChannel SaveChannel(SharedChannel channel) { return(data.SaveChannel(channel)); }