Skip to content
Snippets Groups Projects
Commit 9c10e5dc authored by g0dil's avatar g0dil
Browse files

Console: Implement skeleton executor

Console: Connect server to parser and executor
parent 31f2977d
No related branches found
No related tags found
No related merge requests found
// $Id$
//
// Copyright (C) 2008
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// 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 2 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, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief Executor non-inline non-template implementation */
#include "Executor.hh"
//#include "Executor.ih"
// Custom includes
//#include "Executor.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::console::Executor
prefix_ bool senf::console::Executor::operator()(ParseCommandInfo const & command,
std::ostream & output)
{
# warning Implement Executor::operator()
SENF_LOG(( "Executing '" << command.commandPath() << "'" ));
return true;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "Executor.mpp"
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
// $Id$
//
// Copyright (C) 2008
// Fraunhofer Institute for Open Communication Systems (FOKUS)
// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// 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 2 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, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief Executor public header */
#ifndef HH_Executor_
#define HH_Executor_ 1
// Custom includes
#include "Parse.hh"
#include "../Utils/Logger/SenfLog.hh"
//#include "Executor.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
namespace console {
/** \brief
*/
class Executor
{
SENF_LOG_CLASS_AREA();
SENF_LOG_DEFAULT_LEVEL( senf::log::NOTICE );
public:
///////////////////////////////////////////////////////////////////////////
// Types
typedef boost::iterator_range< ParseCommandInfo::argument_iterator> Arguments;
///////////////////////////////////////////////////////////////////////////
bool operator()(ParseCommandInfo const & command, std::ostream & output);
protected:
private:
};
}}
///////////////////////////////hh.e////////////////////////////////////////
//#include "Executor.cci"
//#include "Executor.ct"
//#include "Executor.cti"
#endif
// Local Variables:
// mode: c++
// fill-column: 100
// comment-column: 40
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
// compile-command: "scons -u test"
// End:
...@@ -27,7 +27,11 @@ ...@@ -27,7 +27,11 @@
#include "Server.ih" #include "Server.ih"
// Custom includes // Custom includes
#include <unistd.h>
#include <iostream>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include "../Utils/senfassert.hh" #include "../Utils/senfassert.hh"
#include "../Utils/membind.hh" #include "../Utils/membind.hh"
#include "../Utils/Logger/SenfLog.hh" #include "../Utils/Logger/SenfLog.hh"
...@@ -38,14 +42,18 @@ ...@@ -38,14 +42,18 @@
prefix_ void senf::console::start(senf::INet4SocketAddress const & address) prefix_ void senf::console::start(senf::INet4SocketAddress const & address)
{ {
senf::console::detail::Server::start(senf::TCPv4ServerSocketHandle(address)); senf::TCPv4ServerSocketHandle handle (address);
handle.protocol().reuseaddr();
senf::console::detail::Server::start(handle);
SENF_LOG((detail::Server::SENFLogArea)(log::NOTICE)( SENF_LOG((detail::Server::SENFLogArea)(log::NOTICE)(
"Console server started at " << address )); "Console server started at " << address ));
} }
prefix_ void senf::console::start(senf::INet6SocketAddress const & address) prefix_ void senf::console::start(senf::INet6SocketAddress const & address)
{ {
senf::console::detail::Server::start(senf::TCPv6ServerSocketHandle(address)); senf::TCPv6ServerSocketHandle handle (address);
handle.protocol().reuseaddr();
senf::console::detail::Server::start(handle);
SENF_LOG((detail::Server::SENFLogArea)(log::NOTICE)( SENF_LOG((detail::Server::SENFLogArea)(log::NOTICE)(
"Console server started at " << address )); "Console server started at " << address ));
} }
...@@ -91,8 +99,9 @@ prefix_ void senf::console::detail::Server::removeClient(Client & client) ...@@ -91,8 +99,9 @@ prefix_ void senf::console::detail::Server::removeClient(Client & client)
// senf::console::detail::Client // senf::console::detail::Client
prefix_ senf::console::detail::Client::Client(ClientHandle handle) prefix_ senf::console::detail::Client::Client(ClientHandle handle)
: handle_ (handle) : handle_ (handle), out_(::dup(handle.fd()))
{ {
out_ << "# " << std::flush;
ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"), ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
senf::membind(&Client::clientData, this) ); senf::membind(&Client::clientData, this) );
} }
...@@ -114,11 +123,22 @@ prefix_ void senf::console::detail::Client::clientData(ReadHelper<ClientHandle>: ...@@ -114,11 +123,22 @@ prefix_ void senf::console::detail::Client::clientData(ReadHelper<ClientHandle>:
return; return;
} }
# warning fix Client::clientData implementation
// Remove the 'dup' needed here so we don't close the same fd twice (see Client constructor)
// Make output non-blocking
// Don't register a new ReadHelper every round
std::string data (tail_ + helper->data()); std::string data (tail_ + helper->data());
tail_ = helper->tail(); tail_ = helper->tail();
boost::trim(data); // Gets rid of superfluous \r or \n characters boost::trim(data); // Gets rid of superfluous \r or \n characters
SENF_LOG(( this << ": " << data )); ParseCommandInfo command;
if (parser_.parseCommand(data, command))
executor_(command, out_);
else
out_ << "syntax error" << std::endl;
out_ << "# " << std::flush;
ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"), ReadHelper<ClientHandle>::dispatch( handle_, 16384u, ReadUntil("\n"),
senf::membind(&Client::clientData, this) ); senf::membind(&Client::clientData, this) );
} }
......
...@@ -31,11 +31,15 @@ ...@@ -31,11 +31,15 @@
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include "../Utils/intrusive_refcount.hh" #include "../Utils/intrusive_refcount.hh"
#include "../Socket/Protocols/INet/TCPSocketHandle.hh" #include "../Socket/Protocols/INet/TCPSocketHandle.hh"
#include "../Socket/ServerSocketHandle.hh" #include "../Socket/ServerSocketHandle.hh"
#include "../Scheduler/Scheduler.hh" #include "../Scheduler/Scheduler.hh"
#include "../Scheduler/ReadHelper.hh" #include "../Scheduler/ReadHelper.hh"
#include "Parse.hh"
#include "Executor.hh"
///////////////////////////////ih.p//////////////////////////////////////// ///////////////////////////////ih.p////////////////////////////////////////
...@@ -105,6 +109,11 @@ namespace detail { ...@@ -105,6 +109,11 @@ namespace detail {
ClientHandle handle_; ClientHandle handle_;
std::string tail_; std::string tail_;
SingleCommandParser parser_;
Executor executor_;
typedef boost::iostreams::stream<boost::iostreams::file_descriptor_sink> fdostream;
fdostream out_;
friend class Server; friend class Server;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment