Statistics
| Branch: | Tag: | Revision:

dvbd / src / source.h @ 59be6a47

History | View | Annotate | Download (2.02 KB)

1
// -*- c++ -*-
2
/*
3
  Copyright 2003 John Knottenbelt
4
  
5
  This program is free software; you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
7
  the Free Software Foundation; either version 2 of the License, or
8
  (at your option) any later version.
9
 
10
  This program is distributed in the hope that it will be useful,
11
  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
  GNU General Public License for more details.
14
 
15
  You should have received a copy of the GNU General Public License
16
  along with this program; if not, write to the Free Software
17
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18
*/
19

    
20
#if !defined __SOURCE_H
21
#define __SOURCE_H
22

    
23
#include <list>
24

    
25
// Priority base class
26

    
27
class Priority {
28
public:
29
  virtual ~Priority();
30
  virtual int getPriority() const = 0;
31
  virtual void setPriority( int newPriority );
32
};
33

    
34
class SavePriority {
35
public:
36
  SavePriority(Priority *p, int newPriority)
37
    : p(p), savePriority(p->getPriority())
38
  {
39
    p->setPriority(newPriority);
40
  }
41

    
42
  ~SavePriority()
43
  {
44
    p->setPriority(savePriority);
45
  }
46

    
47
private:
48
  Priority *p;
49
  int savePriority;
50
};
51

    
52
// Sink abstract base class
53

    
54
class Source;
55

    
56
class Sink : public virtual Priority {
57
 public:
58
  virtual ~Sink();
59
  virtual void receiveData(unsigned char *data, unsigned size) = 0;
60
  virtual void notifyUnsubscribe(Source *source);
61
};
62

    
63
typedef std::list<Source *> SourceList;
64
typedef std::list<Sink *> SinkList;
65

    
66
// Source abstract base class
67
class Source : public virtual Priority {
68
public:
69
  virtual ~Source();
70

    
71
  virtual bool subscribe(Sink *s);
72
  virtual void unsubscribe(Sink *s);
73

    
74
  void unsubscribeAll();
75
  int unsubscribe( int priority );
76

    
77
  int getNumSubscribers() const { return subscribers.size(); };
78
  int getNumSubscribers(int priority) const;
79
  virtual int getPriority() const;
80

    
81
protected:
82
  virtual void sendData(unsigned char *data, unsigned size) const;
83

    
84
  SinkList subscribers;
85
};
86

    
87

    
88
#endif // __SOURCE_H