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