GLPK for C#/CLI  1.10.0
All Classes Namespaces Functions Properties Pages
GlpkTerminal.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Threading;
4 
5 namespace org.gnu.glpk {
6 
26  public class GlpkTerminal {
27 
31  private static ThreadLocal<LinkedList<IGlpkTerminalListener>> listeners
32  = new ThreadLocal<LinkedList<IGlpkTerminalListener>>(() =>
33  {
34  return new LinkedList<IGlpkTerminalListener>();
35  });
36 
40  private GlpkTerminal() {
41  }
42 
49  public static int callback(string str) {
50  bool output = false;
51 
52  if (listeners.Value.Count > 0) {
53  foreach (IGlpkTerminalListener listener in listeners.Value) {
54  output |= listener.output(str);
55  }
56  if (output) {
57  return 0;
58  } else {
59  return 1;
60  }
61  }
62  return 0;
63  }
64 
69  public static void addListener(IGlpkTerminalListener listener) {
70  GLPK.glp_term_hook(null, null);
71  listeners.Value.AddLast(listener);
72  }
73 
79  public static bool removeListener(IGlpkTerminalListener listener) {
80  if (listeners.Value.Contains(listener)) {
81  listeners.Value.Remove(listener);
82  return true;
83  } else {
84  return false;
85  }
86  }
87  }
88 }
static void addListener(IGlpkTerminalListener listener)
Adds a listener for callbacks.
Definition: GlpkTerminal.cs:69
bool output(string str)
Receive terminal output.
static bool removeListener(IGlpkTerminalListener listener)
Removes first occurance of a listener for callbacks.
Definition: GlpkTerminal.cs:79
static void glp_term_hook(SWIGTYPE_p_f_p_void_p_q_const__char__int func, SWIGTYPE_p_void info)
glp_term_hook - install hook to intercept terminal output .
Definition: GLPK.cs:2675
static int callback(string str)
Callback function called by native library.
Definition: GlpkTerminal.cs:49
This class manages terminal output.
Definition: GlpkTerminal.cs:26