OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
request_pipeline.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // request_pipeline.h
7 //
8 
9 #ifndef __REQUEST_PIPELINE_H__
10 #define __REQUEST_PIPELINE_H__
11 
12 #include <boost/ptr_container/ptr_vector.hpp>
13 #include <boost/function.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <vector>
16 
17 class SandeshRequest;
18 class Sandesh;
19 
21 public:
22  class PipeImpl;
23  class StageImpl;
24 
26 
27  // Clients can build and store a (taskId,InstanceId)'s
28  // intermediate information in an object who's type is
29  // derived from InstanceData
30  class InstData {
31  public:
32  virtual ~InstData() {}
33  protected:
34  InstData() {}
35  };
36 
37  // In the callback function, clients can access data from any previous
38  // stage.
39  typedef boost::ptr_vector<InstData> StageData;
40 
41  // Client must provide an allocator for their Data
42  typedef boost::function<InstData*(int stage)> DataFactory;
43 
44  // Clients must provide this callback function on a per-taskID basis
45  struct PipeSpec;
46  typedef boost::function<bool(const Sandesh * sr, const PipeSpec& pspec,
47  int stage, int instNum, InstData* dataInAndOut)> CallbackFunc;
48 
49  // The StageSpec for a Stage of the pipeline contains the taskId to
50  // be used, the InstanceIds to be launched in parallel, the client
51  // callback and an allocator function for allocating InstData
52  // If the allocator function is not provided, NULL will be passed
53  // back in the callback function for that stage
54  struct StageSpec {
55  int taskId_;
56  std::vector<int> instances_;
59  };
60  // The pipespec is used to pass in the stages, and
61  // also has an interface (GetStageData) that the callback can use to
62  // access Data from previous stages
63  struct PipeSpec {
64  PipeSpec(const SandeshRequest * sr);
65  std::vector<StageSpec> stages_;
66  boost::shared_ptr<const SandeshRequest> snhRequest_;
67 
68  const StageData* GetStageData(int stage) const;
69 
70  // This function is not intended for client use
71  PipeSpec(const PipeSpec& ps, PipeImpl * impl) :
72  stages_(ps.stages_), snhRequest_(ps.snhRequest_), impl_(impl) {}
73  private:
75  };
76 
77  // Client Construct a Pipeline by passing the specification
78  RequestPipeline(const PipeSpec& spec);
79 
80 private:
81  class StageWorker;
82 
83  PipeImpl * impl_;
84 };
85 
86 #endif // __REQUEST_PIPELINE_H__
boost::function< bool(const Sandesh *sr, const PipeSpec &pspec, int stage, int instNum, InstData *dataInAndOut)> CallbackFunc
std::vector< int > instances_
boost::ptr_vector< InstData > StageData
PipeSpec(const PipeSpec &ps, PipeImpl *impl)
PipeSpec(const SandeshRequest *sr)
boost::function< InstData *(int stage)> DataFactory
std::vector< StageSpec > stages_
boost::shared_ptr< const SandeshRequest > snhRequest_
const StageData * GetStageData(int stage) const
RequestPipeline(const PipeSpec &spec)