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

TransactionPlugin.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  * @file TransactionPlugin.h
00020  * @brief Contains the interface used in creating Transaciton plugins.
00021  */
00022 
00023 #pragma once
00024 #ifndef ATSCPPAPI_TRANSACTIONPLUGIN_H_
00025 #define ATSCPPAPI_TRANSACTIONPLUGIN_H_
00026 
00027 #include <atscppapi/Plugin.h>
00028 #include <atscppapi/Transaction.h>
00029 #include <atscppapi/shared_ptr.h>
00030 #include <atscppapi/Mutex.h>
00031 
00032 namespace atscppapi {
00033 
00034 namespace utils {
00035  class internal;
00036 } /* utils */
00037 
00038 /**
00039  * @private
00040  */
00041 struct TransactionPluginState;
00042 
00043 /**
00044  * @brief The interface used when creating a TransactionPlugin.
00045  *
00046  * A Transaction Plugin is a plugin that will fire only for the specific Transaction it
00047  * was bound to. When you create a TransactionPlugin you call the parent constructor with
00048  * the associated Transaction and it will become automatically bound. This means that your
00049  * TransactionPlugin will automatically be destroyed when the Transaction dies.
00050  *
00051  * Implications of this are that you can easily add Transaction scoped storage by adding
00052  * a member to a TransactionPlugin since the destructor will be called of your TransactionPlugin
00053  * any cleanup that needs to happen can happen in your destructor as you normally would.
00054  *
00055  * You must always be sure to implement the appropriate callback for the type of hook you register.
00056  *
00057  * \code
00058  * // For a more detailed example see examples/transactionhook/
00059  * class TransactionHookPlugin : publicTransactionPlugin {
00060  * public:
00061  *   TransactionHookPlugin(Transaction &transaction) : TransactionPlugin(transaction) {
00062  *     char_ptr_ = new char[100]; // Transaction scoped storage
00063  *     registerHook(HOOK_SEND_RESPONSE_HEADERS);
00064  *   }
00065  *   virtual ~TransactionHookPlugin() {
00066  *     delete[] char_ptr_; // cleanup
00067  *   }
00068  *   void handleSendResponseHeaders(Transaction &transaction) {
00069  *     transaction.resume();
00070  *   }
00071  * private:
00072  *   char *char_ptr_;
00073  * };
00074  * \endcode
00075  *
00076  * @see Plugin
00077  * @see HookType
00078  */
00079 class TransactionPlugin : public Plugin {
00080 public:
00081   /**
00082    * registerHook is the mechanism used to attach a transaction hook.
00083    *
00084    * \note Whenever you register a hook you must have the appropriate callback definied in your TransactionPlugin
00085    *  see HookType and Plugin for the correspond HookTypes and callback methods. If you fail to implement the
00086    *  callback, a default implmentation will be used that will only resume the Transaction.
00087    *
00088    * @param HookType the type of hook you wish to register
00089    * @see HookType
00090    * @see Plugin
00091    */
00092   void registerHook(Plugin::HookType hook_type);
00093   virtual ~TransactionPlugin();
00094 protected:
00095   TransactionPlugin(Transaction &transaction);
00096 
00097   /**
00098    * This method will return a shared_ptr to a Mutex that can be used for AsyncProvider and AsyncReceiver operations.
00099    *
00100    * If another thread wanted to stop this transaction from dispatching an event it could be passed
00101    * this mutex and it would be able to lock it and prevent another thread from dispatching back into this
00102    * TransactionPlugin.
00103    */
00104   shared_ptr<Mutex> getMutex();
00105 private:
00106   TransactionPluginState *state_; /**< The internal state for a TransactionPlugin */
00107   friend class utils::internal;
00108 };
00109 
00110 } /* atscppapi */
00111 
00112 
00113 #endif /* ATSCPPAPI_TRANSACTIONPLUGIN_H_ */

Generated by  doxygen 1.7.1