mirror of https://gitee.com/bigwinds/arangodb
183 lines
6.5 KiB
C++
183 lines
6.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief abstract class for http handlers
|
|
///
|
|
/// @file
|
|
///
|
|
// DISCLAIMER
|
|
///
|
|
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
|
|
///
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
/// you may not use this file except in compliance with the License.
|
|
/// You may obtain a copy of the License at
|
|
///
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
///
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
/// See the License for the specific language governing permissions and
|
|
/// limitations under the License.
|
|
///
|
|
/// Copyright holder is triAGENS GmbH, Cologne, Germany
|
|
///
|
|
/// @author Dr. Frank Celler
|
|
/// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TRIAGENS_FYN_REST_HTTP_HANDLER_H
|
|
#define TRIAGENS_FYN_REST_HTTP_HANDLER_H 1
|
|
|
|
#include <Logger/Logger.h>
|
|
#include <Scheduler/Scheduler.h>
|
|
#include <Scheduler/Task.h>
|
|
#include <Dispatcher/Dispatcher.h>
|
|
#include <Rest/Handler.h>
|
|
#include <HttpServer/HttpCommTask.h>
|
|
|
|
namespace triagens {
|
|
namespace rest {
|
|
class HttpHandlerFactory;
|
|
class HttpRequest;
|
|
class HttpResponse;
|
|
class HttpCommTask;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @ingroup HttpServer
|
|
/// @brief abstract class for http handlers
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class HttpHandler : public Handler {
|
|
private:
|
|
HttpHandler (HttpHandler const&);
|
|
HttpHandler& operator= (HttpHandler const&);
|
|
|
|
public:
|
|
|
|
using Handler::createJob;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief constructs a new handler
|
|
///
|
|
/// Note that the handler owns the request and the response. It is its
|
|
/// responsibility to destroy them both.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
explicit
|
|
HttpHandler (HttpRequest*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief destructs a handler
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
~HttpHandler ();
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief sets the handler factory
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void setHandlerFactory (HttpHandlerFactory*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief handles the signal
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual bool handleAsync ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief create a job
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual Job* createJob ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief create a job
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual Job* createJob (Scheduler*, Dispatcher*, HttpCommTask*);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief shut down the handler
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void beginShutdown () {
|
|
if (!_job) {
|
|
delete this;
|
|
}
|
|
else {
|
|
LOGGER_DEBUG << "job is still active, trying to shutdown";
|
|
|
|
// this might delete the handler (i.e. ourselves!)
|
|
_job->beginShutdown();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief set the comm task
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void setTask (HttpCommTask* task) {
|
|
_task = task;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief set the job
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void setJob (Job* job) {
|
|
_job = job;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief returns the response
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
HttpResponse* getResponse ();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief default job notification routine
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual void notify (Job* job, Job::notification_e type) {
|
|
// do noting
|
|
}
|
|
|
|
protected:
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the handler factory
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
HttpHandlerFactory* _handlerFactory;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the request
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
HttpRequest* request;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the response
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
HttpResponse* response;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the comm task
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
HttpCommTask* _task;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief the job
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Job* _job;
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif
|