private void SendRadarSettings(BlockAddress block) { try { RadarController controller = EWRegistry <RadarController> .Instance.Get(block); Message <BlockAddress, RadarSettings> msg = new Message <BlockAddress, RadarSettings>(block, controller.GetRadarSettings()); if (Helpers.IsServer) { _logger.debugLog($"RadarSystemSettings -> Clients for block {block}", "SendRadarSettings"); MyAPIGateway.Multiplayer.SendMessageToOthers( Constants.MIDUpdateRadarSettings, msg.ToXML()); } else { _logger.debugLog($"RadarSystemSettings -> Server for block {block}", "SendRadarSettings"); MyAPIGateway.Multiplayer.SendMessageToServer( Constants.MIDUpdateRadarSettingsServer, msg.ToXML()); } } catch (Exception e) { _logger.log(Logger.severity.ERROR, "SendRadarSettings", "Exception caught: " + e.ToString()); } }
/// <summary> /// Calls <paramref name="onBlock"/> on the contents of the block at /// address <paramref name="address"/>. /// </summary> /// <remarks> /// If the block has pending work (such as validating contents, or /// writing them out), that pending work is performed before the call. /// /// Fully thread-safe. /// /// Function <paramref name="onBlock"/> should endeavour to return /// quickly, as the provided span is pinned, for all intents and /// purposes, until it does. /// </remarks> /// <returns> /// True of the block could be extracted and passed to <paramref name="onBlock"/>. /// This may fail if the file is being unpinned, or if the block does not /// have the expected realm/hash, or if it is corrupted, or if the address has /// somehow expired. /// /// The out argument contains the return value of <paramref name="onBlock"/>. /// </returns> /// <see cref="BlockFile.TryWithBlockAtAddress"/> public bool TryWithBlockAtAddress <T>( BlockAddress address, uint realm, Hash hash, WithSpan.ReadOnlyReturns <T> onBlock, out T result) { if (address.IsNone()) { result = default; return(false); } // BlockAddress.File() is 1..1023 but our array is zero-indexed. var fid = address.File() - 1; var file = _readFiles[fid]; if (file == null) { result = default; return(false); } return(file.TryWithBlockAtAddress( address, realm, hash, onBlock, out result)); }
public string GetSymbolicAddress() { switch (DataType) { case S7DataRowType.BOOL: return("X" + BlockAddress.ToString()); case S7DataRowType.WORD: case S7DataRowType.INT: case S7DataRowType.S5TIME: case S7DataRowType.DATE: return("W" + BlockAddress.ByteAddress.ToString()); break; case S7DataRowType.DWORD: case S7DataRowType.DINT: case S7DataRowType.REAL: case S7DataRowType.TIME: case S7DataRowType.TIME_OF_DAY: return("D" + BlockAddress.ByteAddress.ToString()); break; case S7DataRowType.CHAR: case S7DataRowType.BYTE: return("B" + BlockAddress.ByteAddress.ToString()); break; default: return(null); } }
public void preserve_file_offset(uint file, long firstByteOffset) { var addr = new BlockAddress(file, firstByteOffset); Assert.Equal(file, addr.File()); Assert.Equal(firstByteOffset, addr.FirstByteOffset()); }
/// <summary> /// Attempts to schedule a write of the specified length into the file. /// </summary> /// <returns> /// A valid block address representing the location where the written /// block will be found, or a 'None' address if the file does not /// currently have enough room for this. /// </returns> /// <remarks> /// The provided writer will be invoked at some point in the future. /// /// Thread-safe. /// </remarks> public BlockAddress TryScheduleWrite( uint realm, Hash hash, int length, WithSpan.ReadWrite writer) { if (length < 0) { throw new ArgumentException($"Negative length: {length}", nameof(length)); } int rank; long offset; lock (_syncRoot) { offset = _offset; _offset = BlockAddress.Ceiling(offset + BlockHeader.Size + length); if (_offset > _file.Length) { // Since this file is about to be flushed and closed, // because it's "full enough", we prevent additional writes. _offset = _file.Length; return(BlockAddress.None); } rank = _flags.Count; _flags.Append(ReadFlag.Triggered(() => PerformWrite(offset, writer))); } // We touched '_offset' and '_flags' in the critical section, the remaining // work on the actual byte span can be done without mutex. var span = _file.AsMemory(offset, BlockHeader.Size).Span; ref var header = ref MemoryMarshal.Cast <byte, BlockHeader>(span)[0];
public void return_added() { var a = new BlockAddress(1, 0); var h = HashInBucket(0, 0); Assert.True(_index.Add(0, h, a)); Assert.Equal(a, _index.Get(0, h)); }
public void do_not_return_removed() { var a = new BlockAddress(1, 0); var h = HashInBucket(0, 0); Assert.True(_index.Add(0, h, a)); _index.Remove(0, h, a); Assert.True(_index.Get(0, h).IsNone()); }
public void add_remove_add() { var a = new BlockAddress(1, 0); var h = HashInBucket(0, 0); Assert.True(_index.Add(0, h, a)); _index.Remove(0, h, a); Assert.True(_index.Add(0, h, a)); Assert.Equal(a, _index.Get(0, h)); }
public override void jumpToNext(Statement nextLine) { nextBlock = nextLine.block; AllocaInstruction alloc = builder.CreateAlloca(Parser.i8p, "returnAddress"); BlockAddress addr = BlockAddress.Get(Parser.function, nextBlock); builder.CreateStore(addr, alloc); Parser.variables.returnAddresses.Push(alloc); Parser.variables.returnBlocks.Add(nextLine.block); }
public void add_overwrite() { var a1 = new BlockAddress(1, 0); var a2 = new BlockAddress(2, 4096); var h = HashInBucket(0, 0); Assert.True(_index.Add(0, h, a1)); Assert.False(_index.Add(0, h, a2)); Assert.Equal(a2, _index.Get(0, h)); }
public void add_overwrite_remove_new() { var a1 = new BlockAddress(1, 0); var a2 = new BlockAddress(2, 4096); var h = HashInBucket(0, 0); Assert.True(_index.Add(0, h, a1)); Assert.False(_index.Add(0, h, a2)); _index.Remove(0, h, a2); Assert.True(_index.Get(0, h).IsNone()); }
public void CreationRS() { #if !DEBUG Assert.Inconclusive("This test requires DEBUG context"); #endif SBUSRS_message _msg = new SBUSRS_message(null); Assert.IsNotNull(_msg, "Message is not created."); BlockAddress _tb = new BlockAddress(); _msg.Test_PrepareRequest(_tb.station, _tb); Assert.AreEqual(_msg.userDataLength, 7, "Request length is not valid"); }
public void add_no_collision() { var a1 = new BlockAddress(1, 0); var a2 = new BlockAddress(2, 4096); var h1 = HashInBucket(0, 0); var h2 = HashInBucket(1, 1); Assert.True(_index.Add(0, h1, a1)); Assert.True(_index.Add(0, h2, a2)); Assert.Equal(a1, _index.Get(0, h1)); Assert.Equal(a2, _index.Get(0, h2)); }
public void add_collision_remove_second() { var a1 = new BlockAddress(1, 0); var a2 = new BlockAddress(2, 4096); var h1 = HashInBucket(0, 0); var h2 = HashInBucket(0, 1); Assert.True(_index.Add(0, h1, a1)); Assert.True(_index.Add(0, h2, a2)); _index.Remove(0, h2, a2); Assert.True(_index.Get(0, h2).IsNone()); Assert.Equal(a1, _index.Get(0, h1)); }
/// <summary> Add a new block to the index. </summary> /// <remarks> /// If the block already exists, overwrites its address and returns /// false, otherwise returns true. /// </remarks> public bool Add(uint realm, Hash hash, BlockAddress address) { if (address.IsNone()) { throw new ArgumentException("'None' address provided.", nameof(address)); } var key = new IndexEntry.EntryKey(hash, realm); var bucket = IndexEntry.EntryKey.BucketOfHash(hash); lock (_syncRoot) // All write operations require locking. { // Traverse the bucket, looking for an entry with the same key. // If not found, will remember 'last', the last entry in the // sequence. var prev = NoEntry; var search = _entries[bucket].FirstInBucket; while (search != NoEntry) { ref var entry = ref _entries[search]; if (entry.Key.Equals(key)) { // The (realm,hash) already exists in the index: just overwrite // the address with the new one. _entries[search].Address = address; return(false); } prev = search; search = entry.NextInBucket; } var cacheFriendlyPos = FindCacheFriendlyEntry(bucket, prev); // If found no cache-friendly position to place the entry, // pull an arbitrary position from the free list. var free = cacheFriendlyPos == NoEntry ? DequeueOldestFree() : FromFreeList(cacheFriendlyPos); // Initialize the entry at 'pos' to contain the key-address // pair, then insert the entry into the bucket's list right // after element 'prev'. ref var inserted = ref _entries[free];
public string ToString(string spacer) { string retVal = ""; if (BlockAddress != null) { retVal += BlockAddress.ToString().PadLeft(5, '0') + ": "; } retVal += spacer + Name; if (Attributes != null) { retVal += "{"; foreach (Step7Attribute step7Attribute in Attributes) { if (Attributes.IndexOf(step7Attribute) != 0) { retVal += "; "; } retVal += step7Attribute.Name + "=" + "'" + step7Attribute.Value.Replace("$", "$$").Replace("'", "$'") + "'"; } retVal += "}"; } retVal += ": "; /* * if (IsArray) * { * retVal += "ARRAY ["; * for (int n = 0; n < ArrayStart.Count; n++) * { * retVal += ArrayStart[n].ToString() + ".." + ArrayStop[n].ToString(); * if (n < ArrayStart.Count - 1) * retVal += ","; * } * retVal += "] OF "; * } * retVal += DataType.ToString(); * if (DataType == PLCDataRowType.FB || DataType == PLCDataRowType.UDT || DataType == PLCDataRowType.SFB) * retVal += DataTypeBlockNumber.ToString(); * if (DataType == PLCDataRowType.STRING) * retVal += "[" + StringSize.ToString() + "]"; */ retVal += DataTypeAsString; if (StartValue != null) { if (DataType == S7DataRowType.STRING) { retVal += " := '" + StartValue + "'"; } else { retVal += " := " + StartValue; } } if (!string.IsNullOrEmpty(Comment)) { retVal += " //" + Comment; } retVal += Environment.NewLine; if (Children != null) { foreach (S7DataRow plcDataRow in Children) { retVal += plcDataRow.ToString("\t" + spacer); } } return(retVal); }
public T Get(BlockAddress addr) { return(Get(addr.grid, addr.block)); }