Exemple #1
0
        internal bool GetCommunicationModuleOffset(string moduleName, out ushort synReqOffset, out ushort synReqRspOffset, out ushort asynReqOffset)
        {
            /******************
            * Comm. protocol:
            *  - REQUEST : [char_cnt, char[] moduleName]
            *  - RESPONSE: [int synReqOffset, int synReqRspOffset, int asynReqOffset]
            * An response error code other than E_SUCCESS indicates failure of remote module lookup.
            ******************/

            using (TrinityMessage tm = new TrinityMessage(
                       TrinityMessageType.PRESERVED_SYNC_WITH_RSP,
                       (ushort)RequestType.GetCommunicationModuleOffsets,
                       size: sizeof(int) + sizeof(char) * moduleName.Length))
            {
                SmartPointer sp = SmartPointer.New(tm.Buffer + TrinityMessage.Offset);
                *sp.ip++        = moduleName.Length;

                BitHelper.WriteString(moduleName, sp.bp);
                TrinityResponse response;
                this.SendMessage(tm, out response);

                sp.bp = response.Buffer + response.Offset;
                int synReq_msg    = *sp.ip++;
                int synReqRsp_msg = *sp.ip++;
                int asynReq_msg   = *sp.ip++;

                synReqOffset    = (ushort)synReq_msg;
                synReqRspOffset = (ushort)synReqRsp_msg;
                asynReqOffset   = (ushort)asynReq_msg;

                return(response.ErrorCode == TrinityErrorCode.E_SUCCESS);
            }
        }
Exemple #2
0
        public void Move(TKey to, TKey from)
        {
            SmartPointer pTo   = map.Lookup(to);
            SmartPointer pFrom = map.Lookup(from);

            memory.Copy(pFrom.Address, pFrom.Length, pTo.Address, pTo.Length);
        }
Exemple #3
0
        public void Subdivide(TKey register, TKey lower)
        {
            SmartPointer ptr    = map.Lookup(register);
            uint         lowLen = ptr.Length / 2;
            uint         upLen  = ptr.Length - lowLen;

            Map(lower, ptr.Address, lowLen);
        }
Exemple #4
0
        public void ApplyMessageProcessor(string name, MessageDirections direction, bool isTransaction, bool isMarketData, IMessageProcessor defaultProcessor = null)
        {
            var           processor = new MessageProcessorPool(defaultProcessor ?? new MessageProcessor("Processor '{0}' ({1})".Put(name, direction), _errorHandler));
            ISmartPointer pointer   = new SmartPointer <IMessageProcessor>(processor, p =>
            {
                p.Stop();
                _processorPointers.Remove(p);
            });

            _processorPointers[processor] = pointer;

            switch (direction)
            {
            case MessageDirections.In:
                if (isTransaction)
                {
                    DecRefProcessor(TransactionAdapter, direction);

                    pointer.IncRef();
                    TransactionAdapter.InMessageProcessor = processor;
                }

                if (isMarketData)
                {
                    DecRefProcessor(MarketDataAdapter, direction);

                    pointer.IncRef();
                    MarketDataAdapter.InMessageProcessor = processor;
                }

                break;

            case MessageDirections.Out:
                if (isTransaction)
                {
                    DecRefProcessor(TransactionAdapter, direction);

                    pointer.IncRef();
                    TransactionAdapter.OutMessageProcessor = processor;
                }

                if (isMarketData)
                {
                    DecRefProcessor(MarketDataAdapter, direction);

                    pointer.IncRef();
                    MarketDataAdapter.OutMessageProcessor = processor;
                }

                break;

            default:
                _processorPointers.Remove(processor);
                throw new ArgumentOutOfRangeException("direction");
            }
        }
Exemple #5
0
        public Opcode(Opcodes opcode, OpcodeFlags flags, uint16_t opA, uint16_t opB)
        {
            this.opcode = opcode;

            operandA   = opA;
            operandB   = opB;
            this.flags = flags;

            ptr = new SmartPointer(0, 8);
        }
Exemple #6
0
 public void Map(TKey name, SmartPointer ptr)
 {
     try
     {
         map.Map(name, ptr);
     }
     catch
     {
         throw;
     }
 }
Exemple #7
0
 public byte[] Read(SmartPointer ptr)
 {
     try
     {
         return(Read(ptr.Address, ptr.Length));
     }
     catch
     {
         throw;
     }
 }
Exemple #8
0
 public void Append(TKey name, SmartPointer ptr)
 {
     try
     {
         Append(name, ptr.Length);
     }
     catch
     {
         throw;
     }
 }
Exemple #9
0
        /// <summary>Reads data from memory and converts it to the provided type. Includes built-in type safety by matching the requested type with the requested length from the SmartPointer.</summary>
        /// <typeparam name="TDataType">Data type requested.</typeparam>
        /// <param name="ptr">A pointer containing the address and length of the requested data.</param>
        /// <exception cref="Exception">Thrown if the length of the pointer is not equal to that of the data type.</exception>
        public TDataType Read <TDataType>(SmartPointer ptr)
            where TDataType : IDataType
        {
            TDataType value = Activator.CreateInstance <TDataType>();

            // TODO: Replace with a type mismatch error
            if (value.Length != ptr.Length)
            {
                throw new Exception("Type mismatch.");
            }

            value.Address = ptr.Address;
            byte[] data = Read(value.Pointer);
            value.FromBinary(data);

            return(value);
        }
Exemple #10
0
        public void Write(SmartPointer ptr, IIntegral value)
        {
            IIntegral val = value;

            if (ptr.Length != value.Length)
            {
                val = value.CastTo(Int.BestFit((int)ptr.Length));
            }

            try
            {
                Write(ptr.Address, val.ToBinary());
            }
            catch
            {
                throw;
            }
        }
Exemple #11
0
        bool CanWriteMemory(uint address, uint length)
        {
            SmartPointer ptr = new SmartPointer(address, length);

            MemoryAccessData[] mad = MemoryMap.FindEncompassingRanges(ptr);

            for (int i = 0; i < mad.Length; i++)
            {
                if (mad[i].ReadOnly)
                {
                    return(false);
                }
                if (mad[i].Ring < CPU.Ring)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #12
0
        public void Write(SmartPointer ptr, IDataType value)
        {
            if (value is IIntegral val)
            {
                Write(ptr, val);
                return;
            }
            if (ptr.Length != value.Length)
            {
                throw new Exception("Type mismatch.");
            }

            try
            {
                Write(ptr.Address, value.ToBinary());
            }
            catch
            {
                throw;
            }
        }
Exemple #13
0
        internal void GetCommunicationSchema(out string name, out string signature)
        {
            /******************
            * Comm. protocol:
            *  - REQUEST : VOID
            *  - RESPONSE: [char_cnt, char[] name, char_cnt, char[] sig]
            ******************/
            using (TrinityMessage tm = new TrinityMessage(
                       TrinityMessageType.PRESERVED_SYNC_WITH_RSP,
                       (ushort)RequestType.GetCommunicationSchema,
                       size: 0))
            {
                TrinityResponse response;
                this.SendMessage(tm, out response);
                SmartPointer sp = SmartPointer.New(response.Buffer + response.Offset);
                int          name_string_len = *sp.ip++;
                name   = BitHelper.GetString(sp.bp, name_string_len * 2);
                sp.cp += name_string_len;
                int sig_string_len = *sp.ip++;
                signature = BitHelper.GetString(sp.bp, sig_string_len * 2);

                response.Dispose();
            }
        }
Exemple #14
0
 public byte *SetString(SmartPointer data, int index, string newValue)
 {
     return(null);
 }
Exemple #15
0
 // ======== HELPERS : string, int, long, double, DateTime... all primitive and usual struct types !
 public string GetString(SmartPointer data, int index)
 {
     return(null);
 }
Exemple #16
0
        public ushort SizeOf(TKey name)
        {
            SmartPointer ptr = Lookup(name);

            return((ushort)ptr.Length);
        }
Exemple #17
0
 public Register_t(Register value, uint address)
 {
     this.value = (ushort)value;
     ptr        = new SmartPointer(address, 2);
 }
Exemple #18
0
 public uint8_t(byte value, uint address)
 {
     this.value = value;
     ptr        = new SmartPointer(address, 1);
 }
Exemple #19
0
 public uint64_t(UInt64 value, uint address)
 {
     this.value = value;
     ptr        = new SmartPointer(address, 8);
 }
Exemple #20
0
 public uint32_t(UInt32 value, uint address)
 {
     this.value = value;
     ptr        = new SmartPointer(address, 4);
 }
Exemple #21
0
 public uint16_t(UInt16 value, uint address)
 {
     this.value = value;
     ptr        = new SmartPointer(address, 2);
 }
Exemple #22
0
 public Opcode()
 {
     ptr = new SmartPointer(0, 8);
 }
Exemple #23
0
 public MemoryAccessException(SmartPointer ptr, bool read)
     : base(string.Format("Cannot {0} memory at address 0x{1:X8}:0x{2:X8} due to invalid access rights.", read ? "read" : "write", ptr.Address, ptr.Length))
 {
     Pointer = ptr;
 }