Wolframe, 0.0.3

protocolHandler.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_PROTOCOL_HANDLER_HPP_INCLUDED
36 #define _Wolframe_CMDBIND_PROTOCOL_HANDLER_HPP_INCLUDED
39 #include <string>
40 #include <vector>
41 #include <boost/shared_ptr.hpp>
42 
43 namespace _Wolframe {
44 namespace proc {
46 class ExecContext;
47 }//namespace proc
48 namespace cmdbind {
49 
53 {
54 public:
56  enum Operation {
60  };
63  :m_execContext(0){}
64 
66  virtual ~ProtocolHandler(){}
67 
70  virtual void setPeer( const net::RemoteEndpointR&){}
71 
74  virtual void setLocalEndPoint( const net::LocalEndpointR&){}
75 
79  virtual void setInputBuffer( void* buf, std::size_t allocsize)=0;
80 
85  virtual void setOutputBuffer( void* buf, std::size_t size, std::size_t pos)=0;
86 
89  virtual Operation nextOperation()=0;
90 
94  virtual void putInput( const void* begin, std::size_t bytesTransferred)=0;
95 
97  virtual void putEOF(){}
98 
102  virtual void getInputBlock( void*& begin, std::size_t& maxBlockSize)=0;
103 
107  virtual void getOutput( const void*& begin, std::size_t& bytesToTransfer)=0;
108 
112  virtual void getDataLeft( const void*& begin, std::size_t& nofBytes)=0;
113 
115  const char* lastError() const
116  {
117  return m_lastError.empty()?0:m_lastError.c_str();
118  }
119 
121  void setLastError( const std::string& msg)
122  {
123  m_lastError = msg;
124  }
125 
129  {
130  m_execContext = c;
131  }
132 
136  {
137  return m_execContext;
138  }
139 
141  virtual void setArgumentString( const std::string&){};
142 
144  virtual const char* interruptDataSessionMarker() const {return "";}
145 
146 private:
147  std::string m_lastError; //< error operation for the client
148  proc::ExecContext* m_execContext; //< the reference to the execution context of the connection
149 };
150 
151 typedef boost::shared_ptr<ProtocolHandler> ProtocolHandlerR;
152 
153 
157 {
158 public:
160  virtual const char* protocol() const=0;
161 
164 };
165 
167 typedef boost::shared_ptr<ProtocolHandlerUnit> ProtocolHandlerUnitR;
168 
169 }}
170 #endif
171 
Definition: protocolHandler.hpp:57
Interface to a generic command handler.
virtual const char * protocol() const =0
Get the name of the protocol implemented.
boost::shared_ptr< ProtocolHandler > ProtocolHandlerR
Definition: protocolHandler.hpp:151
Operation
Operation type.
Definition: protocolHandler.hpp:56
virtual Operation nextOperation()=0
Get the next operation to do for the connection handler.
virtual void putInput(const void *begin, std::size_t bytesTransferred)=0
Passes the network input to the command handler (READ operation)
virtual void getDataLeft(const void *&begin, std::size_t &nofBytes)=0
Get the data left unprocessed after close. The data belongs to the caller to process.
Class that defines a protocol handler class and is able to create instances of it.
Definition: protocolHandler.hpp:156
Definition: commandHandler.hpp:61
const char * lastError() const
Get the last error message of command execution to be returned to the client.
Definition: protocolHandler.hpp:115
Classes for network endpoints.
Definition: protocolHandler.hpp:59
Execution context passed to functions for referencing resources and to define authorization dependend...
Definition: execContext.hpp:47
boost::shared_ptr< LocalEndpoint > LocalEndpointR
Definition: connectionEndpoint.hpp:163
virtual void getInputBlock(void *&begin, std::size_t &maxBlockSize)=0
Get the input block request (READ operation)
proc::ExecContext * m_execContext
Definition: protocolHandler.hpp:148
virtual void setPeer(const net::RemoteEndpointR &)
Set the client connection end point.
Definition: protocolHandler.hpp:70
std::string m_lastError
Definition: protocolHandler.hpp:147
Definition: commandHandler.hpp:59
virtual void setLocalEndPoint(const net::LocalEndpointR &)
Set the local connection end point.
Definition: protocolHandler.hpp:74
boost::shared_ptr< ProtocolHandlerUnit > ProtocolHandlerUnitR
Protocol handler unit reference.
Definition: protocolHandler.hpp:167
virtual void getOutput(const void *&begin, std::size_t &bytesToTransfer)=0
Get the next output chunk from the command handler (WRITE operation)
virtual void setOutputBuffer(void *buf, std::size_t size, std::size_t pos)=0
Define the input buffer for processing the command.
virtual void setArgumentString(const std::string &)
Pass arguments to protocol handler.
Definition: protocolHandler.hpp:141
virtual ProtocolHandler * createProtocolHandler()=0
Create an instance of this protocol handler.
void setExecContext(proc::ExecContext *c)
Pass the reference to the execution context to the command handler.
Definition: protocolHandler.hpp:128
void setLastError(const std::string &msg)
Set the last error message of command execution to be returned to the client.
Definition: protocolHandler.hpp:121
virtual const char * interruptDataSessionMarker() const
Get the termination marker to send for an abort of a running data session.
Definition: protocolHandler.hpp:144
virtual void setInputBuffer(void *buf, std::size_t allocsize)=0
Define the input buffer for processing the command.
boost::shared_ptr< RemoteEndpoint > RemoteEndpointR
Definition: connectionEndpoint.hpp:208
proc::ExecContext * execContext()
Get the reference to the processor provider.
Definition: protocolHandler.hpp:135
Definition: commandHandler.hpp:60
ProtocolHandler()
Default constructor.
Definition: protocolHandler.hpp:62
Protocol handler interface.
Definition: protocolHandler.hpp:52
virtual void putEOF()
Tell the protocol handler that EOF has been reached, if implemented.
Definition: protocolHandler.hpp:97
virtual ~ProtocolHandler()
Destructor.
Definition: protocolHandler.hpp:66
Definition: protocolHandler.hpp:58