Debian Codegraph @

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Rfc2251/RfcMessageID.cs

raw
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc. www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
23 //
24 // Novell.Directory.Ldap.Rfc2251.RfcMessageID.cs
25 //
26 // Author:
27 // Sunil Kumar ([email protected])
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31
32 using System;
33 using Novell.Directory.Ldap.Asn1;
34
35 namespace Novell.Directory.Ldap.Rfc2251
36 {
37
38 /// <summary> Represents an Ldap Message ID.
39 ///
40 /// <pre>
41 /// MessageID ::= INTEGER (0 .. maxInt)
42 ///
43 /// maxInt INTEGER ::= 2147483647 -- (2^^31 - 1) --
44 ///
45 /// Note: The creation of a MessageID should be hidden within the creation of
46 /// an RfcLdapMessage. The MessageID needs to be in sequence, and has an
47 /// upper and lower limit. There is never a case when a user should be
48 /// able to specify the MessageID for an RfcLdapMessage. The MessageID()
49 /// class should be package protected. (So the MessageID value isn't
50 /// arbitrarily run up.)
51 /// </pre>
52 /// </summary>
53 class RfcMessageID:Asn1Integer
54 {
55 /// <summary> Increments the message number atomically
56 ///
57 /// </summary>
58 /// <returns> the new message number
59 /// </returns>
60 private static int MessageID
61 {
62 get
63 {
64 lock (lock_Renamed)
65 {
66 return (messageID < System.Int32.MaxValue)?++messageID:(messageID = 1);
67 }
68 }
69
70 }
71
72 private static int messageID = 0;
73 private static System.Object lock_Renamed;
74
75 /// <summary> Creates a MessageID with an auto incremented Asn1Integer value.
76 ///
77 /// Bounds: (0 .. 2,147,483,647) (2^^31 - 1 or Integer.MAX_VALUE)
78 ///
79 /// MessageID zero is never used in this implementation. Always
80 /// start the messages with one.
81 /// </summary>
82 protected internal RfcMessageID():base(MessageID)
83 {
84 }
85
86 /// <summary> Creates a MessageID with a specified int value.</summary>
87 protected internal RfcMessageID(int i):base(i)
88 {
89 }
90 static RfcMessageID()
91 {
92 lock_Renamed = new System.Object();
93 }
94 }
95 }