stromx  0.7.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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/Output.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) const;
115 
125  void disconnect(Operator* const targetOp, const unsigned int inputId) const;
126 
137  const Output 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 
215  Thread* addThread();
216 
227  void hideThread(Thread* const thread);
228 
238  void showThread(Thread* const thread);
239 
248  void removeThread(Thread* const thread);
249 
253  const std::vector<Thread*> & threads() const;
254 
262  void addObserver(const ExceptionObserver* const observer);
263 
272  void removeObserver(const ExceptionObserver* const observer);
273 
280  unsigned int delay() const;
281 
291  void setDelay(const unsigned int delay);
292 
298  void start();
299 
305  void stop();
306 
313  void join();
314 
321  void pause();
322 
328  void resume();
329 
330  private:
331  class InternalThreadObserver;
332  class InternalNetworkObserver;
333 
334  void observeException(const ExceptionObserver::Phase phase, const OperatorError & ex, const Thread * const thread) const;
335  bool isPartOfStream(const Operator* const op) const;
336  bool isPartOfStream(const OperatorInfo* const op) const;
337  bool isPartOfInitializedStream(const Operator* const op) const;
338  bool isPartOfUninitializedStream(const Operator* const op) const;
339  void attachOperator(Operator* const op);
340  void attachThread(Thread* const thread);
341  void detachOperator(Operator* const op);
342  void detachThread(Thread* const thread);
343 
344  std::string m_name;
345  impl::Network* const m_network;
346  std::vector<Thread*> m_threads;
347  std::set<const ExceptionObserver*> m_observers;
348  impl::MutexHandle* m_observerMutex;
349  Status m_status;
350  const AbstractFactory* m_factory;
351  impl::MutexHandle* m_delayMutex;
352  unsigned int m_delay;
353  std::set<Operator*> m_uninitializedOperators;
354  std::vector<Operator*> m_operators;
355  std::set<Operator*> m_hiddenOperators;
356  std::set<Thread*> m_hiddenThreads;
357  };
358  }
359 }
360 
361 #endif // STROMX_RUNTIME_STREAM_H
const AbstractFactory * factory() const
Definition: Stream.h:87
Abstract base observer of operator exceptions.
Definition: ExceptionObserver.h:29
Identifier of an output of an operator.
Definition: Output.h:27
Status
Definition: Stream.h:49
void setName(const std::string &name)
Definition: Stream.h:69
Definition: Stream.h:54
Factory of operator and data objects.
Definition: AbstractFactory.h:32
Status status() const
Definition: Stream.h:72
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
Meta-information about an operator.
Definition: OperatorInfo.h:50
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
const std::string & name() const
Definition: Stream.h:66