Essentia  2.1-beta6-dev
sinkbase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_SINKBASE_H
21 #define ESSENTIA_SINKBASE_H
22 
23 #include "../types.h"
24 #include "../connector.h"
25 
26 namespace essentia {
27 namespace streaming {
28 
29 class SinkBase;
30 class SinkProxyBase;
31 class SourceBase;
32 class Algorithm;
33 
34 
35 void connect(SourceBase& source, SinkBase& sink);
36 void disconnect(SourceBase& source, SinkBase& sink);
37 
38 void attach(SinkProxyBase& proxy, SinkBase& innerSink);
39 void detach(SinkProxyBase& proxy, SinkBase& innerSink);
40 
41 
52 class SinkBase : public Connector {
53  protected:
55  ReaderID _id; // ID to use to identify this reader for the source (to know which reader is requesting tokens, etc...)
56 
58 
59  public:
60  SinkBase(Algorithm* parent = 0, const std::string& name = "unnamed") :
61  Connector(parent, name), _source(0), _sproxy(0) {}
62 
63  SinkBase(const std::string& name) :
64  Connector(name), _source(0), _sproxy(0) {}
65 
67  // NB: this call needs to come before the next one because _source is set by the proxy
68  // even though we're not explicitly connected to a source ourselves
69  E_DEBUG(EMemory, "Deleting SinkBase " << fullName());
72  E_DEBUG(EMemory, "Deleting SinkBase " << fullName() << "ok!");
73  }
74 
75  const SourceBase* source() const { return _source; }
76  SourceBase* source() { return _source; }
77  virtual void setSource(SourceBase* source);
78 
79  ReaderID id() const;
80  virtual void setId(ReaderID id);
81 
82  // should return a vector<TokenType>*
83  virtual const void* getTokens() const = 0;
84 
85  // should return a TokenType*
86  virtual const void* getFirstToken() const = 0;
87 
88  protected:
89  // methods for standard connections
90 
91  // made those protected so that only our friend streaming::{dis}connect() functions can access these
92  virtual void connect(SourceBase& source);
93  virtual void disconnect(SourceBase& source);
94 
95  friend void connect(SourceBase& source, SinkBase& sink);
96  friend void disconnect(SourceBase& source, SinkBase& sink);
97 
98 
99  // methods for proxies
100 
101  friend void attach(SinkProxyBase& proxy, SinkBase& innerSink);
102  friend void detach(SinkProxyBase& proxy, SinkBase& innerSink);
103 
104  // Note: these can't be called attach because they would be shadowed by SourceProxyBase::attach(SourceBase)
105  void attachProxy(SinkProxyBase* sproxy);
106  void detachProxy(SinkProxyBase* sproxy);
107 
108  // for SourceBase destructor
109  friend class SourceBase;
110 
111 };
112 
113 } // namespace streaming
114 } // namespace essentia
115 
116 #endif // ESSENTIA_SINKBASE_H
const std::string & name() const
Definition: types.h:284
Definition: streamingalgorithm.h:140
Definition: connector.h:40
std::string fullName() const
const Algorithm * parent() const
Definition: connector.h:53
Definition: sinkbase.h:52
SinkProxyBase * _sproxy
Definition: sinkbase.h:57
~SinkBase()
Definition: sinkbase.h:66
friend void detach(SinkProxyBase &proxy, SinkBase &innerSink)
Definition: sinkproxy.h:257
SourceBase * source()
Definition: sinkbase.h:76
SinkBase(const std::string &name)
Definition: sinkbase.h:63
friend void connect(SourceBase &source, SinkBase &sink)
ReaderID _id
Definition: sinkbase.h:55
virtual const void * getFirstToken() const =0
void detachProxy(SinkProxyBase *sproxy)
SourceBase * _source
Definition: sinkbase.h:54
virtual void disconnect(SourceBase &source)
virtual const void * getTokens() const =0
friend void disconnect(SourceBase &source, SinkBase &sink)
virtual void setSource(SourceBase *source)
virtual void setId(ReaderID id)
const SourceBase * source() const
Definition: sinkbase.h:75
friend void attach(SinkProxyBase &proxy, SinkBase &innerSink)
Definition: sinkproxy.h:239
virtual void connect(SourceBase &source)
void attachProxy(SinkProxyBase *sproxy)
SinkBase(Algorithm *parent=0, const std::string &name="unnamed")
Definition: sinkbase.h:60
Definition: sinkproxy.h:30
Definition: sourcebase.h:52
#define E_DEBUG(module, msg)
Definition: debugging.h:157
void detach(SinkProxyBase &proxy, SinkBase &innerSink)
Definition: sinkproxy.h:257
void disconnect(SourceBase &source, DevNullConnector devnull)
void connect(SourceBase &source, DevNullConnector devnull)
void attach(SinkProxyBase &proxy, SinkBase &innerSink)
Definition: sinkproxy.h:239
Definition: algorithm.h:28
int ReaderID
Definition: types.h:344
@ EMemory
Definition: debugging.h:48