|
36 | 36 |
|
37 | 37 | class RuntimeControlledObject; |
38 | 38 |
|
| 39 | +/** |
| 40 | + * Main controller object of the OCC library. |
| 41 | + * |
| 42 | + * OccInstance spawns a gRPC server in a separate thread in order to receive and react to inbound |
| 43 | + * control commands. These commands are then executed on the global state machine of the process, |
| 44 | + * which the user of this library provides by implementing RuntimeControlledObject. |
| 45 | + */ |
39 | 46 | class OCC_EXPORT OccInstance |
40 | 47 | { |
41 | 48 | public: |
| 49 | + /** |
| 50 | + * Creates a new OccInstance, with a control command server thread. |
| 51 | + * |
| 52 | + * @param rco Pointer to the state machine of the process, which must implement |
| 53 | + * RuntimeControlledObject. |
| 54 | + * @param controlPort Optional inbound TCP port on which to receive control messages. If no port |
| 55 | + * is provided, this constructor will try to read OCC_CONTROL_PORT from the environment, and |
| 56 | + * if that too fails, it will fallback to a default control port. |
| 57 | + * |
| 58 | + * @see OccGlobals.h |
| 59 | + * |
| 60 | + * @note This constructor spawns a server thread for gRPC. Incoming message handlers are triggered |
| 61 | + * from there and eventually result in calls to the transition functions in RuntimeControlledObject. |
| 62 | + * The OccInstance destructor takes care of safely tearing down this server. |
| 63 | + */ |
42 | 64 | explicit OccInstance(RuntimeControlledObject *rco, int controlPort = 0); |
| 65 | + |
| 66 | + /** |
| 67 | + * @overload explicit OccInstance(RuntimeControlledObject *rco, int controlPort = 0); |
| 68 | + * |
| 69 | + * @param vm The boost::program_options::variables_map which the application may provide in order |
| 70 | + * to simplify handling of the control port command line option. |
| 71 | + * |
| 72 | + * @see OccInstance::ProgramOptions |
| 73 | + */ |
43 | 74 | explicit OccInstance(RuntimeControlledObject *rco, const boost::program_options::variables_map& vm); |
| 75 | + |
| 76 | + /** |
| 77 | + * Tears down the OccInstance and its control command server. |
| 78 | + */ |
44 | 79 | virtual ~OccInstance(); |
45 | 80 |
|
46 | | - void wait(); //blocking |
| 81 | + /** |
| 82 | + * Blocks until the state machine reaches t_State::done. |
| 83 | + * |
| 84 | + * Generally, the application's main function should instantiate the state machine (which |
| 85 | + * must inherit from RuntimeControlledObject), pass it to the OccInstance constructor, |
| 86 | + * and finally call wait() in order to yield control until the OCC controller is done. |
| 87 | + * |
| 88 | + * Usage example: |
| 89 | + * @code |
| 90 | + * int main(int argc, char* argv[]) { |
| 91 | + * ControlledStateMachine csm; // inherits from RuntimeControlledObject |
| 92 | + * OccInstance occ(&csm); // no control port set, will read it from env var |
| 93 | + * occ.wait(); // block until all control is done |
| 94 | + * printf("all done\n"); |
| 95 | + * } |
| 96 | + * @endcode |
| 97 | + */ |
| 98 | + void wait(); |
47 | 99 |
|
| 100 | + /** |
| 101 | + * Convenience function for acquiring a control port from command line parameters. |
| 102 | + * |
| 103 | + * @return a boost::program_options::options_description which defines a single program option |
| 104 | + * (by default --control-port). This object can be merged with the application's main |
| 105 | + * boost::program_options::options_description, which is then used to parse argv. |
| 106 | + * |
| 107 | + * Usage example: |
| 108 | + * @code |
| 109 | + * boost::program_options::options_description desc("Program options"); |
| 110 | + * desc.add(OccInstance::ProgramOptions()); |
| 111 | + * boost::program_options::variables_map vm; |
| 112 | + * boost::program_options::store(po::parse_command_line(argc, argv, desc), vm); |
| 113 | + * boost::program_options::notify(vm); |
| 114 | + * ControlledStateMachine csm; // inherits from RuntimeControlledObject |
| 115 | + * OccInstance occ(&csm, vm); |
| 116 | + * @endcode |
| 117 | + */ |
48 | 118 | static boost::program_options::options_description ProgramOptions(); |
49 | 119 |
|
50 | 120 | private: |
|
0 commit comments