-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogcatManager.cs
137 lines (107 loc) · 3.33 KB
/
LogcatManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Text;
namespace yald
{
class LogcatManager
{
public delegate void DeviceConnectedEventHandler();
private GenericArrayList<FilteredLogSlot> Slots;
private EntryList GeneralEntries;
private TabContent GeneralTabUi;
ProcessObject LogcatProcess;
public LogcatManager()
{
Slots = new GenericArrayList<FilteredLogSlot>(10);
GeneralEntries = new EntryList();
LogcatProcess = new ProcessObject("logcat");
LogcatProcess.OnLineOutputReceive += new ProcessObject.ConsoleLineOutputHandler(LogcatProcess_OnLineOutputReceive);
}
void LogcatProcess_OnLineOutputReceive(string line)
{
if (line == "DEVCON")
{
if (OnDeviceConnected != null)
OnDeviceConnected();
return;
}
LogEntry entry = LogEntry.Parse(line);
bool IsGeneralEntry = true;
Slots.Iterate(delegate(FilteredLogSlot slot)
{
if (slot.TryAdd(entry))
{
IsGeneralEntry = false;
return true;
}
IsGeneralEntry = true;
return false;
});
if (IsGeneralEntry)
{
GeneralEntries.AddEntry(entry);
if (GeneralTabUi.InvokeRequired)
{
GeneralTabUi.Invoke(new System.Windows.Forms.MethodInvoker(delegate()
{
GeneralTabUi.WriteLog(entry);
}));
}
}
}
public FilteredLogSlot AddSlot(string Name, FilterList Filters)
{
FilteredLogSlot Slot = null;
if (string.IsNullOrEmpty(Name) || Filters == null)
return null;
Slot = new FilteredLogSlot(Name, Filters);
Slots.Add(Slot);
return Slot;
}
public void RemoveSlot(string Name)
{
FilteredLogSlot ToRemoveSlot = null;
foreach (FilteredLogSlot slot in Slots)
{
if (slot.Name == Name)
{
ToRemoveSlot = slot;
break;
}
}
if (ToRemoveSlot != null)
{
ToRemoveSlot.Dispose();
Slots.Remove(ToRemoveSlot);
}
}
public void Stop()
{
LogcatProcess.Kill();
}
public bool Start()
{
if (string.IsNullOrEmpty(LogcatProcess.ExecutableFile))
throw new Exception("adb executable is not set!");
LogcatProcess.Start();
return LogcatProcess.IsRunning;
}
public TabContent GeneralTabContent
{
get
{
return GeneralTabUi;
}
set
{
GeneralTabUi = value;
}
}
public string Adb
{
get { return LogcatProcess.ExecutableFile; }
set { LogcatProcess.ExecutableFile = value; }
}
public event DeviceConnectedEventHandler OnDeviceConnected;
}
}