blob: b0d8beeb7bf5e0bbc98cc4feae1a3e2c1fe266ae [file] [log] [blame]
Jan Tattermuscha7608b02015-02-03 17:54:38 -08001using System;
2using System.Runtime.InteropServices;
3using System.Threading;
4using System.Threading.Tasks;
5using Google.GRPC.Core.Internal;
6
7namespace 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}