Initial commit
[mono.git] / mcs / class / referencesource / mscorlib / system / diagnostics / eventing / eventdescriptor.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="etwprovider.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <OWNER>[....]</OWNER>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Runtime.InteropServices;
9 using System.Diagnostics.Contracts;
10
11 namespace System.Diagnostics.Tracing
12 {
13     [StructLayout(LayoutKind.Explicit, Size = 16)]
14     [System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
15     internal struct EventDescriptor
16     {
17         # region private
18         [FieldOffset(0)]
19         private ushort m_id;
20         [FieldOffset(2)]
21         private byte m_version;
22         [FieldOffset(3)]
23         private byte m_channel;
24         [FieldOffset(4)]
25         private byte m_level;
26         [FieldOffset(5)]
27         private byte m_opcode;
28         [FieldOffset(6)]
29         private ushort m_task;
30         [FieldOffset(8)]
31         private long m_keywords;
32         #endregion
33
34         public EventDescriptor(
35                 int id,
36                 byte version,
37                 byte channel,
38                 byte level,
39                 byte opcode,
40                 int task,
41                 long keywords
42                 )
43         {
44             if (id < 0)
45             {
46                 throw new ArgumentOutOfRangeException("id", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
47             }
48
49             if (id > ushort.MaxValue)
50             {
51                 throw new ArgumentOutOfRangeException("id", Environment.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
52             }
53
54             m_id = (ushort)id;
55             m_version = version;
56             m_channel = channel;
57             m_level = level;
58             m_opcode = opcode;
59             m_keywords = keywords;
60
61             if (id < 0)
62             {
63                 throw new ArgumentOutOfRangeException("task", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
64             }
65
66             if (id > ushort.MaxValue)
67             {
68                 throw new ArgumentOutOfRangeException("task", Environment.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
69             }
70
71             m_task = (ushort)task;
72         }
73
74         public int EventId { 
75             get {
76                 return m_id;
77             }
78         }
79         public byte Version
80         {
81             get
82             {
83                 return m_version;
84             }
85         }
86         public byte Channel
87         {
88             get
89             {
90                 return m_channel;
91             }
92         }
93         public byte Level
94         {
95             get
96             {
97                 return m_level;
98             }
99         }
100         public byte Opcode
101         {
102             get
103             {
104                 return m_opcode;
105             }
106         }
107         public int Task
108         {
109             get
110             {
111                 return m_task;
112             }
113         }
114         public long Keywords
115         {
116             get
117             {
118                 return m_keywords;
119             }
120         }
121
122         public override bool Equals(object obj)
123         {
124             if (!(obj is EventDescriptor))
125                 return false;
126
127             return Equals((EventDescriptor) obj);
128         }
129
130         public override int GetHashCode()
131         {
132             return m_id ^ m_version ^ m_channel ^ m_level ^ m_opcode ^ m_task ^ (int)m_keywords; 
133         }
134
135         public bool Equals(EventDescriptor other)
136         {
137             if ((m_id != other.m_id) ||
138                 (m_version != other.m_version) ||
139                 (m_channel != other.m_channel) ||
140                 (m_level != other.m_level) ||
141                 (m_opcode != other.m_opcode) ||
142                 (m_task != other.m_task) ||
143                 (m_keywords != other.m_keywords))
144             {
145                 return false;
146             }
147             return true;
148         }
149
150         public static bool operator ==(EventDescriptor event1, EventDescriptor event2)
151         {
152             return event1.Equals(event2);
153         }
154
155         public static bool operator !=(EventDescriptor event1, EventDescriptor event2)
156         {
157             return !event1.Equals(event2);
158         }    
159     }
160 }