Posix stuff to its own module

parent fe59d6c0
......@@ -15,7 +15,7 @@ the thread is put asleep.
\section thread-irc IRC Connection
The IRC connection (network::irc::IrcConnection) uses two threads:
The IRC connection (irc::IrcConnection) uses two threads:
one to get input from the network and one to handle messages to send.
Both will be blocked if there is no input coming to them.
......@@ -27,4 +27,10 @@ a single thread to handle asyncronous requests.
It will wait for an incoming request, then it will fully complete that
before looking for the next one.
\section thread-stdin POSIX Stdin Connection
The Stdin "connection" (StdinConnection) uses a thread to
get input from the user.
*/
......@@ -17,3 +17,4 @@ include_directories("${CMAKE_SOURCE_DIR}/modules")
melanomodule(irc "Internet Relay Chat support" ON)
melanomodule(xonotic "Xonotic integration" ON)
melanomodule(posix "Extra features for POSIX systems" OFF)
# Copyright (C) 2015 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(MODULE_NAME melanomodule_posix)
set(SOURCES stdin.cpp)
add_library(${MODULE_NAME} ${SOURCES})
......@@ -27,12 +27,10 @@
#include "melanobot.hpp"
#include "network/connection.hpp"
namespace network {
/**
* \brief Acts as a network connection to handle standard input
*/
class StdinConnection : public Connection
class StdinConnection : public network::Connection
{
public:
static std::unique_ptr<StdinConnection> create(Melanobot* bot, const Settings& settings)
......@@ -75,7 +73,7 @@ public:
std::string protocol() const override { return "stdin"; }
std::string name() const override { return "stdin"; }
Server server() const override { return {"stdin",0}; }
network::Server server() const override { return {"stdin",0}; }
// dummy overrides:
Status status() const override { return CONNECTED; }
......@@ -93,8 +91,8 @@ public:
// maybe could be given some actual functionality:
std::string get_property(const std::string&) const override { return {}; }
bool set_property(const std::string& , const std::string& ) override { return false; }
void command ( const Command&) override {}
void say ( const OutputMessage& ) override {}
void command ( const network::Command&) override {}
void say ( const network::OutputMessage& ) override {}
private:
Melanobot* bot;
......@@ -132,7 +130,7 @@ private:
}
std::istream buffer_stream(&buffer_read);
Message msg;
network::Message msg;
std::getline(buffer_stream,msg.raw);
Log("std",'>',1) << formatter_->decode(msg.raw);
std::istringstream socket_stream(msg.raw);
......@@ -147,9 +145,12 @@ private:
}
};
REGISTER_CONNECTION(stdin,&network::StdinConnection::create);
REGISTER_LOG_TYPE(std,color::white);
} // namespace network
/**
* \brief POSIX module initialization
*/
void melanomodule_posix()
{
REGISTER_CONNECTION(stdin,&StdinConnection::create);
REGISTER_LOG_TYPE(std,color::white);
}
#endif // BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment