ardour
selectable.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 1998-99 Paul Barton-Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #ifndef __selectable_h__
21 #define __selectable_h__
22 
23 #include <list>
24 #include <string>
25 #include <stdio.h>
26 
27 #include <sigc++/sigc++.h>
28 
29 #include <sys/types.h>
30 
31 #include "pbd/libpbd_visibility.h"
32 
33 namespace Select {
34  enum LIBPBD_API Condition {
35  Readable = 0x1,
36  Writable = 0x2,
37  Exception = 0x4
38  };
39 
40 class LIBPBD_API Selectable : public sigc::trackable
41 
42 {
43  public:
44  Selectable (int fd);
45  Selectable (const std::string &, int flags, int mode = 0);
46  Selectable (FILE *);
47  ~Selectable ();
48 
49  sigc::signal<void,Selectable *,Select::Condition> readable;
50  sigc::signal<void,Selectable *,Select::Condition> writable;
51  sigc::signal<void,Selectable *,Select::Condition> exceptioned;
52 
53  int fd() { return _fd; }
54  bool ok() { return _ok; }
55 
56  protected:
57  void selected (unsigned int condition);
58  int condition;
59  int _fd;
60 
61  friend class Selector;
62 
63  private:
64  enum {
67  fromFILE
68  };
69 
70  bool _ok;
71  int _type;
72  std::string path;
73 };
74 
76  private:
77  int post_select (fd_set *, fd_set *, fd_set *);
78  int _max_fd;
79 
80  typedef std::list<Selectable *> Selectables;
81  Selectables selectables;
82  pthread_mutex_t list_lock;
83 
84  static bool use_list_lock;
85 
86  public:
87  Selector ();
88 
89  void multithreaded (bool yn) {
90  use_list_lock = yn;
91  }
92 
93  void add (int condition, Selectable *s);
94  void remove (Selectable *);
95  int select (unsigned long usecs);
96 };
97 
98 
99 
100 } /* namespace */
101 
102 
103 #endif // __selectable_h__
Readable
Definition: selectable.h:35
std::list< Selectable * > Selectables
Definition: selectable.h:80
#define LIBPBD_API
pthread_mutex_t list_lock
Definition: selectable.h:82
sigc::signal< void, Selectable *, Select::Condition > writable
Definition: selectable.h:50
std::string path
Definition: selectable.h:72
void multithreaded(bool yn)
Definition: selectable.h:89
Writable
Definition: selectable.h:36
LIBARDOUR_API PBD::PropertyDescriptor< bool > select
Definition: route_group.cc:48
sigc::signal< void, Selectable *, Select::Condition > readable
Definition: selectable.h:49
Selectables selectables
Definition: selectable.h:81
static bool use_list_lock
Definition: selectable.h:84
sigc::signal< void, Selectable *, Select::Condition > exceptioned
Definition: selectable.h:51