root/trunk/AprSharp/dev/src/Apr-old.cs

Revision 1, 2.1 kB (checked in by DenisG, 3 years ago)

Initial import

  • Property svn:eol-style set to native
Line 
1 //
2 // Softec
3 //
4 // Contact:
5 //
6 // Designed by Denis Gervalle and Olivier Desaive
7 // Written by Denis Gervalle
8 //
9 // Copyright 2004 by SOFTEC. All rights reserved.
10 //
11 using System;
12 using System.Runtime.InteropServices;
13 using System.Text;
14 using System.Diagnostics;
15
16 namespace Softec.AprSharp
17 {
18     public class Apr : IDisposable
19     {
20         private static Apr mSingleton = null;
21    
22         #region DLL imports
23             [DllImport("apr-0")]
24         private static extern int apr_initialize( );
25        
26             [DllImport("apr-0")]
27         private static extern void apr_terminate2( );
28
29             [DllImport("apr-0"), CLSCompliant(false)]
30         private static extern void apr_strerror(int apr_status,
31                                                 StringBuilder buf,
32                                                 uint size);
33         #endregion
34
35         #region Constructor / IDisposable
36         public static Apr Initialize()
37         {
38             lock( typeof(Apr) ) {
39                 if(Apr.mSingleton == null)
40                 {
41                     Apr.mSingleton = new Apr();
42                 }
43                 return Apr.mSingleton;
44             }
45         }
46        
47         public void Dispose()
48         {
49             lock( typeof(Apr) ) {
50                 if (Apr.mSingleton != null)
51                 {
52                     Debug.Write("apr_terminate2...");
53                     apr_terminate2();
54                     Debug.WriteLine("Done");
55                     Apr.mSingleton = null;
56                     GC.SuppressFinalize(this);
57                 }
58             }
59         }
60
61         private Apr() {
62             int apr_status;
63             Debug.Write("apr_initialize...");
64             apr_status = apr_initialize();
65             Debug.WriteLine("Done");
66             if( apr_status != 0 )
67                 throw new AprException(apr_status);
68         }
69        
70         ~Apr() {
71             Dispose();
72         }
73         #endregion
74  
75         public static string StrError(int apr_status)
76         {       
77             StringBuilder buf = new StringBuilder (1024);
78             Apr.apr_strerror(apr_status, buf, (uint)buf.Capacity);
79             return(buf.ToString());
80         }   
81     }
82 }   
Note: See TracBrowser for help on using the browser.