WorkerOptions.hpp
Go to the documentation of this file.
1 /**********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2016, Philipp Leemann
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Robotic Systems Lab nor ETH Zurich
18  * nor the names of its contributors may be used to endorse or
19  * promote products derived from this software without specific
20  * prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
42 #pragma once
43 
44 #include <atomic>
45 #include <string>
46 
49 
50 namespace bota_worker
51 {
52 using WorkerCallback = std::function<bool(const WorkerEvent&)>;
53 using WorkerCallbackFailureReaction = std::function<void(void)>;
54 
55 struct WorkerOptions : public RateOptions
56 {
59  {
60  }
61 
62  WorkerOptions(const std::string& name, const double timestep, WorkerCallback callback, const int priority = 0)
63  : RateOptions(name, timestep)
64  , callback_(std::move(callback))
65  , callbackFailureReaction_([]() {})
66  , defaultPriority_(priority)
67  , destructWhenDone_(false)
68  {
69  }
70 
71  WorkerOptions(const std::string& name, const double timestep, WorkerCallback callback,
72  WorkerCallbackFailureReaction callbackFailureReaction, const int priority = 0)
73  : RateOptions(name, timestep)
74  , callback_(std::move(callback))
75  , callbackFailureReaction_(std::move(callbackFailureReaction))
76  , defaultPriority_(priority)
77  , destructWhenDone_(false)
78  {
79  }
80 
81  WorkerOptions(const WorkerOptions& other) = default;
82 
83  WorkerOptions(WorkerOptions&& other) noexcept
84  : RateOptions(std::move(other))
85  , callback_(std::move(other.callback_))
89  {
90  }
91 
96 
101 
106 
111 };
112 
113 } // namespace bota_worker
WorkerOptions(const std::string &name, const double timestep, WorkerCallback callback, WorkerCallbackFailureReaction callbackFailureReaction, const int priority=0)
WorkerCallbackFailureReaction callbackFailureReaction_
std::function< void(void)> WorkerCallbackFailureReaction
std::function< bool(const WorkerEvent &)> WorkerCallback
WorkerOptions(WorkerOptions &&other) noexcept
WorkerOptions(const std::string &name, const double timestep, WorkerCallback callback, const int priority=0)


bota_worker
Author(s):
autogenerated on Wed Mar 3 2021 03:09:10