|
| 1 | +// -- BEGIN LICENSE BLOCK ---------------------------------------------- |
| 2 | +// Copyright © 2024-2025 Ocado Group |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are met: |
| 6 | +// |
| 7 | +// * Redistributions of source code must retain the above copyright |
| 8 | +// notice, this list of conditions and the following disclaimer. |
| 9 | +// |
| 10 | +// * Redistributions in binary form must reproduce the above copyright |
| 11 | +// notice, this list of conditions and the following disclaimer in the |
| 12 | +// documentation and/or other materials provided with the distribution. |
| 13 | +// |
| 14 | +// * Neither the name of the {copyright_holder} nor the names of its |
| 15 | +// contributors may be used to endorse or promote products derived from |
| 16 | +// this software without specific prior written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | +// POSSIBILITY OF SUCH DAMAGE. |
| 29 | +// -- END LICENSE BLOCK ------------------------------------------------ |
| 30 | + |
| 31 | +#ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED |
| 32 | +#define UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED |
| 33 | + |
| 34 | +#include <memory> |
| 35 | +#include <deque> |
| 36 | + |
| 37 | +#include <ur_client_library/comm/stream.h> |
| 38 | +#include <ur_client_library/comm/pipeline.h> |
| 39 | +#include <ur_client_library/comm/producer.h> |
| 40 | +#include <ur_client_library/primary/abstract_primary_consumer.h> |
| 41 | +#include <ur_client_library/primary/primary_consumer.h> |
| 42 | +#include <ur_client_library/primary/primary_package.h> |
| 43 | +#include <ur_client_library/primary/primary_parser.h> |
| 44 | + |
| 45 | +namespace urcl |
| 46 | +{ |
| 47 | +namespace primary_interface |
| 48 | +{ |
| 49 | +class PrimaryClient |
| 50 | +{ |
| 51 | +public: |
| 52 | + PrimaryClient() = delete; |
| 53 | + PrimaryClient(const std::string& robot_ip, comm::INotifier& notifier); |
| 54 | + ~PrimaryClient(); |
| 55 | + |
| 56 | + /*! |
| 57 | + * \brief Adds a primary consumer to the list of consumers |
| 58 | + * |
| 59 | + * \param primary_consumer Primary consumer that should be added to the list |
| 60 | + */ |
| 61 | + void addPrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer); |
| 62 | + |
| 63 | + /*! |
| 64 | + * \brief Remove a primary consumer from the list of consumers |
| 65 | + * |
| 66 | + * \param primary_consumer Primary consumer that should be removed from the list |
| 67 | + */ |
| 68 | + void removePrimaryConsumer(std::shared_ptr<comm::IConsumer<PrimaryPackage>> primary_consumer); |
| 69 | + void start(); |
| 70 | + |
| 71 | + /*! |
| 72 | + * \brief Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will be |
| 73 | + * deleted. |
| 74 | + */ |
| 75 | + std::deque<ErrorCode> getErrorCodes(); |
| 76 | + |
| 77 | +private: |
| 78 | + // The function is called whenever an error code message is received |
| 79 | + void errorMessageCallback(ErrorCode& code); |
| 80 | + |
| 81 | + PrimaryParser parser_; |
| 82 | + std::shared_ptr<PrimaryConsumer> consumer_; |
| 83 | + std::unique_ptr<comm::MultiConsumer<PrimaryPackage>> multi_consumer_; |
| 84 | + |
| 85 | + comm::INotifier notifier_; |
| 86 | + |
| 87 | + comm::URStream<PrimaryPackage> stream_; |
| 88 | + std::unique_ptr<comm::URProducer<PrimaryPackage>> prod_; |
| 89 | + std::unique_ptr<comm::Pipeline<PrimaryPackage>> pipeline_; |
| 90 | + |
| 91 | + std::mutex error_code_queue_mutex_; |
| 92 | + std::deque<ErrorCode> error_code_queue_; |
| 93 | +}; |
| 94 | + |
| 95 | +} // namespace primary_interface |
| 96 | +} // namespace urcl |
| 97 | + |
| 98 | +#endif // ifndef UR_CLIENT_LIBRARY_PRIMARY_CLIENT_H_INCLUDED |
0 commit comments