2 * Firebird ADO.NET Data provider for .NET and Mono
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
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.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
21 using FirebirdSql.Data.Common;
23 namespace FirebirdSql.Data.Gds
25 internal sealed class GdsServiceManager : IServiceManager
30 private GdsConnection connection;
38 get { return this.handle; }
41 public bool IsLittleEndian
50 public GdsServiceManager()
58 public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service)
64 if (this.connection == null)
66 this.connection = new GdsConnection();
69 this.connection.Connect(dataSource, port, 8192, Charset.DefaultCharset);
71 this.connection.Send.Write(IscCodes.op_service_attach);
72 this.connection.Send.Write(0);
73 this.connection.Send.Write(service);
74 this.connection.Send.WriteBuffer(spb.ToArray());
75 this.connection.Send.Flush();
79 this.handle = this.connection.ReadGenericResponse().ObjectHandle;
96 this.connection.Disconnect();
98 throw new IscException(IscCodes.isc_net_write_err);
109 this.connection.Send.Write(IscCodes.op_service_detach);
110 this.connection.Send.Write(this.Handle);
111 this.connection.Send.Flush();
113 this.connection.ReadGenericResponse();
119 throw new IscException(IscCodes.isc_network_error);
125 this.connection.Disconnect();
129 throw new IscException(IscCodes.isc_network_error);
135 public void Start(ServiceParameterBuffer spb)
141 this.connection.Send.Write(IscCodes.op_service_start);
142 this.connection.Send.Write(this.Handle);
143 this.connection.Send.Write(0);
144 this.connection.Send.WriteBuffer(spb.ToArray(), spb.Length);
145 this.connection.Send.Flush();
149 this.connection.ReadGenericResponse();
158 throw new IscException(IscCodes.isc_net_write_err);
164 ServiceParameterBuffer spb,
166 byte[] requestBuffer,
174 this.connection.Send.Write(IscCodes.op_service_info); // operation
175 this.connection.Send.Write(this.Handle); // db_handle
176 this.connection.Send.Write((int)0); // incarnation
177 this.connection.Send.WriteTyped(
178 IscCodes.isc_spb_version, spb.ToArray()); // Service parameter buffer
179 this.connection.Send.WriteBuffer(
180 requestBuffer, requestLength); // request buffer
181 this.connection.Send.Write(bufferLength); // result buffer length
183 this.connection.Send.Flush();
185 GdsResponse r = this.connection.ReadGenericResponse();
187 Buffer.BlockCopy(r.Data, 0, buffer, 0, bufferLength);
191 throw new IscException(IscCodes.isc_network_error);
198 #region Buffer creation methods
200 public ServiceParameterBuffer CreateParameterBuffer()
202 return new ServiceParameterBuffer();