* HttpRemotingHandlerFactory.cs: Loading of remoting configuration moved
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Http / HttpChannel.cs
1 //
2 // System.Runtime.Remoting.Channels.Http.HttpChannel
3 //
4 // Summary:     Implements a wrapper class for HTTP client and server channels.
5 //
6 // Classes:    public HttpChannel
7 //
8 // Authors:
9 //      Martin Willemoes Hansen (mwh@sysrq.dk)
10 //              Ahmad Tantawy (popsito82@hotmail.com)
11 //              Ahmad Kadry (kadrianoz@hotmail.com)
12 //              Hussein Mehanna (hussein_mehanna@hotmail.com)
13 //
14 // (C) 2003 Martin Willemoes Hansen
15 //
16
17 using System;
18 using System.Collections;
19 using System.Runtime.Remoting.Messaging;
20
21
22 namespace System.Runtime.Remoting.Channels.Http  
23 {
24
25         public class HttpChannel: IChannelReceiver, IChannelSender, IChannel, IChannelReceiverHook
26         {
27                 private HttpServerChannel serverChannel;
28                 private HttpClientChannel clientChannel;
29                 private string channelName = "http";
30                 private int channelPriority = 1;
31
32                 public HttpChannel()
33                 {
34                         SetupChannel (new Hashtable(), null, null);
35                 }
36
37                 public HttpChannel (int port)
38                 {
39                         Hashtable prop = new Hashtable();
40                         prop["port"] = port;
41                         SetupChannel(prop,null,null);
42                 }
43
44                 public HttpChannel (IDictionary Properties,IClientChannelSinkProvider clientSinkProvider,IServerChannelSinkProvider serverSinkProvider)
45                 {
46                         SetupChannel (Properties,clientSinkProvider,serverSinkProvider);
47                 }
48
49                 private void SetupChannel (IDictionary properties, IClientChannelSinkProvider clientSinkProvider, IServerChannelSinkProvider serverSinkProvider)
50                 {
51                         clientChannel = new HttpClientChannel (properties, clientSinkProvider);
52                         serverChannel = new HttpServerChannel (properties, serverSinkProvider);
53                         
54                         object val = properties ["name"];
55                         if (val != null) channelName = val as string;
56                         
57                         val = properties ["priority"];
58                         if (val != null) channelPriority = Convert.ToInt32 (val);
59                 }
60
61
62                 //IChannel Members
63                 public String ChannelName
64                 {
65                         get { return channelName; }
66                 }
67
68                 public int ChannelPriority
69                 {
70                         get { return channelPriority; }
71                 }
72
73                 public String Parse(String url, out String objectURI)
74                 {
75                         return HttpHelper.Parse(url, out objectURI);
76                 }
77
78                 //IChannelSender Members
79                 public IMessageSink CreateMessageSink(String url, Object remoteChannelData, out String objectURI)
80                 {
81                         return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
82                 }
83
84                 //IChannelReciever Members
85                 public String[] GetUrlsForUri(String objectURI)
86                 {
87                         return serverChannel.GetUrlsForUri(objectURI);
88                 } 
89
90                 public void StartListening(Object data)
91                 {
92                         serverChannel.StartListening(data);
93                 }
94
95                 public void StopListening(Object data)
96                 {
97                         serverChannel.StopListening(data);
98                 } 
99                 
100                 public Object ChannelData
101                 {
102                         get { return serverChannel.ChannelData; }
103                 }
104                 
105                 public String ChannelScheme 
106                 {
107                         get { return "http"; } 
108                 }
109
110                 public bool WantsToListen 
111                 { 
112                         get { return serverChannel.WantsToListen; } 
113                         set { serverChannel.WantsToListen = value; }
114                 } 
115                 
116                 public IServerChannelSink ChannelSinkChain 
117                 {
118                         get { return serverChannel.ChannelSinkChain; }
119                 }
120
121                 public void AddHookChannelUri (String channelUri)
122                 {
123                         serverChannel.AddHookChannelUri (channelUri);
124                 } 
125         }
126 }