2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-08-17 01:47:36 +02:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-02-25 19:58:16 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Lm
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class ILogger : IpcService
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-02-25 19:58:16 +01:00
|
|
|
|
|
|
|
public ILogger()
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
|
|
|
{ 0, Log }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public long Log(ServiceCtx context)
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
2018-08-22 23:06:29 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
(long bufPos, long bufSize) = context.Request.GetBufferType0x21();
|
|
|
|
byte[] logBuffer = context.Memory.ReadBytes(bufPos, bufSize);
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream ms = new MemoryStream(logBuffer))
|
2018-04-24 20:57:39 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryReader reader = new BinaryReader(ms);
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
long pid = reader.ReadInt64();
|
|
|
|
long threadContext = reader.ReadInt64();
|
|
|
|
short flags = reader.ReadInt16();
|
|
|
|
byte level = reader.ReadByte();
|
|
|
|
byte verbosity = reader.ReadByte();
|
|
|
|
int payloadLength = reader.ReadInt32();
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
sb.AppendLine("Guest log:");
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
while (ms.Position < ms.Length)
|
2018-02-25 19:58:16 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
byte type = reader.ReadByte();
|
|
|
|
byte size = reader.ReadByte();
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
LmLogField field = (LmLogField)type;
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string fieldStr = string.Empty;
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (field == LmLogField.Start)
|
2018-04-24 20:57:39 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
reader.ReadBytes(size);
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-04-24 20:57:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (field == LmLogField.Stop)
|
2018-08-22 23:06:29 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (field == LmLogField.Line)
|
2018-04-24 20:57:39 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt32()}";
|
2018-02-25 19:58:16 +01:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (field == LmLogField.DropCount)
|
2018-08-22 23:06:29 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}";
|
2018-08-22 23:06:29 +02:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (field == LmLogField.Time)
|
2018-08-22 23:06:29 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}s";
|
2018-08-22 23:06:29 +02:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (field < LmLogField.Count)
|
2018-04-24 20:57:39 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
2018-04-24 20:57:39 +02:00
|
|
|
}
|
2018-08-22 23:06:29 +02:00
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
2018-08-22 23:06:29 +02:00
|
|
|
}
|
2018-04-24 20:57:39 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
sb.AppendLine(" " + fieldStr);
|
2018-02-25 19:58:16 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string text = sb.ToString();
|
2018-02-25 19:58:16 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
switch((LmLogLevel)level)
|
2018-04-24 20:57:39 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
case LmLogLevel.Trace: Logger.PrintDebug (LogClass.ServiceLm, text); break;
|
|
|
|
case LmLogLevel.Info: Logger.PrintInfo (LogClass.ServiceLm, text); break;
|
|
|
|
case LmLogLevel.Warning: Logger.PrintWarning(LogClass.ServiceLm, text); break;
|
|
|
|
case LmLogLevel.Error: Logger.PrintError (LogClass.ServiceLm, text); break;
|
|
|
|
case LmLogLevel.Critical: Logger.PrintError (LogClass.ServiceLm, text); break;
|
2018-04-24 20:57:39 +02:00
|
|
|
}
|
2018-02-25 19:58:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|