Remove some deprecated libraries
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Embedded / FesServiceManager.cs
1 /*
2  *      Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *         The contents of this file are subject to the Initial 
5  *         Developer's Public License Version 1.0 (the "License"); 
6  *         you may not use this file except in compliance with the 
7  *         License. You may obtain a copy of the License at 
8  *         http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *         Software distributed under the License is distributed on 
11  *         an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *         express or implied. See the License for the specific 
13  *         language governing rights and limitations under the License.
14  * 
15  *      Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16  *      All Rights Reserved.
17  */
18
19 using System;
20 using System.IO;
21 using FirebirdSql.Data.Common;
22
23 namespace FirebirdSql.Data.Embedded
24 {
25         internal sealed class FesServiceManager : IServiceManager
26         {
27                 #region Fields
28
29                 private int handle;
30
31                 #endregion
32
33                 #region Properties
34
35                 public int Handle
36                 {
37                         get { return this.handle; }
38                 }
39
40                 public bool IsLittleEndian
41                 {
42                         get { return BitConverter.IsLittleEndian; }
43                 }
44
45                 #endregion
46
47                 #region Constructors
48
49                 public FesServiceManager()
50                 {
51                 }
52
53                 #endregion
54
55                 #region Methods
56
57                 public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service)
58                 {
59                         int[] statusVector = FesConnection.GetNewStatusVector();
60                         int svcHandle = this.Handle;
61
62                         FbClient.isc_service_attach(
63                                 statusVector,
64                                 (short)service.Length,
65                                 service,
66                                 ref     svcHandle,
67                                 (short)spb.Length,
68                                 spb.ToArray());
69
70                         // Parse status vector
71                         this.ParseStatusVector(statusVector);
72
73                         // Update status vector
74                         this.handle = svcHandle;
75                 }
76
77                 public void Detach()
78                 {
79                         int[] statusVector = FesConnection.GetNewStatusVector();
80                         int svcHandle = this.Handle;
81
82                         FbClient.isc_service_detach(statusVector, ref svcHandle);
83
84                         // Parse status vector
85                         this.ParseStatusVector(statusVector);
86
87                         // Update status vector
88                         this.handle = svcHandle;
89                 }
90
91                 public void Start(ServiceParameterBuffer spb)
92                 {
93                         int[] statusVector = FesConnection.GetNewStatusVector();
94                         int svcHandle = this.Handle;
95                         int reserved = 0;
96
97                         FbClient.isc_service_start(
98                                 statusVector,
99                                 ref     svcHandle,
100                                 ref     reserved,
101                                 (short)spb.Length,
102                                 spb.ToArray());
103
104                         // Parse status vector
105                         this.ParseStatusVector(statusVector);
106                 }
107
108                 public void Query(
109                         ServiceParameterBuffer spb,
110                         int requestLength,
111                         byte[] requestBuffer,
112                         int bufferLength,
113                         byte[] buffer)
114                 {
115                         int[] statusVector = FesConnection.GetNewStatusVector();
116                         int svcHandle = this.Handle;
117                         int reserved = 0;
118
119                         FbClient.isc_service_query(
120                                 statusVector,
121                                 ref     svcHandle,
122                                 ref     reserved,
123                                 (short)spb.Length,
124                                 spb.ToArray(),
125                                 (short)requestLength,
126                                 requestBuffer,
127                                 (short)buffer.Length,
128                                 buffer);
129
130                         // Parse status vector
131                         this.ParseStatusVector(statusVector);
132                 }
133
134                 #endregion
135
136                 #region Buffer Creation methods
137
138                 public ServiceParameterBuffer CreateParameterBuffer()
139                 {
140                         return new ServiceParameterBuffer();
141                 }
142
143                 #endregion
144
145                 #region Private Methods
146
147                 private void ParseStatusVector(int[] statusVector)
148                 {
149                         IscException ex = FesConnection.ParseStatusVector(statusVector);
150
151                         if (ex != null && !ex.IsWarning)
152                         {
153                                 throw ex;
154                         }
155                 }
156
157                 #endregion
158         }
159 }