summaryrefslogtreecommitdiff
path: root/reference
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@gmail.com>2018-11-02 11:56:25 +0100
committerXavi Artigas <xavierartigas@yahoo.es>2018-11-02 12:02:52 +0100
commitc2e4308dd1710ff181387f71e22bf06ea13f7365 (patch)
tree01064273a19ee56b0578d92a1dd6d613f8e0dc64 /reference
parent8a4df21de88bc8cac9a48ba5c6e38c97c0af0c16 (diff)
csharp: Remove efl-net examples.
Summary: The Efl.Net library is self contained and the bindings do not expose it, favoring.the use of C# own networking classes. Reviewers: segfaultxavi, vitor.sousa, bu5hm4n Reviewed By: segfaultxavi Differential Revision: https://phab.enlightenment.org/D7228
Diffstat (limited to 'reference')
-rw-r--r--reference/csharp/net/meson.build10
-rw-r--r--reference/csharp/net/src/meson.build22
-rw-r--r--reference/csharp/net/src/net_io.cs269
-rw-r--r--reference/csharp/net/src/net_io_buffered.cs181
-rw-r--r--reference/csharp/net/src/net_session.cs135
5 files changed, 0 insertions, 617 deletions
diff --git a/reference/csharp/net/meson.build b/reference/csharp/net/meson.build
deleted file mode 100644
index 18a81719..00000000
--- a/reference/csharp/net/meson.build
+++ /dev/null
@@ -1,10 +0,0 @@
1project(
2 'efl-reference-net', 'c',
3 version : '0.0.1',
4 meson_version : '>= 0.38.0')
5
6efl_mono = dependency('efl-mono', version : '>=1.20.99')
7efl_mono_libs = efl_mono.get_pkgconfig_variable('mono_libs')
8
9subdir('src')
10
diff --git a/reference/csharp/net/src/meson.build b/reference/csharp/net/src/meson.build
deleted file mode 100644
index 9897ac68..00000000
--- a/reference/csharp/net/src/meson.build
+++ /dev/null
@@ -1,22 +0,0 @@
1deps = [efl_mono]
2
3executable('efl_reference_net_io',
4 files(['net_io.cs']),
5 dependencies : deps,
6 cs_args : efl_mono_libs,
7 install : true
8)
9
10executable('efl_reference_net_io_buffered',
11 files(['net_io_buffered.cs']),
12 dependencies : deps,
13 cs_args : efl_mono_libs,
14 install : true
15)
16
17executable('efl_reference_net_session',
18 files(['net_session.cs']),
19 dependencies : deps,
20 cs_args : efl_mono_libs,
21 install : true
22)
diff --git a/reference/csharp/net/src/net_io.cs b/reference/csharp/net/src/net_io.cs
deleted file mode 100644
index f7978672..00000000
--- a/reference/csharp/net/src/net_io.cs
+++ /dev/null
@@ -1,269 +0,0 @@
1/*
2 * Efl.Net input/output examples.
3 *
4 * This example builds on the core_io example by connecting to a remote server
5 * using a dialer and a command queue. The response is printed to stdout.
6 */
7
8using System;
9
10public class ExampleRunner
11{
12 private eina.List<efl.io.Copier> waiting = null;
13 private eina.List<string> commands = null;
14 private eina.Slice delimiter;
15 private efl.net.dialer.Tcp dialer = null;
16 private efl.io.Copier sender = null;
17 private efl.io.Copier receiver = null;
18
19 public void Run()
20 {
21 efl.ui.Config.Run();
22 }
23
24 // call this method to cleanly shut down our example
25 public void Quit()
26 {
27 if (waiting != null)
28 {
29 Console.Error.WriteLine("ERROR: {0} operations were waiting!", waiting.Length);
30 waiting.Dispose();
31 waiting = null;
32 }
33
34 if (receiver != null)
35 {
36 receiver.Close();
37 receiver.GetDestination().Dispose();
38 receiver.Dispose();
39 receiver = null;
40 }
41
42 if (sender)
43 {
44 sender.Close();
45 sender.GetSource().Dispose();
46 source.Dispose();
47 }
48
49 if (dialer)
50 dialer.Dispose();
51
52 // efl_exit(retval); // TODO missing
53 efl.ui.Config.Exit();
54 }
55
56 // iterate through the commands to send through the dialler
57 public void CommandNext()
58 {
59 efl.io.Reader send_queue = sender.GetSource();
60 if (commands != null)
61 {
62 send_queue.EosMark();
63 return;
64 }
65
66 string cmd = commands[0];
67 // commands.RemoveAt(0); // TODO missing
68
69 eina.Slice slice;
70 // slice = (Eina_Slice)EINA_SLICE_STR(cmd); // TODO missing
71 send_queue.Write(slice, null);
72 // Console.WriteLine("INFO: sent '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
73
74 // don't use delimiter directly, 'Len' may be changed!
75 slice = delimiter;
76 send_queue.Write(slice, null);
77 }
78
79 void ReceiverData(efl.io.Queue sender, EventArgs e)
80 {
81 eina.Slice slice = sender.GetSlice();
82
83 // Can be caused when we issue efl.io.Queue.Clear()
84 if (slice.Len == 0) return;
85
86 // If the server didn't send us the line terminator and closed the
87 // connection (ie: efl_io_reader_eos_get() == true) or if the buffer
88 // limit was reached then we may have a line without a trailing delimiter.
89
90 // if (slice.EndsWith(delimiter)) // TODO missing
91 // slice.Len -= delimiter.Len;
92
93 // Console.WriteLine("INFO: received '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
94
95 sender.Clear();
96 CommandNext();
97 }
98
99 void DialerConnected(efl.net.dialer.Tcp sender, EventArgs e)
100 {
101 Console.WriteLine("INFO: connected to {0} ({1})", sender.GetAddressDial(), sender.GetAddressRemote());
102
103 CommandNext();
104 }
105
106 void CopierDone(efl.io.Copier sender, EventArgs e)
107 {
108 Console.WriteLine("INFO: {0} done", sender.GetName());
109
110 // waiting.Remove(sender); // TODO missing
111 if (waiting.Empty())
112 Quit(EXIT_SUCCESS);
113 }
114
115 void CopierError(efl.io.Copier sender, eina.Error perr)
116 {
117 Console.Error.WriteLine(stderr, "INFO: {0} error: #{1} '{2}'", sender.GetName(), perr, perr.Message);
118
119 Quit(EXIT_FAILURE);
120 }
121
122 private static void SetCopierCbs(efl.io.Copier copier)
123 {
124 copier.DONE += CopierDone;
125 copier.ERROR += CopierError;
126 }
127
128
129 public ExampleRunner()
130 {
131 string address = "example.com:80";
132 ulong buffer_limit = 128;
133 efl.io.Queue send_queue, receive_queue;
134
135 commands = new eina.List<string>();
136 commands.Append("HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
137 // delimiter = (Eina_Slice)EINA_SLICE_STR("\r\n"); // TODO missing
138
139 // Without a send_queue we'd have to manually implement an
140 // efl.io.Reader object that would provide partial data when
141 // efl.io.Reader.read() is called by efl.io.Copier. This is
142 // cumbersome... we just want to write a full command and have the
143 // queue to handle that for us.
144 //
145 // Our example's usage is to write each command at once followed by
146 // the line delimiter, then wait for a reply from the server, then
147 // write another.
148
149 try
150 {
151 send_queue = new efl.io.QueueConcrete(null, (efl.io.Queue equeue) => {
152 equeue.SetName("send_queue");
153 equeue.SetLimit(buffer_limit);
154 });
155 }
156 catch
157 {
158 Console.Error.WriteLine("ERROR: could not create efl.io.Queue (send)");
159 Quit(EXIT_FAILURE);
160 throw;
161 }
162
163 // Without a receive_queue we'd have to manually implement an
164 // efl.io.Writer object that would handle write of partial data
165 // with efl.io.Writer.write() is called by efl.io.Copier.
166 //
167 // For output we could have another solution as well: use null
168 // destination and handle "line" or "data" events manually,
169 // stealing the buffer so it doesn't grow.
170 //
171 // Our example's usage is to peek its data with GetSlice() then
172 // Clear().
173 try
174 {
175 receive_queue = new efl.io.QueueConcrete(null, (efl.io.Queue equeue) => {
176 equeue.SetName("receive_queue");
177 equeue.SetLimit(buffer_limit);
178 });
179 receive_queue.SLICE_CHANGED += ReceiverData;
180 }
181 catch
182 {
183 Console.Error.WriteLine("ERROR: could not create efl.io.Queue (receive)");
184 Quit(EXIT_FAILURE);
185 throw;
186 }
187
188 // some objects such as the Efl.Io.Copier and Efl.Net.Dialer.Tcp
189 // depend on main loop, thus their parent must be a loop
190 // provider. We use the loop passed to our main method.
191 // efl.Loop loop = ev->object; // TODO missing
192
193 // The TCP client to use to send/receive network data
194 try
195 {
196 dialer = new efl.net.dialer.TcpConcrete(loop, (efl.net.dialer.Tcp edialer) => {
197 edialer.SetName("dialer");
198 });
199 dialer.CONNECTED += DialerConnected;
200 }
201 catch
202 {
203 Console.Error.WriteLine("ERROR: could not create efl.net.dialer.Tcp");
204 Quit(EXIT_FAILURE);
205 throw;
206 }
207
208 // sender: send_queue->network
209 try
210 {
211 sender = new efl.io.CopierConcrete(loop, (efl.io.Copier esender) => {
212 esender.SetName("sender");
213 esender.SetLineDelimiter(delimiter);
214 esender.SetSource(send_queue);
215 esender.SetDestination(dialer);
216 });
217 SetCopierCbs(sender);
218 }
219 catch
220 {
221 Console.Error.WriteLine("ERROR: could not create efl.io.Copier (sender)");
222 Quit(EXIT_FAILURE);
223 throw;
224 }
225
226 // receiver: network->receive_queue
227 try
228 {
229 receiver = new efl.io.CopierConcrete(loop, (efl.io.Copier ereceiver) => {
230 ereceiver.SetName("receiver");
231 ereceiver.SetLineDelimiter(delimiter);
232 ereceiver.SetSource(dialer);
233 ereceiver.SetDestination(send_queue);
234 });
235 SetCopierCbs(receiver);
236 }
237 catch
238 {
239 Console.Error.WriteLine("ERROR: could not create Efl_Io_Copier (receiver)");
240 Quit(EXIT_FAILURE);
241 throw;
242 }
243
244 eina.Error err = dialer.Dial(address);
245 if (err != eina.Error.NO_ERROR)
246 {
247 var msg = $"ERROR: could not dial {address}: {err.Message}";
248 Console.Error.WriteLine(msg);
249 Quit(EXIT_FAILURE);
250 throw new SEHException(msg);
251 }
252
253 waiting.Append(sender);
254 waiting.Append(receiver);
255 }
256}
257
258public static class Example
259{
260 public static void Main()
261 {
262 efl.All.Init(efl.Components.Basic);
263
264 var exr = new ExampleRunner();
265 exr.Run();
266
267 efl.All.Shutdown();
268 }
269}
diff --git a/reference/csharp/net/src/net_io_buffered.cs b/reference/csharp/net/src/net_io_buffered.cs
deleted file mode 100644
index 3a159e75..00000000
--- a/reference/csharp/net/src/net_io_buffered.cs
+++ /dev/null
@@ -1,181 +0,0 @@
1/*
2 * Efl.Net buffered input/output examples.
3 *
4 * This example builds on the net_io example by using a buffered_stream to
5 * simplify the logic. This helpfully provides the input and output queues
6 * and a copier internally. They can be accessed from the buffered stream
7 * if required but as demonstrated here that is likely not necessary.
8 */
9
10using System;
11
12public class ExampleRunner
13{
14 private eina.List<string> commands = null;
15 private eina.Slice delimiter;
16 private efl.net.dialer.Tcp dialer = null;
17 private efl.io.buffered.Stream stream = null;
18
19 public void Run()
20 {
21 efl.ui.Config.Run();
22 }
23
24 public void Quit(int retval)
25 {
26 if (stream != null)
27 {
28 stream.Close();
29 stream.Dispose();
30 stream = null;
31 }
32
33 if (dialer != null)
34 {
35 dialer.Dispose();
36 dialer = null;
37 }
38
39 // efl_exit(retval); TODO missing
40 efl.ui.Config.Exit();
41 }
42
43 public void CommandNext()
44 {
45 if (commands.Empty())
46 {
47 stream.EosMark();
48 return;
49 }
50
51 string cmd = commands[0];
52 // commands.RemoveAt(0); // TODO missing
53
54 // eina.Slice slice = (Eina_Slice)EINA_SLICE_STR(cmd); // TODO missing
55 stream.Write(slice, null);
56 // Console.Error.WriteLine("INFO: sent '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
57
58 // don't use delimiter directly, 'Len' may be changed!
59 slice = delimiter;
60 stream.Write(slice, null);
61 }
62
63 void StreamLine(efl.io.buffered.Stream sender, EventArgs e)
64 {
65 eina.Slice slice = sender.GetSlice();
66
67 // Can be caused when we issue efl.io.buffered.Stream.Clear()
68 if (slice.Len == 0) return;
69
70 // If the server didn't send us the line terminator and closed the
71 // connection (ie: efl_io_reader_eos_get() == true) or if the buffer
72 // limit was reached then we may have a line without a trailing delimiter.
73 // if (slice.EndsWith(delimiter)) // TODO missing
74 // slice.Len -= delimiter.Len;
75
76 // Console.WriteLine("INFO: received '{0}'", EINA_SLICE_STR_PRINT(slice)); // TODO missing
77
78 sender.Clear();
79 CommandNext();
80 }
81
82 void DialerConnected(efl.net.dialer.Tcp sender, EventArgs e)
83 {
84 Console.WriteLine("INFO: connected to {0} ({1})", sender.GetAddressDial(), sender.GetAddressRemote());
85
86 CommandNext();
87 }
88
89 void StreamDone(efl.io.buffered.Stream sender, EventArgs e)
90 {
91 Console.WriteLine("INFO: {0} done", sender.GetName());
92
93 Quit(EXIT_SUCCESS);
94 }
95
96 void StreamError(efl.io.buffered.Stream sender, eina.Error err)
97 {
98 Console.Error.WriteLine("INFO: {0} error: #{1} '{2}'", sender;GetName(), err, err.Message);
99
100 Quit(EXIT_FAILURE);
101 }
102
103 private static void SetStreamCbs(efl.io.buffered.Stream s)
104 {
105 s.LINE += StreamLine;
106 s.EOS += StreamDone;
107 s.ERROR += StreamError;
108 }
109
110 public ExampleRunner()
111 {
112 string address = "example.com:80";
113 ulong bufferLimit = 128;
114
115 commands = new eina.List<string>();
116 commands.Append("HEAD / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n");
117 // delimiter = (Eina_Slice)EINA_SLICE_STR("\r\n"); // TODO missing
118
119 // some objects such as the Efl.Io.Copier and Efl.Net.Dialer.Tcp
120 // depend on main loop, thus their parent must be a loop
121 // provider. We use the loop passed to our main method.
122 // efl.Loop loop = ev->object; // TODO missing
123
124 // The TCP client to use to send/receive network data
125 try
126 {
127 dialer = new efl.net.dialer.TcpConcrete(loop, (efl.net.dialer.Tcp edialer) => {
128 edialer.SetName("dialer");
129 });
130 dialer.CONNECTED += DialerConnected;
131 }
132 catch
133 {
134 Console.Error.WriteLine("ERROR: could not create efl.net.dialer.Tcp");
135 Quit(EXIT_FAILURE);
136 throw;
137 }
138
139
140 // Without the buffered stream we'd have to create two Efl.Io.Queue
141 // ourselves, as well as two Efl.Io.Copier to link them with the
142 // dialer.
143 //
144 // Our example's usage is to write each command at once followed by
145 // the line delimiter, then wait for a reply from the server, then
146 // write another.
147 //
148 // On incoming data we peek at it with GetSlice() and then Clear().
149
150 stream = new efl.io.buffered.StreamConcrete(loop, (efl.io.buffered.Stream estream) => {
151 estream.SetName("stream");
152 estream.SetInnerIo(dialer);
153 estream.SetDelimiter(delimiter);
154 estream.SetMaxQueueSizeInput(bufferLimit);
155 estream.SetMaxQueueSizeOutput(bufferLimit);
156 });
157 SetStreamCbs(stream);
158
159 eina.Error err = dialer.Dial(address);
160 if (err != eina.Error.NO_ERROR)
161 {
162 var msg = $"ERROR: could not dial {address}: {err.Message}";
163 Console.Error.WriteLine(msg);
164 Quit(EXIT_FAILURE);
165 throw new SEHException(msg);
166 }
167 }
168}
169
170public class Example
171{
172 public static void Main()
173 {
174 efl.All.Init(efl.Components.Basic);
175
176 var exr = new ExampleRunner();
177 exr.Run();
178
179 efl.All.Shutdown();
180 }
181}
diff --git a/reference/csharp/net/src/net_session.cs b/reference/csharp/net/src/net_session.cs
deleted file mode 100644
index 2c703970..00000000
--- a/reference/csharp/net/src/net_session.cs
+++ /dev/null
@@ -1,135 +0,0 @@
1/*
2 * Efl.Net session/connectivity examples.
3 *
4 * NOTE: This example currently requires the Connman backend to be running.
5 *
6 * This example uses the Efl.Net.Session APIs to get connectivity information
7 * about the current networking setup. It then sets up a callback for network
8 * changes and will print the details on any change.
9 */
10
11using System;
12
13public class Example
14{
15 // Convert a session state to a string for printing.
16 public static string StateName(efl.net.session.State state)
17 {
18 switch (state)
19 {
20 case efl.net.session.State.Offline:
21 return "offline";
22 case efl.net.session.State.Local:
23 return "local";
24 case efl.net.session.State.Online:
25 return "online";
26 default:
27 return "???";
28 }
29 }
30
31 private static readonly Dictionary<efl.net.session.Technology, string> names =
32 new Dictionary<efl.net.session.Technology, string> {
33 { efl.net.session.Technology.Unknown, "unknown" },
34 { efl.net.session.Technology.Ethernet, "ethernet" },
35 { efl.net.session.Technology.Wifi, "wifi" },
36 { efl.net.session.Technology.Bluetooth, "bluetooth" },
37 { efl.net.session.Technology.Cellular, "cellular" },
38 { efl.net.session.Technology.Vpn, "vpn" },
39 { efl.net.session.Technology.Gadget, "gadget" }
40 };
41
42 // Convert a session technology to a string for printing.
43 public static string TechnologyName(efl.net.session.Technology tech)
44 {
45 string name;
46 if (!names.TryGetValue(tech, out name))
47 return "???";
48 return name;
49 }
50
51 // Tthe callback that indicates some connectivity changed within the session.
52 // Print information about the session to the console.
53 static void SessionChanged(efl.net.Session session, EventArgs e)
54 {
55 Console.WriteLine("Session changed:");
56 Console.WriteLine(" name: '{0}'", session.GetName());
57 Console.WriteLine(" state: {0}", StateName(session.GetState()));
58 Console.WriteLine(" technology: {0}", TechnologyName(session.GetTechnology()));
59 Console.WriteLine(" interface: '{0}'", session.GetInterface());
60
61 // print out additional information if we have an IPv4 session
62 string ip, netmask, gateway;
63 session.GetIpv4(out ip, out netmask, out gateway);
64 if (ip != null)
65 {
66 Console.WriteLine($" IPv4: {ip}, gateway={gateway}, netmask={netmask}");
67 }
68
69 // print out additional information if we have an IPv6 session
70 byte prefix;
71 session.GetIpv6(out ip, out prefix, out netmask, out gateway);
72 if (ip != null)
73 {
74 Console.WriteLine($" IPv6: {ip}/{prefix}, gateway={gateway}, netmask={netmask}");
75 }
76 }
77
78 // Quit the app after a timer tick.
79 static void QuitCb(object sender, EventArgs e)
80 {
81 // efl_exit(0); // TODO missing
82 efl.ui.Config.Exit();
83 }
84
85 public static void Main()
86 {
87 bool doConnect = true;
88 bool requireOnline = false;
89
90 efl.All.Init(efl.Components.Basic);
91
92 // efl.Loop loop = ev->object; // TODO missing
93
94 // create a session that watches specifically for ethernet, wifi and bluetooth
95 int technologies = efl.net.session.Technology.Ethernet |
96 efl.net.session.Technology.Wifi | efl.net.session.Technology.Bluetooth;
97
98 try
99 {
100 efl.net.Session session = new efl.net.SessionConcrete(loop, (efl.net.Session esession) => {
101 esession.SetName("Example Session");
102 // register the change callback for network state
103 esession.CHANGED += SessionChanged;
104 });
105 }
106 catch
107 {
108 eina.Log.Error("Could not create Efl.Net.Session object.\n");
109 // efl_exit(EXIT_FAILURE); // TODO missing
110 efl.ui.Config.Exit();
111 throw;
112 }
113
114 if (doConnect)
115 {
116 Console.WriteLine("Requesting a {0} connection.", requireOnline ? "online" : "local");
117 session.Connect(requireOnline, technologies);
118 }
119
120 Console.WriteLine("The session will remain active while this application runs.");
121 Console.WriteLine("Use ^C (Control + C) to close it");
122
123 // Wait for 10 seconds before exiting this example
124 new efl.loop.TimerConcrete(loop, (efl.loop.Timer etimer) => {
125 etimer.SetInterval(10.0);
126 etimer.TICK += QuitCb;
127 });
128
129 // start the main loop
130 efl.ui.Config.Run();
131
132 efl.All.Shutdown();
133 }
134}
135