stromx  0.8.0
Stream.h
1 /*
2 * Copyright 2011 Thomas Fidler
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef STROMX_RUNTIME_STREAM_H
18 #define STROMX_RUNTIME_STREAM_H
19 
20 #include <set>
21 #include <string>
22 #include <vector>
23 #include "stromx/runtime/Config.h"
24 #include "stromx/runtime/ExceptionObserver.h"
25 #include "stromx/runtime/OutputConnector.h"
26 
27 namespace stromx
28 {
29  namespace runtime
30  {
31  class AbstractFactory;
32  class Operator;
33  class OperatorError;
34  class OperatorKernel;
35  class Registry;
36  class Thread;
37 
38  namespace impl
39  {
40  class MutexHandle;
41  class Network;
42  }
43 
45  class STROMX_RUNTIME_API Stream
46  {
47  public:
49  enum Status
50  {
58  PAUSED
59  };
60 
62  Stream();
63  ~Stream();
64 
66  const std::string& name() const { return m_name; }
67 
69  void setName(const std::string& name) { m_name = name; }
70 
72  Status status() const { return m_status; }
73 
75  const std::vector<Operator*>& operators() const;
76 
78  const std::vector<Operator*>& initializedOperators() const;
79 
87  const AbstractFactory* factory() const { return m_factory; }
88 
101  void setFactory(const AbstractFactory* const factory);
102 
113  void connect(Operator* const sourceOp, const unsigned int outputId,
114  Operator* const targetOp, const unsigned int inputId);
115 
125  void disconnect(Operator* const targetOp, const unsigned int inputId);
126 
137  const OutputConnector connectionSource(const Operator* const targetOp, const unsigned int inputId) const;
138 
148  Operator* addOperator(OperatorKernel* const op);
149 
163  void hideOperator(Operator* const op);
164 
177  void showOperator(Operator* const op);
178 
191  void removeOperator(Operator* const op);
192 
199  void initializeOperator(Operator* const op);
200 
207  void deinitializeOperator(Operator* const op);
208 
221  void setConnectorType(Operator* const op, const unsigned int id,
223 
230  Thread* addThread();
231 
242  void hideThread(Thread* const thread);
243 
253  void showThread(Thread* const thread);
254 
263  void removeThread(Thread* const thread);
264 
268  const std::vector<Thread*> & threads() const;
269 
277  void addObserver(const ExceptionObserver* const observer);
278 
287  void removeObserver(const ExceptionObserver* const observer);
288 
295  unsigned int delay() const;
296 
306  void setDelay(const unsigned int delay);
307 
313  void start();
314 
320  void stop();
321 
328  void join();
329 
336  void pause();
337 
343  void resume();
344 
345  private:
346  class InternalThreadObserver;
347  class InternalNetworkObserver;
348 
349  void observeException(const ExceptionObserver::Phase phase, const OperatorError & ex, const Thread * const thread) const;
350  bool isPartOfStream(const Operator* const op) const;
351  bool isPartOfStream(const OperatorInfo* const op) const;
352  bool isPartOfInitializedStream(const Operator* const op) const;
353  bool isPartOfUninitializedStream(const Operator* const op) const;
354  void attachOperator(Operator* const op);
355  void attachThread(Thread* const thread);
356  void detachOperator(Operator* const op);
357  void detachThread(Thread* const thread);
358  void disconnectInput(Operator* const op, const unsigned int id);
359  void disconnectOutput(Operator* const op, const unsigned int id);
360 
361  std::string m_name;
362  impl::Network* const m_network;
363  std::vector<Thread*> m_threads;
364  std::set<const ExceptionObserver*> m_observers;
365  impl::MutexHandle* m_observerMutex;
366  Status m_status;
367  const AbstractFactory* m_factory;
368  impl::MutexHandle* m_delayMutex;
369  unsigned int m_delay;
370  std::set<Operator*> m_uninitializedOperators;
371  std::vector<Operator*> m_operators;
372  std::set<Operator*> m_hiddenOperators;
373  std::set<Thread*> m_hiddenThreads;
374  };
375  }
376 }
377 
378 #endif // STROMX_RUNTIME_STREAM_H
Abstract base observer of operator exceptions.
Definition: ExceptionObserver.h:29
const AbstractFactory * factory() const
Definition: Stream.h:87
Type
Definition: Description.h:73
Status
Definition: Stream.h:49
void setName(const std::string &name)
Definition: Stream.h:69
Status status() const
Definition: Stream.h:72
Definition: Stream.h:54
Factory of operator and data objects.
Definition: AbstractFactory.h:32
UpdateBehavior
Definition: Description.h:86
The stromx class library.
Definition: AdjustRgbChannels.cpp:29
Definition: Stream.h:52
The core data processing pipeline of stromx.
Definition: Stream.h:45
Phase
Definition: ExceptionObserver.h:36
const std::string & name() const
Definition: Stream.h:66
Meta-information about an operator.
Definition: OperatorInfo.h:51
Abstract operator.
Definition: Operator.h:60
A thread which visits input nodes.
Definition: Thread.h:53
Abstract operator kernel.
Definition: OperatorKernel.h:46
Error in connection with a specified operator.
Definition: OperatorException.h:32
Identifier of an output of an operator.
Definition: OutputConnector.h:27
Definition: Description.h:99