Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame^] | 1 | using System; |
| 2 | using System.Runtime.InteropServices; |
| 3 | using System.Threading; |
| 4 | using System.Threading.Tasks; |
| 5 | using Google.GRPC.Core.Internal; |
| 6 | |
| 7 | namespace Google.GRPC.Core |
| 8 | { |
| 9 | public class Channel : IDisposable |
| 10 | { |
| 11 | /// <summary> |
| 12 | /// Make sure GPRC environment is initialized before any channels get used. |
| 13 | /// </summary> |
| 14 | static Channel() { |
| 15 | GrpcEnvironment.EnsureInitialized(); |
| 16 | } |
| 17 | |
| 18 | readonly ChannelSafeHandle handle; |
| 19 | readonly String target; |
| 20 | |
| 21 | // TODO: add way how to create grpc_secure_channel.... |
| 22 | // TODO: add support for channel args... |
| 23 | public Channel(string target) |
| 24 | { |
| 25 | this.handle = ChannelSafeHandle.Create(target, IntPtr.Zero); |
| 26 | this.target = target; |
| 27 | } |
| 28 | |
| 29 | internal ChannelSafeHandle Handle |
| 30 | { |
| 31 | get |
| 32 | { |
| 33 | return this.handle; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public string Target |
| 38 | { |
| 39 | get |
| 40 | { |
| 41 | return this.target; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public void Dispose() |
| 46 | { |
| 47 | Dispose(true); |
| 48 | GC.SuppressFinalize(this); |
| 49 | } |
| 50 | |
| 51 | protected virtual void Dispose(bool disposing) |
| 52 | { |
| 53 | if (handle != null && !handle.IsInvalid) |
| 54 | { |
| 55 | handle.Dispose(); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |