corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * CVS identifier: |
||
3 | * |
||
4 | * $Id: FacilityManager.java,v 1.12 2002/05/22 15:00:24 grosbois Exp $ |
||
5 | * |
||
6 | * Class: MsgLoggerManager |
||
7 | * |
||
8 | * Description: Manages common facilities across threads |
||
9 | * |
||
10 | * |
||
11 | * |
||
12 | * COPYRIGHT: |
||
13 | * |
||
14 | * This software module was originally developed by Raphaël Grosbois and |
||
15 | * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel |
||
16 | * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David |
||
17 | * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research |
||
18 | * Centre France S.A) in the course of development of the JPEG2000 |
||
19 | * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This |
||
20 | * software module is an implementation of a part of the JPEG 2000 |
||
21 | * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio |
||
22 | * Systems AB and Canon Research Centre France S.A (collectively JJ2000 |
||
23 | * Partners) agree not to assert against ISO/IEC and users of the JPEG |
||
24 | * 2000 Standard (Users) any of their rights under the copyright, not |
||
25 | * including other intellectual property rights, for this software module |
||
26 | * with respect to the usage by ISO/IEC and Users of this software module |
||
27 | * or modifications thereof for use in hardware or software products |
||
28 | * claiming conformance to the JPEG 2000 Standard. Those intending to use |
||
29 | * this software module in hardware or software products are advised that |
||
30 | * their use may infringe existing patents. The original developers of |
||
31 | * this software module, JJ2000 Partners and ISO/IEC assume no liability |
||
32 | * for use of this software module or modifications thereof. No license |
||
33 | * or right to this software module is granted for non JPEG 2000 Standard |
||
34 | * conforming products. JJ2000 Partners have full right to use this |
||
35 | * software module for his/her own purpose, assign or donate this |
||
36 | * software module to any third party and to inhibit third parties from |
||
37 | * using this software module for non JPEG 2000 Standard conforming |
||
38 | * products. This copyright notice must be included in all copies or |
||
39 | * derivative works of this software module. |
||
40 | * |
||
41 | * Copyright (c) 1999/2000 JJ2000 Partners. |
||
42 | * */ |
||
43 | using System; |
||
44 | namespace CSJ2K.j2k.util |
||
45 | { |
||
46 | |||
47 | /// <summary> This class manages common facilities for multi-threaded |
||
48 | /// environments, It can register different facilities for each thread, |
||
49 | /// and also a default one, so that they can be referred by static |
||
50 | /// methods, while possibly having different ones for different |
||
51 | /// threads. Also a default facility exists that is used for threads |
||
52 | /// for which no particular facility has been registerd registered. |
||
53 | /// |
||
54 | /// <p>Currently the only kind of facilities managed is MsgLogger.</p> |
||
55 | /// |
||
56 | /// <P>An example use of this class is if 2 instances of a decoder are running |
||
57 | /// in different threads and the messages of the 2 instances should be |
||
58 | /// separated. |
||
59 | /// |
||
60 | /// <P>The default MsgLogger is a StreamMsgLogger that uses System.out as |
||
61 | /// the 'out' stream and System.err as the 'err' stream, and a line width of |
||
62 | /// 78. This can be changed using the registerMsgLogger() method. |
||
63 | /// |
||
64 | /// </summary> |
||
65 | /// <seealso cref="MsgLogger"> |
||
66 | /// </seealso> |
||
67 | /// <seealso cref="StreamMsgLogger"> |
||
68 | /// |
||
69 | /// </seealso> |
||
70 | public class FacilityManager |
||
71 | { |
||
72 | /// <summary> Returns the ProgressWatch instance registered with the current |
||
73 | /// thread (the thread that calls this method). If the current |
||
74 | /// thread has no registered ProgressWatch, then the default one is used. |
||
75 | /// |
||
76 | /// </summary> |
||
77 | public static ProgressWatch ProgressWatch |
||
78 | { |
||
79 | get |
||
80 | { |
||
81 | ProgressWatch pw = (ProgressWatch) watchProgList[SupportClass.ThreadClass.Current()]; |
||
82 | return (pw == null)?defWatchProg:pw; |
||
83 | } |
||
84 | |||
85 | } |
||
86 | |||
87 | /// <summary>The loggers associated to different threads </summary> |
||
88 | //UPGRADE_NOTE: Final was removed from the declaration of 'loggerList '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
89 | private static readonly System.Collections.Hashtable loggerList = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); |
||
90 | |||
91 | /// <summary>The default logger, for threads that have none associated with them </summary> |
||
92 | private static MsgLogger defMsgLogger = new StreamMsgLogger(System.Console.OpenStandardOutput(), System.Console.OpenStandardError(), 78); |
||
93 | |||
94 | /// <summary>The ProgressWatch instance associated to different threads </summary> |
||
95 | //UPGRADE_NOTE: Final was removed from the declaration of 'watchProgList '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" |
||
96 | private static readonly System.Collections.Hashtable watchProgList = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); |
||
97 | |||
98 | /// <summary>The default ProgressWatch for threads that have none |
||
99 | /// associated with them. |
||
100 | /// </summary> |
||
101 | private static ProgressWatch defWatchProg = null; |
||
102 | |||
103 | |||
104 | internal static void registerProgressWatch(SupportClass.ThreadClass t, ProgressWatch pw) |
||
105 | { |
||
106 | if (pw == null) |
||
107 | { |
||
108 | throw new System.NullReferenceException(); |
||
109 | } |
||
110 | if (t == null) |
||
111 | { |
||
112 | defWatchProg = pw; |
||
113 | } |
||
114 | else |
||
115 | { |
||
116 | watchProgList[t] = pw; |
||
117 | } |
||
118 | } |
||
119 | |||
120 | /// <summary> Registers the MsgLogger 'ml' as the logging facility of the |
||
121 | /// thread 't'. If any other logging facility was registered with |
||
122 | /// the thread 't' it is overriden by 'ml'. If 't' is null then |
||
123 | /// 'ml' is taken as the default message logger that is used for |
||
124 | /// threads that have no MsgLogger registered. |
||
125 | /// |
||
126 | /// </summary> |
||
127 | /// <param name="t">The thread to associate with 'ml' |
||
128 | /// |
||
129 | /// </param> |
||
130 | /// <param name="ml">The MsgLogger to associate with therad ml |
||
131 | /// |
||
132 | /// </param> |
||
133 | internal static void registerMsgLogger(SupportClass.ThreadClass t, MsgLogger ml) |
||
134 | { |
||
135 | if (ml == null) |
||
136 | { |
||
137 | throw new System.NullReferenceException(); |
||
138 | } |
||
139 | if (t == null) |
||
140 | { |
||
141 | defMsgLogger = ml; |
||
142 | } |
||
143 | else |
||
144 | { |
||
145 | loggerList[t] = ml; |
||
146 | } |
||
147 | } |
||
148 | |||
149 | /// <summary> Returns the MsgLogger registered with the current thread (the |
||
150 | /// thread that calls this method). If the current thread has no |
||
151 | /// registered MsgLogger then the default message logger is |
||
152 | /// returned. |
||
153 | /// |
||
154 | /// </summary> |
||
155 | /// <returns> The MsgLogger registerd for the current thread, or the |
||
156 | /// default one if there is none registered for it. |
||
157 | /// |
||
158 | /// </returns> |
||
159 | public static MsgLogger getMsgLogger() |
||
160 | { |
||
161 | MsgLogger ml = (MsgLogger) loggerList[SupportClass.ThreadClass.Current()]; |
||
162 | return (ml == null)?defMsgLogger:ml; |
||
163 | } |
||
164 | |||
165 | /// <summary> Returns the MsgLogger registered with the thread 't' (the |
||
166 | /// thread that calls this method). If the thread 't' has no |
||
167 | /// registered MsgLogger then the default message logger is |
||
168 | /// returned. |
||
169 | /// |
||
170 | /// </summary> |
||
171 | /// <param name="t">The thread for which to return the MsgLogger |
||
172 | /// |
||
173 | /// </param> |
||
174 | /// <returns> The MsgLogger registerd for the current thread, or the |
||
175 | /// default one if there is none registered for it. |
||
176 | /// |
||
177 | /// </returns> |
||
178 | internal static MsgLogger getMsgLogger(SupportClass.ThreadClass t) |
||
179 | { |
||
180 | MsgLogger ml = (MsgLogger) loggerList[t]; |
||
181 | return (ml == null)?defMsgLogger:ml; |
||
182 | } |
||
183 | } |
||
184 | } |