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

I_OneWayMultiTunnel.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   One way multi tunnel
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022 
00023   @section details Details
00024 
00025   Part of the utils library which contains classes that use multiple
00026   components of the IO-Core to implement some useful functionality. The
00027   classes also serve as good examples of how to use the IO-Core.
00028 
00029  */
00030 
00031 #if !defined (_I_OneWayMultiTunnel_h_)
00032 #define _I_OneWayMultiTunnel_h_
00033 
00034 #include "I_OneWayTunnel.h"
00035 
00036 /** Maximum number which can be tunnelled too */
00037 #define ONE_WAY_MULTI_TUNNEL_LIMIT          4
00038 
00039 /**
00040   A generic state machine that connects a source virtual conection to
00041   multiple target virtual connections. A OneWayMultiTunnel is similar to
00042   the OneWayTunnel module. However, instead of connection one source
00043   to one target, it connects multiple virtual connections - a source
00044   vc and multiple target vcs, and copies the data from the source
00045   to the target vcs. The maximum number of Target VCs is limited by
00046   ONE_WAY_MULTI_TUNNEL_LIMIT.
00047 
00048   If manipulate_fn is not NULL, then the tunnel acts as a filter,
00049   processing all data arriving from the source vc by the manipulate_fn
00050   function, before sending to the target vcs. By default, the
00051   manipulate_fn is set to NULL, yielding the identity function.
00052 
00053   @see OneWayTunnel
00054 
00055 */
00056 struct OneWayMultiTunnel: public OneWayTunnel
00057 {
00058   //
00059   // Public Interface
00060   //
00061 
00062   // Use these to construct/destruct OneWayMultiTunnel objects
00063 
00064   /**
00065     Allocates a OneWayMultiTunnel object.
00066 
00067     @return new OneWayTunnel object.
00068 
00069   */
00070   static OneWayMultiTunnel *OneWayMultiTunnel_alloc();
00071 
00072   /**
00073     Deallocates a OneWayTunnel object.
00074 
00075   */
00076   static void OneWayMultiTunnel_free(OneWayMultiTunnel *);
00077 
00078     OneWayMultiTunnel();
00079 
00080   // Use One of the following init functions to start the tunnel.
00081 
00082   /**
00083     This init function sets up the read (calls do_io_read) and the write
00084     (calls do_io_write).
00085 
00086     @param vcSource source VConnection. A do_io_read should not have
00087       been called on the vcSource. The tunnel calls do_io_read on this VC.
00088     @param vcTargets array of Target VConnections. A do_io_write should
00089       not have been called on any of the vcTargets. The tunnel calls
00090       do_io_write on these VCs.
00091     @param n_vcTargets size of vcTargets.
00092     @param aCont continuation to call back when the tunnel finishes. If
00093       not specified, the tunnel deallocates itself without calling
00094       back anybody.
00095     @param size_estimate size of the MIOBuffer to create for reading/
00096       writing to/from the VC's.
00097     @param nbytes number of bytes to transfer.
00098     @param asingle_buffer whether the same buffer should be used to read
00099       from vcSource and write to vcTarget. This should be set to true
00100       in most cases, unless the data needs be transformed.
00101     @param aclose_source if true, the tunnel closes vcSource at the
00102       end. If aCont is not specified, this should be set to true.
00103     @param aclose_target if true, the tunnel closes vcTarget at the end.
00104       If aCont is not specified, this should be set to true.
00105     @param manipulate_fn if specified, the tunnel calls this function
00106       with the input and the output buffer, whenever it gets new data
00107       in the input buffer. This function can transform the data in the
00108       input buffer.
00109     @param water_mark for the MIOBuffer used for reading.
00110 
00111   */
00112   void init(VConnection * vcSource, VConnection ** vcTargets, int n_vcTargets, Continuation * aCont = NULL, int size_estimate = 0,      // 0 == best guess
00113             int64_t nbytes = TUNNEL_TILL_DONE,
00114             bool asingle_buffer = true,
00115             bool aclose_source = true,
00116             bool aclose_target = true, Transform_fn manipulate_fn = NULL, int water_mark = 0);
00117 
00118   /**
00119     Use this init function if both the read and the write sides have
00120     already been setup. The tunnel assumes that the read VC and the
00121     write VCs are using the same buffer and frees that buffer when the
00122     transfer is done (either successful or unsuccessful).
00123 
00124     @param aCont continuation to call back when the tunnel finishes. If
00125       not specified, the tunnel deallocates itself without calling back
00126       anybody.
00127     @param SourceVio read VIO of the Source VC.
00128     @param TargetVios array of write VIOs of the Target VCs.
00129     @param n_vioTargets size of TargetVios array.
00130     @param aclose_source if true, the tunnel closes vcSource at the
00131       end. If aCont is not specified, this should be set to true.
00132     @param aclose_target ff true, the tunnel closes vcTarget at the
00133       end. If aCont is not specified, this should be set to true.
00134 
00135   */
00136   void init(Continuation * aCont, VIO * SourceVio, VIO ** TargetVios, int n_vioTargets, bool aclose_source = true,
00137             bool aclose_target = true);
00138 
00139   //
00140   // Private
00141   //
00142   int startEvent(int event, void *data);
00143 
00144   virtual void reenable_all();
00145   virtual void close_target_vio(int result, VIO * vio = NULL);
00146 
00147   int n_vioTargets;
00148   VIO *vioTargets[ONE_WAY_MULTI_TUNNEL_LIMIT];
00149   MIOBufferAccessor topOutBuffer;
00150   bool source_read_previously_completed;
00151 };
00152 
00153 extern ClassAllocator<OneWayMultiTunnel> OneWayMultiTunnelAllocator;
00154 #endif

Generated by  doxygen 1.7.1