The Pedigree Project  0.1
system/include/pedigree/kernel/process/Ipc.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 _PROCESS_IPC_H
21 #define _PROCESS_IPC_H
22 
23 #include "pedigree/kernel/Log.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/process/Mutex.h"
26 #include "pedigree/kernel/process/Semaphore.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/List.h"
29 #include "pedigree/kernel/utilities/String.h"
30 #include "pedigree/kernel/utilities/new"
31 
32 class MemoryRegion;
33 
34 namespace Ipc
35 {
37 {
38  public:
39  IpcMessage();
40 
54  IpcMessage(size_t nBytes, uintptr_t regionHandle = 0);
55 
56  virtual ~IpcMessage();
57 
60  void *getBuffer();
61 
65  void *getHandle();
66 
71  IpcMessage(const IpcMessage &src)
72  {
73  if (src.nPages > 1)
74  FATAL("IpcMessage: copy constructor misused.");
75  nPages = src.nPages;
76  m_vAddr = src.m_vAddr;
77  m_pMemRegion = src.m_pMemRegion;
78  }
79 
80  private:
81  size_t nPages;
82 
84  uintptr_t m_vAddr;
85 
90 };
91 
96 {
97  public:
98  IpcEndpoint(const String &name)
99  : m_Name(name), m_Queue(), m_QueueSize(0), m_QueueLock(false)
100  {
101  NOTICE("Creating endpoint with name " << name);
102  NOTICE("Endpoint is at " << reinterpret_cast<uintptr_t>(this));
103  }
104 
106  {
107  FATAL("IpcEndpoint " << m_Name << " is being destroyed.");
108  }
109 
110  Mutex *pushMessage(IpcMessage *pMessage, bool bAsync);
111 
112  IpcMessage *getMessage(bool bBlock = false);
113 
114  const String &getName() const
115  {
116  return m_Name;
117  }
118 
119  private:
122  {
123  Mutex *pMutex;
124  IpcMessage *pMessage;
125  bool bAsync;
126  };
127 
128  String m_Name;
129 
130  List<QueuedMessage *> m_Queue;
131  Semaphore m_QueueSize;
132 
133  Mutex m_QueueLock;
134 };
135 
136 EXPORTED_PUBLIC bool
137 send(IpcEndpoint *pEndpoint, IpcMessage *pMessage, bool bAsync = false);
138 EXPORTED_PUBLIC bool
139 recv(IpcEndpoint *pEndpoint, IpcMessage **pMessage, bool bAsync = false);
140 
141 EXPORTED_PUBLIC IpcEndpoint *getEndpoint(String &name);
142 
143 EXPORTED_PUBLIC void createEndpoint(String &name);
144 EXPORTED_PUBLIC void removeEndpoint(String &name);
145 }; // namespace Ipc
146 
147 #endif
uintptr_t m_vAddr
Virtual address of a message when m_pMemRegion is invalid.
Definition: Mutex.h:58
Definition: String.h:49
Definition: List.h:64
#define NOTICE(text)
Definition: Log.h:74
Special memory entity in the kernel&#39;s virtual address space.
Definition: MemoryRegion.h:35
#define FATAL(text)
Definition: Log.h:89