L4Re - L4 Runtime Environment
fd_store.h
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  * economic rights: Technische Universit├Ąt Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction. Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License. This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18 #pragma once
19 
20 #include <l4/l4re_vfs/vfs.h>
21 
22 namespace L4Re { namespace Core {
23 
24 using cxx::Ref_ptr;
25 
26 class Fd_store
27 {
28 public:
29  enum { MAX_FILES = 50 };
30 
31  Fd_store() throw() : _fd_hint(0) {}
32 
33  int alloc() throw();
34  void free(int fd) throw();
35  Ref_ptr<L4Re::Vfs::File> get(int fd) throw();
36  void set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) throw();
37 
38 private:
39  int _fd_hint;
40  Ref_ptr<L4Re::Vfs::File> _files[MAX_FILES];
41 };
42 
43 
44 inline
45 Ref_ptr<L4Re::Vfs::File>
46 Fd_store::get(int fd) throw()
47 {
48  if (fd >= 0 && fd < MAX_FILES)
49  return _files[fd];
50 
51  return Ref_ptr<>::Nil;
52 }
53 
54 inline
55 void
56 Fd_store::set(int fd, Ref_ptr<L4Re::Vfs::File> const &f) throw()
57 {
58  _files[fd] = f;
59 }
60 
61 }}
A reference-counting pointer with automatic cleanup.
Definition: ref_ptr:80
L4Re C++ Interfaces.
Definition: cmd_control:15