Beispiel #1
0
        public static Message parse(byte[] buffer)
        {
            int i = 0;
            int type = buffer[i++];

            Message msg = new Message(type);
            switch (type)
            {
                case Message.MSG_REQ_COMPONENT://flag
                    i = msg.decodeInt(buffer, i, ref msg.flag);
                    break;
                case Message.MSG_REQ_PROCESS://flag and pid
                    i = msg.decodeInt(buffer, i, ref msg.flag);
                    i = msg.decodeInt(buffer, i, ref msg.pid);
                    break;
                case Message.MSG_REQ_SYSTEM_ENG://time
                case Message.MSG_REQ_CPU_ENG:
                case Message.MSG_REQ_MEM_ENG:
                case Message.MSG_REQ_DISK_ENG:
                case Message.MSG_REQ_NIC_ENG:
                    i = msg.decodeLong(buffer, i, ref msg.time);
                    break;
                case Message.MSG_REQ_PRO_ENG://time and pid
                case Message.MSG_REQ_PRO_CPU_ENG:
                case Message.MSG_REQ_PRO_MEM_ENG:
                case Message.MSG_REQ_PRO_DISK_ENG:
                case Message.MSG_REQ_PRO_NIC_ENG:
                    i = msg.decodeLong(buffer, i, ref msg.time);
                    i = msg.decodeInt(buffer, i, ref msg.pid);
                    break;
                case Message.MSG_RESP_COMPONENT://data
                case Message.MSG_RESP_PROCESS:
                    i = msg.decodeDoubleArray(buffer, i, ref msg.data);
                    break;
                case Message.MSG_RESP_PROINFO:// process info
                    i = msg.decodeTable(buffer, i, ref msg.info);
                    break;
                case Message.MSG_RESP_SYSTEM_ENG://energy
                case Message.MSG_RESP_CPU_ENG:
                case Message.MSG_RESP_MEM_ENG:
                case Message.MSG_RESP_DISK_ENG:
                case Message.MSG_RESP_NIC_ENG:
                case Message.MSG_RESP_PRO_ENG:
                case Message.MSG_RESP_PRO_CPU_ENG:
                case Message.MSG_RESP_PRO_MEM_ENG:
                case Message.MSG_RESP_PRO_DISK_ENG:
                case Message.MSG_RESP_PRO_NIC_ENG:
                    i = msg.decodeDouble(buffer, i, ref msg.energy);
                    break;
                case Message.MSG_RESP_PRO_AVGPOWER:
                    i = msg.decodeAvgPower(buffer, i, ref msg.info);
                    break;
                case Message.MSG_RESP_SYS_AVGPOWER:
                    i = msg.decodeDouble(buffer, i, ref msg.energy);
                    break;
                default:
                    break;
            }
            return msg;
        }
Beispiel #2
0
 private void processRequest(Message req, Message resp)
 {
     switch(req.type)
     {
         case Message.MSG_REQ_COMPONENT:
             resp.data= ComponentInfo(req.flag);
             break;
         case Message.MSG_REQ_PROCESS:
             resp.data = ProcessInfo(req.flag, req.pid);
             break;
         case Message.MSG_REQ_SYSTEM_ENG:
             resp.energy = systemEnergy(req.time);
             break;
         case Message.MSG_REQ_CPU_ENG:
             resp.energy = cpuEnergy(req.time);
             break;
         case Message.MSG_REQ_MEM_ENG:
             resp.energy = memoryEnergy(req.time);
             break;
         case Message.MSG_REQ_DISK_ENG:
             resp.energy = diskEnergy(req.time);
             break;
         case Message.MSG_REQ_NIC_ENG:
             resp.energy = nicEnergy(req.time);
             break;
         case Message.MSG_REQ_PRO_ENG:
             resp.energy = totalProcessEnergy(req.time, req.pid);
             break;
         case Message.MSG_REQ_PRO_CPU_ENG:
             resp.energy = cpuProcessEnergy(req.time, req.pid);
             break;
         case Message.MSG_REQ_PRO_MEM_ENG:
             resp.energy = memoryProcessEnergy(req.time, req.pid);
             break;
         case Message.MSG_REQ_PRO_DISK_ENG:
             resp.energy = diskProcessEnergy(req.time, req.pid);
             break;
         case Message.MSG_REQ_PRO_NIC_ENG:
             resp.energy = nicProcessEnergy(req.time, req.pid);
             break;
         case Message.MSG_REQ_PROINFO:
             resp.info = processEnergy();
             break;
         case Message.MSG_REQ_PRO_AVGPOWER:
             resp.info = processAvgPower();
             break;
         case Message.MSG_REQ_SYS_AVGPOWER:
             resp.energy = systemAvgPower();
             break;
         default:
             break;
     }
 }
Beispiel #3
0
        public int WriteMessage(Message msg)
        {
            try{
                byte[] outBuffer = msg.encode();
                int len = outBuffer.Length;
                if (len > Int32.MaxValue)
                {
                    len = Int32.MaxValue;
                }

                ioStream.Write(BitConverter.GetBytes(len), 0, 4);
                ioStream.Write(outBuffer, 0, len);
                ioStream.Flush();

                return outBuffer.Length + 4;
            }
            catch (System.Exception ex)
            {
                throw new MyException(ex.Message, MyException.MSG_WRITE_MESSAGE_ERROR);
            }
        }