gflow-node.vala 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /********************************************************************
  2. # Copyright 2014-2022 Daniel 'grindhold' Brendle, 2015 Daniel Espinosa <esodan@gmail.com>
  3. #
  4. # This file is part of libgflow.
  5. #
  6. # libgflow is free software: you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public License
  8. # as published by the Free Software Foundation, either
  9. # version 3 of the License, or (at your option) any later
  10. # version.
  11. #
  12. # libgtkflow is distributed in the hope that it will be
  13. # useful, but WITHOUT ANY WARRANTY; without even the implied
  14. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with libgtkflow.
  19. # If not, see http://www.gnu.org/licenses/.
  20. *********************************************************************/
  21. /**
  22. * Flowgraphs for Gtk
  23. */
  24. namespace GFlow {
  25. public errordomain NodeError {
  26. /**
  27. * Throw when the user tries to connect a source to a sink that
  28. * Delivers a different type
  29. */
  30. INCOMPATIBLE_SINKTYPE,
  31. /**
  32. * Throw when a user tries to assign a value with a wrong type
  33. * to a sink
  34. */
  35. INCOMPATIBLE_VALUE,
  36. /**
  37. * Throw when the user tries to add a dock to a node
  38. * That already contains a dock
  39. */
  40. ALREADY_HAS_DOCK,
  41. /**
  42. * Throw when the dock that the user tries to add already
  43. * belongs to another node
  44. */
  45. DOCK_ALREADY_BOUND_TO_NODE,
  46. /**
  47. * Throw when the user tries to remove a dock from a node
  48. * that hasn't yet been added to the node
  49. */
  50. NO_SUCH_DOCK,
  51. /**
  52. * Throw when the value of a sink is invalid
  53. */
  54. INVALID
  55. }
  56. /**
  57. * Represents an element that can generate, process or receive data
  58. * This is done by adding Sources and Sinks to it.
  59. */
  60. public interface Node : GLib.Object {
  61. /**
  62. * This signal is being triggered when a {@link Sink} is added to this Node
  63. */
  64. public signal void sink_added (Sink s);
  65. /**
  66. * This signal is being triggered when a {@link Source} is added to this Node
  67. */
  68. public signal void source_added (Source s);
  69. /**
  70. * This signal is being triggered when a {@link Sink} is removed from this Node
  71. */
  72. public signal void sink_removed (Sink s);
  73. /**
  74. * This signal is being triggered when a {@link Source} is removed from this Node
  75. */
  76. public signal void source_removed (Source s);
  77. /**
  78. * This node's name
  79. */
  80. public abstract string name { get; set; }
  81. /**
  82. * Determines wheter the user be allowed to remove the node. Otherwise
  83. * the node can only be removed programmatically
  84. */
  85. public abstract bool deletable { get; set; default=true;}
  86. /**
  87. * Determines wheter the user be allowed to remove the node. Otherwise
  88. * the node can only be removed programmatically
  89. */
  90. public abstract bool resizable { get; set; default=true;}
  91. /**
  92. * Implementations should destroy all connections of this Node's {@link Sink}s
  93. * and {@link Source}s when this method is executed
  94. */
  95. public abstract void unlink_all ();
  96. /**
  97. * Determines whether the given from-{@link Node} can be found if we
  98. * recursively follow all nodes that are connected to this node's {@link Source}s
  99. */
  100. public abstract bool is_recursive_forward (Node from, bool initial=false);
  101. /**
  102. * Determines whether the given from-{@link Node} can be found if we
  103. * recursively follow all nodes that are connected to this node's {@link Sink}s
  104. */
  105. public abstract bool is_recursive_backward (Node from, bool initial=false);
  106. /**
  107. * Implementations should return the {@link Dock} with the given name if they contain
  108. * any. If not, return null.
  109. */
  110. public abstract Dock? get_dock (string name);
  111. /**
  112. * Implementations should return true if the given {@link Dock} has been
  113. * assigned to this node
  114. */
  115. public abstract bool has_dock(Dock d);
  116. /**
  117. * Return a {@link GLib.List} of this Node's {@link Source}s
  118. */
  119. public abstract unowned List<Source> get_sources ();
  120. /**
  121. * Return a {@link GLib.List} of this Node's {@link Sink}s
  122. */
  123. public abstract unowned List<Sink> get_sinks ();
  124. /**
  125. * Returns the Nodes that this Node is connected to
  126. */
  127. public abstract List<Node> get_neighbors();
  128. /**
  129. * Returns true if the given node is directly connected to this node
  130. */
  131. public abstract bool is_neighbor(Node n);
  132. /**
  133. * Assign a {@link Source} to this Node
  134. */
  135. public abstract void add_source (Source source) throws NodeError;
  136. /**
  137. * Remove a {@link Source} from this Node
  138. */
  139. public abstract void remove_source (Source source) throws NodeError;
  140. /**
  141. * Return true if the supplied {@link Source} is assigned to this Node
  142. */
  143. public abstract bool has_source (Source s);
  144. /**
  145. * Assign a {@link Sink} to this Node
  146. */
  147. public abstract void add_sink (Sink sink) throws NodeError;
  148. /**
  149. * Return true if the supplied {@link Sink} is assigned to this Node
  150. */
  151. public abstract bool has_sink (Sink s);
  152. /**
  153. * Remove a {@link Sink} from this Node
  154. */
  155. public abstract void remove_sink (Sink sink) throws NodeError;
  156. }
  157. }