Wolframe, 0.0.3

commandHandler.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 #ifndef _Wolframe_CMDBIND_COMMAND_HANDLER_HPP_INCLUDED
36 #define _Wolframe_CMDBIND_COMMAND_HANDLER_HPP_INCLUDED
37 #include <string>
38 #include <vector>
39 #include <boost/shared_ptr.hpp>
40 #include "types/doctypeinfo.hpp"
42 
43 namespace _Wolframe {
44 
45 namespace proc {
47 class ExecContext;
48 }//namespace proc
49 
50 namespace cmdbind {
51 
55 {
56 public:
58  enum Operation {
59  READ,
62  };
63 
66  :m_execContext(0){}
67 
69  virtual ~CommandHandler(){}
70 
73  virtual Operation nextOperation()=0;
74 
79  virtual void putInput( const void* begin, std::size_t bytesTransferred, bool eod)=0;
80 
84  virtual void getOutput( const void*& begin, std::size_t& bytesToTransfer)=0;
85 
86 
88  const char* lastError() const
89  {
90  return m_lastError.empty()?0:m_lastError.c_str();
91  }
92 
94  void setLastError( const std::string& msg)
95  {
96  m_lastError = msg;
97  }
98 
102  {
103  m_execContext = c;
104  }
105 
109  {
110  return m_execContext;
111  }
112 
115  {
116  return m_doctypeinfo.get();
117  }
118 
120  virtual void setDoctypeInfo( const types::DoctypeInfoR& doctypeinfo_)
121  {
122  m_doctypeinfo = doctypeinfo_;
123  }
124 
126  std::size_t outputChunkSize() const
127  {
128  return m_outputChunkSize;
129  }
130 
132  virtual void setOutputChunkSize( std::size_t outputChunkSize_)
133  {
134  m_outputChunkSize = outputChunkSize_;
135  }
136 
137 private:
138  std::string m_lastError;
141  std::size_t m_outputChunkSize;
142 };
143 
144 typedef boost::shared_ptr<CommandHandler> CommandHandlerR;
145 
146 
150 {
151 public:
154 
156  virtual bool loadPrograms( const proc::ProcessorProviderInterface* provider)=0;
157 
159  virtual std::vector<std::string> commands() const=0;
160 
162  virtual CommandHandler* createCommandHandler( const std::string& cmdname, const std::string& docformat)=0;
163 };
164 
166 typedef boost::shared_ptr<CommandHandlerUnit> CommandHandlerUnitR;
167 
168 
169 }}//namespace
170 #endif
171 
proc::ExecContext * m_execContext
The reference to the execution context of the connection.
Definition: commandHandler.hpp:139
Class that defines a command handler class and is able to create instances of it. ...
Definition: commandHandler.hpp:149
CommandHandler()
Defaul constructor.
Definition: commandHandler.hpp:65
virtual Operation nextOperation()=0
Get the next operation to do for the connection handler.
boost::shared_ptr< DoctypeInfo > DoctypeInfoR
Definition: doctypeinfo.hpp:74
types::DoctypeInfoR m_doctypeinfo
Document type information.
Definition: commandHandler.hpp:140
virtual void putInput(const void *begin, std::size_t bytesTransferred, bool eod)=0
Passes the network input to the command handler (READ operation)
virtual void setExecContext(proc::ExecContext *c)
Pass the reference to the execution context to the command handler.
Definition: commandHandler.hpp:101
virtual void getOutput(const void *&begin, std::size_t &bytesToTransfer)=0
Get the next output chunk from the command handler (WRITE operation)
Definition: commandHandler.hpp:61
Command handler interface.
Definition: commandHandler.hpp:54
Abstract class as processor provider interface.
Definition: procProviderInterface.hpp:81
boost::shared_ptr< CommandHandlerUnit > CommandHandlerUnitR
Command handler unit reference.
Definition: commandHandler.hpp:166
virtual ~CommandHandler()
Destructor.
Definition: commandHandler.hpp:69
virtual ~CommandHandlerUnit()
Destructor.
Definition: commandHandler.hpp:153
Document type information representation created by a document type recognizer.
Definition: doctypeinfo.hpp:45
Structure for document type and format.
void setLastError(const std::string &msg)
Set the last error message of command execution to be returned to the client.
Definition: commandHandler.hpp:94
Execution context passed to functions for referencing resources and to define authorization dependend...
Definition: execContext.hpp:47
const types::DoctypeInfo * doctypeInfo() const
Get info about processed document type.
Definition: commandHandler.hpp:114
virtual bool loadPrograms(const proc::ProcessorProviderInterface *provider)=0
Load all configured programs.
const char * lastError() const
Get the last error message of command execution to be returned to the client.
Definition: commandHandler.hpp:88
virtual void setOutputChunkSize(std::size_t outputChunkSize_)
Set a hint for the size of output chunks in bytes.
Definition: commandHandler.hpp:132
Definition: commandHandler.hpp:59
Interface to processor provider for language bindings and database.
std::size_t outputChunkSize() const
Get a hint for the size of output chunks in bytes.
Definition: commandHandler.hpp:126
proc::ExecContext * execContext()
Get the reference to the processor provider.
Definition: commandHandler.hpp:108
std::size_t m_outputChunkSize
Hint for the size of output chunks.
Definition: commandHandler.hpp:141
boost::shared_ptr< CommandHandler > CommandHandlerR
Definition: commandHandler.hpp:144
virtual void setDoctypeInfo(const types::DoctypeInfoR &doctypeinfo_)
Set info about processed document type.
Definition: commandHandler.hpp:120
Definition: commandHandler.hpp:60
Operation
Operation type.
Definition: commandHandler.hpp:58
std::string m_lastError
Error operation for the client.
Definition: commandHandler.hpp:138
virtual std::vector< std::string > commands() const =0
Get the list of all commands inplemented by this command handler.
virtual CommandHandler * createCommandHandler(const std::string &cmdname, const std::string &docformat)=0
Create an instance of this command handler.