FreeNOS
UDPFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
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 3 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "UDP.h"
19 #include "UDPFactory.h"
20 #include "UDPSocket.h"
21 
23  UDP *udp)
24  : File(inode)
25  , m_udp(udp)
26 {
27 }
28 
30 {
31 }
32 
34  Size & size,
35  const Size offset)
36 {
37  DEBUG("");
38 
39  String path;
40  UDPSocket *sock;
41  const FileSystemMessage *msg = buffer.getMessage();
42 
43  if (offset > 0)
44  {
45  size = 0;
46  return FileSystem::Success;
47  }
48 
49  sock = m_udp->createSocket(path, msg->from);
50  if (!sock)
51  {
52  ERROR("failed to create UDP socket");
53  return FileSystem::IOError;
54  }
55 
56  buffer.write(*path, path.length() + 1);
57  size = path.length() + 1;
58  return FileSystem::Success;
59 }
UDPFactory::m_udp
UDP * m_udp
UDP protocol instance.
Definition: UDPFactory.h:73
String::length
Size length() const
Same as count().
Definition: String.cpp:105
IOBuffer::getMessage
const FileSystemMessage * getMessage() const
Get filesystem message.
Definition: IOBuffer.cpp:120
UDP.h
String
Abstraction of strings.
Definition: String.h:41
UDP
User Datagram Protocol (UDP)
Definition: UDP.h:41
UDP::createSocket
UDPSocket * createSocket(String &path, const ProcessID pid)
Creates an UDP socket.
Definition: UDP.cpp:47
UDPFactory::~UDPFactory
virtual ~UDPFactory()
Destructor.
Definition: UDPFactory.cpp:29
FileSystemMessage
FileSystem IPC message.
Definition: FileSystemMessage.h:37
FileSystem::IOError
@ IOError
Definition: FileSystem.h:58
FileSystem::Success
@ Success
Definition: FileSystem.h:54
File
Represents a file present on a FileSystem.
Definition: File.h:39
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
UDPFactory.h
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
UDPFactory::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Create UDP socket.
Definition: UDPFactory.cpp:33
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
ChannelMessage::from
ProcessID from
Source process of the message.
Definition: ChannelMessage.h:54
IOBuffer::write
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition: IOBuffer.cpp:180
UDPSocket.h
UDPSocket
User Datagram Protocol (UDP) socket.
Definition: UDPSocket.h:42
UDPFactory::UDPFactory
UDPFactory(const u32 inode, UDP *udp)
Constructor.
Definition: UDPFactory.cpp:22