The Pedigree Project  0.1
Pipe.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef PIPE_H
21 #define PIPE_H
22 
23 #include "File.h"
24 #include "pedigree/kernel/Log.h"
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/process/Semaphore.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/time/Time.h"
29 #include "pedigree/kernel/utilities/Buffer.h"
30 #include "pedigree/kernel/utilities/String.h"
31 
32 #define PIPE_BUF_MAX 2048
33 
35 class EXPORTED_PUBLIC Pipe : public File
36 {
37  friend class Filesystem;
38  friend class ZombiePipe;
39 
40  public:
42  static Pipe *fromFile(File *pF)
43  {
44  if (!(pF->isPipe() || pF->isFifo()))
45  FATAL("Casting non-pipe/fifo File to Pipe!");
46  return reinterpret_cast<Pipe *>(pF);
47  }
48 
50  Pipe();
51 
53  Pipe(const Pipe &file);
54 
55  private:
56  Pipe &operator=(const Pipe &);
57 
58  public:
60  Pipe(
61  const String &name, Time::Timestamp accessedTime,
62  Time::Timestamp modifiedTime, Time::Timestamp creationTime,
63  uintptr_t inode, class Filesystem *pFs, size_t size, File *pParent,
64  bool bIsAnonymous = false);
66  virtual ~Pipe();
67 
69  virtual int select(bool bWriting = false, int timeout = 0);
70 
72  virtual uint64_t readBytewise(
73  uint64_t location, uint64_t size, uintptr_t buffer,
74  bool bCanBlock = true);
76  virtual uint64_t writeBytewise(
77  uint64_t location, uint64_t size, uintptr_t buffer,
78  bool bCanBlock = true);
79 
81  virtual bool isPipe() const;
83  virtual bool isFifo() const;
84 
85  virtual void increaseRefCount(bool bIsWriter);
86 
89  virtual void decreaseRefCount(bool bIsWriter);
90 
91  size_t getReaderCount() const
92  {
93  return m_nReaders;
94  }
95 
96  size_t getWriterCount() const
97  {
98  return m_nWriters;
99  }
100 
101  // Wait for a reader - returns false if interrupted before a reader arrived.
102  bool waitForReader();
103 
104  protected:
108 
110  volatile bool m_bIsEOF;
111 
114 
117 
118  virtual bool isBytewise() const
119  {
120  return true;
121  }
122 };
123 
124 #endif
virtual bool isFifo() const
Definition: File.cc:446
volatile bool m_bIsEOF
Definition: Pipe.h:110
virtual bool isBytewise() const
Definition: Pipe.h:118
Semaphore m_ReaderSem
Definition: Pipe.h:116
virtual int select(bool bWriting=false, int timeout=0)
Definition: File.cc:534
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: File.cc:582
Buffer< uint8_t > m_Buffer
Definition: Pipe.h:113
Definition: String.h:49
bool m_bIsAnonymous
Definition: Pipe.h:107
virtual bool isPipe() const
Definition: File.cc:441
#define FATAL(text)
Definition: Log.h:89
Definition: File.h:66
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: File.cc:592
static Pipe * fromFile(File *pF)
Definition: Pipe.h:42
Definition: Pipe.h:35