FreeNOS
ICMPFactory.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 "ICMPFactory.h"
19 #include "ICMPSocket.h"
20 
22  ICMP *icmp)
23  : File(inode)
24 {
25  m_icmp = icmp;
26 }
27 
29 {
30 }
31 
33  Size & size,
34  const Size offset)
35 {
36  DEBUG("");
37 
38  String path;
39  ICMPSocket *sock;
40  const FileSystemMessage *msg = buffer.getMessage();
41 
42  if (offset > 0)
43  {
44  size = 0;
45  return FileSystem::Success;
46  }
47 
48  sock = m_icmp->createSocket(path, msg->from);
49  if (!sock)
50  {
51  ERROR("failed to create ICMP socket");
52  return FileSystem::IOError;
53  }
54 
55  buffer.write(*path, path.length() + 1);
56  size = path.length() + 1;
57  return FileSystem::Success;
58 }
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
String
Abstraction of strings.
Definition: String.h:41
ICMP::createSocket
ICMPSocket * createSocket(String &path, const ProcessID pid)
Creates an ICMP socket.
Definition: ICMP.cpp:87
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
ICMPFactory::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Create ICMP socket.
Definition: ICMPFactory.cpp:32
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
ICMPFactory::~ICMPFactory
virtual ~ICMPFactory()
Destructor.
Definition: ICMPFactory.cpp:28
ICMPFactory.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
ICMPSocket.h
ICMPFactory::ICMPFactory
ICMPFactory(const u32 inode, ICMP *icmp)
Constructor.
Definition: ICMPFactory.cpp:21
ERROR
#define ERROR(msg)
Output an error message.
Definition: Log.h:61
ICMPFactory::m_icmp
ICMP * m_icmp
ICMP protocol instance.
Definition: ICMPFactory.h:74
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
ICMPSocket
Internet Control Message Protocol (ICMP) socket.
Definition: ICMPSocket.h:42
ICMP
Internet Control Message Protocol (ICMP)
Definition: ICMP.h:42