• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

InterceptPlugin.h

Go to the documentation of this file.
00001 /**
00002   Licensed to the Apache Software Foundation (ASF) under one
00003   or more contributor license agreements.  See the NOTICE file
00004   distributed with this work for additional information
00005   regarding copyright ownership.  The ASF licenses this file
00006   to you under the Apache License, Version 2.0 (the
00007   "License"); you may not use this file except in compliance
00008   with the License.  You may obtain a copy of the License at
00009 
00010       http://www.apache.org/licenses/LICENSE-2.0
00011 
00012   Unless required by applicable law or agreed to in writing, software
00013   distributed under the License is distributed on an "AS IS" BASIS,
00014   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015   See the License for the specific language governing permissions and
00016   limitations under the License.
00017  */
00018 
00019 /**
00020  * @file InterceptPlugin.h
00021  */
00022 
00023 #pragma once
00024 #ifndef ATSCPPAPI_INTERCEPT_PLUGIN_H_
00025 #define ATSCPPAPI_INTERCEPT_PLUGIN_H_
00026 
00027 #include <string>
00028 #include <atscppapi/Transaction.h>
00029 #include <atscppapi/TransactionPlugin.h>
00030 
00031 namespace atscppapi {
00032 
00033 
00034 
00035 /**
00036  * Allows a plugin to act as a server and return the response. This
00037  * plugin can be created in read request headers hook (pre or post
00038  * remap).
00039  */
00040 class InterceptPlugin : public TransactionPlugin {
00041 protected:
00042   /**
00043    * The available types of intercepts.
00044    */
00045   enum Type {
00046     SERVER_INTERCEPT = 0, /**< Plugin will act as origin */
00047     TRANSACTION_INTERCEPT /**< Plugin will act as cache and origin (on cache miss) */
00048   };
00049 
00050   /** a plugin must implement this interface, it cannot be constructed directly */
00051   InterceptPlugin(Transaction &transaction, Type type);
00052 
00053 public:
00054   enum RequestDataType {
00055     REQUEST_HEADER = 0,
00056     REQUEST_BODY
00057   };
00058 
00059   /**
00060    * A method that you must implement when writing an InterceptPlugin, this method will be
00061    * invoked whenever client request data is read.
00062    */
00063   virtual void consume(const std::string &data, RequestDataType type) = 0;
00064 
00065   /**
00066    * A method that you must implement when writing an InterceptPlugin, this method
00067    * will be invoked when the client request is deemed complete.
00068    */
00069   virtual void handleInputComplete() = 0;
00070 
00071   /** Should be called only after request header has completely been consumed */
00072   Headers &getRequestHeaders();
00073 
00074   virtual ~InterceptPlugin();
00075 
00076   struct State; /** Internal use only */
00077 
00078 protected:
00079   /**
00080    * This method is how an InterceptPlugin will send output back to
00081    * the client.
00082    */
00083   bool produce(const void *data, int data_size);
00084 
00085   bool produce(const std::string &data) { return produce(data.data(), data.size()); }
00086 
00087   bool setOutputComplete();
00088 
00089 private:
00090   State *state_;
00091   
00092   bool doRead();
00093   void handleEvent(int, void *);
00094 
00095   friend class utils::internal;
00096 };
00097 
00098 } /* atscppapi */
00099 
00100 
00101 #endif /* ATSCPPAPI_INTERCEPT_PLUGIN_H_ */

Generated by  doxygen 1.7.1