annotate Implab/Diagnostics/OperationContext.cs @ 92:4c0e5ef99986 v2

rewritten tracing
author cin
date Wed, 22 Oct 2014 18:37:56 +0400
parents
children dc4942d09e74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
1 namespace Implab.Diagnostics {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
2 struct OperationContext {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
3 readonly LogicalOperation m_initial;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
5 LogicalOperation m_current;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
6 readonly bool m_ownership;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
7
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
8 public OperationContext(LogicalOperation operation, bool ownership) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
9 Safe.ArgumentNotNull(operation, "operation");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
10
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
11 m_initial = operation;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
12 m_current = operation;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
13 m_ownership = ownership;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
14 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
15
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
16 public LogicalOperation CurrentOperation {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
17 get { return m_current; }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
18 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
19
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
20 public void BeginLogicalOperation(string name) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
21 m_current = new LogicalOperation(name, m_current);
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
22 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
23
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
24 public LogicalOperation DetachLogicalOperation() {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
25 var detached = m_current;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
26 if (m_current != LogicalOperation.EMPTY) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
27 if (m_current != m_initial)
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
28 m_current = m_current.Parent;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
29 else if (m_ownership)
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
30 m_current = LogicalOperation.EMPTY;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
31 else
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
32 detached = LogicalOperation.EMPTY;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
33 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
34 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
35 return detached;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
36 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
37
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
38 public void EndLogicalOperation() {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
39 if (m_current != m_initial) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
40 m_current = m_current.Parent;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
41 } else if (m_current != null && m_ownership) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
42 m_current = null;
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
43 } else {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
44 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
45 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
46 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
47 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
48 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
49