Wolframe, 0.0.3

ioFilterCommandHandler.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _Wolframe_IOFILTER_COMMAND_HANDLER_BASE_HPP_INCLUDED
37 #define _Wolframe_IOFILTER_COMMAND_HANDLER_BASE_HPP_INCLUDED
38 #include "filter/filter.hpp"
39 #include "langbind/input.hpp"
40 #include "langbind/output.hpp"
43 
44 namespace _Wolframe {
45 namespace cmdbind {
46 
50  :public CommandHandler
51 {
52 public:
55  :m_writeptr(0)
56  ,m_writesize(0)
57  ,m_done(false){}
59  IOFilterCommandHandler( const std::string& docformat_)
60  :m_input(docformat_)
61  ,m_writeptr(0)
62  ,m_writesize(0)
63  ,m_done(false){}
64 
67 
69  void setInputFilter( const langbind::InputFilterR& in);
70 
72  void setOutputFilter( const langbind::OutputFilterR& out);
73 
76  {
77  return m_input.inputfilter();
78  }
79 
82  {
83  return m_output;
84  }
85 
88  {
89  return m_input;
90  }
91 
94  {
95  return m_output.outputfilter();
96  }
97 
100  virtual Operation nextOperation();
101 
106  virtual void putInput( const void* begin, std::size_t bytesTransferred, bool eod);
107 
111  virtual void getOutput( const void*& begin, std::size_t& bytesToTransfer);
112 
116  {
117  Ok, //< successful termination of call
118  Error, //< termination of call with error (not completed)
119  Yield //< call interrupted with request for a network operation
120  };
121 
123  static const char* callResultName( CallResult cr)
124  {
125  static const char* ar[] = {"Ok","Error","Yield"};
126  return ar[ (int)cr];
127  }
128 
132  virtual CallResult call( const char*& err)=0;
133 
135  virtual void setOutputChunkSize( std::size_t outputChunkSize_)
136  {
137  CommandHandler::setOutputChunkSize( outputChunkSize_);
138  m_output.setOutputChunkSize( outputChunkSize_);
139  }
140 
141 private:
144  const void* m_writeptr;
145  std::size_t m_writesize;
146  bool m_done;
147 };
148 }}
149 #endif
150 
Interface to a generic command handler.
virtual void putInput(const void *begin, std::size_t bytesTransferred, bool eod)
Passes the network input to the command handler (READ operation)
virtual void getOutput(const void *&begin, std::size_t &bytesToTransfer)
Get the next output chunk from the command handler (WRITE operation)
virtual void setOutputChunkSize(std::size_t outputChunkSize_)
Overloaded setter of the size of output chunk, setting it also in output.
Definition: ioFilterCommandHandler.hpp:135
void setInputFilter(const langbind::InputFilterR &in)
Define the input filter to use (makes an own copy of it)
const langbind::Input & input()
Get a const reference to the input object.
Definition: ioFilterCommandHandler.hpp:87
virtual ~IOFilterCommandHandler()
Destructor.
Definition: ioFilterCommandHandler.hpp:66
Command handler interface.
Definition: commandHandler.hpp:54
Definition: ioFilterCommandHandler.hpp:119
langbind::Input m_input
Input interface for this command handler.
Definition: ioFilterCommandHandler.hpp:142
Interface to network output for processor language bindings.
const langbind::Output & output()
Get a const reference to the output object.
Definition: ioFilterCommandHandler.hpp:81
Output as seen from scripting language binding.
Definition: output.hpp:43
Definition: ioFilterCommandHandler.hpp:118
Abstract class for command handler processing filter input/output.
Definition: ioFilterCommandHandler.hpp:49
virtual CallResult call(const char *&err)=0
Hook to call function to execute.
Base class for the connection handler and related objects.
virtual void setOutputChunkSize(std::size_t outputChunkSize_)
Set a hint for the size of output chunks in bytes.
Definition: commandHandler.hpp:132
Definition: ioFilterCommandHandler.hpp:117
static const char * callResultName(CallResult cr)
Get an enumeration value of call states as string.
Definition: ioFilterCommandHandler.hpp:123
CallResult
Enumeration of call states of this application processor instance.
Definition: ioFilterCommandHandler.hpp:115
IOFilterCommandHandler(const std::string &docformat_)
Constructor.
Definition: ioFilterCommandHandler.hpp:59
const InputFilterR & inputfilter() const
Get the input filter attached to input.
Definition: input.hpp:74
bool m_done
Terminated.
Definition: ioFilterCommandHandler.hpp:146
Input as seen from the application processor program.
Definition: input.hpp:47
std::size_t m_writesize
Size of what to write next in bytes.
Definition: ioFilterCommandHandler.hpp:145
langbind::Output m_output
Output interface for this command handler.
Definition: ioFilterCommandHandler.hpp:143
void setOutputChunkSize(unsigned int outputChunkSize_)
Definition: output.hpp:83
langbind::OutputFilterR outputfilter()
Get a reference to the output filter.
Definition: ioFilterCommandHandler.hpp:93
const void * m_writeptr
What to write next.
Definition: ioFilterCommandHandler.hpp:144
virtual Operation nextOperation()
Get the next operation to do for the connection handler.
langbind::InputFilterR inputfilter()
Get a reference to the input filter.
Definition: ioFilterCommandHandler.hpp:75
Operation
Operation type.
Definition: commandHandler.hpp:58
Interface to network output for processor language bindings.
void setOutputFilter(const langbind::OutputFilterR &out)
Define the output filter to use (makes an own copy of it)
const OutputFilterR & outputfilter() const
Definition: output.hpp:76
IOFilterCommandHandler()
Constructor.
Definition: ioFilterCommandHandler.hpp:54
Interface for filter class.